GNOME Bugzilla – Bug 750398
avenc_mjpeg fails to negotiate the source format
Last modified: 2015-06-12 23:44:56 UTC
To reproduce this, simply run the following command: $ GST_DEBUG=1 gst-launch-1.0 videotestsrc num-buffers=40 ! videoconvert ! avenc_mjpeg ! fakesink Setting pipeline to PAUSED ... Pipeline is PREROLLING ... 0:00:00.013323325 30166 0x18b1230 ERROR libav :0:: Specified pix_fmt is not supported ERROR: from element /GstPipeline:pipeline0/avenc_mjpeg:avenc_mjpeg0: GStreamer error: negotiation problem. Additional debug info: gstvideoencoder.c(1463): gst_video_encoder_chain (): /GstPipeline:pipeline0/avenc_mjpeg:avenc_mjpeg0: encoder not initialized ERROR: pipeline doesn't want to preroll. Setting pipeline to NULL ... Freeing pipeline ... This worked fine in 1.0.6 but is broken in 1.2.4 and 1.4.5. It seems to be related to the 'format: { I420, Y42B }' restriction on the sink pad.
Note that the recommended encoder for JPEG is jpegenc, which works in this scenario. This bug remains valid, thanks for reporting.
Looks like we need to use AV_PIX_FMT_YUVJ420P instead of AV_PIX_FMT_YUV420P when encoding JPEG.
The mjpeg encoder is the only encoder not yet ported to the new .color_range property. That means we need an exception specifically for that. (We should probably add .color_range too).
Created attachment 304620 [details] [review] avcodec: Check against codec format list There exist few formats (deprecated though) used by mjpeg decoder and encoder that maps to the same GStreamer format. To properly pick the right format, also lookup each Codec list before accepting the format. This fixes error when trying to use mjpeg encoder. Note that this may results in faded colors. In fact, these special format are meant to specify that this is full range YUV. Colorimetry in gst-libav is not yet implemented, hence is ignored in general. So I think it's fine to first fix the issue before addressing the missing feature.
This patch works for me. The colors are indeed a bit faded, which was already the case with the GStreamer 0.10 ffenc_mjpeg version. That's particularly visible when Spice switches from the native rendering to the GStreamer-based video streaming. But otherwise I'm not sure one would really notice it. So while it would be nice to improve this aspect, it's not a blocker. Regarding jpegenc, the issue is that it does not have a 'bitrate' property and as such is not a direct replacement for avenc_mjpeg. That's why I use avenc_mjpeg in the Spice GStreamer backend: it can easily be substituted with other encoders like VP8 or x264 with uniform code for adjusting each to the network conditions.
I'll file a bug for the color issues. Thanks for testing and confirming my thoughts.
Attachment 304620 [details] pushed as a33a1bf - avcodec: Check against codec format list
Create this bug: https://bugzilla.gnome.org/show_bug.cgi?id=750882