Menu

#8 ENCODER: could not open video codec (mjpeg)

next
closed
None
2014-10-10
2014-07-14
No

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.

Discussion

  • Paulo Assis

    Paulo Assis - 2014-07-15

    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
  • Mario Ray M.

    Mario Ray M. - 2014-07-15

    As a side note, do other codecs work OK?

    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)

     
  • Mario Ray M.

    Mario Ray M. - 2014-07-15

    I pull your latest changes, it still crashes:

    $ gdb guvcview
    GNU gdb (GDB) 7.7.1
    Copyright (C) 2014 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-unknown-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    ---Type <return> to continue, or q <return> to quit---
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from guvcview...done.
    (gdb) run
    Starting program: /usr/bin/guvcview 
    warning: Could not load shared library symbols for linux-vdso.so.1.
    Do you need "set solib-search-path" or "set sysroot"?
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/usr/lib/libthread_db.so.1".
    GUVCVIEW: couldn't read line 46 of config file: File exists
    [New Thread 0x7fffe3f47700 (LWP 17498)]
    ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
    ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
    ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
    ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
    ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
    [New Thread 0x7fffdf332700 (LWP 17499)]
    ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
    
    [Thread 0x7fffdf332700 (LWP 17499) exited]
    [New Thread 0x7fffdf332700 (LWP 17501)]
    ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
    
    [Thread 0x7fffdf332700 (LWP 17501) exited]
    [New Thread 0x7ffff7f54700 (LWP 17503)]
    [New Thread 0x7ffff7ed3700 (LWP 17504)]
    [Thread 0x7ffff7ed3700 (LWP 17504) exited]
    [Thread 0x7ffff7f54700 (LWP 17503) exited]
    [New Thread 0x7ffff7f54700 (LWP 17505)]
    [New Thread 0x7ffff7ed3700 (LWP 17506)]
    [Thread 0x7ffff7ed3700 (LWP 17506) exited]
    [Thread 0x7ffff7f54700 (LWP 17505) exited]
    ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
    [New Thread 0x7ffff7f54700 (LWP 17507)]
    [New Thread 0x7ffff7ed3700 (LWP 17508)]
    [Thread 0x7ffff7ed3700 (LWP 17508) exited]
    [Thread 0x7ffff7f54700 (LWP 17507) exited]
    [New Thread 0x7ffff7f54700 (LWP 17509)]
    [New Thread 0x7ffff7ed3700 (LWP 17510)]
    [Thread 0x7ffff7ed3700 (LWP 17510) exited]
    [Thread 0x7ffff7f54700 (LWP 17509) exited]
    [New Thread 0x7ffff7f54700 (LWP 17511)]
    [New Thread 0x7ffff7ed3700 (LWP 17512)]
    [New Thread 0x7fffe312f700 (LWP 17513)]
    [New Thread 0x7fffdf332700 (LWP 17514)]
    [New Thread 0x7fffe2e56700 (LWP 17515)]
    [New Thread 0x7fffe14b9700 (LWP 17518)]
    GUVCVIEW: video codec changed to 1
    [New Thread 0x7fffde331700 (LWP 17520)]
    [mjpeg @ 0x7fffc8000b80] qmin and or qmax are invalid, they must be 0 < min <= max
    ENCODER: could not open video codec (mjpeg) - using raw input
    GUVCVIEW: (status) saving video to /home/xxx/my_video.mkv
    ENCODER: add stream 0 to stream list
    
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0x7fffde331700 (LWP 17520)]
    0x00007ffff62aed51 in encoder_set_video_mkvCodecPriv (encoder_ctx=0x7fffc80008c0) at video_codecs.c:699
    699             int codec_id = encoder_ctx->enc_video_ctx->codec_context->codec_id;
    (gdb) bt
    #0  0x00007ffff62aed51 in encoder_set_video_mkvCodecPriv (encoder_ctx=0x7fffc80008c0) at video_codecs.c:699
    #1  0x00007ffff62b497f in encoder_muxer_init (encoder_ctx=0x7fffc80008c0, filename=0x7fffc8005c50 "/home/xxx/my_video.mkv") at muxer.c:308
    #2  0x0000000000407a19 in encoder_loop (data=0x672980) at video_capture.c:820
    #3  0x00007ffff670d124 in start_thread () from /usr/lib/libpthread.so.0
    #4  0x00007ffff22c64bd in clone () from /usr/lib/libc.so.6
    
     
  • Paulo Assis

    Paulo Assis - 2014-07-16

    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

     
  • Mario Ray M.

    Mario Ray M. - 2014-07-16

    OK, some default mjpg codec values were incorrect, this should be fixed now.

    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:

    [aac @ 0x7fffc81e4820] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
    ENCODER: could not open audio codec
    GUVCVIEW: (status) saving video to /home/leledumbo/my_video-2.avi
    ENCODER: add stream 0 to stream list
    ENCODER: (avi) bad time base (0/0): set it later
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0x7fffdd959700 (LWP 21138)]
    0x00007ffff62ae907 in encoder_close (encoder_ctx=encoder_ctx@entry=0x7fffc80008c0) at encoder.c:1587
    1587            if(encoder_ctx->enc_audio_ctx->priv_data)
    (gdb) bt
    #0  0x00007ffff62ae907 in encoder_close (encoder_ctx=encoder_ctx@entry=0x7fffc80008c0) at encoder.c:1587
    #1  0x0000000000407ae2 in encoder_loop (data=0x672980) at video_capture.c:871
    #2  0x00007ffff670d124 in start_thread () from /usr/lib/libpthread.so.0
    #3  0x00007ffff22c64bd in clone () from /usr/lib/libc.so.6
    

    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 ?

    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.

     
    • Paulo Assis

      Paulo Assis - 2014-07-17

      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

       
  • Mario Ray M.

    Mario Ray M. - 2014-07-17

    If you don't have pulseaudio running then you should disable it when building guvcview.

    I thought as many other apps, configure script will check for it.

    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.

    Yup, easily deduced from the backtrace.

    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.

    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.

     
    • Paulo Assis

      Paulo Assis - 2014-07-18

      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

       
  • Mario Ray M.

    Mario Ray M. - 2014-07-18

    Can you check the avi fps value in the file header for mjpg + pcm ?

    Here's an output from tcprobe:

    [tcprobe] RIFF data, AVI video
    [tcprobe] summary for my_video-1.avi, (*) = not default, 0 = not detected
    import frame size: -g 1280x720 [720x576] (*)
         aspect ratio: 16:9 (*)
           frame rate: -f 12.000 [25.000] frc=12 (*)
          audio track: -a 0 [0] -e 48000,32,1 [48000,16,2] -n 0x3 [0x2000] (*)
               length: 71 frames, frame_time=83 msec, duration=0:00:05.916
    

    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:

    [avi @ 0x7f8358000ae0] scale/rate is 1/0 which is invalid. (This file has been generated by broken software.)
    [avi @ 0x7f8358000ae0] non-interleaved AVI
    Input #0, avi, from 'my_video-1.avi':B vq=    0KB sq=    0B f=0/0   
      Duration: 00:00:05.92, start: 0.000000, bitrate: 6006 kb/s
        Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 1280x720, SAR 1:1 DAR 16:9, 12 tbr, 12 tbn, 12 tbc
        Stream #0:1: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, 1 channels, flt, 1536 kb/s
    

    The first line looks interesting...

     
  • Paulo Assis

    Paulo Assis - 2014-10-10

    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

     
  • Paulo Assis

    Paulo Assis - 2014-10-10
    • status: open --> closed
    • assigned_to: Paulo Assis
     

Log in to post a comment.