History

lavc/encode: print separate messages for unknown and unsupported formats

The former is typically a bug in the calling program, while the latter will more often be a user configuration issue.

Anton Khirnov committed 3 years ago

Commit 160fefa1 parent 2bbb6cf1 file · +17 −8Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/encode.c+17−8
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include "libavutil/frame.h"
2525 #include "libavutil/imgutils.h"
2626 #include "libavutil/internal.h"
27+#include "libavutil/pixdesc.h"
2728 #include "libavutil/samplefmt.h"
2829
2930 #include "avcodec.h"
@@ -576,15 +577,19 @@ static int encode_preinit_video(AVCodecContext *avctx) · 546 unmodified lines
576577 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
577578 int i;
578579
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+
579586 if (avctx->codec->pix_fmts) {
580587 for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
581588 if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
582589 break;
583590 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));
588593 return AVERROR(EINVAL);
589594 }
590595 if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
@@ -646,6 +651,12 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 55 unmodified lines
646651 {
647652 int i;
648653
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+
649660 if (avctx->codec->sample_fmts) {
650661 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
651662 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
@@ -658,10 +669,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 6 unmodified lines
658669 }
659670 }
660671 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));
665674 return AVERROR(EINVAL);
666675 }
667676 }

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