* [FFmpeg-devel] [PATCH 02/11] fftools/ffmpeg: eliminate need_output()
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 03/11] fftools/ffmpeg_enc: stop configuring filter inputs from encoder flush Anton Khirnov
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
Replace it by simply calling choose_output() earlier.
---
fftools/ffmpeg.c | 38 ++++++++++----------------------------
1 file changed, 10 insertions(+), 28 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8c1c5b7fec..983573b991 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1667,19 +1667,6 @@ static int transcode_init(void)
return 0;
}
-/* Return 1 if there remain streams where more output is wanted, 0 otherwise. */
-static int need_output(void)
-{
- for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
- if (ost->finished)
- continue;
-
- return 1;
- }
-
- return 0;
-}
-
/**
* Select the output stream to process.
*
@@ -2044,22 +2031,11 @@ discard_packet:
*
* @return 0 for success, <0 for error
*/
-static int transcode_step(void)
+static int transcode_step(OutputStream *ost)
{
- OutputStream *ost;
InputStream *ist = NULL;
int ret;
- ret = choose_output(&ost);
- if (ret == AVERROR(EAGAIN)) {
- reset_eagain();
- av_usleep(10000);
- return 0;
- } else if (ret < 0) {
- av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
- return AVERROR_EOF;
- }
-
if (ost->filter && !ost->filter->graph->graph) {
if (ifilter_has_all_input_formats(ost->filter->graph)) {
ret = configure_filtergraph(ost->filter->graph);
@@ -2126,6 +2102,7 @@ static int transcode(void)
timer_start = av_gettime_relative();
while (!received_sigterm) {
+ OutputStream *ost;
int64_t cur_time= av_gettime_relative();
/* if 'q' pressed, exits */
@@ -2133,13 +2110,18 @@ static int transcode(void)
if (check_keyboard_interaction(cur_time) < 0)
break;
- /* check if there's any stream where output is still needed */
- if (!need_output()) {
+ ret = choose_output(&ost);
+ if (ret == AVERROR(EAGAIN)) {
+ reset_eagain();
+ av_usleep(10000);
+ continue;
+ } else if (ret < 0) {
av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n");
+ ret = 0;
break;
}
- ret = transcode_step();
+ ret = transcode_step(ost);
if (ret < 0 && ret != AVERROR_EOF) {
av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
break;
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 03/11] fftools/ffmpeg_enc: stop configuring filter inputs from encoder flush
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 02/11] fftools/ffmpeg: eliminate need_output() Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 04/11] fftools/ffmpeg_filter: take fallback parameters from decoder, not demuxer Anton Khirnov
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
When no frames are ever seen by an encoder, encoder flush will do a
last-ditch attempt to configure its source filtergraph in order to at
least get the stream parameters. This involves extracting demuxer
parameters from filtergraph source inputs, which is
* a bad layering violation
* probably unreachable, because decoders are flushed before encoders,
which should call ifilter_send_eof(), which will also set these
parameters; however due to complex control flow it is hard to be
entirely sure this code can never be triggered
Even if this code can actually be reached, it is probably better to
return an error as the comment above it says.
---
fftools/ffmpeg_enc.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5707199ac5..06a1cbc95f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1137,16 +1137,6 @@ void enc_flush(void)
"Finishing stream without any data written to it.\n");
if (ost->filter && !fg->graph) {
- int x;
- for (x = 0; x < fg->nb_inputs; x++) {
- InputFilter *ifilter = fg->inputs[x];
- if (ifilter->format < 0 &&
- ifilter_parameters_from_codecpar(ifilter, ifilter->ist->par) < 0) {
- av_log(ost, AV_LOG_ERROR, "Error copying paramerets from input stream\n");
- exit_program(1);
- }
- }
-
if (!ifilter_has_all_input_formats(fg))
continue;
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 04/11] fftools/ffmpeg_filter: take fallback parameters from decoder, not demuxer
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 02/11] fftools/ffmpeg: eliminate need_output() Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 03/11] fftools/ffmpeg_enc: stop configuring filter inputs from encoder flush Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 05/11] fftools/ffmpeg_filter: move InputFilter.eof to private data Anton Khirnov
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
When an input stream terminates and no frames were successfully decoded,
filtering code will currently configure the filtergraph using demuxer
stream parameters. Use decoder parameters instead, which should be more
reliable. Also, initialize them immediately when an input stream is
bound to a filtergraph input, so that these parameters are always
available (if at all) and filtering code does not need to reach into the
decoder at some arbitrary later point.
---
fftools/ffmpeg.c | 18 -------------
fftools/ffmpeg.h | 8 +++++-
fftools/ffmpeg_demux.c | 7 +++++
fftools/ffmpeg_filter.c | 59 ++++++++++++++++++++++++++++++++++++-----
4 files changed, 67 insertions(+), 25 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 983573b991..38569c60a4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -769,24 +769,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
first_report = 0;
}
-int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
-{
- int ret;
-
- // We never got any input. Set a fake format, which will
- // come from libavformat.
- ifilter->format = par->format;
- ifilter->sample_rate = par->sample_rate;
- ifilter->width = par->width;
- ifilter->height = par->height;
- ifilter->sample_aspect_ratio = par->sample_aspect_ratio;
- ret = av_channel_layout_copy(&ifilter->ch_layout, &par->ch_layout);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
static void check_decode_result(InputStream *ist, int *got_output, int ret)
{
if (*got_output || ret<0)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ec4c580b91..525a00bfcb 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -791,7 +791,13 @@ void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub);
int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference);
int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb);
-int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par);
+/**
+ * Set up fallback filtering parameters from a decoder context. They will only
+ * be used if no frames are ever sent on this input, otherwise the actual
+ * parameters are taken from the frame.
+ */
+int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec);
+
int ifilter_has_all_input_formats(FilterGraph *fg);
/**
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6727193697..ad283356ba 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -586,10 +586,17 @@ void ist_output_add(InputStream *ist, OutputStream *ost)
void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
{
+ int ret;
+
ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER);
GROW_ARRAY(ist->filters, ist->nb_filters);
ist->filters[ist->nb_filters - 1] = ifilter;
+
+ // initialize fallback parameters for filtering
+ ret = ifilter_parameters_from_dec(ifilter, ist->dec_ctx);
+ if (ret < 0)
+ report_and_exit(ret);
}
static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8c408eb7c4..3fad38f782 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -58,6 +58,19 @@ typedef struct InputFilterPriv {
AVRational time_base;
AVFifo *frame_queue;
+
+ // fallback parameters to use when no input is ever sent
+ struct {
+ int format;
+
+ int width;
+ int height;
+ AVRational sample_aspect_ratio;
+
+ int sample_rate;
+ AVChannelLayout ch_layout;
+ } fallback;
+
} InputFilterPriv;
static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
@@ -225,6 +238,8 @@ static InputFilter *ifilter_alloc(FilterGraph *fg)
ifilter->graph = fg;
ifilter->format = -1;
+ ifp->fallback.format = -1;
+
ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifp->frame_queue)
report_and_exit(AVERROR(ENOMEM));
@@ -260,6 +275,9 @@ void fg_free(FilterGraph **pfg)
avsubtitle_free(&sub);
av_fifo_freep2(&ist->sub2video.sub_queue);
}
+
+ av_channel_layout_uninit(&ifp->fallback.ch_layout);
+
av_buffer_unref(&ifilter->hw_frames_ctx);
av_freep(&ifilter->name);
av_freep(&fg->inputs[j]);
@@ -1361,6 +1379,29 @@ fail:
return ret;
}
+int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec)
+{
+ InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
+
+ if (dec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ ifp->fallback.format = dec->pix_fmt;
+ ifp->fallback.width = dec->width;
+ ifp->fallback.height = dec->height;
+ ifp->fallback.sample_aspect_ratio = dec->sample_aspect_ratio;
+ } else {
+ int ret;
+
+ ifp->fallback.format = dec->sample_fmt;
+ ifp->fallback.sample_rate = dec->sample_rate;
+
+ ret = av_channel_layout_copy(&ifp->fallback.ch_layout, &dec->ch_layout);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
{
AVFrameSideData *sd;
@@ -1469,12 +1510,18 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb)
if (ret < 0)
return ret;
} else {
- // the filtergraph was never configured
- if (ifilter->format < 0) {
- ret = ifilter_parameters_from_codecpar(ifilter, ifilter->ist->par);
- if (ret < 0)
- return ret;
- }
+ // the filtergraph was never configured, use the fallback parameters
+ ifilter->format = ifp->fallback.format;
+ ifilter->sample_rate = ifp->fallback.sample_rate;
+ ifilter->width = ifp->fallback.width;
+ ifilter->height = ifp->fallback.height;
+ ifilter->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio;
+
+ ret = av_channel_layout_copy(&ifilter->ch_layout,
+ &ifp->fallback.ch_layout);
+ if (ret < 0)
+ return ret;
+
if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) {
av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index);
return AVERROR_INVALIDDATA;
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 05/11] fftools/ffmpeg_filter: move InputFilter.eof to private data
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (2 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 04/11] fftools/ffmpeg_filter: take fallback parameters from decoder, not demuxer Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 06/11] fftools/ffmpeg_filter: move InputFilter.displaymatrix " Anton Khirnov
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
It is not used outside of ffmpeg_filter.
---
fftools/ffmpeg.h | 2 --
fftools/ffmpeg_filter.c | 7 +++++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 525a00bfcb..0231ebc84f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -292,8 +292,6 @@ typedef struct InputFilter {
AVBufferRef *hw_frames_ctx;
int32_t *displaymatrix;
-
- int eof;
} InputFilter;
typedef struct OutputFilter {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3fad38f782..5d9242f476 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -55,6 +55,8 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg)
typedef struct InputFilterPriv {
InputFilter ifilter;
+ int eof;
+
AVRational time_base;
AVFifo *frame_queue;
@@ -1353,7 +1355,8 @@ int configure_filtergraph(FilterGraph *fg)
/* send the EOFs for the finished inputs */
for (i = 0; i < fg->nb_inputs; i++) {
- if (fg->inputs[i]->eof) {
+ InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]);
+ if (ifp->eof) {
ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL);
if (ret < 0)
goto fail;
@@ -1500,7 +1503,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb)
InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
int ret;
- ifilter->eof = 1;
+ ifp->eof = 1;
if (ifilter->filter) {
pts = av_rescale_q_rnd(pts, tb, ifp->time_base,
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 06/11] fftools/ffmpeg_filter: move InputFilter.displaymatrix to private data
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (3 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 05/11] fftools/ffmpeg_filter: move InputFilter.eof to private data Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 07/11] fftools/ffmpeg_filter: move InputFilter.hw_frames_ctx " Anton Khirnov
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
It is not used outside of ffmpeg_filter.
---
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_filter.c | 15 +++++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0231ebc84f..8a2254d2a8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -291,7 +291,6 @@ typedef struct InputFilter {
AVChannelLayout ch_layout;
AVBufferRef *hw_frames_ctx;
- int32_t *displaymatrix;
} InputFilter;
typedef struct OutputFilter {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 5d9242f476..087ef8b894 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -61,6 +61,8 @@ typedef struct InputFilterPriv {
AVFifo *frame_queue;
+ int32_t *displaymatrix;
+
// fallback parameters to use when no input is ever sent
struct {
int format;
@@ -270,7 +272,7 @@ void fg_free(FilterGraph **pfg)
av_frame_free(&frame);
av_fifo_freep2(&ifp->frame_queue);
}
- av_freep(&ifilter->displaymatrix);
+ av_freep(&ifp->displaymatrix);
if (ist->sub2video.sub_queue) {
AVSubtitle sub;
while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
@@ -1061,7 +1063,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
// TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
if (ist->autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
- int32_t *displaymatrix = ifilter->displaymatrix;
+ int32_t *displaymatrix = ifp->displaymatrix;
double theta;
if (!displaymatrix)
@@ -1407,6 +1409,7 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec)
static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
{
+ InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
AVFrameSideData *sd;
int ret;
@@ -1423,10 +1426,10 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
if (ret < 0)
return ret;
- av_freep(&ifilter->displaymatrix);
+ av_freep(&ifp->displaymatrix);
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
if (sd)
- ifilter->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
+ ifp->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
if (frame->hw_frames_ctx) {
ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
@@ -1567,9 +1570,9 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
need_reinit = 1;
if (sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX)) {
- if (!ifilter->displaymatrix || memcmp(sd->data, ifilter->displaymatrix, sizeof(int32_t) * 9))
+ if (!ifp->displaymatrix || memcmp(sd->data, ifp->displaymatrix, sizeof(int32_t) * 9))
need_reinit = 1;
- } else if (ifilter->displaymatrix)
+ } else if (ifp->displaymatrix)
need_reinit = 1;
if (need_reinit) {
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 07/11] fftools/ffmpeg_filter: move InputFilter.hw_frames_ctx to private data
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (4 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 06/11] fftools/ffmpeg_filter: move InputFilter.displaymatrix " Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 08/11] fftools/ffmpeg_filter: use av_buffer_replace() to improve code Anton Khirnov
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
It is not used outside of ffmpeg_filter.
---
fftools/ffmpeg.h | 2 --
fftools/ffmpeg_filter.c | 16 +++++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8a2254d2a8..c7e225d1a0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -289,8 +289,6 @@ typedef struct InputFilter {
int sample_rate;
AVChannelLayout ch_layout;
-
- AVBufferRef *hw_frames_ctx;
} InputFilter;
typedef struct OutputFilter {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 087ef8b894..34c51c23d9 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -61,6 +61,8 @@ typedef struct InputFilterPriv {
AVFifo *frame_queue;
+ AVBufferRef *hw_frames_ctx;
+
int32_t *displaymatrix;
// fallback parameters to use when no input is ever sent
@@ -282,7 +284,7 @@ void fg_free(FilterGraph **pfg)
av_channel_layout_uninit(&ifp->fallback.ch_layout);
- av_buffer_unref(&ifilter->hw_frames_ctx);
+ av_buffer_unref(&ifp->hw_frames_ctx);
av_freep(&ifilter->name);
av_freep(&fg->inputs[j]);
}
@@ -1051,7 +1053,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
args.str, NULL, fg->graph)) < 0)
goto fail;
- par->hw_frames_ctx = ifilter->hw_frames_ctx;
+ par->hw_frames_ctx = ifp->hw_frames_ctx;
ret = av_buffersrc_parameters_set(ifilter->filter, par);
if (ret < 0)
goto fail;
@@ -1413,7 +1415,7 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
AVFrameSideData *sd;
int ret;
- av_buffer_unref(&ifilter->hw_frames_ctx);
+ av_buffer_unref(&ifp->hw_frames_ctx);
ifilter->format = frame->format;
@@ -1432,8 +1434,8 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
ifp->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
if (frame->hw_frames_ctx) {
- ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
- if (!ifilter->hw_frames_ctx)
+ ifp->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
+ if (!ifp->hw_frames_ctx)
return AVERROR(ENOMEM);
}
@@ -1565,8 +1567,8 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
if (!ifilter->ist->reinit_filters && fg->graph)
need_reinit = 0;
- if (!!ifilter->hw_frames_ctx != !!frame->hw_frames_ctx ||
- (ifilter->hw_frames_ctx && ifilter->hw_frames_ctx->data != frame->hw_frames_ctx->data))
+ if (!!ifp->hw_frames_ctx != !!frame->hw_frames_ctx ||
+ (ifp->hw_frames_ctx && ifp->hw_frames_ctx->data != frame->hw_frames_ctx->data))
need_reinit = 1;
if (sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX)) {
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 08/11] fftools/ffmpeg_filter: use av_buffer_replace() to improve code
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (5 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 07/11] fftools/ffmpeg_filter: move InputFilter.hw_frames_ctx " Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 09/11] fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter Anton Khirnov
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
It is shorter and more efficient.
---
fftools/ffmpeg_filter.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 34c51c23d9..0165be8f77 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1415,7 +1415,9 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
AVFrameSideData *sd;
int ret;
- av_buffer_unref(&ifp->hw_frames_ctx);
+ ret = av_buffer_replace(&ifp->hw_frames_ctx, frame->hw_frames_ctx);
+ if (ret < 0)
+ return ret;
ifilter->format = frame->format;
@@ -1433,12 +1435,6 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
if (sd)
ifp->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9);
- if (frame->hw_frames_ctx) {
- ifp->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
- if (!ifp->hw_frames_ctx)
- return AVERROR(ENOMEM);
- }
-
return 0;
}
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 09/11] fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (6 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 08/11] fftools/ffmpeg_filter: use av_buffer_replace() to improve code Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_filter: use InputFilterPriv.eof instead of InputFile.eof_reached Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg: discard packets for unused streams in demuxing thread Anton Khirnov
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
This code more properly belongs there.
---
fftools/ffmpeg.c | 25 +------------------------
fftools/ffmpeg_filter.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38569c60a4..1ae9445b5d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2018,34 +2018,11 @@ static int transcode_step(OutputStream *ost)
InputStream *ist = NULL;
int ret;
- if (ost->filter && !ost->filter->graph->graph) {
- if (ifilter_has_all_input_formats(ost->filter->graph)) {
- ret = configure_filtergraph(ost->filter->graph);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
- return ret;
- }
- }
- }
-
- if (ost->filter && ost->filter->graph->graph) {
+ if (ost->filter) {
if ((ret = fg_transcode_step(ost->filter->graph, &ist)) < 0)
return ret;
if (!ist)
return 0;
- } else if (ost->filter) {
- int i;
- for (i = 0; i < ost->filter->graph->nb_inputs; i++) {
- InputFilter *ifilter = ost->filter->graph->inputs[i];
- if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
- ist = ifilter->ist;
- break;
- }
- }
- if (!ist) {
- ost->inputs_done = 1;
- return 0;
- }
} else {
ist = ost->ist;
av_assert0(ist);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0165be8f77..634315fa34 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1623,6 +1623,33 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
InputFilter *ifilter;
InputStream *ist;
+ if (!graph->graph && ifilter_has_all_input_formats(graph)) {
+ // graph has not been configured yet, but everything is ready;
+ // this can happen for graphs with no inputs, or when some input
+ // EOF'ed with zero frames and fallback parameters were used
+ ret = configure_filtergraph(graph);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
+ return ret;
+ }
+ }
+
+ if (!graph->graph) {
+ for (int i = 0; i < graph->nb_inputs; i++) {
+ InputFilter *ifilter = graph->inputs[i];
+ if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
+ *best_ist = ifilter->ist;
+ return 0;
+ }
+ }
+
+ // graph not configured, but all inputs are either initialized or EOF
+ for (int i = 0; i < graph->nb_outputs; i++)
+ graph->outputs[i]->ost->inputs_done = 1;
+
+ return 0;
+ }
+
*best_ist = NULL;
ret = avfilter_graph_request_oldest(graph->graph);
if (ret >= 0)
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_filter: use InputFilterPriv.eof instead of InputFile.eof_reached
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (7 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 09/11] fftools/ffmpeg: move unconfigured graph handling to ffmpeg_filter Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg: discard packets for unused streams in demuxing thread Anton Khirnov
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
The two checks using eof_reached are testing whether more input can
possibly appear on this filtergraph input. InputFilterPriv.eof is the
more authoritative source for this information.
---
fftools/ffmpeg_filter.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 634315fa34..aea951a2da 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1620,7 +1620,6 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
{
int i, ret;
int nb_requests, nb_requests_max = 0;
- InputFilter *ifilter;
InputStream *ist;
if (!graph->graph && ifilter_has_all_input_formats(graph)) {
@@ -1637,7 +1636,8 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
if (!graph->graph) {
for (int i = 0; i < graph->nb_inputs; i++) {
InputFilter *ifilter = graph->inputs[i];
- if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
+ InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
+ if (!ifilter->ist->got_output && !ifp->eof) {
*best_ist = ifilter->ist;
return 0;
}
@@ -1665,10 +1665,11 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
return ret;
for (i = 0; i < graph->nb_inputs; i++) {
- ifilter = graph->inputs[i];
+ InputFilter *ifilter = graph->inputs[i];
+ InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
+
ist = ifilter->ist;
- if (input_files[ist->file_index]->eagain ||
- input_files[ist->file_index]->eof_reached)
+ if (input_files[ist->file_index]->eagain || ifp->eof)
continue;
nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->filter);
if (nb_requests > nb_requests_max) {
--
2.39.2
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg: discard packets for unused streams in demuxing thread
2023-05-05 9:07 [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() Anton Khirnov
` (8 preceding siblings ...)
2023-05-05 9:07 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_filter: use InputFilterPriv.eof instead of InputFile.eof_reached Anton Khirnov
@ 2023-05-05 9:07 ` Anton Khirnov
9 siblings, 0 replies; 11+ messages in thread
From: Anton Khirnov @ 2023-05-05 9:07 UTC (permalink / raw)
To: ffmpeg-devel
Avoids the pointless overhead of transferring them to the main thread.
---
fftools/ffmpeg.c | 4 ----
fftools/ffmpeg_demux.c | 3 ++-
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1ae9445b5d..0edcd3466e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1961,9 +1961,6 @@ static int process_input(int file_index)
ist->data_size += pkt->size;
ist->nb_packets++;
- if (ist->discard)
- goto discard_packet;
-
/* add the stream-global side data to the first packet */
if (ist->nb_packets == 1) {
for (i = 0; i < ist->st->nb_side_data; i++) {
@@ -2002,7 +1999,6 @@ static int process_input(int file_index)
process_input_packet(ist, pkt, 0);
-discard_packet:
av_packet_free(&pkt);
return 0;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index ad283356ba..6ba9aaca33 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -318,7 +318,8 @@ static void *input_thread(void *arg)
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
- if (pkt->stream_index >= f->nb_streams) {
+ if (pkt->stream_index >= f->nb_streams ||
+ f->streams[pkt->stream_index]->discard) {
report_new_stream(d, pkt);
av_packet_unref(pkt);
continue;
--
2.39.2
_______________________________________________
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] 11+ messages in thread