History

avcodec/mjpegenc: Include all supported pix_fmts in mpegenc pix_fmts

Currently said list contains only the pixel formats that are always supported irrespective of the range and the value of strict_std_compliance. This makes the MJPEG encoder an outlier as all other codecs put all potentially supported pixel formats into said list and error out if the chosen pixel format is unsupported. This commit brings it therefore in line with the other encoders. The behaviour of fftools/ffmpeg_filter.c has been preserved. A more informed decision would be possible if colour range were available at this point, but it isn't.

Andreas Rheinhardt committed 5 years ago

Commit 059fc2d1 parent 48cda7d7 files · +40 −55Browse files

Showing the changes to libavcodec (6 of 7 files). Show all

Unified · Split

6 files
  1. libavcodec/encode.c +1 −3
  2. libavcodec/ljpegenc.c +3 −11
  3. libavcodec/mjpegenc.c +10 −1
  4. libavcodec/mjpegenc_common.c +16 −0
  5. libavcodec/mjpegenc_common.h +2 −0
  6. libavcodec/mpegvideo_enc.c +1 −27
libavcodec/encode.c+1−3
@@ -564,9 +564,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 563 unmodified lines
564564 for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
565565 if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
566566 break;
567− if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
568− && !(avctx->codec_id == AV_CODEC_ID_MJPEG
569− && avctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL)) {
567+ if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
570568 char buf[128];
571569 snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
572570 av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
libavcodec/ljpegenc.c+3−11
@@ -289,19 +289,11 @@ static av_cold int ljpeg_encode_close(AVCodecContext *avctx) · 288 unmodified lines
289289
290290 static av_cold int ljpeg_encode_init(AVCodecContext *avctx)
291291 {
292+ int ret = ff_mjpeg_encode_check_pix_fmt(avctx);
292293 LJpegEncContext *s = avctx->priv_data;
293294
294− if ((avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
295− avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
296− avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
297− avctx->color_range == AVCOL_RANGE_MPEG) &&
298− avctx->color_range != AVCOL_RANGE_JPEG &&
299− avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
300− av_log(avctx, AV_LOG_ERROR,
301− "Non full-range YUV is non-standard, set strict_std_compliance "
302− "to at most unofficial to use it.\n");
303− return AVERROR(EINVAL);
304− }
295+ if (ret < 0)
296+ return ret;
305297
306298 #if FF_API_CODED_FRAME
307299 FF_DISABLE_DEPRECATION_WARNINGS
libavcodec/mjpegenc.c+10−1
@@ -261,9 +261,16 @@ static int alloc_huffman(MpegEncContext *s) · 260 unmodified lines
261261 av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
262262 {
263263 MJpegContext *m;
264+ int ret;
264265
265266 av_assert0(s->slice_context_count == 1);
266267
268+ /* The following check is automatically true for AMV,
269+ * but it doesn't hurt either. */
270+ ret = ff_mjpeg_encode_check_pix_fmt(s->avctx);
271+ if (ret < 0)
272+ return ret;
273+
267274 if (s->width > 65500 || s->height > 65500) {
268275 av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
269276 return AVERROR(EINVAL);
@@ -609,7 +616,9 @@ AVCodec ff_mjpeg_encoder = { · 339 unmodified lines
609616 .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
610617 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
611618 .pix_fmts = (const enum AVPixelFormat[]) {
612− AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE
619+ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
620+ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
621+ AV_PIX_FMT_NONE
613622 },
614623 .priv_class = &mjpeg_class,
615624 .profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles),
libavcodec/mjpegenc_common.c+16−0
@@ -436,3 +436,19 @@ void ff_mjpeg_encode_dc(PutBitContext *pb, int val, · 435 unmodified lines
436436 put_sbits(pb, nbits, mant);
437437 }
438438 }
439+
440+int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx)
441+{
442+ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL &&
443+ avctx->color_range != AVCOL_RANGE_JPEG &&
444+ (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
445+ avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
446+ avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
447+ avctx->color_range == AVCOL_RANGE_MPEG)) {
448+ av_log(avctx, AV_LOG_ERROR,
449+ "Non full-range YUV is non-standard, set strict_std_compliance "
450+ "to at most unofficial to use it.\n");
451+ return AVERROR(EINVAL);
452+ }
453+ return 0;
454+}
libavcodec/mjpegenc_common.h+2−0
@@ -41,4 +41,6 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4 · 40 unmodified lines
4141 void ff_mjpeg_encode_dc(PutBitContext *pb, int val,
4242 uint8_t *huff_size, uint16_t *huff_code);
4343
44+int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx);
45+
4446 #endif /* AVCODEC_MJPEGENC_COMMON_H */
libavcodec/mpegvideo_enc.c+1−27
@@ -297,36 +297,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 296 unmodified lines
297297 {
298298 MpegEncContext *s = avctx->priv_data;
299299 AVCPBProperties *cpb_props;
300− int i, ret, format_supported;
300+ int i, ret;
301301
302302 mpv_encode_defaults(s);
303303
304− switch (avctx->codec_id) {
305− case AV_CODEC_ID_MJPEG:
306− format_supported = 0;
307− /* JPEG color space */
308− if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
309− avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
310− avctx->pix_fmt == AV_PIX_FMT_YUVJ444P ||
311− (avctx->color_range == AVCOL_RANGE_JPEG &&
312− (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
313− avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
314− avctx->pix_fmt == AV_PIX_FMT_YUV444P)))
315− format_supported = 1;
316− /* MPEG color space */
317− else if (avctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL &&
318− (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
319− avctx->pix_fmt == AV_PIX_FMT_YUV422P ||
320− avctx->pix_fmt == AV_PIX_FMT_YUV444P))
321− format_supported = 1;
322−
323− if (!format_supported) {
324− av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
325− return AVERROR(EINVAL);
326− }
327− break;
328− }
329−
330304 switch (avctx->pix_fmt) {
331305 case AV_PIX_FMT_YUVJ444P:
332306 case AV_PIX_FMT_YUV444P:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t