The former is typically a bug in the calling program, while the latter will more often be a user configuration issue.
Unified · Split
| @@ -24,6 +24,7 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "libavutil/frame.h" |
| 25 | 25 | #include "libavutil/imgutils.h" |
| 26 | 26 | #include "libavutil/internal.h" |
| 27 | +#include "libavutil/pixdesc.h" | |
| 27 | 28 | #include "libavutil/samplefmt.h" |
| 28 | 29 | |
| 29 | 30 | #include "avcodec.h" |
| @@ -576,15 +577,19 @@ static int encode_preinit_video(AVCodecContext *avctx) · 546 unmodified lines | ||
| 576 | 577 | const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); |
| 577 | 578 | int i; |
| 578 | 579 | |
| 580 | + if (!av_get_pix_fmt_name(avctx->pix_fmt)) { | |
| 581 | + av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n", | |
| 582 | + avctx->pix_fmt); | |
| 583 | + return AVERROR(EINVAL); | |
| 584 | + } | |
| 585 | + | |
| 579 | 586 | if (avctx->codec->pix_fmts) { |
| 580 | 587 | for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) |
| 581 | 588 | if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) |
| 582 | 589 | break; |
| 583 | 590 | if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) { |
| 584 | − char buf[128]; | |
| 585 | − snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt); | |
| 586 | − av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n", | |
| 587 | − (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf)); | |
| 591 | + av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is not supported\n", | |
| 592 | + av_get_pix_fmt_name(avctx->pix_fmt)); | |
| 588 | 593 | return AVERROR(EINVAL); |
| 589 | 594 | } |
| 590 | 595 | if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || |
| @@ -646,6 +651,12 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 55 unmodified lines | ||
| 646 | 651 | { |
| 647 | 652 | int i; |
| 648 | 653 | |
| 654 | + if (!av_get_sample_fmt_name(avctx->sample_fmt)) { | |
| 655 | + av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n", | |
| 656 | + avctx->sample_fmt); | |
| 657 | + return AVERROR(EINVAL); | |
| 658 | + } | |
| 659 | + | |
| 649 | 660 | if (avctx->codec->sample_fmts) { |
| 650 | 661 | for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { |
| 651 | 662 | if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) |
| @@ -658,10 +669,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 6 unmodified lines | ||
| 658 | 669 | } |
| 659 | 670 | } |
| 660 | 671 | if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { |
| 661 | − char buf[128]; | |
| 662 | − snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt); | |
| 663 | − av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n", | |
| 664 | − (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf)); | |
| 672 | + av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is not supported\n", | |
| 673 | + av_get_sample_fmt_name(avctx->sample_fmt)); | |
| 665 | 674 | return AVERROR(EINVAL); |
| 666 | 675 | } |
| 667 | 676 | } |