ENCODER: could not open video codec (mjpeg)
A simple v4l2 full-featured video grabber
Brought to you by:
assisp
Fresh git clone-d master branch of guvcview built on arch based system will have that warning message when choosing "MJPG - compressed" as video codec for recording, which will lead to crash when cap. video button is pressed with the following message and backtrace (xxx is used instead of actual argument):
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffde331700 (LWP 31475)] 0x00007ffff62b4704 in encoder_muxer_init (encoder_ctx=0x7fffc80008c0, filename=0x7fffc800a310 "xxx") at muxer.c:225 225 else if(encoder_ctx->enc_video_ctx->codec_context) (gdb) bt #0 0x00007ffff62b4704 in encoder_muxer_init (encoder_ctx=0x7fffc80008c0, filename=0x7fffc800a310 "xxx) at muxer.c:225 #1 0x0000000000407a24 in encoder_loop (data=0x6a8fe0) at video_capture.c:820 #2 0x00007ffff670d124 in start_thread () from /usr/lib/libpthread.so.0 #3 0x00007ffff22c64bd in clone () from /usr/lib/libc.so.6
easily guessed, indeed encoder_ctx->enc_video_ctx is NULL because message in the title happens in the place where enc_video_ctx should be initialized:
#if LIBAVCODEC_VER_AT_LEAST(53,6) if (avcodec_open2( enc_video_ctx->codec_context, enc_video_ctx->codec, &enc_video_ctx->private_options) < 0) #else if (avcodec_open( enc_video_ctx->codec_context, enc_video_ctx->codec) < 0) #endif { fprintf(stderr, "ENCODER: could not open video codec (%s)\n", video_defaults->codec_name); free(enc_video_ctx->codec_context); free(enc_video_ctx); return(NULL); }
The problem could be because arch based system doesn't have libavcodec in the repository but seems to use ffmpeg which provides the same API.
Hi,
Thank you for reporting this.
For some reason your ffmpeg version fails to load the MJPEG codec, this isn't a major problem per si, but guvcview shouldn't crash because of it.
I've now made some changes that should allow guvcview to save the raw stream if a codec fails to load.
If you set your camera to output MJPEG, then mjpeg data will be save to file (no encoding is performed, but also video effects, if any, will not be saved).
These changes still require testing, so they are still unstable.
As a side note, do other codecs work OK?
I've received another arch user report on issues with portaudio and also with the H264 decoder (for H264 enabled cameras).
Last edit: Paulo Assis 2014-07-15
Yes, other codecs work fine. It's just the audio gets out of sync. On other OS (Zorin, which is an Ubuntu derivative) the MJPEG codec works best and video/audio syncs well, so MJPEG is my only solution. Only the repo contains a rather old version of guvcview (1.6.0)
I pull your latest changes, it still crashes:
OK, some default mjpg codec values were incorrect, this should be fixed now.
As for audio/video out of sync, does this happens rigth away (after a couple of seconds) or only after some time (> 30 min) ? Did you try it with a different audio source ?
I've tested it quit a bit and didn't notice any sync issues, at least with pulse, portaudio still needs some work.
Regards,
Paulo
Tested, nice. Even the pictures are brighter now!
I found two new bugs though:
1: changing the audio combobox to an unsupported value (say PulseAudio when I don't have it installed) freezes the GUI. no error message, no crash, just freeze.
2: a crash happens when you try to use experimental audio codec (aac in this case). right after stop recording, it crashes with:
Right away. I only have portaudio and I use jack as my sound server, which should work fine (well, other portaudio based apps can run well) because I've reroute every alsa request to jack.
Ok,
If you don't have pulseaudio running then you should disable it when building guvcview.
The freeze happens because guvcview is waiting for a server that is not running, I guess it should be a way of telling right away if pulse is available or not (need to investigate this).
AAC works fine with libav, in any case I think I understand where the error comes from, enc_audio_ctx is null if the codec failed to open.
I see you are using the avi muxer, does the sync issues also happen if you use matroska (mkv)? (change in video->File)
Avi unlike matroska has no support for timestamps, so it's really hard to keep audio and video in sync.
Regards,
Paulo
I thought as many other apps, configure script will check for it.
Yup, easily deduced from the backtrace.
On MJPG + PCM, mkv does keep both in sync, while avi makes the video ends in turbo. But for other pairs, avi seems fine. So I guess it's just a matter of choosing the correct pair.
Configure checks for pulse headers (if they are present it builds with pulse support), but you can have these installed and not be running the server (I guess this your case), anyway you can always disable pulse explicitly with configure.
Can you check the avi fps value in the file header for mjpg + pcm ?
Regards,
Paulo
Here's an output from tcprobe:
I don't know if there's anything wrong with that, but I have a little info. smplayer, which is my main player, displays the video too fast. But, ffplay displays it normally. However, ffplay gives this in the output:
The first line looks interesting...
Ok,
I'm closing the mjpeg codec ticket since this was fixed in 2.0.0.
If you still have problems with the audio codecs in the latest version (2.0.1), please open a new ticket for that specific issue.
Thank you