* [FFmpeg-devel] [PATCH 02/22] lavc/encode: shorten code by using a local variable
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 03/22] lavc/encoder: always print an error on an unsupported channel layout Anton Khirnov
` (19 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/encode.c | 48 +++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 2da9f6ba23..0d44f70ee9 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -550,6 +550,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *
static int encode_preinit_video(AVCodecContext *avctx)
{
+ const AVCodec *c = avctx->codec;
const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
int i;
@@ -559,20 +560,20 @@ static int encode_preinit_video(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (avctx->codec->pix_fmts) {
- for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
- if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
+ if (c->pix_fmts) {
+ for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
+ if (avctx->pix_fmt == c->pix_fmts[i])
break;
- if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
+ if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is not supported\n",
av_get_pix_fmt_name(avctx->pix_fmt));
return AVERROR(EINVAL);
}
- if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
- avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
- avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
- avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
- avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
+ if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
+ c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
+ c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
+ c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
+ c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
avctx->color_range = AVCOL_RANGE_JPEG;
}
@@ -625,6 +626,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int encode_preinit_audio(AVCodecContext *avctx)
{
+ const AVCodec *c = avctx->codec;
int i;
if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
@@ -633,28 +635,28 @@ static int encode_preinit_audio(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (avctx->codec->sample_fmts) {
- for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
- if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
+ if (c->sample_fmts) {
+ for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
+ if (avctx->sample_fmt == c->sample_fmts[i])
break;
if (avctx->ch_layout.nb_channels == 1 &&
av_get_planar_sample_fmt(avctx->sample_fmt) ==
- av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) {
- avctx->sample_fmt = avctx->codec->sample_fmts[i];
+ av_get_planar_sample_fmt(c->sample_fmts[i])) {
+ avctx->sample_fmt = c->sample_fmts[i];
break;
}
}
- if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
+ if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is not supported\n",
av_get_sample_fmt_name(avctx->sample_fmt));
return AVERROR(EINVAL);
}
}
- if (avctx->codec->supported_samplerates) {
- for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
- if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
+ if (c->supported_samplerates) {
+ for (i = 0; c->supported_samplerates[i] != 0; i++)
+ if (avctx->sample_rate == c->supported_samplerates[i])
break;
- if (avctx->codec->supported_samplerates[i] == 0) {
+ if (c->supported_samplerates[i] == 0) {
av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
avctx->sample_rate);
return AVERROR(EINVAL);
@@ -665,12 +667,12 @@ static int encode_preinit_audio(AVCodecContext *avctx)
avctx->sample_rate);
return AVERROR(EINVAL);
}
- if (avctx->codec->ch_layouts) {
- for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) {
- if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i]))
+ if (c->ch_layouts) {
+ for (i = 0; c->ch_layouts[i].nb_channels; i++) {
+ if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))
break;
}
- if (!avctx->codec->ch_layouts[i].nb_channels) {
+ if (!c->ch_layouts[i].nb_channels) {
char buf[512];
int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
if (ret > 0)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 03/22] lavc/encoder: always print an error on an unsupported channel layout
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 02/22] lavc/encode: shorten code by using a local variable Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 04/22] lavc/encode: improve input sample rate validation Anton Khirnov
` (18 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Even if the layout is indescribable.
---
libavcodec/encode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 0d44f70ee9..ba91dcc31e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -675,8 +675,8 @@ static int encode_preinit_audio(AVCodecContext *avctx)
if (!c->ch_layouts[i].nb_channels) {
char buf[512];
int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
- if (ret > 0)
- av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
+ av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n",
+ ret > 0 ? buf : "?");
return AVERROR(EINVAL);
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 04/22] lavc/encode: improve input sample rate validation
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 02/22] lavc/encode: shorten code by using a local variable Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 03/22] lavc/encoder: always print an error on an unsupported channel layout Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 05/22] lavc/encode: improve unsupported-format error messages Anton Khirnov
` (17 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Reject zero sample rates in addition to negative ones and describe them
as 'invalid' rather than 'unsupported'.
---
libavcodec/encode.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index ba91dcc31e..9a279d9842 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -634,6 +634,11 @@ static int encode_preinit_audio(AVCodecContext *avctx)
avctx->sample_fmt);
return AVERROR(EINVAL);
}
+ if (avctx->sample_rate <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid audio sample rate: %d\n",
+ avctx->sample_rate);
+ return AVERROR(EINVAL);
+ }
if (c->sample_fmts) {
for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
@@ -662,11 +667,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
}
- if (avctx->sample_rate < 0) {
- av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
- avctx->sample_rate);
- return AVERROR(EINVAL);
- }
if (c->ch_layouts) {
for (i = 0; c->ch_layouts[i].nb_channels; i++) {
if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 05/22] lavc/encode: improve unsupported-format error messages
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (2 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 04/22] lavc/encode: improve input sample rate validation Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 06/22] lavfi: make sure frame SAR matches the link value Anton Khirnov
` (16 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Mention encoder name in the message to emphasize that the value in
question is not supported by this specific encoder, not necessarily by
libavcodec in general.
Print a list of values supported by the encoder.
---
libavcodec/encode.c | 45 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 9a279d9842..ee501132da 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -565,8 +565,16 @@ static int encode_preinit_video(AVCodecContext *avctx)
if (avctx->pix_fmt == c->pix_fmts[i])
break;
if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
- av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is not supported\n",
- av_get_pix_fmt_name(avctx->pix_fmt));
+ av_log(avctx, AV_LOG_ERROR,
+ "Specified pixel format %s is not supported by the %s encoder.\n",
+ av_get_pix_fmt_name(avctx->pix_fmt), c->name);
+
+ av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n");
+ for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
+ av_log(avctx, AV_LOG_ERROR, " %s\n",
+ av_get_pix_fmt_name(c->pix_fmts[p]));
+ }
+
return AVERROR(EINVAL);
}
if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
@@ -652,8 +660,16 @@ static int encode_preinit_audio(AVCodecContext *avctx)
}
}
if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
- av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is not supported\n",
- av_get_sample_fmt_name(avctx->sample_fmt));
+ av_log(avctx, AV_LOG_ERROR,
+ "Specified sample format %s is not supported by the %s encoder\n",
+ av_get_sample_fmt_name(avctx->sample_fmt), c->name);
+
+ av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
+ for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
+ av_log(avctx, AV_LOG_ERROR, " %s\n",
+ av_get_sample_fmt_name(c->sample_fmts[p]));
+ }
+
return AVERROR(EINVAL);
}
}
@@ -662,8 +678,14 @@ static int encode_preinit_audio(AVCodecContext *avctx)
if (avctx->sample_rate == c->supported_samplerates[i])
break;
if (c->supported_samplerates[i] == 0) {
- av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
- avctx->sample_rate);
+ av_log(avctx, AV_LOG_ERROR,
+ "Specified sample rate %d is not supported by the %s encoder\n",
+ avctx->sample_rate, c->name);
+
+ av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n");
+ for (int p = 0; c->supported_samplerates[p]; p++)
+ av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]);
+
return AVERROR(EINVAL);
}
}
@@ -675,8 +697,15 @@ static int encode_preinit_audio(AVCodecContext *avctx)
if (!c->ch_layouts[i].nb_channels) {
char buf[512];
int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
- av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n",
- ret > 0 ? buf : "?");
+ av_log(avctx, AV_LOG_ERROR,
+ "Specified channel layout '%s' is not supported by the %s encoder\n",
+ ret > 0 ? buf : "?", c->name);
+
+ av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n");
+ for (int p = 0; c->ch_layouts[p].nb_channels; p++) {
+ ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf));
+ av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?");
+ }
return AVERROR(EINVAL);
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 06/22] lavfi: make sure frame SAR matches the link value
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (3 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 05/22] lavc/encode: improve unsupported-format error messages Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-15 21:10 ` Michael Niedermayer
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_filter: make sure no input or output is bound twice Anton Khirnov
` (15 subsequent siblings)
20 siblings, 1 reply; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
---
libavfilter/avfilter.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 0141b64cbc..04887b6ee5 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -984,6 +984,8 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
av_assert1(frame->width == link->w);
av_assert1(frame->height == link->h);
}
+
+ frame->sample_aspect_ratio = link->sample_aspect_ratio;
} else {
if (frame->format != link->format) {
av_log(link->dst, AV_LOG_ERROR, "Format change is not supported\n");
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [FFmpeg-devel] [PATCH 06/22] lavfi: make sure frame SAR matches the link value
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 06/22] lavfi: make sure frame SAR matches the link value Anton Khirnov
@ 2023-07-15 21:10 ` Michael Niedermayer
0 siblings, 0 replies; 26+ messages in thread
From: Michael Niedermayer @ 2023-07-15 21:10 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 936 bytes --]
On Fri, Jul 07, 2023 at 11:48:31AM +0200, Anton Khirnov wrote:
> ---
> libavfilter/avfilter.c | 2 ++
> 1 file changed, 2 insertions(+)
Breaks aspect ratio of this, and likely others
./ffmpeg -i ~/tickets/4161/VR_MOVIE_GuyMartinsSpitfireBcast169\ qsf\ lappyAspectNoChnge_extract.mpg -bitexact -vcodec libx264 -an -vsync cfr -y file-169.ts
./ffplay file-169.ts
the ffplay displays the wrong aspect and it also shows the video with the wrong aspect
after this change
ffmpeg-bugs/trac/ticket4161/VR_MOVIE_GuyMartinsSpitfireBcast169 qsf lappyAspectNoChnge_extract.mpg
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Old school: Use the lowest level language in which you can solve the problem
conveniently.
New school: Use the highest level language in which the latest supercomputer
can solve the problem without the user falling asleep waiting.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_filter: make sure no input or output is bound twice
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (4 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 06/22] lavfi: make sure frame SAR matches the link value Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg_filter: make OutputFile.format/sample_rate private Anton Khirnov
` (14 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 60e09866af..432e2fced9 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -595,6 +595,8 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist)
InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
int ret;
+ av_assert0(!ifp->ist);
+
ifp->ist = ist;
ifp->type_src = ist->st->codecpar->codec_type;
@@ -654,6 +656,8 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
FilterGraph *fg = ofilter->graph;
const AVCodec *c = ost->enc_ctx->codec;
+ av_assert0(!ofilter->ost);
+
ofilter->ost = ost;
av_freep(&ofilter->linklabel);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg_filter: make OutputFile.format/sample_rate private
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (5 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_filter: make sure no input or output is bound twice Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_filter: make OutputFile.ch_layout private Anton Khirnov
` (13 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
They are not used outside of the filtering code.
---
fftools/ffmpeg.h | 2 --
fftools/ffmpeg_filter.c | 39 +++++++++++++++++++++++++++++----------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 316cd2b7a6..5b4117eeea 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -296,8 +296,6 @@ typedef struct OutputFilter {
/* desired output stream properties */
int width, height;
- int format;
- int sample_rate;
AVChannelLayout ch_layout;
// those are only set if no format is specified and the encoder gives us multiple options
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 432e2fced9..b1fda7b9e8 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -133,6 +133,19 @@ static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
return (InputFilterPriv*)ifilter;
}
+typedef struct OutputFilterPriv {
+ OutputFilter ofilter;
+
+ /* desired output stream properties */
+ int format;
+ int sample_rate;
+} OutputFilterPriv;
+
+static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
+{
+ return (OutputFilterPriv*)ofilter;
+}
+
static int configure_filtergraph(FilterGraph *fg);
static int sub2video_get_blank_frame(InputFilterPriv *ifp)
@@ -333,11 +346,12 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
{ \
- if (ofilter->var == none && !ofilter->supported_list) \
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); \
+ if (ofp->var == none && !ofilter->supported_list) \
return; \
av_bprintf(bprint, #name "="); \
- if (ofilter->var != none) { \
- av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
+ if (ofp->var != none) { \
+ av_bprintf(bprint, printf_format, get_name(ofp->var)); \
} else { \
const type *p; \
\
@@ -580,11 +594,14 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
static OutputFilter *ofilter_alloc(FilterGraph *fg)
{
+ OutputFilterPriv *ofp;
OutputFilter *ofilter;
- ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
+ ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp),
+ &fg->nb_outputs);
+ ofilter = &ofp->ofilter;
ofilter->graph = fg;
- ofilter->format = -1;
+ ofp->format = -1;
ofilter->last_pts = AV_NOPTS_VALUE;
return ofilter;
@@ -653,6 +670,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost)
void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
{
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
FilterGraph *fg = ofilter->graph;
const AVCodec *c = ost->enc_ctx->codec;
@@ -666,19 +684,19 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
ofilter->width = ost->enc_ctx->width;
ofilter->height = ost->enc_ctx->height;
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
- ofilter->format = ost->enc_ctx->pix_fmt;
+ ofp->format = ost->enc_ctx->pix_fmt;
} else {
ofilter->formats = c->pix_fmts;
}
break;
case AVMEDIA_TYPE_AUDIO:
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
- ofilter->format = ost->enc_ctx->sample_fmt;
+ ofp->format = ost->enc_ctx->sample_fmt;
} else {
ofilter->formats = c->sample_fmts;
}
if (ost->enc_ctx->sample_rate) {
- ofilter->sample_rate = ost->enc_ctx->sample_rate;
+ ofp->sample_rate = ost->enc_ctx->sample_rate;
} else {
ofilter->sample_rates = c->supported_samplerates;
}
@@ -1570,14 +1588,15 @@ static int configure_filtergraph(FilterGraph *fg)
* make sure they stay the same if the filtergraph is reconfigured later */
for (i = 0; i < fg->nb_outputs; i++) {
OutputFilter *ofilter = fg->outputs[i];
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
AVFilterContext *sink = ofilter->filter;
- ofilter->format = av_buffersink_get_format(sink);
+ ofp->format = av_buffersink_get_format(sink);
ofilter->width = av_buffersink_get_w(sink);
ofilter->height = av_buffersink_get_h(sink);
- ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
+ ofp->sample_rate = av_buffersink_get_sample_rate(sink);
av_channel_layout_uninit(&ofilter->ch_layout);
ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
if (ret < 0)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_filter: make OutputFile.ch_layout private
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (6 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg_filter: make OutputFile.format/sample_rate private Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_filter: make OutputFile.width, height private Anton Khirnov
` (12 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
It is not used outside of the filtering code.
---
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_filter.c | 17 ++++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5b4117eeea..b789233a08 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -296,7 +296,6 @@ typedef struct OutputFilter {
/* desired output stream properties */
int width, height;
- AVChannelLayout ch_layout;
// those are only set if no format is specified and the encoder gives us multiple options
// They point directly to the relevant lists of the encoder.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index b1fda7b9e8..0272b0a96b 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -139,6 +139,7 @@ typedef struct OutputFilterPriv {
/* desired output stream properties */
int format;
int sample_rate;
+ AVChannelLayout ch_layout;
} OutputFilterPriv;
static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
@@ -375,9 +376,10 @@ DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
{
- if (av_channel_layout_check(&ofilter->ch_layout)) {
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
+ if (av_channel_layout_check(&ofp->ch_layout)) {
av_bprintf(bprint, "channel_layouts=");
- av_channel_layout_describe_bprint(&ofilter->ch_layout, bprint);
+ av_channel_layout_describe_bprint(&ofp->ch_layout, bprint);
} else if (ofilter->ch_layouts) {
const AVChannelLayout *p;
@@ -630,7 +632,7 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist)
return 0;
}
-static void set_channel_layout(OutputFilter *f, OutputStream *ost)
+static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
{
const AVCodec *c = ost->enc_ctx->codec;
int i, err;
@@ -701,7 +703,7 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
ofilter->sample_rates = c->supported_samplerates;
}
if (ost->enc_ctx->ch_layout.nb_channels) {
- set_channel_layout(ofilter, ost);
+ set_channel_layout(ofp, ost);
} else if (c->ch_layouts) {
ofilter->ch_layouts = c->ch_layouts;
}
@@ -782,10 +784,11 @@ void fg_free(FilterGraph **pfg)
av_freep(&fg->inputs);
for (int j = 0; j < fg->nb_outputs; j++) {
OutputFilter *ofilter = fg->outputs[j];
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
av_freep(&ofilter->linklabel);
av_freep(&ofilter->name);
- av_channel_layout_uninit(&ofilter->ch_layout);
+ av_channel_layout_uninit(&ofp->ch_layout);
av_freep(&fg->outputs[j]);
}
av_freep(&fg->outputs);
@@ -1597,8 +1600,8 @@ static int configure_filtergraph(FilterGraph *fg)
ofilter->height = av_buffersink_get_h(sink);
ofp->sample_rate = av_buffersink_get_sample_rate(sink);
- av_channel_layout_uninit(&ofilter->ch_layout);
- ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
+ av_channel_layout_uninit(&ofp->ch_layout);
+ ret = av_buffersink_get_ch_layout(sink, &ofp->ch_layout);
if (ret < 0)
goto fail;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_filter: make OutputFile.width, height private
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (7 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_filter: make OutputFile.ch_layout private Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_filter: make OutputFile.{formats, ch_layouts, sample_rates} private Anton Khirnov
` (11 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
They are not used outside of the filtering code.
---
fftools/ffmpeg.h | 3 ---
fftools/ffmpeg_filter.c | 14 ++++++++------
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b789233a08..79f3f35b3a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -294,9 +294,6 @@ typedef struct OutputFilter {
enum AVMediaType type;
- /* desired output stream properties */
- int width, height;
-
// those are only set if no format is specified and the encoder gives us multiple options
// They point directly to the relevant lists of the encoder.
const int *formats;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0272b0a96b..0874187f3e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -138,6 +138,7 @@ typedef struct OutputFilterPriv {
/* desired output stream properties */
int format;
+ int width, height;
int sample_rate;
AVChannelLayout ch_layout;
} OutputFilterPriv;
@@ -683,8 +684,8 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
switch (ost->enc_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- ofilter->width = ost->enc_ctx->width;
- ofilter->height = ost->enc_ctx->height;
+ ofp->width = ost->enc_ctx->width;
+ ofp->height = ost->enc_ctx->height;
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
ofp->format = ost->enc_ctx->pix_fmt;
} else {
@@ -1068,6 +1069,7 @@ static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
{
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
OutputFile *of = output_files[ost->file_index];
AVFilterContext *last_filter = out->filter_ctx;
@@ -1085,13 +1087,13 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
if (ret < 0)
return ret;
- if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
+ if ((ofp->width || ofp->height) && ofilter->ost->autoscale) {
char args[255];
AVFilterContext *filter;
const AVDictionaryEntry *e = NULL;
snprintf(args, sizeof(args), "%d:%d",
- ofilter->width, ofilter->height);
+ ofp->width, ofp->height);
while ((e = av_dict_iterate(ost->sws_dict, e))) {
av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
@@ -1596,8 +1598,8 @@ static int configure_filtergraph(FilterGraph *fg)
ofp->format = av_buffersink_get_format(sink);
- ofilter->width = av_buffersink_get_w(sink);
- ofilter->height = av_buffersink_get_h(sink);
+ ofp->width = av_buffersink_get_w(sink);
+ ofp->height = av_buffersink_get_h(sink);
ofp->sample_rate = av_buffersink_get_sample_rate(sink);
av_channel_layout_uninit(&ofp->ch_layout);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_filter: make OutputFile.{formats, ch_layouts, sample_rates} private
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (8 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_filter: make OutputFile.width, height private Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_filter: consolidate calling avfilter_graph_set_auto_convert() Anton Khirnov
` (10 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
They are not used outside of the filtering code.
---
fftools/ffmpeg.h | 6 ------
fftools/ffmpeg_filter.c | 35 ++++++++++++++++++++---------------
2 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 79f3f35b3a..3201163a4f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -294,12 +294,6 @@ typedef struct OutputFilter {
enum AVMediaType type;
- // those are only set if no format is specified and the encoder gives us multiple options
- // They point directly to the relevant lists of the encoder.
- const int *formats;
- const AVChannelLayout *ch_layouts;
- const int *sample_rates;
-
/* pts of the last frame received from this filter, in AV_TIME_BASE_Q */
int64_t last_pts;
} OutputFilter;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0874187f3e..f60d1cd23b 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -141,6 +141,12 @@ typedef struct OutputFilterPriv {
int width, height;
int sample_rate;
AVChannelLayout ch_layout;
+
+ // those are only set if no format is specified and the encoder gives us multiple options
+ // They point directly to the relevant lists of the encoder.
+ const int *formats;
+ const AVChannelLayout *ch_layouts;
+ const int *sample_rates;
} OutputFilterPriv;
static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
@@ -346,10 +352,9 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
/* Define a function for appending a list of allowed formats
* to an AVBPrint. If nonempty, the list will have a header. */
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
-static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
+static void choose_ ## name (OutputFilterPriv *ofp, AVBPrint *bprint) \
{ \
- OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); \
- if (ofp->var == none && !ofilter->supported_list) \
+ if (ofp->var == none && !ofp->supported_list) \
return; \
av_bprintf(bprint, #name "="); \
if (ofp->var != none) { \
@@ -357,7 +362,7 @@ static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
} else { \
const type *p; \
\
- for (p = ofilter->supported_list; *p != none; p++) { \
+ for (p = ofp->supported_list; *p != none; p++) { \
av_bprintf(bprint, printf_format "|", get_name(*p)); \
} \
if (bprint->len > 0) \
@@ -375,17 +380,16 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
"%d", )
-static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
+static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint)
{
- OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
if (av_channel_layout_check(&ofp->ch_layout)) {
av_bprintf(bprint, "channel_layouts=");
av_channel_layout_describe_bprint(&ofp->ch_layout, bprint);
- } else if (ofilter->ch_layouts) {
+ } else if (ofp->ch_layouts) {
const AVChannelLayout *p;
av_bprintf(bprint, "channel_layouts=");
- for (p = ofilter->ch_layouts; p->nb_channels; p++) {
+ for (p = ofp->ch_layouts; p->nb_channels; p++) {
av_channel_layout_describe_bprint(p, bprint);
av_bprintf(bprint, "|");
}
@@ -689,24 +693,24 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
ofp->format = ost->enc_ctx->pix_fmt;
} else {
- ofilter->formats = c->pix_fmts;
+ ofp->formats = c->pix_fmts;
}
break;
case AVMEDIA_TYPE_AUDIO:
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
ofp->format = ost->enc_ctx->sample_fmt;
} else {
- ofilter->formats = c->sample_fmts;
+ ofp->formats = c->sample_fmts;
}
if (ost->enc_ctx->sample_rate) {
ofp->sample_rate = ost->enc_ctx->sample_rate;
} else {
- ofilter->sample_rates = c->supported_samplerates;
+ ofp->sample_rates = c->supported_samplerates;
}
if (ost->enc_ctx->ch_layout.nb_channels) {
set_channel_layout(ofp, ost);
} else if (c->ch_layouts) {
- ofilter->ch_layouts = c->ch_layouts;
+ ofp->ch_layouts = c->ch_layouts;
}
break;
}
@@ -1144,6 +1148,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
{
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
OutputFile *of = output_files[ost->file_index];
AVFilterContext *last_filter = out->filter_ctx;
@@ -1196,9 +1201,9 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
}
#endif
- choose_sample_fmts(ofilter, &args);
- choose_sample_rates(ofilter, &args);
- choose_channel_layouts(ofilter, &args);
+ choose_sample_fmts(ofp, &args);
+ choose_sample_rates(ofp, &args);
+ choose_channel_layouts(ofp, &args);
if (!av_bprint_is_complete(&args)) {
ret = AVERROR(ENOMEM);
goto fail;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_filter: consolidate calling avfilter_graph_set_auto_convert()
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (9 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_filter: make OutputFile.{formats, ch_layouts, sample_rates} private Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format Anton Khirnov
` (9 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Do not call it from choose_pix_fmts(), as that function is not supposed
to modify random filtergraph properties.
---
fftools/ffmpeg_filter.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index f60d1cd23b..caf85194c5 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -48,6 +48,7 @@ typedef struct FilterGraphPriv {
// true when the filtergraph contains only meta filters
// that do not modify the frame data
int is_meta;
+ int disable_conversions;
const char *graph_desc;
@@ -321,8 +322,6 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
if (ost->keep_pix_fmt) {
- avfilter_graph_set_auto_convert(ofilter->graph->graph,
- AVFILTER_AUTO_CONVERT_NONE);
if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
return NULL;
return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
@@ -679,6 +678,7 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
{
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
FilterGraph *fg = ofilter->graph;
+ FilterGraphPriv *fgp = fgp_from_fg(fg);
const AVCodec *c = ost->enc_ctx->codec;
av_assert0(!ofilter->ost);
@@ -695,6 +695,9 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
} else {
ofp->formats = c->pix_fmts;
}
+
+ fgp->disable_conversions |= ost->keep_pix_fmt;
+
break;
case AVMEDIA_TYPE_AUDIO:
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
@@ -830,6 +833,7 @@ FilterGraph *fg_create(char *graph_desc)
fg->class = &fg_class;
fg->index = nb_filtergraphs - 1;
fgp->graph_desc = graph_desc;
+ fgp->disable_conversions = !auto_conversion_filters;
snprintf(fgp->log_name, sizeof(fgp->log_name), "fc#%d", fg->index);
@@ -1587,7 +1591,7 @@ static int configure_filtergraph(FilterGraph *fg)
configure_output_filter(fg, fg->outputs[i], cur);
avfilter_inout_free(&outputs);
- if (!auto_conversion_filters)
+ if (fgp->disable_conversions)
avfilter_graph_set_auto_convert(fg->graph, AVFILTER_AUTO_CONVERT_NONE);
if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
goto fail;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (10 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_filter: consolidate calling avfilter_graph_set_auto_convert() Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-08 22:15 ` Michael Niedermayer
2023-07-08 22:51 ` Michael Niedermayer
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection Anton Khirnov
` (8 subsequent siblings)
20 siblings, 2 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
When the user explicitly specifies a pixel format that is not supported
by the encoder, ffmpeg CLI will currently use some heuristics to pick
another supported format. This is wrong and the correct action here is
to fail.
Surprisingly, a number of FATE tests are affected by this and actually
use a different pixel format than is specified in the makefiles.
---
fftools/ffmpeg_filter.c | 36 ++-----------------
tests/fate/fits.mak | 6 ++--
tests/fate/lavf-video.mak | 2 +-
tests/fate/vcodec.mak | 4 +--
.../{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 +--
.../fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 +--
tests/ref/lavf/gif | 2 +-
7 files changed, 13 insertions(+), 45 deletions(-)
rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%)
rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index caf85194c5..c283ee2b7a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -277,43 +277,12 @@ static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *c
}
}
-static enum AVPixelFormat
-choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target,
- int strict_std_compliance)
-{
- if (codec && codec->pix_fmts) {
- const enum AVPixelFormat *p = codec->pix_fmts;
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
- //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
- int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
- enum AVPixelFormat best= AV_PIX_FMT_NONE;
-
- if (strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
- p = get_compliance_normal_pix_fmts(codec, p);
- }
- for (; *p != AV_PIX_FMT_NONE; p++) {
- best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
- if (*p == target)
- break;
- }
- if (*p == AV_PIX_FMT_NONE) {
- if (target != AV_PIX_FMT_NONE)
- av_log(NULL, AV_LOG_WARNING,
- "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
- av_get_pix_fmt_name(target),
- codec->name,
- av_get_pix_fmt_name(best));
- return best;
- }
- }
- return target;
-}
-
/* May return NULL (no pixel format found), a static string or a string
* backed by the bprint. Nothing has been written to the AVBPrint in case
* NULL is returned. The AVBPrint provided should be clean. */
static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
{
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
AVCodecContext *enc = ost->enc_ctx;
const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
@@ -327,8 +296,7 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
}
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
- return av_get_pix_fmt_name(choose_pixel_fmt(enc->codec, enc->pix_fmt,
- ost->enc_ctx->strict_std_compliance));
+ return av_get_pix_fmt_name(enc->pix_fmt);
} else if (enc->codec->pix_fmts) {
const enum AVPixelFormat *p;
diff --git a/tests/fate/fits.mak b/tests/fate/fits.mak
index b9e99d97ee..d85946bc1a 100644
--- a/tests/fate/fits.mak
+++ b/tests/fate/fits.mak
@@ -8,8 +8,8 @@ tests/data/fits-multi.fits: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
# TODO: Use an actual 64bit input file and fix the gbrp16 test on big-endian
fits-png-map-gray := gray8
fits-png-map-gbrp := rgb24
-fits-png-map-gbrp16 := rgb48
-fits-png-map-gbrap16le := rgba64
+fits-png-map-gbrp16be := rgb48
+fits-png-map-gbrap16be := rgba64
FATE_FITS_DEC-$(call FRAMECRC, FITS, FITS, SCALE_FILTER) += fate-fitsdec-ext_data_min_max
fate-fitsdec-ext_data_min_max: CMD = framecrc -i $(TARGET_SAMPLES)/fits/x0cj010ct_d0h.fit -pix_fmt gray16le -vf scale
@@ -30,7 +30,7 @@ fate-fitsdec-multi: CMD = framecrc -i $(TARGET_PATH)/tests/data/fits-multi.fits
fate-fitsdec%: PIXFMT = $(word 3, $(subst -, ,$(@)))
fate-fitsdec%: CMD = transcode image2 $(TARGET_SAMPLES)/png1/lena-$(fits-png-map-$(PIXFMT)).png fits "-vf scale -pix_fmt $(PIXFMT)"
-FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16 gbrap16le
+FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16be gbrap16be
FATE_FITS_DEC-$(call TRANSCODE, FITS, FITS, IMAGE2_DEMUXER PNG_DECODER SCALE_FILTER) += $(FATE_FITS_DEC_PIXFMT:%=fate-fitsdec-%)
FATE_FITS += $(FATE_FITS_DEC-yes)
diff --git a/tests/fate/lavf-video.mak b/tests/fate/lavf-video.mak
index e73f8f203b..da3b114bc8 100644
--- a/tests/fate/lavf-video.mak
+++ b/tests/fate/lavf-video.mak
@@ -27,7 +27,7 @@ fate-lavf-gbrp.fits: CMD = lavf_video "-pix_fmt gbrp"
fate-lavf-gbrap.fits: CMD = lavf_video "-pix_fmt gbrap"
fate-lavf-gbrp16be.fits: CMD = lavf_video "-pix_fmt gbrp16be"
fate-lavf-gbrap16be.fits: CMD = lavf_video "-pix_fmt gbrap16be"
-fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb24"
+fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb8"
FATE_AVCONV += $(FATE_LAVF_VIDEO)
fate-lavf-video fate-lavf: $(FATE_LAVF_VIDEO)
diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index 2839e54de8..e32d28c556 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -210,9 +210,9 @@ fate-vsynth%-h263p: ENCOPTS = -qscale 2 -flags +aic -umv 1 -aiv 1 -
FATE_VCODEC_SCALE-$(call ENCDEC, HUFFYUV, AVI) += huffyuv huffyuvbgr24 huffyuvbgra
fate-vsynth%-huffyuv: ENCOPTS = -c:v huffyuv -pix_fmt yuv422p -sws_flags neighbor
fate-vsynth%-huffyuv: DECOPTS = -sws_flags neighbor
-fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt bgr24 -sws_flags neighbor
+fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt rgb24 -sws_flags neighbor
fate-vsynth%-huffyuvbgr24: DECOPTS = -sws_flags neighbor
-fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt bgr32 -sws_flags neighbor
+fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt rgb32 -sws_flags neighbor
fate-vsynth%-huffyuvbgra: DECOPTS = -sws_flags neighbor
FATE_VCODEC_SCALE-$(call ENCDEC, JPEGLS, AVI) += jpegls
diff --git a/tests/ref/fate/fitsdec-gbrap16le b/tests/ref/fate/fitsdec-gbrap16be
similarity index 79%
rename from tests/ref/fate/fitsdec-gbrap16le
rename to tests/ref/fate/fitsdec-gbrap16be
index 53ef980b13..1174a0f1d8 100644
--- a/tests/ref/fate/fitsdec-gbrap16le
+++ b/tests/ref/fate/fitsdec-gbrap16be
@@ -1,5 +1,5 @@
-64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16le.fits
-135360 tests/data/fate/fitsdec-gbrap16le.fits
+64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16be.fits
+135360 tests/data/fate/fitsdec-gbrap16be.fits
#tb 0: 1/1
#media_type 0: video
#codec_id 0: rawvideo
diff --git a/tests/ref/fate/fitsdec-gbrp16 b/tests/ref/fate/fitsdec-gbrp16be
similarity index 79%
rename from tests/ref/fate/fitsdec-gbrp16
rename to tests/ref/fate/fitsdec-gbrp16be
index 9250690e9b..ff4ca9e65c 100644
--- a/tests/ref/fate/fitsdec-gbrp16
+++ b/tests/ref/fate/fitsdec-gbrp16be
@@ -1,5 +1,5 @@
-2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16.fits
-103680 tests/data/fate/fitsdec-gbrp16.fits
+2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16be.fits
+103680 tests/data/fate/fitsdec-gbrp16be.fits
#tb 0: 1/1
#media_type 0: video
#codec_id 0: rawvideo
diff --git a/tests/ref/lavf/gif b/tests/ref/lavf/gif
index fc94b9df3d..7f353df286 100644
--- a/tests/ref/lavf/gif
+++ b/tests/ref/lavf/gif
@@ -1,3 +1,3 @@
e35f5ea283bbcb249818e0078ec72664 *tests/data/lavf/lavf.gif
2011766 tests/data/lavf/lavf.gif
-tests/data/lavf/lavf.gif CRC=0x2429faff
+tests/data/lavf/lavf.gif CRC=0x37f4d323
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format Anton Khirnov
@ 2023-07-08 22:15 ` Michael Niedermayer
2023-07-09 2:18 ` Anton Khirnov
2023-07-08 22:51 ` Michael Niedermayer
1 sibling, 1 reply; 26+ messages in thread
From: Michael Niedermayer @ 2023-07-08 22:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1681 bytes --]
On Fri, Jul 07, 2023 at 11:48:38AM +0200, Anton Khirnov wrote:
> When the user explicitly specifies a pixel format that is not supported
> by the encoder, ffmpeg CLI will currently use some heuristics to pick
> another supported format. This is wrong and the correct action here is
> to fail.
>
> Surprisingly, a number of FATE tests are affected by this and actually
> use a different pixel format than is specified in the makefiles.
> ---
> fftools/ffmpeg_filter.c | 36 ++-----------------
> tests/fate/fits.mak | 6 ++--
> tests/fate/lavf-video.mak | 2 +-
> tests/fate/vcodec.mak | 4 +--
> .../{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 +--
> .../fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 +--
> tests/ref/lavf/gif | 2 +-
> 7 files changed, 13 insertions(+), 45 deletions(-)
> rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%)
> rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%)
breaks png
./ffmpeg -y -i lena.pnm -s 696x300 -pix_fmt rgb48 -y out2.png
Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Conversion failed!
before
./ffprobe out2.png
...
Stream #0:0: Video: png, rgb48be(pc, gbr/unknown/unknown), 696x300, 25 fps, 25 tbr, 25 tbn
Yes internally its BE vs LE but thats not what the user wrote on the command line
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format
2023-07-08 22:15 ` Michael Niedermayer
@ 2023-07-09 2:18 ` Anton Khirnov
0 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-09 2:18 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2023-07-09 00:15:30)
> On Fri, Jul 07, 2023 at 11:48:38AM +0200, Anton Khirnov wrote:
> > When the user explicitly specifies a pixel format that is not supported
> > by the encoder, ffmpeg CLI will currently use some heuristics to pick
> > another supported format. This is wrong and the correct action here is
> > to fail.
> >
> > Surprisingly, a number of FATE tests are affected by this and actually
> > use a different pixel format than is specified in the makefiles.
> > ---
> > fftools/ffmpeg_filter.c | 36 ++-----------------
> > tests/fate/fits.mak | 6 ++--
> > tests/fate/lavf-video.mak | 2 +-
> > tests/fate/vcodec.mak | 4 +--
> > .../{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 +--
> > .../fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 +--
> > tests/ref/lavf/gif | 2 +-
> > 7 files changed, 13 insertions(+), 45 deletions(-)
> > rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%)
> > rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%)
>
> breaks png
>
> ./ffmpeg -y -i lena.pnm -s 696x300 -pix_fmt rgb48 -y out2.png
>
> Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
> Conversion failed!
>
> before
> ./ffprobe out2.png
> ...
> Stream #0:0: Video: png, rgb48be(pc, gbr/unknown/unknown), 696x300, 25 fps, 25 tbr, 25 tbn
>
> Yes internally its BE vs LE but thats not what the user wrote on the command line
The pixel format that is printed in your "before" is different from what
the user wrote as well, so the new behavior is correct IMO.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format Anton Khirnov
2023-07-08 22:15 ` Michael Niedermayer
@ 2023-07-08 22:51 ` Michael Niedermayer
1 sibling, 0 replies; 26+ messages in thread
From: Michael Niedermayer @ 2023-07-08 22:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2117 bytes --]
On Fri, Jul 07, 2023 at 11:48:38AM +0200, Anton Khirnov wrote:
> When the user explicitly specifies a pixel format that is not supported
> by the encoder, ffmpeg CLI will currently use some heuristics to pick
> another supported format. This is wrong and the correct action here is
> to fail.
>
> Surprisingly, a number of FATE tests are affected by this and actually
> use a different pixel format than is specified in the makefiles.
> ---
> fftools/ffmpeg_filter.c | 36 ++-----------------
> tests/fate/fits.mak | 6 ++--
> tests/fate/lavf-video.mak | 2 +-
> tests/fate/vcodec.mak | 4 +--
> .../{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 +--
> .../fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 +--
> tests/ref/lavf/gif | 2 +-
> 7 files changed, 13 insertions(+), 45 deletions(-)
> rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%)
> rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%)
This also seems to break the user interface and seems to violates what is documented:
(unless iam too tired and mix something up here)
@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream})
Set pixel format. Use @code{-pix_fmts} to show all the supported
pixel formats.
If the selected pixel format can not be selected, ffmpeg will print a
warning and select the best pixel format supported by the encoder.
If @var{pix_fmt} is prefixed by a @code{+}, ffmpeg will exit with an error
if the requested pixel format can not be selected, and automatic conversions
inside filtergraphs are disabled.
If @var{pix_fmt} is a single @code{+}, ffmpeg selects the same pixel format
as the input (or graph output) and automatic conversions are disabled.
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (11 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_filter: stop disregarding user-specified pixel format Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: drop an obsolete debug log Anton Khirnov
` (7 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
ffmpeg CLI pixel format selection for filtering currently special-cases
MJPEG encoding, where it will restrict the supported list of pixel
formats depending on the value of the -strict option. In order to get
that value it will apply it from the options dict into the encoder
context, which is a highly invasive action even now, and would become a
race once encoding is moved to its own thread.
The ugliness of this code can be much reduced by moving the special
handling of MJPEG into ofilter_bind_ost(), which is called from encoder
init and is thus synchronized with it. There is also no need to write
anything to the encoder context, we can evaluate the option into our
stack variable.
There is also no need to access AVCodec at all during pixel format
selection, as the pixel formats array is already stored in
OutputFilterPriv.
---
fftools/ffmpeg_filter.c | 64 ++++++++++++++++++++---------------------
1 file changed, 31 insertions(+), 33 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c283ee2b7a..67a5f48245 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -262,21 +262,6 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts,
ifp->sub2video.initialize = 0;
}
-// FIXME: YUV420P etc. are actually supported with full color range,
-// yet the latter information isn't available here.
-static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
-{
- static const enum AVPixelFormat mjpeg_formats[] =
- { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
- AV_PIX_FMT_NONE };
-
- if (!strcmp(codec->name, "mjpeg")) {
- return mjpeg_formats;
- } else {
- return default_formats;
- }
-}
-
/* May return NULL (no pixel format found), a static string or a string
* backed by the bprint. Nothing has been written to the AVBPrint in case
* NULL is returned. The AVBPrint provided should be clean. */
@@ -284,26 +269,15 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
{
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
- AVCodecContext *enc = ost->enc_ctx;
- const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
- if (strict_dict)
- // used by choose_pixel_fmt() and below
- av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
- if (ost->keep_pix_fmt) {
- if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
- return NULL;
- return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
+ if (ost->keep_pix_fmt) {
+ return ofp->format == AV_PIX_FMT_NONE ? NULL :
+ av_get_pix_fmt_name(ofp->format);
}
- if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
- return av_get_pix_fmt_name(enc->pix_fmt);
- } else if (enc->codec->pix_fmts) {
- const enum AVPixelFormat *p;
-
- p = enc->codec->pix_fmts;
- if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
- p = get_compliance_normal_pix_fmts(enc->codec, p);
- }
+ if (ofp->format != AV_PIX_FMT_NONE) {
+ return av_get_pix_fmt_name(ofp->format);
+ } else if (ofp->formats) {
+ const enum AVPixelFormat *p = ofp->formats;
for (; *p != AV_PIX_FMT_NONE; p++) {
const char *name = av_get_pix_fmt_name(*p);
@@ -662,6 +636,30 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
ofp->format = ost->enc_ctx->pix_fmt;
} else {
ofp->formats = c->pix_fmts;
+
+ // MJPEG encoder exports a full list of supported pixel formats,
+ // but the full-range ones are experimental-only.
+ // Restrict the auto-conversion list unless -strict experimental
+ // has been specified.
+ if (!strcmp(c->name, "mjpeg")) {
+ // FIXME: YUV420P etc. are actually supported with full color range,
+ // yet the latter information isn't available here.
+ static const enum AVPixelFormat mjpeg_formats[] =
+ { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
+ AV_PIX_FMT_NONE };
+
+ const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
+ int strict_val = ost->enc_ctx->strict_std_compliance;
+
+ if (strict) {
+ const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0);
+ av_assert0(o);
+ av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val);
+ }
+
+ if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
+ ofp->formats = mjpeg_formats;
+ }
}
fgp->disable_conversions |= ost->keep_pix_fmt;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: drop an obsolete debug log
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (12 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg: rework initializing encoders with no frames Anton Khirnov
` (6 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
The value it prints has not been cur_dts from lavf for a very long time,
so it's misleading.
---
fftools/ffmpeg.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 435e12a37b..013935d6ce 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -941,10 +941,6 @@ static int choose_output(OutputStream **post)
} else {
opts = ost->last_mux_dts == AV_NOPTS_VALUE ?
INT64_MIN : ost->last_mux_dts;
- if (ost->last_mux_dts == AV_NOPTS_VALUE)
- av_log(ost, AV_LOG_DEBUG,
- "cur_dts is invalid [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
- ost->initialized, ost->inputs_done, ost->finished);
}
if (!ost->initialized && !ost->inputs_done && !ost->finished) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg: rework initializing encoders with no frames
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (13 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: drop an obsolete debug log Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg_filter: only flush vsync code if encoding actually started Anton Khirnov
` (5 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
When no frames were passed from a filtergraph to an encoder, but the
filtergraph is configured (i.e. has output parameters), encoder flush
code will use those parameters to initialize the encoder in a last-ditch
effort to produce some useful output.
Rework this process so that it is triggered by the filtergraph, which
now sends a dummy frame with parameters, but no data, to the encoder,
rather than the encoder reaching backwards into the filter.
This approach is more in line with the natural data flow from filters to
encoders and will allow to reduce encoder-filter interactions in
following commits.
This code is tested by fate-adpcm-ima-cunning-trunc-t2-track1, which (as
confirmed by Zane) is supposed to produce empty output.
---
fftools/ffmpeg_enc.c | 22 ++---------------
fftools/ffmpeg_filter.c | 54 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 4029501313..dd056e42f5 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1142,26 +1142,8 @@ void enc_flush(void)
AVCodecContext *enc = ost->enc_ctx;
OutputFile *of = output_files[ost->file_index];
- if (!enc)
- continue;
-
- // Try to enable encoding with no input frames.
- // Maybe we should just let encoding fail instead.
- if (!e->opened) {
- FilterGraph *fg = ost->filter->graph;
-
- av_log(ost, AV_LOG_WARNING,
- "Finishing stream without any data written to it.\n");
-
- if (!fg->graph)
- continue;
-
- ret = enc_open(ost, NULL);
- if (ret < 0)
- exit_program(1);
- }
-
- if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
+ if (!enc || !e->opened ||
+ (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO))
continue;
ret = submit_encode_frame(of, ost, NULL);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 67a5f48245..f8e64ce6cc 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -143,11 +143,17 @@ typedef struct OutputFilterPriv {
int sample_rate;
AVChannelLayout ch_layout;
+ AVRational time_base;
+ AVRational sample_aspect_ratio;
+
// those are only set if no format is specified and the encoder gives us multiple options
// They point directly to the relevant lists of the encoder.
const int *formats;
const AVChannelLayout *ch_layouts;
const int *sample_rates;
+
+ // set to 1 after at least one frame passed through this output
+ int got_frame;
} OutputFilterPriv;
static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
@@ -1576,6 +1582,9 @@ static int configure_filtergraph(FilterGraph *fg)
ofp->width = av_buffersink_get_w(sink);
ofp->height = av_buffersink_get_h(sink);
+ ofp->time_base = av_buffersink_get_time_base(sink);
+ ofp->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink);
+
ofp->sample_rate = av_buffersink_get_sample_rate(sink);
av_channel_layout_uninit(&ofp->ch_layout);
ret = av_buffersink_get_ch_layout(sink, &ofp->ch_layout);
@@ -1688,6 +1697,7 @@ int reap_filters(int flush)
{
/* Reap all buffers present in the buffer sinks */
for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+ OutputFilterPriv *ofp;
FilterGraphPriv *fgp;
AVFrame *filtered_frame;
AVFilterContext *filter;
@@ -1697,6 +1707,7 @@ int reap_filters(int flush)
continue;
filter = ost->filter->filter;
fgp = fgp_from_fg(ost->filter->graph);
+ ofp = ofp_from_ofilter(ost->filter);
filtered_frame = fgp->frame;
@@ -1749,6 +1760,7 @@ int reap_filters(int flush)
enc_frame(ost, filtered_frame);
av_frame_unref(filtered_frame);
+ ofp->got_frame = 1;
}
}
@@ -1961,6 +1973,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
{
+ FilterGraphPriv *fgp = fgp_from_fg(graph);
int i, ret;
int nb_requests, nb_requests_max = 0;
InputStream *ist;
@@ -1988,10 +2001,43 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
return reap_filters(0);
if (ret == AVERROR_EOF) {
- ret = reap_filters(1);
- for (i = 0; i < graph->nb_outputs; i++)
- close_output_stream(graph->outputs[i]->ost);
- return ret;
+ reap_filters(1);
+ for (int i = 0; i < graph->nb_outputs; i++) {
+ OutputFilter *ofilter = graph->outputs[i];
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
+
+ // we are finished and no frames were ever seen at this output,
+ // at least initialize the encoder with a dummy frame
+ if (!ofp->got_frame) {
+ AVFrame *frame = fgp->frame;
+
+ frame->time_base = ofp->time_base;
+ frame->format = ofp->format;
+
+ frame->width = ofp->width;
+ frame->height = ofp->height;
+ frame->sample_aspect_ratio = ofp->sample_aspect_ratio;
+
+ frame->sample_rate = ofp->sample_rate;
+ if (ofp->ch_layout.nb_channels) {
+ ret = av_channel_layout_copy(&frame->ch_layout, &ofp->ch_layout);
+ if (ret < 0)
+ return ret;
+ }
+
+ av_assert0(!frame->buf[0]);
+
+ av_log(ofilter->ost, AV_LOG_WARNING,
+ "No filtered frames for output stream, trying to "
+ "initialize anyway.\n");
+
+ enc_open(ofilter->ost, frame);
+ av_frame_unref(frame);
+ }
+
+ close_output_stream(ofilter->ost);
+ }
+ return 0;
}
if (ret != AVERROR(EAGAIN))
return ret;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg_filter: only flush vsync code if encoding actually started
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (14 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg: rework initializing encoders with no frames Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg_enc: initialize audio/video encoders from frame parameters Anton Khirnov
` (4 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Otherwise this has no effect.
Will be useful in following commits.
---
fftools/ffmpeg_filter.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index f8e64ce6cc..4955fe38dd 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1720,10 +1720,10 @@ int reap_filters(int flush)
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
av_log(fgp, AV_LOG_WARNING,
"Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
- } else if (flush && ret == AVERROR_EOF) {
- if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
- enc_frame(ost, NULL);
- }
+ } else if (flush && ret == AVERROR_EOF && ofp->got_frame &&
+ av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
+ enc_frame(ost, NULL);
+
break;
}
if (ost->finished) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg_enc: initialize audio/video encoders from frame parameters
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (15 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg_filter: only flush vsync code if encoding actually started Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg_filter: make OutputFilter.filter private Anton Khirnov
` (3 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
This is possible now that enc_open() is always called with a non-NULL
frame for audio/video.
Previously the code would directly reach into the buffersink, which is a
layering violation.
---
fftools/ffmpeg_enc.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index dd056e42f5..1347493f9f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -34,8 +34,6 @@
#include "libavutil/rational.h"
#include "libavutil/timestamp.h"
-#include "libavfilter/buffersink.h"
-
#include "libavcodec/avcodec.h"
// FIXME private header, used for mid_pred()
@@ -198,12 +196,21 @@ int enc_open(OutputStream *ost, AVFrame *frame)
AVCodecContext *dec_ctx = NULL;
const AVCodec *enc = enc_ctx->codec;
OutputFile *of = output_files[ost->file_index];
- FrameData *fd = frame ? frame_data(frame) : NULL;
+ FrameData *fd;
int ret;
if (e->opened)
return 0;
+ // frame is always non-NULL for audio and video
+ av_assert0(frame || (enc->type != AVMEDIA_TYPE_VIDEO && enc->type != AVMEDIA_TYPE_AUDIO));
+
+ if (frame) {
+ fd = frame_data(frame);
+ if (!fd)
+ return AVERROR(ENOMEM);
+ }
+
set_encoder_id(output_files[ost->file_index], ost);
if (ist) {
@@ -212,15 +219,15 @@ int enc_open(OutputStream *ost, AVFrame *frame)
switch (enc_ctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter);
- enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter);
- ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout);
+ enc_ctx->sample_fmt = frame->format;
+ enc_ctx->sample_rate = frame->sample_rate;
+ ret = av_channel_layout_copy(&enc_ctx->ch_layout, &frame->ch_layout);
if (ret < 0)
return ret;
if (ost->bits_per_raw_sample)
enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
- else if (fd)
+ else
enc_ctx->bits_per_raw_sample = FFMIN(fd->bits_per_raw_sample,
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
@@ -231,7 +238,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
case AVMEDIA_TYPE_VIDEO: {
AVRational fr = ost->frame_rate;
- if (!fr.num && fd)
+ if (!fr.num)
fr = fd->frame_rate_filter;
if (!fr.num && !ost->max_frame_rate.num) {
fr = (AVRational){25, 1};
@@ -261,7 +268,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
av_inv_q(fr);
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
- enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
+ enc_ctx->time_base = frame->time_base;
if ( av_q2d(enc_ctx->time_base) < 0.001 && ost->vsync_method != VSYNC_PASSTHROUGH
&& (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR ||
(ost->vsync_method == VSYNC_AUTO && !(of->format->flags & AVFMT_VARIABLE_FPS)))){
@@ -270,18 +277,18 @@ int enc_open(OutputStream *ost, AVFrame *frame)
"setting vsync/fps_mode to vfr\n");
}
- enc_ctx->width = av_buffersink_get_w(ost->filter->filter);
- enc_ctx->height = av_buffersink_get_h(ost->filter->filter);
+ enc_ctx->width = frame->width;
+ enc_ctx->height = frame->height;
enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
- av_buffersink_get_sample_aspect_ratio(ost->filter->filter);
+ frame->sample_aspect_ratio;
- enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter);
+ enc_ctx->pix_fmt = frame->format;
if (ost->bits_per_raw_sample)
enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
- else if (fd)
+ else
enc_ctx->bits_per_raw_sample = FFMIN(fd->bits_per_raw_sample,
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg_filter: make OutputFilter.filter private
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (16 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg_enc: initialize audio/video encoders from frame parameters Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg: add more structure to FrameData Anton Khirnov
` (2 subsequent siblings)
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
It should not be accessed from outside of filtering code.
---
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_filter.c | 18 ++++++++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3201163a4f..abea424486 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -283,7 +283,6 @@ typedef struct InputFilter {
} InputFilter;
typedef struct OutputFilter {
- AVFilterContext *filter;
struct OutputStream *ost;
struct FilterGraph *graph;
uint8_t *name;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 4955fe38dd..e14b8f0f3c 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -137,6 +137,8 @@ static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
typedef struct OutputFilterPriv {
OutputFilter ofilter;
+ AVFilterContext *filter;
+
/* desired output stream properties */
int format;
int width, height;
@@ -1060,7 +1062,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
char name[255];
snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
- ret = avfilter_graph_create_filter(&ofilter->filter,
+ ret = avfilter_graph_create_filter(&ofp->filter,
avfilter_get_by_name("buffersink"),
name, NULL, NULL, fg->graph);
@@ -1116,7 +1118,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
return ret;
- if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
+ if ((ret = avfilter_link(last_filter, pad_idx, ofp->filter, 0)) < 0)
return ret;
return 0;
@@ -1134,12 +1136,12 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
int ret;
snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
- ret = avfilter_graph_create_filter(&ofilter->filter,
+ ret = avfilter_graph_create_filter(&ofp->filter,
avfilter_get_by_name("abuffersink"),
name, NULL, NULL, fg->graph);
if (ret < 0)
return ret;
- if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
+ if ((ret = av_opt_set_int(ofp->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
return ret;
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
@@ -1222,7 +1224,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
if (ret < 0)
goto fail;
- if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
+ if ((ret = avfilter_link(last_filter, pad_idx, ofp->filter, 0)) < 0)
goto fail;
fail:
av_bprint_finalize(&args, NULL);
@@ -1470,7 +1472,7 @@ static void cleanup_filtergraph(FilterGraph *fg)
{
int i;
for (i = 0; i < fg->nb_outputs; i++)
- fg->outputs[i]->filter = (AVFilterContext *)NULL;
+ ofp_from_ofilter(fg->outputs[i])->filter = NULL;
for (i = 0; i < fg->nb_inputs; i++)
ifp_from_ifilter(fg->inputs[i])->filter = NULL;
avfilter_graph_free(&fg->graph);
@@ -1575,7 +1577,7 @@ static int configure_filtergraph(FilterGraph *fg)
for (i = 0; i < fg->nb_outputs; i++) {
OutputFilter *ofilter = fg->outputs[i];
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
- AVFilterContext *sink = ofilter->filter;
+ AVFilterContext *sink = ofp->filter;
ofp->format = av_buffersink_get_format(sink);
@@ -1705,9 +1707,9 @@ int reap_filters(int flush)
if (!ost->filter || !ost->filter->graph->graph)
continue;
- filter = ost->filter->filter;
fgp = fgp_from_fg(ost->filter->graph);
ofp = ofp_from_ofilter(ost->filter);
+ filter = ofp->filter;
filtered_frame = fgp->frame;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg: add more structure to FrameData
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (17 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg_filter: make OutputFilter.filter private Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg: rework -enc_time_base handling Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 22/22] doc/ffmpeg: fix -enc_time_base documentation Anton Khirnov
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
It now contains data from multiple sources, so group those items that
always come from the decoder. Also, initialize them to invalid values,
so that frames that did not originate from a decoder can be
distinguished.
---
fftools/ffmpeg.c | 8 +++++++-
fftools/ffmpeg.h | 10 +++++++---
fftools/ffmpeg_dec.c | 6 +++---
fftools/ffmpeg_enc.c | 6 +++---
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 013935d6ce..96fbcd626a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -434,9 +434,15 @@ InputStream *ist_iter(InputStream *prev)
FrameData *frame_data(AVFrame *frame)
{
if (!frame->opaque_ref) {
- frame->opaque_ref = av_buffer_allocz(sizeof(FrameData));
+ FrameData *fd;
+
+ frame->opaque_ref = av_buffer_allocz(sizeof(*fd));
if (!frame->opaque_ref)
return NULL;
+ fd = (FrameData*)frame->opaque_ref->data;
+
+ fd->dec.frame_num = UINT64_MAX;
+ fd->dec.pts = AV_NOPTS_VALUE;
}
return (FrameData*)frame->opaque_ref->data;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index abea424486..28474c1162 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -626,9 +626,13 @@ typedef struct OutputFile {
// optionally attached as opaque_ref to decoded AVFrames
typedef struct FrameData {
- uint64_t idx;
- int64_t pts;
- AVRational tb;
+ // properties that come from the decoder
+ struct {
+ uint64_t frame_num;
+
+ int64_t pts;
+ AVRational tb;
+ } dec;
AVRational frame_rate_filter;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 85bf8dc536..1ae8544394 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -610,9 +610,9 @@ static int packet_decode(InputStream *ist, const AVPacket *pkt, AVFrame *frame)
av_frame_unref(frame);
return AVERROR(ENOMEM);
}
- fd->pts = frame->pts;
- fd->tb = dec->pkt_timebase;
- fd->idx = dec->frame_num - 1;
+ fd->dec.pts = frame->pts;
+ fd->dec.tb = dec->pkt_timebase;
+ fd->dec.frame_num = dec->frame_num - 1;
fd->bits_per_raw_sample = dec->bits_per_raw_sample;
frame->time_base = dec->pkt_timebase;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1347493f9f..612bf23770 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -569,8 +569,8 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
if ((frame && frame->opaque_ref) || (pkt && pkt->opaque_ref)) {
fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data);
- tbi = fd->tb;
- ptsi = fd->pts;
+ tbi = fd->dec.tb;
+ ptsi = fd->dec.pts;
}
for (size_t i = 0; i < es->nb_components; i++) {
@@ -588,7 +588,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
case ENC_STATS_PTS_TIME_IN: avio_printf(io, "%g", ptsi == INT64_MAX ?
INFINITY : ptsi * av_q2d(tbi)); continue;
case ENC_STATS_FRAME_NUM: avio_printf(io, "%"PRIu64, frame_num); continue;
- case ENC_STATS_FRAME_NUM_IN: avio_printf(io, "%"PRIu64, fd ? fd->idx : -1); continue;
+ case ENC_STATS_FRAME_NUM_IN: avio_printf(io, "%"PRIu64, fd ? fd->dec.frame_num : -1); continue;
}
if (frame) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg: rework -enc_time_base handling
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (18 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg: add more structure to FrameData Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 22/22] doc/ffmpeg: fix -enc_time_base documentation Anton Khirnov
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Read the timebase from FrameData rather than the input stream. This
should fix #10393 and generally be more reliable.
Replace the use of '-1' to indicate demuxing timebase with the string
'demux'. Also allow to request filter timebase with
'-enc_time_base filter'.
---
doc/ffmpeg.texi | 7 ++++---
fftools/ffmpeg.h | 6 ++++++
fftools/ffmpeg_enc.c | 16 ++++++++++++++--
fftools/ffmpeg_mux_init.c | 29 ++++++++++++++++++-----------
tests/fate/video.mak | 2 +-
5 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 6769f8d305..59e9fbfcb2 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1812,10 +1812,11 @@ Assign a default value according to the media type.
For video - use 1/framerate, for audio - use 1/samplerate.
-@item -1
-Use the input stream timebase when possible.
+@item demux
+Use the timebase from the demuxer.
-If an input stream is not available, the default timebase will be used.
+@item filter
+Use the timebase from the filtergraph.
@item >0
Use the provided number as the timebase.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 28474c1162..59ce29d815 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -56,6 +56,7 @@
#define FFMPEG_ROTATION_METADATA 1
#define FFMPEG_OPT_QPHIST 1
#define FFMPEG_OPT_ADRIFT_THRESHOLD 1
+#define FFMPEG_OPT_ENC_TIME_BASE_NUM 1
enum VideoSyncMethod {
VSYNC_AUTO = -1,
@@ -66,6 +67,11 @@ enum VideoSyncMethod {
VSYNC_DROP,
};
+enum EncTimeBase {
+ ENC_TIME_BASE_DEMUX = -1,
+ ENC_TIME_BASE_FILTER = -2,
+};
+
#define MAX_STREAMS 1024 /* arbitrary sanity check value */
enum HWAccelID {
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 612bf23770..6fafd3ff60 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -264,8 +264,20 @@ int enc_open(OutputStream *ost, AVFrame *frame)
fr.num, fr.den, 65535);
}
- enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
- av_inv_q(fr);
+ if (ost->enc_timebase.num == ENC_TIME_BASE_DEMUX) {
+ if (fd->dec.tb.num <= 0 || fd->dec.tb.den <= 0) {
+ av_log(ost, AV_LOG_ERROR,
+ "Demuxing timebase not available - cannot use it for encoding\n");
+ return AVERROR(EINVAL);
+ }
+
+ enc_ctx->time_base = fd->dec.tb;
+ } else if (ost->enc_timebase.num == ENC_TIME_BASE_FILTER) {
+ enc_ctx->time_base = frame->time_base;
+ } else {
+ enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
+ av_inv_q(fr);
+ }
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
enc_ctx->time_base = frame->time_base;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6ab541d7c5..89da128881 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1140,20 +1140,27 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
if (enc_time_base) {
AVRational q;
- if (av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL) < 0 ||
- q.den <= 0) {
- av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
- exit_program(1);
- }
- if (q.num < 0) {
- if (!ost->ist) {
- av_log(ost, AV_LOG_FATAL,
- "Cannot use input stream timebase for encoding - "
- "no input stream available\n");
+ if (!strcmp(enc_time_base, "demux")) {
+ q = (AVRational){ ENC_TIME_BASE_DEMUX, 0 };
+ } else if (!strcmp(enc_time_base, "filter")) {
+ q = (AVRational){ ENC_TIME_BASE_FILTER, 0 };
+ } else {
+ ret = av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL);
+ if (ret < 0 || q.den <= 0
+#if !FFMPEG_OPT_ENC_TIME_BASE_NUM
+ || q.num < 0
+#endif
+ ) {
+ av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
exit_program(1);
}
- q = ost->ist->st->time_base;
+#if FFMPEG_OPT_ENC_TIME_BASE_NUM
+ if (q.num < 0)
+ av_log(ost, AV_LOG_WARNING, "-enc_time_base -1 is deprecated,"
+ " use -enc_timebase demux\n");
+#endif
}
+
ost->enc_timebase = q;
}
} else {
diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index a2011d0dad..4e7a77537f 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -270,7 +270,7 @@ FATE_VIDEO-$(call FRAMECRC, MXG, MXPEG) += fate-mxpeg
fate-mxpeg: CMD = framecrc -idct simple -flags +bitexact -i $(TARGET_SAMPLES)/mxpeg/m1.mxg -an
FATE_NUV += fate-nuv-rtjpeg
-fate-nuv-rtjpeg: CMD = framecrc -idct simple -i $(TARGET_SAMPLES)/nuv/Today.nuv -an -enc_time_base -1
+fate-nuv-rtjpeg: CMD = framecrc -idct simple -i $(TARGET_SAMPLES)/nuv/Today.nuv -an -enc_time_base demux
FATE_NUV += fate-nuv-rtjpeg-fh
fate-nuv-rtjpeg-fh: CMD = framecrc -idct simple -i $(TARGET_SAMPLES)/nuv/rtjpeg_frameheader.nuv -an
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread
* [FFmpeg-devel] [PATCH 22/22] doc/ffmpeg: fix -enc_time_base documentation
2023-07-07 9:48 [FFmpeg-devel] [PATCH 01/22] lavc/encode: print separate messages for unknown and unsupported formats Anton Khirnov
` (19 preceding siblings ...)
2023-07-07 9:48 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg: rework -enc_time_base handling Anton Khirnov
@ 2023-07-07 9:48 ` Anton Khirnov
20 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-07-07 9:48 UTC (permalink / raw)
To: ffmpeg-devel
Stop claiming the argument is always a floating point number, which
* confuses floating point and decimal numbers
* is not always true even accounting for the above point
---
doc/ffmpeg.texi | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 59e9fbfcb2..2273c39214 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1803,8 +1803,7 @@ Try to make the choice automatically, in order to generate a sane output.
Default value is -1.
@item -enc_time_base[:@var{stream_specifier}] @var{timebase} (@emph{output,per-stream})
-Set the encoder timebase. @var{timebase} is a floating point number,
-and can assume one of the following values:
+Set the encoder timebase. @var{timebase} can assume one of the following values:
@table @option
@item 0
@@ -1818,11 +1817,11 @@ Use the timebase from the demuxer.
@item filter
Use the timebase from the filtergraph.
-@item >0
+@item a positive number
Use the provided number as the timebase.
This field can be provided as a ratio of two integers (e.g. 1:24, 1:48000)
-or as a floating point number (e.g. 0.04166, 2.0833e-5)
+or as a decimal number (e.g. 0.04166, 2.0833e-5)
@end table
Default value is 0.
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 26+ messages in thread