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.
Showing the changes to libavcodec (6 of 7 files). Show all
Unified · Split
| @@ -564,9 +564,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 563 unmodified lines | |||
| 564 | for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) | 564 | for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) |
| 565 | if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) | 565 | if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) |
| 566 | break; | 566 | break; |
| 567 | if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE | 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)) { | ||
| 570 | char buf[128]; | 568 | char buf[128]; |
| 571 | snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt); | 569 | snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt); |
| 572 | av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n", | 570 | av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n", |
| @@ -289,19 +289,11 @@ static av_cold int ljpeg_encode_close(AVCodecContext *avctx) · 288 unmodified lines | |||
| 289 | 289 | ||
| 290 | static av_cold int ljpeg_encode_init(AVCodecContext *avctx) | 290 | static av_cold int ljpeg_encode_init(AVCodecContext *avctx) |
| 291 | { | 291 | { |
| 292 | int ret = ff_mjpeg_encode_check_pix_fmt(avctx); | ||
| 292 | LJpegEncContext *s = avctx->priv_data; | 293 | LJpegEncContext *s = avctx->priv_data; |
| 293 | 294 | ||
| 294 | if ((avctx->pix_fmt == AV_PIX_FMT_YUV420P || | 295 | if (ret < 0) |
| 295 | avctx->pix_fmt == AV_PIX_FMT_YUV422P || | 296 | return ret; |
| 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 | } | ||
| 305 | 297 | ||
| 306 | #if FF_API_CODED_FRAME | 298 | #if FF_API_CODED_FRAME |
| 307 | FF_DISABLE_DEPRECATION_WARNINGS | 299 | FF_DISABLE_DEPRECATION_WARNINGS |
| @@ -261,9 +261,16 @@ static int alloc_huffman(MpegEncContext *s) · 260 unmodified lines | |||
| 261 | av_cold int ff_mjpeg_encode_init(MpegEncContext *s) | 261 | av_cold int ff_mjpeg_encode_init(MpegEncContext *s) |
| 262 | { | 262 | { |
| 263 | MJpegContext *m; | 263 | MJpegContext *m; |
| 264 | int ret; | ||
| 264 | 265 | ||
| 265 | av_assert0(s->slice_context_count == 1); | 266 | av_assert0(s->slice_context_count == 1); |
| 266 | 267 | ||
| 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 | |||
| 267 | if (s->width > 65500 || s->height > 65500) { | 274 | if (s->width > 65500 || s->height > 65500) { |
| 268 | av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n"); | 275 | av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n"); |
| 269 | return AVERROR(EINVAL); | 276 | return AVERROR(EINVAL); |
| @@ -609,7 +616,9 @@ AVCodec ff_mjpeg_encoder = { · 339 unmodified lines | |||
| 609 | .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, | 616 | .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, |
| 610 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | 617 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, |
| 611 | .pix_fmts = (const enum AVPixelFormat[]) { | 618 | .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 | ||
| 613 | }, | 622 | }, |
| 614 | .priv_class = &mjpeg_class, | 623 | .priv_class = &mjpeg_class, |
| 615 | .profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles), | 624 | .profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles), |
| @@ -436,3 +436,19 @@ void ff_mjpeg_encode_dc(PutBitContext *pb, int val, · 435 unmodified lines | |||
| 436 | put_sbits(pb, nbits, mant); | 436 | put_sbits(pb, nbits, mant); |
| 437 | } | 437 | } |
| 438 | } | 438 | } |
| 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 | } | ||
| @@ -41,4 +41,6 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4 · 40 unmodified lines | |||
| 41 | void ff_mjpeg_encode_dc(PutBitContext *pb, int val, | 41 | void ff_mjpeg_encode_dc(PutBitContext *pb, int val, |
| 42 | uint8_t *huff_size, uint16_t *huff_code); | 42 | uint8_t *huff_size, uint16_t *huff_code); |
| 43 | 43 | ||
| 44 | int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx); | ||
| 45 | |||
| 44 | #endif /* AVCODEC_MJPEGENC_COMMON_H */ | 46 | #endif /* AVCODEC_MJPEGENC_COMMON_H */ |
| @@ -297,36 +297,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 296 unmodified lines | |||
| 297 | { | 297 | { |
| 298 | MpegEncContext *s = avctx->priv_data; | 298 | MpegEncContext *s = avctx->priv_data; |
| 299 | AVCPBProperties *cpb_props; | 299 | AVCPBProperties *cpb_props; |
| 300 | int i, ret, format_supported; | 300 | int i, ret; |
| 301 | 301 | ||
| 302 | mpv_encode_defaults(s); | 302 | mpv_encode_defaults(s); |
| 303 | 303 | ||
| 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 | |||
| 330 | switch (avctx->pix_fmt) { | 304 | switch (avctx->pix_fmt) { |
| 331 | case AV_PIX_FMT_YUVJ444P: | 305 | case AV_PIX_FMT_YUVJ444P: |
| 332 | case AV_PIX_FMT_YUV444P: | 306 | case AV_PIX_FMT_YUV444P: |