* [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 03/23] fftools/ffmpeg_filter: drop a write-only variable Anton Khirnov
` (20 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Stop assuming the encoder knows the muxing timebase, which does not
always have to hold (e.g. due to bitstream filters).
---
fftools/ffmpeg_enc.c | 4 ----
fftools/ffmpeg_mux.c | 5 +++++
fftools/ffmpeg_mux.h | 3 +++
fftools/ffmpeg_mux_init.c | 10 ++++++----
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f3e291a9e4..fab71ca0c0 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -445,10 +445,6 @@ int enc_open(OutputStream *ost, AVFrame *frame)
if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1});
- // copy estimated duration as a hint to the muxer
- if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
- ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
-
ost->mux_timebase = enc_ctx->time_base;
ret = of_stream_init(of, ost);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index feb014ca31..121796a55a 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -666,6 +666,11 @@ int of_stream_init(OutputFile *of, OutputStream *ost)
if (ret < 0)
return ret;
+ if (ms->stream_duration) {
+ ost->st->duration = av_rescale_q(ms->stream_duration, ms->stream_duration_tb,
+ ost->st->time_base);
+ }
+
ost->initialized = 1;
return mux_check_init(mux);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index 7e0454dfba..bee7addd6a 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -69,6 +69,9 @@ typedef struct MuxStream {
* used for making up missing dts values */
int64_t last_mux_dts;
+ int64_t stream_duration;
+ AVRational stream_duration_tb;
+
// audio streamcopy - state for av_rescale_delta()
int64_t ts_rescale_delta_last;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 4fc6f0fb46..33c93e40f2 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -914,10 +914,6 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
}
- // copy estimated duration as a hint to the muxer
- if (ost->st->duration <= 0 && ist->st->duration > 0)
- ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
-
if (!ms->copy_prior_start) {
ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ?
0 : mux->of.start_time;
@@ -1283,6 +1279,12 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
exit_program(1);
}
+ // copy estimated duration as a hint to the muxer
+ if (ost->ist && ost->ist->st->duration > 0) {
+ ms->stream_duration = ist->st->duration;
+ ms->stream_duration_tb = ist->st->time_base;
+ }
+
return ost;
}
--
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/23] fftools/ffmpeg_filter: drop a write-only variable
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012 Anton Khirnov
` (19 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_filter.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index cef4b5d000..0e9ad5f9f7 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -296,7 +296,6 @@ typedef struct OutputFilter {
/* desired output stream properties */
int width, height;
- AVRational frame_rate;
int format;
int sample_rate;
AVChannelLayout ch_layout;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c3075ef854..287b1e6f9d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -654,7 +654,6 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
switch (ost->enc_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- ofilter->frame_rate = ost->frame_rate;
ofilter->width = ost->enc_ctx->width;
ofilter->height = ost->enc_ctx->height;
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
--
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/23] fftools/ffmpeg_filter: drop a block disabled since 2012
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 03/23] fftools/ffmpeg_filter: drop a write-only variable Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate Anton Khirnov
` (18 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 287b1e6f9d..1150f6fc65 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1075,26 +1075,6 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
pad_idx = 0;
}
- if (ost->frame_rate.num && 0) {
- AVFilterContext *fps;
- char args[255];
-
- snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
- ost->frame_rate.den);
- snprintf(name, sizeof(name), "fps_out_%d_%d",
- ost->file_index, ost->index);
- ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
- name, args, NULL, fg->graph);
- if (ret < 0)
- return ret;
-
- ret = avfilter_link(last_filter, pad_idx, fps, 0);
- if (ret < 0)
- return ret;
- last_filter = fps;
- pad_idx = 0;
- }
-
snprintf(name, sizeof(name), "trim_out_%d_%d",
ost->file_index, ost->index);
ret = insert_trim(of->start_time, of->recording_time,
--
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/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (2 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012 Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code Anton Khirnov
` (17 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
For decoding, this field is used by the decoder to export information
to the caller; it does not make sense for the caller to set it.
---
fftools/ffmpeg_demux.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 5c15b8bad3..5e5f106368 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1194,9 +1194,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
switch (par->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- // avformat_find_stream_info() doesn't set this for us anymore.
- ist->dec_ctx->framerate = st->avg_frame_rate;
-
MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
if (framerate && av_parse_video_rate(&ist->framerate,
framerate) < 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 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (3 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy Anton Khirnov
` (16 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
The code will currently add a small offset to avoid exact midpoints, but
this can cause inexact results when a float timestamp is exactly
representable as an integer.
Fixes off-by-one in the first frame duration in multiple FATE tests.
---
fftools/ffmpeg_enc.c | 6 ++++--
tests/ref/fate/apng-osample | 2 +-
tests/ref/fate/film-cvid | 2 +-
tests/ref/fate/filter-concat-vfr | 2 +-
tests/ref/fate/gif-gray | 2 +-
5 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index fab71ca0c0..d390e384ed 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -888,9 +888,11 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
float_pts = av_rescale_q(frame->pts, filter_tb, tb) -
av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
float_pts /= 1 << extra_bits;
- // avoid exact midoints to reduce the chance of rounding differences, this
+ // when float_pts is not exactly an integer,
+ // avoid exact midpoints to reduce the chance of rounding differences, this
// can be removed in case the fps code is changed to work with integers
- float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
+ if (float_pts != llrint(float_pts))
+ float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) -
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
diff --git a/tests/ref/fate/apng-osample b/tests/ref/fate/apng-osample
index c91dd5284d..6cf74a99ee 100644
--- a/tests/ref/fate/apng-osample
+++ b/tests/ref/fate/apng-osample
@@ -3,7 +3,7 @@
#codec_id 0: rawvideo
#dimensions 0: 116x135
#sar 0: 0/1
-0, 0, 0, 2, 62640, 0x31eb581d
+0, 0, 0, 3, 62640, 0x31eb581d
0, 3, 3, 3, 62640, 0x29e11b82
0, 6, 6, 3, 62640, 0x207ed588
0, 9, 9, 3, 62640, 0x3845c906
diff --git a/tests/ref/fate/film-cvid b/tests/ref/fate/film-cvid
index 60bbc192d8..428cb6e9f0 100644
--- a/tests/ref/fate/film-cvid
+++ b/tests/ref/fate/film-cvid
@@ -3,7 +3,7 @@
#codec_id 0: rawvideo
#dimensions 0: 320x224
#sar 0: 0/1
-0, 0, 0, 1, 215040, 0x067c5362
+0, 0, 0, 2, 215040, 0x067c5362
0, 2, 2, 2, 215040, 0xd9eacb98
0, 4, 4, 2, 215040, 0x3c8a4cbd
0, 6, 6, 2, 215040, 0xbdf996e1
diff --git a/tests/ref/fate/filter-concat-vfr b/tests/ref/fate/filter-concat-vfr
index 66e9007da8..3d984a4968 100644
--- a/tests/ref/fate/filter-concat-vfr
+++ b/tests/ref/fate/filter-concat-vfr
@@ -8,7 +8,7 @@
#codec_id 1: pcm_s16le
#sample_rate 1: 44100
#channel_layout_name 1: mono
-0, 0, 0, 199999, 230400, 0x88c4d19a
+0, 0, 0, 200000, 230400, 0x88c4d19a
1, 0, 0, 1024, 2048, 0xb3f10192
1, 1024, 1024, 1024, 2048, 0xb340fe4e
1, 2048, 2048, 1024, 2048, 0x0a5f0111
diff --git a/tests/ref/fate/gif-gray b/tests/ref/fate/gif-gray
index aa3969212d..c246d8a670 100644
--- a/tests/ref/fate/gif-gray
+++ b/tests/ref/fate/gif-gray
@@ -3,7 +3,7 @@
#codec_id 0: rawvideo
#dimensions 0: 480x360
#sar 0: 0/1
-0, 0, 0, 4, 691200, 0xef6c0f3d
+0, 0, 0, 5, 691200, 0xef6c0f3d
0, 5, 5, 2, 691200, 0xc18b32de
0, 7, 7, 2, 691200, 0x2395a3d7
0, 9, 9, 2, 691200, 0x81dc3cf2
--
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 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (4 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks Anton Khirnov
` (15 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
The values currently written into it are not used after
streamcopy_init(), so it is better to confine them to that function.
---
fftools/ffmpeg_mux_init.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 33c93e40f2..b5295ad445 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -861,6 +861,9 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
AVCodecContext *codec_ctx = NULL;
AVDictionary *codec_opts = NULL;
+
+ AVRational fr = ost->frame_rate;
+
int ret = 0;
codec_ctx = avcodec_alloc_context3(NULL);
@@ -893,11 +896,11 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
par->codec_tag = codec_tag;
- if (!ost->frame_rate.num)
- ost->frame_rate = ist->framerate;
+ if (!fr.num)
+ fr = ist->framerate;
- if (ost->frame_rate.num)
- ost->st->avg_frame_rate = ost->frame_rate;
+ if (fr.num)
+ ost->st->avg_frame_rate = fr;
else
ost->st->avg_frame_rate = ist->st->avg_frame_rate;
@@ -908,8 +911,8 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
// copy timebase while removing common factors
if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
- if (ost->frame_rate.num)
- ost->st->time_base = av_inv_q(ost->frame_rate);
+ if (fr.num)
+ ost->st->time_base = av_inv_q(fr);
else
ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
}
--
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/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (5 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded Anton Khirnov
` (14 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
There is no meaningful reason for them to be separated.
---
fftools/ffmpeg_enc.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index d390e384ed..07928b3557 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -219,7 +219,24 @@ int enc_open(OutputStream *ost, AVFrame *frame)
dec_ctx = ist->dec_ctx;
}
- if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+ 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);
+ if (ret < 0)
+ return ret;
+
+ if (ost->bits_per_raw_sample)
+ enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
+ else if (dec_ctx && ost->filter->graph->is_meta)
+ enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
+ av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
+
+ init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
+ break;
+
+ case AVMEDIA_TYPE_VIDEO:
if (!ost->frame_rate.num)
ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
if (!ost->frame_rate.num && !ost->max_frame_rate.num) {
@@ -245,26 +262,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
av_reduce(&ost->frame_rate.num, &ost->frame_rate.den,
ost->frame_rate.num, ost->frame_rate.den, 65535);
}
- }
- 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);
- if (ret < 0)
- return ret;
-
- if (ost->bits_per_raw_sample)
- enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
- else if (dec_ctx && ost->filter->graph->is_meta)
- enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
- av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
-
- init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
- break;
-
- case AVMEDIA_TYPE_VIDEO:
init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
--
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/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (6 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation Anton Khirnov
` (13 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
It has no effect otherwise.
---
fftools/ffmpeg_mux_init.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b5295ad445..d0b89cd188 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1073,6 +1073,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
AVIOContext *s = NULL;
char *buf = NULL, *arg = NULL, *preset = NULL;
const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
+ const char *enc_time_base = NULL;
ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
oc, st, enc->codec);
@@ -1139,6 +1140,17 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
if (ret < 0)
exit_program(1);
}
+
+ 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);
+ }
+ ost->enc_timebase = q;
+ }
} else {
ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
}
@@ -1162,17 +1174,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
st->time_base = q;
}
- MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
- if (time_base) {
- AVRational q;
- if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
- q.den <= 0) {
- av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
- exit_program(1);
- }
- ost->enc_timebase = q;
- }
-
ms->max_frames = INT64_MAX;
MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
for (i = 0; i<o->nb_max_frames; 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 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (7 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers Anton Khirnov
` (12 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
There is no reason to postpone it until opening the encoder. Also, abort
when the input stream is unknown, rather than disregard an explicit
request from the user.
---
fftools/ffmpeg_enc.c | 11 -----------
fftools/ffmpeg_mux_init.c | 9 +++++++++
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 07928b3557..04d2c3c201 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -179,7 +179,6 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
{
- InputStream *ist = ost->ist;
AVCodecContext *enc_ctx = ost->enc_ctx;
if (ost->enc_timebase.num > 0) {
@@ -187,16 +186,6 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba
return;
}
- if (ost->enc_timebase.num < 0) {
- if (ist) {
- enc_ctx->time_base = ist->st->time_base;
- return;
- }
-
- av_log(ost, AV_LOG_WARNING,
- "Input stream data not available, using default time base\n");
- }
-
enc_ctx->time_base = default_time_base;
}
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d0b89cd188..c49f906dc7 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1149,6 +1149,15 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
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");
+ exit_program(1);
+ }
+ q = ost->ist->st->time_base;
+ }
ost->enc_timebase = q;
}
} else {
--
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/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (8 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate Anton Khirnov
` (11 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
The function now reduces to a ternary operator, so it is shorter and
clearer to eliminate it.
---
fftools/ffmpeg_enc.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 04d2c3c201..4a5ae3aa1b 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -177,18 +177,6 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
}
-static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
-{
- AVCodecContext *enc_ctx = ost->enc_ctx;
-
- if (ost->enc_timebase.num > 0) {
- enc_ctx->time_base = ost->enc_timebase;
- return;
- }
-
- enc_ctx->time_base = default_time_base;
-}
-
int enc_open(OutputStream *ost, AVFrame *frame)
{
InputStream *ist = ost->ist;
@@ -222,7 +210,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
- init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
+ enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
+ av_make_q(1, enc_ctx->sample_rate);
break;
case AVMEDIA_TYPE_VIDEO:
@@ -252,7 +241,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
ost->frame_rate.num, ost->frame_rate.den, 65535);
}
- init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
+ enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
+ av_inv_q(ost->frame_rate);
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
--
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/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (9 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 15:16 ` Paul B Mahol
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding Anton Khirnov
` (10 subsequent siblings)
21 siblings, 1 reply; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
There is no reason to expect input frame durations to match output
framerate.
---
fftools/ffmpeg_enc.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 4a5ae3aa1b..5be6e9332a 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1042,9 +1042,6 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
if (frame)
duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base));
- if (duration <= 0 && ost->frame_rate.num)
- duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
-
frame_rate = av_buffersink_get_frame_rate(filter);
if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0)
duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
--
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/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (10 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 14/23] fftools/ffmpeg: convert timestamps inside the muxer Anton Khirnov
` (9 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
The values currently written into it are not used after
enc_open(), so it is better to confine them to that function.
---
fftools/ffmpeg_enc.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5be6e9332a..1b0410ae74 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -214,11 +214,13 @@ int enc_open(OutputStream *ost, AVFrame *frame)
av_make_q(1, enc_ctx->sample_rate);
break;
- case AVMEDIA_TYPE_VIDEO:
- if (!ost->frame_rate.num)
- ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
- if (!ost->frame_rate.num && !ost->max_frame_rate.num) {
- ost->frame_rate = (AVRational){25, 1};
+ case AVMEDIA_TYPE_VIDEO: {
+ AVRational fr = ost->frame_rate;
+
+ if (!fr.num)
+ fr = av_buffersink_get_frame_rate(ost->filter->filter);
+ if (!fr.num && !ost->max_frame_rate.num) {
+ fr = (AVRational){25, 1};
av_log(ost, AV_LOG_WARNING,
"No information "
"about the input framerate is available. Falling "
@@ -227,22 +229,22 @@ int enc_open(OutputStream *ost, AVFrame *frame)
}
if (ost->max_frame_rate.num &&
- (av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
- !ost->frame_rate.den))
- ost->frame_rate = ost->max_frame_rate;
+ (av_q2d(fr) > av_q2d(ost->max_frame_rate) ||
+ !fr.den))
+ fr = ost->max_frame_rate;
if (enc->supported_framerates && !ost->force_fps) {
- int idx = av_find_nearest_q_idx(ost->frame_rate, enc->supported_framerates);
- ost->frame_rate = enc->supported_framerates[idx];
+ int idx = av_find_nearest_q_idx(fr, enc->supported_framerates);
+ fr = enc->supported_framerates[idx];
}
// reduce frame rate for mpeg4 to be within the spec limits
if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) {
- av_reduce(&ost->frame_rate.num, &ost->frame_rate.den,
- ost->frame_rate.num, ost->frame_rate.den, 65535);
+ av_reduce(&fr.num, &fr.den,
+ fr.num, fr.den, 65535);
}
enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
- av_inv_q(ost->frame_rate);
+ 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);
@@ -277,9 +279,9 @@ int enc_open(OutputStream *ost, AVFrame *frame)
enc_ctx->chroma_sample_location = frame->chroma_location;
}
- enc_ctx->framerate = ost->frame_rate;
+ enc_ctx->framerate = fr;
- ost->st->avg_frame_rate = ost->frame_rate;
+ ost->st->avg_frame_rate = fr;
// Field order: autodetection
if (frame) {
@@ -307,6 +309,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
}
break;
+ }
case AVMEDIA_TYPE_SUBTITLE:
enc_ctx->time_base = AV_TIME_BASE_Q;
if (!enc_ctx->width) {
--
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 14/23] fftools/ffmpeg: convert timestamps inside the muxer
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (11 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame Anton Khirnov
` (8 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.
---
fftools/ffmpeg_enc.c | 17 ++---------------
fftools/ffmpeg_mux.c | 6 ++++++
2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1b0410ae74..f6431b29d1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -512,8 +512,8 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
}
av_shrink_packet(pkt, subtitle_out_size);
- pkt->time_base = ost->mux_timebase;
- pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, pkt->time_base);
+ pkt->time_base = AV_TIME_BASE_Q;
+ pkt->pts = sub->pts;
pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, pkt->time_base);
if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
/* XXX: the pts correction is handled here. Maybe handling
@@ -735,19 +735,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base));
}
- av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
- pkt->time_base = ost->mux_timebase;
-
- if (debug_ts) {
- av_log(ost, AV_LOG_INFO, "encoder -> type:%s "
- "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
- "duration:%s duration_time:%s\n",
- type_desc,
- av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base),
- av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base),
- av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base));
- }
-
if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) {
av_log(NULL, AV_LOG_ERROR,
"Subtitle heartbeat logic failed in %s! (%s)\n",
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 121796a55a..dc2d189ff0 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -334,6 +334,12 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
if (!eof && pkt->dts != AV_NOPTS_VALUE)
ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+ /* rescale timestamps to the muxing timebase */
+ if (!eof) {
+ av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
+ pkt->time_base = ost->mux_timebase;
+ }
+
/* apply the output bitstream filters */
if (ms->bsf_ctx) {
int bsf_eof = 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 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (12 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 14/23] fftools/ffmpeg: convert timestamps inside the muxer Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to frames Anton Khirnov
` (7 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Will be useful in following commits.
---
fftools/ffmpeg.c | 11 +++++++++++
fftools/ffmpeg.h | 6 ++++++
fftools/ffmpeg_dec.c | 5 ++---
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index bcda7570e9..9997881572 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -431,6 +431,17 @@ InputStream *ist_iter(InputStream *prev)
return NULL;
}
+FrameData *frame_data(AVFrame *frame)
+{
+ if (!frame->opaque_ref) {
+ frame->opaque_ref = av_buffer_allocz(sizeof(FrameData));
+ if (!frame->opaque_ref)
+ return NULL;
+ }
+
+ return (FrameData*)frame->opaque_ref->data;
+}
+
void remove_avoptions(AVDictionary **a, AVDictionary *b)
{
const AVDictionaryEntry *t = NULL;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0e9ad5f9f7..6f71e85658 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -737,6 +737,12 @@ int init_complex_filtergraph(FilterGraph *fg);
int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src);
+/**
+ * Get our axiliary frame data attached to the frame, allocating it
+ * if needed.
+ */
+FrameData *frame_data(AVFrame *frame);
+
int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference);
int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb);
int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub);
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 30959c64b7..799be63215 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -499,12 +499,11 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
FrameData *fd;
av_assert0(!frame->opaque_ref);
- frame->opaque_ref = av_buffer_allocz(sizeof(*fd));
- if (!frame->opaque_ref) {
+ fd = frame_data(frame);
+ if (!fd) {
av_frame_unref(frame);
report_and_exit(AVERROR(ENOMEM));
}
- fd = (FrameData*)frame->opaque_ref->data;
fd->pts = frame->pts;
fd->tb = dec->pkt_timebase;
fd->idx = dec->frame_num - 1;
--
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/23] fftools/ffmpeg: attach filter framerate to frames
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (13 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized Anton Khirnov
` (6 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
This way the encoder does not need to reach backward into the filter.
---
fftools/ffmpeg.h | 2 ++
fftools/ffmpeg_enc.c | 19 +++++++++++--------
fftools/ffmpeg_filter.c | 10 ++++++++++
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6f71e85658..49c07ede95 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -655,6 +655,8 @@ typedef struct FrameData {
uint64_t idx;
int64_t pts;
AVRational tb;
+
+ AVRational frame_rate_filter;
} FrameData;
extern InputFile **input_files;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f6431b29d1..cd2faccf4e 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -217,8 +217,10 @@ int enc_open(OutputStream *ost, AVFrame *frame)
case AVMEDIA_TYPE_VIDEO: {
AVRational fr = ost->frame_rate;
- if (!fr.num)
- fr = av_buffersink_get_frame_rate(ost->filter->filter);
+ if (!fr.num && frame) {
+ FrameData *fd = frame_data(frame);
+ fr = fd->frame_rate_filter;
+ }
if (!fr.num && !ost->max_frame_rate.num) {
fr = (AVRational){25, 1};
av_log(ost, AV_LOG_WARNING,
@@ -1024,17 +1026,18 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
int ret;
Encoder *e = ost->enc;
AVCodecContext *enc = ost->enc_ctx;
- AVRational frame_rate;
int64_t nb_frames, nb_frames_prev, i;
double duration = 0;
- AVFilterContext *filter = ost->filter->filter;
- if (frame)
+ if (frame) {
+ FrameData *fd = frame_data(frame);
+
duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base));
- frame_rate = av_buffersink_get_frame_rate(filter);
- if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0)
- duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
+ if (duration <= 0 &&
+ fd->frame_rate_filter.num > 0 && fd->frame_rate_filter.den > 0)
+ duration = 1 / (av_q2d(fd->frame_rate_filter) * av_q2d(enc->time_base));
+ }
video_sync_process(of, ost, frame, duration,
&nb_frames, &nb_frames_prev);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1150f6fc65..a2b45a14b8 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1711,6 +1711,16 @@ int reap_filters(int flush)
tb.num, tb.den);
}
+ if (ost->type == AVMEDIA_TYPE_VIDEO) {
+ FrameData *fd = frame_data(filtered_frame);
+ if (!fd) {
+ av_frame_unref(filtered_frame);
+ report_and_exit(AVERROR(ENOMEM));
+ }
+
+ fd->frame_rate_filter = av_buffersink_get_frame_rate(filter);
+ }
+
enc_frame(ost, filtered_frame);
av_frame_unref(filtered_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 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (14 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to frames Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy Anton Khirnov
` (5 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
It is set by the muxing code, which will not be synchronized with
encoding code after upcoming threading changes. Use an encoder-private
variable instead.
---
fftools/ffmpeg_enc.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index cd2faccf4e..1515ca971f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -62,6 +62,8 @@ struct Encoder {
// number of packets received from the encoder
uint64_t packets_encoded;
+
+ int opened;
};
static uint64_t dup_warning = 1000;
@@ -187,7 +189,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
OutputFile *of = output_files[ost->file_index];
int ret;
- if (ost->initialized)
+ if (e->opened)
return 0;
set_encoder_id(output_files[ost->file_index], ost);
@@ -362,6 +364,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
return ret;
}
+ e->opened = 1;
+
if (ost->sq_idx_encode >= 0) {
e->sq_frame = av_frame_alloc();
if (!e->sq_frame)
@@ -1123,6 +1127,7 @@ void enc_flush(void)
}
for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+ Encoder *e = ost->enc;
AVCodecContext *enc = ost->enc_ctx;
OutputFile *of = output_files[ost->file_index];
@@ -1131,7 +1136,7 @@ void enc_flush(void)
// Try to enable encoding with no input frames.
// Maybe we should just let encoding fail instead.
- if (!ost->initialized) {
+ if (!e->opened) {
FilterGraph *fg = ost->filter->graph;
av_log(ost, AV_LOG_WARNING,
--
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/23] fftools/ffmpeg: simplify handling input -t for streamcopy
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (15 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF Anton Khirnov
` (4 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Output stream will be closed implicitly after a NULL packet is sent to
it, there is no need to explicitly call close_output_stream().
---
fftools/ffmpeg.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9997881572..7d2a25f2bf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -785,7 +785,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
int64_t dts_est = AV_NOPTS_VALUE;
int ret = 0;
int eof_reached = 0;
- int duration_exceeded;
if (ist->decoding_needed)
ret = dec_packet(ist, pkt, no_eof);
@@ -797,7 +796,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
dts_est = pd->dts_est;
}
- duration_exceeded = 0;
if (f->recording_time != INT64_MAX) {
int64_t start_time = 0;
if (copy_ts) {
@@ -805,7 +803,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
start_time += start_at_zero ? 0 : f->start_time_effective;
}
if (dts_est >= f->recording_time + start_time)
- duration_exceeded = 1;
+ pkt = NULL;
}
for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
@@ -813,11 +811,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
if (ost->enc || (!pkt && no_eof))
continue;
- if (duration_exceeded) {
- close_output_stream(ost);
- continue;
- }
-
of_streamcopy(ost, pkt, dts_est);
}
--
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/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (16 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 21:15 ` Michael Niedermayer
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output Anton Khirnov
` (3 subsequent siblings)
21 siblings, 1 reply; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Sending an empty packet already does that implicitly.
---
fftools/ffmpeg.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7d2a25f2bf..462365ed02 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1104,7 +1104,6 @@ static int process_input(int file_index)
for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
OutputStream *ost = ist->outputs[oidx];
OutputFile *of = output_files[ost->file_index];
- close_output_stream(ost);
of_output_packet(of, ost->pkt, ost, 1);
}
}
--
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 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF Anton Khirnov
@ 2023-05-31 21:15 ` Michael Niedermayer
2023-06-03 20:09 ` Anton Khirnov
0 siblings, 1 reply; 26+ messages in thread
From: Michael Niedermayer @ 2023-05-31 21:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 647 bytes --]
On Wed, May 31, 2023 at 04:54:49PM +0200, Anton Khirnov wrote:
> Sending an empty packet already does that implicitly.
> ---
> fftools/ffmpeg.c | 1 -
> 1 file changed, 1 deletion(-)
seems to infinite loop this:
ffmpeg -y -threads:a 1 -i /home/michael/tickets//1208/702121h264-TTA.mkvtest82.mkv -bitexact -vn 1208.mkv
file seems here: ffmpeg-bugs/trac/ticket1208/702121h264-TTA.mkvtest82.mkv
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
[-- 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 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF
2023-05-31 21:15 ` Michael Niedermayer
@ 2023-06-03 20:09 ` Anton Khirnov
0 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-06-03 20:09 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2023-05-31 23:15:47)
> On Wed, May 31, 2023 at 04:54:49PM +0200, Anton Khirnov wrote:
> > Sending an empty packet already does that implicitly.
> > ---
> > fftools/ffmpeg.c | 1 -
> > 1 file changed, 1 deletion(-)
>
> seems to infinite loop this:
>
> ffmpeg -y -threads:a 1 -i /home/michael/tickets//1208/702121h264-TTA.mkvtest82.mkv -bitexact -vn 1208.mkv
>
> file seems here: ffmpeg-bugs/trac/ticket1208/702121h264-TTA.mkvtest82.mkv
ok, I'm dropping this patch from the set (it will probably reappear
later in some form).
I've also submited a test that would catch this.
Let me know if there are any other problems with this set.
Thanks,
--
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
* [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (17 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet() Anton Khirnov
` (2 subsequent siblings)
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
---
fftools/ffmpeg_mux.c | 9 +++++++--
fftools/ffmpeg_mux.h | 1 +
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index dc2d189ff0..485f499971 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -351,7 +351,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
}
while (!bsf_eof) {
- ret = av_bsf_receive_packet(ms->bsf_ctx, pkt);
+ ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
if (ret == AVERROR(EAGAIN))
return;
else if (ret == AVERROR_EOF)
@@ -361,7 +361,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
goto fail;
}
- ret = submit_packet(mux, bsf_eof ? NULL : pkt, ost);
+ ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost);
if (ret < 0)
goto mux_fail;
}
@@ -656,6 +656,10 @@ static int bsf_init(MuxStream *ms)
return ret;
ost->st->time_base = ctx->time_base_out;
+ ms->bsf_pkt = av_packet_alloc();
+ if (!ms->bsf_pkt)
+ return AVERROR(ENOMEM);
+
return 0;
}
@@ -856,6 +860,7 @@ static void ost_free(OutputStream **post)
avcodec_parameters_free(&ost->par_in);
av_bsf_free(&ms->bsf_ctx);
+ av_packet_free(&ms->bsf_pkt);
av_packet_free(&ost->pkt);
av_dict_free(&ost->encoder_opts);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index bee7addd6a..ad7b1df8a7 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -44,6 +44,7 @@ typedef struct MuxStream {
AVFifo *muxing_queue;
AVBSFContext *bsf_ctx;
+ AVPacket *bsf_pkt;
EncStats stats;
--
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/23] fftools/ffmpeg_mux: simplify calling of_output_packet()
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (18 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private Anton Khirnov
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
---
fftools/ffmpeg.c | 2 +-
fftools/ffmpeg.h | 13 +------------
fftools/ffmpeg_enc.c | 6 +++---
fftools/ffmpeg_mux.c | 14 +++++++-------
4 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 462365ed02..79baceb1fc 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1104,7 +1104,7 @@ static int process_input(int file_index)
for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
OutputStream *ost = ist->outputs[oidx];
OutputFile *of = output_files[ost->file_index];
- of_output_packet(of, ost->pkt, ost, 1);
+ of_output_packet(of, ost, NULL);
}
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 49c07ede95..890081edb4 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -844,18 +844,7 @@ void of_close(OutputFile **pof);
void of_enc_stats_close(void);
-/*
- * Send a single packet to the output, applying any bitstream filters
- * associated with the output stream. This may result in any number
- * of packets actually being written, depending on what bitstream
- * filters are applied. The supplied packet is consumed and will be
- * blank (as if newly-allocated) when this function returns.
- *
- * If eof is set, instead indicate EOF to all bitstream filters and
- * therefore flush any delayed packets to the output. A blank packet
- * must be supplied in this case.
- */
-void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof);
+void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
/**
* @param dts predicted packet dts in AV_TIME_BASE_Q
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1515ca971f..8dd8104cea 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -531,7 +531,7 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
}
pkt->dts = pkt->pts;
- of_output_packet(of, pkt, ost, 0);
+ of_output_packet(of, ost, pkt);
}
}
@@ -718,7 +718,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_assert0(frame); // should never happen during flushing
return 0;
} else if (ret == AVERROR_EOF) {
- of_output_packet(of, pkt, ost, 1);
+ of_output_packet(of, ost, NULL);
return ret;
} else if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc);
@@ -752,7 +752,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
e->packets_encoded++;
- of_output_packet(of, pkt, ost, 0);
+ of_output_packet(of, ost, pkt);
}
av_assert0(0);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 485f499971..879a291ba9 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -324,18 +324,18 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost)
return 0;
}
-void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
+void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
{
Muxer *mux = mux_from_of(of);
MuxStream *ms = ms_from_ost(ost);
const char *err_msg;
int ret = 0;
- if (!eof && pkt->dts != AV_NOPTS_VALUE)
+ if (pkt && pkt->dts != AV_NOPTS_VALUE)
ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
/* rescale timestamps to the muxing timebase */
- if (!eof) {
+ if (pkt) {
av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
pkt->time_base = ost->mux_timebase;
}
@@ -344,7 +344,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
if (ms->bsf_ctx) {
int bsf_eof = 0;
- ret = av_bsf_send_packet(ms->bsf_ctx, eof ? NULL : pkt);
+ ret = av_bsf_send_packet(ms->bsf_ctx, pkt);
if (ret < 0) {
err_msg = "submitting a packet for bitstream filtering";
goto fail;
@@ -366,7 +366,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
goto mux_fail;
}
} else {
- ret = submit_packet(mux, eof ? NULL : pkt, ost);
+ ret = submit_packet(mux, pkt, ost);
if (ret < 0)
goto mux_fail;
}
@@ -399,7 +399,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
// EOF: flush output bitstream filters.
if (!pkt) {
- of_output_packet(of, opkt, ost, 1);
+ of_output_packet(of, ost, NULL);
return;
}
@@ -453,7 +453,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
}
}
- of_output_packet(of, opkt, ost, 0);
+ of_output_packet(of, ost, opkt);
ms->streamcopy_started = 1;
}
--
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/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (19 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet() Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private Anton Khirnov
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
The code currently uses OutputStream.pkt, which complicates its
ownership semantics.
---
fftools/ffmpeg_enc.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 8dd8104cea..2bf4782a9f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -57,6 +57,9 @@ struct Encoder {
AVFrame *sq_frame;
+ // packet for receiving encoded output
+ AVPacket *pkt;
+
// combined size of all the packets received from the encoder
uint64_t data_size;
@@ -78,6 +81,8 @@ void enc_free(Encoder **penc)
av_frame_free(&enc->last_frame);
av_frame_free(&enc->sq_frame);
+ av_packet_free(&enc->pkt);
+
av_freep(penc);
}
@@ -97,6 +102,10 @@ int enc_alloc(Encoder **penc, const AVCodec *codec)
goto fail;
}
+ enc->pkt = av_packet_alloc();
+ if (!enc->pkt)
+ goto fail;
+
*penc = enc;
return 0;
@@ -454,10 +463,11 @@ static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
{
+ Encoder *e = ost->enc;
int subtitle_out_max_size = 1024 * 1024;
int subtitle_out_size, nb, i, ret;
AVCodecContext *enc;
- AVPacket *pkt = ost->pkt;
+ AVPacket *pkt = e->pkt;
int64_t pts;
if (sub->pts == AV_NOPTS_VALUE) {
@@ -669,7 +679,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
{
Encoder *e = ost->enc;
AVCodecContext *enc = ost->enc_ctx;
- AVPacket *pkt = ost->pkt;
+ AVPacket *pkt = e->pkt;
const char *type_desc = av_get_media_type_string(enc->codec_type);
const char *action = frame ? "encode" : "flush";
int 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 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private
2023-05-31 14:54 [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream Anton Khirnov
` (20 preceding siblings ...)
2023-05-31 14:54 ` [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding Anton Khirnov
@ 2023-05-31 14:54 ` Anton Khirnov
21 siblings, 0 replies; 26+ messages in thread
From: Anton Khirnov @ 2023-05-31 14:54 UTC (permalink / raw)
To: ffmpeg-devel
It is no longer used outside of muxing code.
---
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_mux.c | 4 ++--
fftools/ffmpeg_mux.h | 2 ++
fftools/ffmpeg_mux_init.c | 4 ++--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 890081edb4..88e3516243 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -551,7 +551,6 @@ typedef struct OutputStream {
Encoder *enc;
AVCodecContext *enc_ctx;
- AVPacket *pkt;
uint64_t nb_frames_dup;
uint64_t nb_frames_drop;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 879a291ba9..66b2324bb3 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -389,7 +389,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
MuxStream *ms = ms_from_ost(ost);
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
- AVPacket *opkt = ost->pkt;
+ AVPacket *opkt = ms->pkt;
av_packet_unref(opkt);
@@ -862,7 +862,7 @@ static void ost_free(OutputStream **post)
av_bsf_free(&ms->bsf_ctx);
av_packet_free(&ms->bsf_pkt);
- av_packet_free(&ost->pkt);
+ av_packet_free(&ms->pkt);
av_dict_free(&ost->encoder_opts);
av_freep(&ost->kf.pts);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index ad7b1df8a7..7f34b86548 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -46,6 +46,8 @@ typedef struct MuxStream {
AVBSFContext *bsf_ctx;
AVPacket *bsf_pkt;
+ AVPacket *pkt;
+
EncStats stats;
int64_t max_frames;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index c49f906dc7..a18320fa9b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1064,8 +1064,8 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
else av_assert0(0);
av_log(ost, AV_LOG_VERBOSE, "\n");
- ost->pkt = av_packet_alloc();
- if (!ost->pkt)
+ ms->pkt = av_packet_alloc();
+ if (!ms->pkt)
report_and_exit(AVERROR(ENOMEM));
if (ost->enc_ctx) {
--
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