* [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders
@ 2022-11-26 8:18 Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct Anton Khirnov
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:18 UTC (permalink / raw)
To: ffmpeg-devel
It serves no purpose, they will be closed and freed in
avcodec_free_context() called from ist_free().
---
fftools/ffmpeg.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3767ab444b..ba91af2c95 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3908,13 +3908,6 @@ static int transcode(void)
exit_program(1);
}
- /* close each decoder */
- for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
- if (ist->decoding_needed) {
- avcodec_close(ist->dec_ctx);
- }
- }
-
hw_device_free_all();
/* finished ! */
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q Anton Khirnov
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
There are 8 of them and they are typically used together. Allows to pass
just this struct to forced_kf_apply(), which makes it clear that the
rest of the OutputStream is not accessed there.
---
fftools/ffmpeg.c | 92 +++++++++++++++++++--------------------
fftools/ffmpeg.h | 25 +++++++----
fftools/ffmpeg_mux.c | 7 +--
fftools/ffmpeg_mux_init.c | 8 ++--
4 files changed, 68 insertions(+), 64 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ba91af2c95..3d10ffc3b2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1042,52 +1042,49 @@ static void do_subtitle_out(OutputFile *of,
}
}
-static enum AVPictureType forced_kf_apply(OutputStream *ost,
+static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb,
const AVFrame *in_picture, int dup_idx)
{
- AVCodecContext *enc = ost->enc_ctx;
double pts_time;
- if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
- ost->forced_kf_ref_pts = in_picture->pts;
+ if (kf->ref_pts == AV_NOPTS_VALUE)
+ kf->ref_pts = in_picture->pts;
- pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * av_q2d(enc->time_base);
- if (ost->forced_kf_index < ost->forced_kf_count &&
- in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
- ost->forced_kf_index++;
+ pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb);
+ if (kf->index < kf->nb_pts &&
+ in_picture->pts >= kf->pts[kf->index]) {
+ kf->index++;
goto force_keyframe;
- } else if (ost->forced_keyframes_pexpr) {
+ } else if (kf->pexpr) {
double res;
- ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
- res = av_expr_eval(ost->forced_keyframes_pexpr,
- ost->forced_keyframes_expr_const_values, NULL);
+ kf->expr_const_values[FKF_T] = pts_time;
+ res = av_expr_eval(kf->pexpr,
+ kf->expr_const_values, NULL);
ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
- ost->forced_keyframes_expr_const_values[FKF_N],
- ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
- ost->forced_keyframes_expr_const_values[FKF_T],
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
+ kf->expr_const_values[FKF_N],
+ kf->expr_const_values[FKF_N_FORCED],
+ kf->expr_const_values[FKF_PREV_FORCED_N],
+ kf->expr_const_values[FKF_T],
+ kf->expr_const_values[FKF_PREV_FORCED_T],
res);
- ost->forced_keyframes_expr_const_values[FKF_N] += 1;
+ kf->expr_const_values[FKF_N] += 1;
if (res) {
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
- ost->forced_keyframes_expr_const_values[FKF_N] - 1;
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
- ost->forced_keyframes_expr_const_values[FKF_T];
- ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
+ kf->expr_const_values[FKF_PREV_FORCED_N] = kf->expr_const_values[FKF_N] - 1;
+ kf->expr_const_values[FKF_PREV_FORCED_T] = kf->expr_const_values[FKF_T];
+ kf->expr_const_values[FKF_N_FORCED] += 1;
goto force_keyframe;
}
- } else if (ost->forced_keyframes &&
- !strncmp(ost->forced_keyframes, "source", 6) &&
+ } else if (kf->forced_keyframes &&
+ !strncmp(kf->forced_keyframes, "source", 6) &&
in_picture->key_frame == 1 && !dup_idx) {
goto force_keyframe;
- } else if (ost->forced_keyframes &&
- !strncmp(ost->forced_keyframes, "source_no_drop", 14) &&
+ } else if (kf->forced_keyframes &&
+ !strncmp(kf->forced_keyframes, "source_no_drop", 14) &&
!dup_idx) {
- ost->dropped_keyframe = 0;
- if ((in_picture->key_frame == 1) || ost->dropped_keyframe)
+ kf->dropped_keyframe = 0;
+ if ((in_picture->key_frame == 1) || kf->dropped_keyframe)
goto force_keyframe;
}
@@ -1223,7 +1220,7 @@ static void do_video_out(OutputFile *of,
}
}
ost->last_dropped = nb_frames == nb0_frames && next_picture;
- ost->dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame;
+ ost->kf.dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame;
/* duplicates frame if needed */
for (i = 0; i < nb_frames; i++) {
@@ -1243,7 +1240,7 @@ static void do_video_out(OutputFile *of,
return;
in_picture->quality = enc->global_quality;
- in_picture->pict_type = forced_kf_apply(ost, in_picture, i);
+ in_picture->pict_type = forced_kf_apply(&ost->kf, enc->time_base, in_picture, i);
ret = submit_encode_frame(of, ost, in_picture);
if (ret == AVERROR_EOF)
@@ -2751,14 +2748,14 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
}
-static void parse_forced_key_frames(char *kf, OutputStream *ost,
+static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of,
AVCodecContext *avctx)
{
- char *p;
+ const char *p;
int n = 1, i, size, index = 0;
int64_t t, *pts;
- for (p = kf; *p; p++)
+ for (p = kf->forced_keyframes; *p; p++)
if (*p == ',')
n++;
size = n;
@@ -2766,7 +2763,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
if (!pts)
report_and_exit(AVERROR(ENOMEM));
- p = kf;
+ p = kf->forced_keyframes;
for (i = 0; i < n; i++) {
char *next = strchr(p, ',');
@@ -2774,7 +2771,6 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
*next++ = 0;
if (!memcmp(p, "chapters", 8)) {
- OutputFile *of = output_files[ost->file_index];
AVChapter * const *ch;
unsigned int nb_ch;
int j;
@@ -2808,8 +2804,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
av_assert0(index == size);
qsort(pts, size, sizeof(*pts), compare_int64);
- ost->forced_kf_count = size;
- ost->forced_kf_pts = pts;
+ kf->nb_pts = size;
+ kf->pts = pts;
}
static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
@@ -2958,24 +2954,24 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
enc_ctx->field_order = AV_FIELD_TT;
}
- if (ost->forced_keyframes) {
- if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
- ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,
+ if (ost->kf.forced_keyframes) {
+ if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) {
+ ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5,
forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR,
- "Invalid force_key_frames expression '%s'\n", ost->forced_keyframes+5);
+ "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5);
return ret;
}
- ost->forced_keyframes_expr_const_values[FKF_N] = 0;
- ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0;
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN;
- ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN;
+ ost->kf.expr_const_values[FKF_N] = 0;
+ ost->kf.expr_const_values[FKF_N_FORCED] = 0;
+ ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
+ ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
// Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
// parse it only for static kf timings
- } else if(strncmp(ost->forced_keyframes, "source", 6)) {
- parse_forced_key_frames(ost->forced_keyframes, ost, ost->enc_ctx);
+ } else if(strncmp(ost->kf.forced_keyframes, "source", 6)) {
+ parse_forced_key_frames(&ost->kf, of, ost->enc_ctx);
}
}
break;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 4b76b1d0d7..db1f00b259 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -487,6 +487,21 @@ typedef enum {
MUXER_FINISHED = 2,
} OSTFinished ;
+typedef struct KeyframeForceCtx {
+ char *forced_keyframes;
+
+ int64_t ref_pts;
+
+ int64_t *pts;
+ int nb_pts;
+ int index;
+
+ AVExpr *pexpr;
+ double expr_const_values[FKF_NB];
+
+ int dropped_keyframe;
+} KeyframeForceCtx;
+
typedef struct OutputStream {
int file_index; /* file index */
int index; /* stream index in the output file */
@@ -543,15 +558,7 @@ typedef struct OutputStream {
AVRational frame_aspect_ratio;
- /* forced key frames */
- int64_t forced_kf_ref_pts;
- int64_t *forced_kf_pts;
- int forced_kf_count;
- int forced_kf_index;
- char *forced_keyframes;
- AVExpr *forced_keyframes_pexpr;
- double forced_keyframes_expr_const_values[FKF_NB];
- int dropped_keyframe;
+ KeyframeForceCtx kf;
/* audio only */
#if FFMPEG_OPT_MAP_CHANNEL
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 2b885f7ab0..7da29db8f4 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -667,11 +667,12 @@ static void ost_free(OutputStream **post)
av_packet_free(&ost->pkt);
av_dict_free(&ost->encoder_opts);
- av_freep(&ost->forced_keyframes);
- av_expr_free(ost->forced_keyframes_pexpr);
+ av_freep(&ost->kf.forced_keyframes);
+ av_freep(&ost->kf.pts);
+ av_expr_free(ost->kf.pexpr);
+
av_freep(&ost->avfilter);
av_freep(&ost->logfile_prefix);
- av_freep(&ost->forced_kf_pts);
av_freep(&ost->apad);
#if FFMPEG_OPT_MAP_CHANNEL
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 7aa2e030d8..bdec0744a9 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -202,7 +202,7 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o,
ost->file_index = nb_output_files - 1;
ost->index = idx;
ost->st = st;
- ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
+ ost->kf.ref_pts = AV_NOPTS_VALUE;
st->codecpar->codec_type = type;
ret = choose_encoder(o, oc, ost, &enc);
@@ -604,9 +604,9 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, Input
}
}
- MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
- if (ost->forced_keyframes)
- ost->forced_keyframes = av_strdup(ost->forced_keyframes);
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->kf.forced_keyframes, oc, st);
+ if (ost->kf.forced_keyframes)
+ ost->kf.forced_keyframes = av_strdup(ost->kf.forced_keyframes);
MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg: parse forced keyframes in of_open() Anton Khirnov
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Rather than the encoder timebase. Since the times are parsed as
microseconds, this will not reduce precision, except possibly when
chapter times are used and the chapter timebase happens to be better
aligned with the encoder timebase, which is unlikely.
This will allow parsing the keyframe times earlier (before encoder
timebase is known) in future commits.
---
fftools/ffmpeg.c | 15 +++++----------
fftools/ffmpeg.h | 1 +
2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3d10ffc3b2..5d39d8f69b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1052,7 +1052,7 @@ static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb,
pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb);
if (kf->index < kf->nb_pts &&
- in_picture->pts >= kf->pts[kf->index]) {
+ av_compare_ts(in_picture->pts, tb, kf->pts[kf->index], AV_TIME_BASE_Q) >= 0) {
kf->index++;
goto force_keyframe;
} else if (kf->pexpr) {
@@ -2748,8 +2748,7 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
}
-static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of,
- AVCodecContext *avctx)
+static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of)
{
const char *p;
int n = 1, i, size, index = 0;
@@ -2782,21 +2781,17 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of,
sizeof(*pts))))
report_and_exit(AVERROR(ENOMEM));
t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
- t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
for (j = 0; j < nb_ch; j++) {
const AVChapter *c = ch[j];
av_assert1(index < size);
pts[index++] = av_rescale_q(c->start, c->time_base,
- avctx->time_base) + t;
+ AV_TIME_BASE_Q) + t;
}
} else {
-
- t = parse_time_or_die("force_key_frames", p, 1);
av_assert1(index < size);
- pts[index++] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
-
+ pts[index++] = parse_time_or_die("force_key_frames", p, 1);
}
p = next;
@@ -2971,7 +2966,7 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
// Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
// parse it only for static kf timings
} else if(strncmp(ost->kf.forced_keyframes, "source", 6)) {
- parse_forced_key_frames(&ost->kf, of, ost->enc_ctx);
+ parse_forced_key_frames(&ost->kf, of);
}
}
break;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index db1f00b259..f5d51b90ec 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -492,6 +492,7 @@ typedef struct KeyframeForceCtx {
int64_t ref_pts;
+ // timestamps of the forced keyframes, in AV_TIME_BASE_Q
int64_t *pts;
int nb_pts;
int index;
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg: parse forced keyframes in of_open()
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: avoid storing full forced keyframe spec Anton Khirnov
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Allows to remove the ugly of_get_chapters() wrapper.
---
fftools/ffmpeg.c | 89 --------------------------------
fftools/ffmpeg.h | 2 -
fftools/ffmpeg_mux.c | 8 ---
fftools/ffmpeg_mux_init.c | 106 ++++++++++++++++++++++++++++++++++++++
4 files changed, 106 insertions(+), 99 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d39d8f69b..12ce108cc6 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -113,15 +113,6 @@ const int program_birth_year = 2000;
static FILE *vstats_file;
-const char *const forced_keyframes_const_names[] = {
- "n",
- "n_forced",
- "prev_forced_n",
- "prev_forced_t",
- "t",
- NULL
-};
-
typedef struct BenchmarkTimeStamps {
int64_t real_usec;
int64_t user_usec;
@@ -2590,11 +2581,6 @@ static int init_input_stream(InputStream *ist, char *error, int error_len)
return 0;
}
-static int compare_int64(const void *a, const void *b)
-{
- return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
-}
-
static int init_output_stream_streamcopy(OutputStream *ost)
{
OutputFile *of = output_files[ost->file_index];
@@ -2748,61 +2734,6 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
}
-static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of)
-{
- const char *p;
- int n = 1, i, size, index = 0;
- int64_t t, *pts;
-
- for (p = kf->forced_keyframes; *p; p++)
- if (*p == ',')
- n++;
- size = n;
- pts = av_malloc_array(size, sizeof(*pts));
- if (!pts)
- report_and_exit(AVERROR(ENOMEM));
-
- p = kf->forced_keyframes;
- for (i = 0; i < n; i++) {
- char *next = strchr(p, ',');
-
- if (next)
- *next++ = 0;
-
- if (!memcmp(p, "chapters", 8)) {
- AVChapter * const *ch;
- unsigned int nb_ch;
- int j;
-
- ch = of_get_chapters(of, &nb_ch);
-
- if (nb_ch > INT_MAX - size ||
- !(pts = av_realloc_f(pts, size += nb_ch - 1,
- sizeof(*pts))))
- report_and_exit(AVERROR(ENOMEM));
- t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
-
- for (j = 0; j < nb_ch; j++) {
- const AVChapter *c = ch[j];
- av_assert1(index < size);
- pts[index++] = av_rescale_q(c->start, c->time_base,
- AV_TIME_BASE_Q) + t;
- }
-
- } else {
- av_assert1(index < size);
- pts[index++] = parse_time_or_die("force_key_frames", p, 1);
- }
-
- p = next;
- }
-
- av_assert0(index == size);
- qsort(pts, size, sizeof(*pts), compare_int64);
- kf->nb_pts = size;
- kf->pts = pts;
-}
-
static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
{
InputStream *ist = ost->ist;
@@ -2949,26 +2880,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
enc_ctx->field_order = AV_FIELD_TT;
}
- if (ost->kf.forced_keyframes) {
- if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) {
- ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5,
- forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR,
- "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5);
- return ret;
- }
- ost->kf.expr_const_values[FKF_N] = 0;
- ost->kf.expr_const_values[FKF_N_FORCED] = 0;
- ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
- ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
-
- // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
- // parse it only for static kf timings
- } else if(strncmp(ost->kf.forced_keyframes, "source", 6)) {
- parse_forced_key_frames(&ost->kf, of);
- }
- }
break;
case AVMEDIA_TYPE_SUBTITLE:
enc_ctx->time_base = AV_TIME_BASE_Q;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f5d51b90ec..bf2abf55ee 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -757,8 +757,6 @@ void of_close(OutputFile **pof);
*/
void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof);
int64_t of_filesize(OutputFile *of);
-AVChapter * const *
-of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
int ifile_open(const OptionsContext *o, const char *filename);
void ifile_close(InputFile **f);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 7da29db8f4..de5facbdc0 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -736,11 +736,3 @@ int64_t of_filesize(OutputFile *of)
Muxer *mux = mux_from_of(of);
return atomic_load(&mux->last_filesize);
}
-
-AVChapter * const *
-of_get_chapters(OutputFile *of, unsigned int *nb_chapters)
-{
- Muxer *mux = mux_from_of(of);
- *nb_chapters = mux->fc->nb_chapters;
- return mux->fc->chapters;
-}
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index bdec0744a9..25e2ab8631 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1745,6 +1745,104 @@ finish:
return ret;
}
+const char *const forced_keyframes_const_names[] = {
+ "n",
+ "n_forced",
+ "prev_forced_n",
+ "prev_forced_t",
+ "t",
+ NULL
+};
+
+static int compare_int64(const void *a, const void *b)
+{
+ return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
+}
+
+static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux)
+{
+ const char *p;
+ int n = 1, i, size, index = 0;
+ int64_t t, *pts;
+
+ for (p = kf->forced_keyframes; *p; p++)
+ if (*p == ',')
+ n++;
+ size = n;
+ pts = av_malloc_array(size, sizeof(*pts));
+ if (!pts)
+ report_and_exit(AVERROR(ENOMEM));
+
+ p = kf->forced_keyframes;
+ for (i = 0; i < n; i++) {
+ char *next = strchr(p, ',');
+
+ if (next)
+ *next++ = 0;
+
+ if (!memcmp(p, "chapters", 8)) {
+ AVChapter * const *ch = mux->fc->chapters;
+ unsigned int nb_ch = mux->fc->nb_chapters;
+ int j;
+
+ if (nb_ch > INT_MAX - size ||
+ !(pts = av_realloc_f(pts, size += nb_ch - 1,
+ sizeof(*pts))))
+ report_and_exit(AVERROR(ENOMEM));
+ t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
+
+ for (j = 0; j < nb_ch; j++) {
+ const AVChapter *c = ch[j];
+ av_assert1(index < size);
+ pts[index++] = av_rescale_q(c->start, c->time_base,
+ AV_TIME_BASE_Q) + t;
+ }
+
+ } else {
+ av_assert1(index < size);
+ pts[index++] = parse_time_or_die("force_key_frames", p, 1);
+ }
+
+ p = next;
+ }
+
+ av_assert0(index == size);
+ qsort(pts, size, sizeof(*pts), compare_int64);
+ kf->nb_pts = size;
+ kf->pts = pts;
+}
+
+static int process_forced_keyframes(Muxer *mux)
+{
+ for (int i = 0; i < mux->of.nb_streams; i++) {
+ OutputStream *ost = mux->of.streams[i];
+
+ if (!ost->kf.forced_keyframes)
+ continue;
+
+ if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) {
+ int ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5,
+ forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5);
+ return ret;
+ }
+ ost->kf.expr_const_values[FKF_N] = 0;
+ ost->kf.expr_const_values[FKF_N_FORCED] = 0;
+ ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN;
+ ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN;
+
+ // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
+ // parse it only for static kf timings
+ } else if (strncmp(ost->kf.forced_keyframes, "source", 6)) {
+ parse_forced_key_frames(&ost->kf, mux);
+ }
+ }
+
+ return 0;
+}
+
static void validate_enc_avopt(const Muxer *mux, const AVDictionary *codec_avopt)
{
const AVClass *class = avcodec_get_class();
@@ -1961,6 +2059,14 @@ int of_open(const OptionsContext *o, const char *filename)
exit_program(1);
}
+ // parse forced keyframe specifications;
+ // must be done after chapters are created
+ err = process_forced_keyframes(mux);
+ if (err < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Error processing forced keyframes\n");
+ exit_program(1);
+ }
+
err = setup_sync_queues(mux, oc, o->shortest_buf_duration * AV_TIME_BASE);
if (err < 0) {
av_log(NULL, AV_LOG_FATAL, "Error setting up output sync queues\n");
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: avoid storing full forced keyframe spec
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (2 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg: parse forced keyframes in of_open() Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 06/13] fftools/ffmpeg: move logging filtered frame timestamps Anton Khirnov
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
It is not needed after the spec is parsed. Also avoids ugly string
comparisons for each video frame.
---
fftools/ffmpeg.c | 7 ++-----
fftools/ffmpeg.h | 7 ++++++-
fftools/ffmpeg_mux.c | 1 -
fftools/ffmpeg_mux_init.c | 35 ++++++++++++++++++++---------------
4 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 12ce108cc6..44582e3568 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1067,13 +1067,10 @@ static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb,
kf->expr_const_values[FKF_N_FORCED] += 1;
goto force_keyframe;
}
- } else if (kf->forced_keyframes &&
- !strncmp(kf->forced_keyframes, "source", 6) &&
+ } else if (kf->type == KF_FORCE_SOURCE &&
in_picture->key_frame == 1 && !dup_idx) {
goto force_keyframe;
- } else if (kf->forced_keyframes &&
- !strncmp(kf->forced_keyframes, "source_no_drop", 14) &&
- !dup_idx) {
+ } else if (kf->type == KF_FORCE_SOURCE_NO_DROP && !dup_idx) {
kf->dropped_keyframe = 0;
if ((in_picture->key_frame == 1) || kf->dropped_keyframe)
goto force_keyframe;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index bf2abf55ee..5527dbe49b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -487,8 +487,13 @@ typedef enum {
MUXER_FINISHED = 2,
} OSTFinished ;
+enum {
+ KF_FORCE_SOURCE = 1,
+ KF_FORCE_SOURCE_NO_DROP = 2,
+};
+
typedef struct KeyframeForceCtx {
- char *forced_keyframes;
+ int type;
int64_t ref_pts;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index de5facbdc0..20524e5a28 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -667,7 +667,6 @@ static void ost_free(OutputStream **post)
av_packet_free(&ost->pkt);
av_dict_free(&ost->encoder_opts);
- av_freep(&ost->kf.forced_keyframes);
av_freep(&ost->kf.pts);
av_expr_free(ost->kf.pexpr);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 25e2ab8631..0280759b05 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -604,10 +604,6 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, Input
}
}
- MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->kf.forced_keyframes, oc, st);
- if (ost->kf.forced_keyframes)
- ost->kf.forced_keyframes = av_strdup(ost->kf.forced_keyframes);
-
MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
ost->top_field_first = -1;
@@ -1759,13 +1755,14 @@ static int compare_int64(const void *a, const void *b)
return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
}
-static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux)
+static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
+ const char *spec)
{
const char *p;
int n = 1, i, size, index = 0;
int64_t t, *pts;
- for (p = kf->forced_keyframes; *p; p++)
+ for (p = spec; *p; p++)
if (*p == ',')
n++;
size = n;
@@ -1773,7 +1770,7 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux)
if (!pts)
report_and_exit(AVERROR(ENOMEM));
- p = kf->forced_keyframes;
+ p = spec;
for (i = 0; i < n; i++) {
char *next = strchr(p, ',');
@@ -1812,20 +1809,24 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux)
kf->pts = pts;
}
-static int process_forced_keyframes(Muxer *mux)
+static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
{
for (int i = 0; i < mux->of.nb_streams; i++) {
OutputStream *ost = mux->of.streams[i];
+ const char *forced_keyframes = NULL;
+
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st);
- if (!ost->kf.forced_keyframes)
+ if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+ ost->enc_ctx && forced_keyframes))
continue;
- if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) {
- int ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5,
+ if (!strncmp(forced_keyframes, "expr:", 5)) {
+ int ret = av_expr_parse(&ost->kf.pexpr, forced_keyframes + 5,
forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR,
- "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5);
+ "Invalid force_key_frames expression '%s'\n", forced_keyframes + 5);
return ret;
}
ost->kf.expr_const_values[FKF_N] = 0;
@@ -1835,8 +1836,12 @@ static int process_forced_keyframes(Muxer *mux)
// Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
// parse it only for static kf timings
- } else if (strncmp(ost->kf.forced_keyframes, "source", 6)) {
- parse_forced_key_frames(&ost->kf, mux);
+ } else if (!strcmp(forced_keyframes, "source")) {
+ ost->kf.type = KF_FORCE_SOURCE;
+ } else if (!strcmp(forced_keyframes, "source_no_drop")) {
+ ost->kf.type = KF_FORCE_SOURCE_NO_DROP;
+ } else {
+ parse_forced_key_frames(&ost->kf, mux, forced_keyframes);
}
}
@@ -2061,7 +2066,7 @@ int of_open(const OptionsContext *o, const char *filename)
// parse forced keyframe specifications;
// must be done after chapters are created
- err = process_forced_keyframes(mux);
+ err = process_forced_keyframes(mux, o);
if (err < 0) {
av_log(NULL, AV_LOG_FATAL, "Error processing forced keyframes\n");
exit_program(1);
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 06/13] fftools/ffmpeg: move logging filtered frame timestamps
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (3 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: avoid storing full forced keyframe spec Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 07/13] fftools/ffmpeg: set AVFrame.time_base after filtering Anton Khirnov
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Do it right after the frame is received from the filtergraph. This is a
more logical place for this and will simplify future commits.
---
fftools/ffmpeg.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 44582e3568..263670d3f5 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -676,7 +676,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
AVFrame *frame)
{
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
- int64_t orig_pts = AV_NOPTS_VALUE;
AVCodecContext *enc = ost->enc_ctx;
AVRational filter_tb = (AVRational){ -1, -1 };
if (!frame || frame->pts == AV_NOPTS_VALUE ||
@@ -690,7 +689,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
AVRational tb = enc->time_base;
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
filter_tb = av_buffersink_get_time_base(filter);
- orig_pts = frame->pts;
tb.den <<= extra_bits;
float_pts =
@@ -708,11 +706,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
early_exit:
if (debug_ts) {
- av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
- frame ? av_ts2str(orig_pts) : "NULL",
- frame ? av_ts2timestr(orig_pts, &filter_tb) : "NULL",
- filter_tb.num, filter_tb.den);
-
av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n",
frame ? av_ts2str(frame->pts) : "NULL",
(enc && frame) ? av_ts2timestr(frame->pts, &enc->time_base) : "NULL",
@@ -1302,6 +1295,12 @@ static int reap_filters(int flush)
AVRational tb = av_buffersink_get_time_base(filter);
ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
AV_TIME_BASE_Q);
+
+ if (debug_ts)
+ av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
+ av_ts2str(filtered_frame->pts),
+ av_ts2timestr(filtered_frame->pts, &tb),
+ tb.num, tb.den);
}
switch (av_buffersink_get_type(filter)) {
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 07/13] fftools/ffmpeg: set AVFrame.time_base after filtering
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (4 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 06/13] fftools/ffmpeg: move logging filtered frame timestamps Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio Anton Khirnov
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Makes it easier to track what timebase are the frame timestamps in and
allows to stop accessing filters in code that shouldn't deal with
filtering.
---
fftools/ffmpeg.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 263670d3f5..2ee40890a9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -678,17 +678,14 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
AVCodecContext *enc = ost->enc_ctx;
AVRational filter_tb = (AVRational){ -1, -1 };
- if (!frame || frame->pts == AV_NOPTS_VALUE ||
- !enc || !ost->filter || !ost->filter->graph->graph)
+ if (!frame || frame->pts == AV_NOPTS_VALUE || !enc)
goto early_exit;
{
- AVFilterContext *filter = ost->filter->filter;
-
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
AVRational tb = enc->time_base;
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
- filter_tb = av_buffersink_get_time_base(filter);
+ filter_tb = frame->time_base;
tb.den <<= extra_bits;
float_pts =
@@ -701,6 +698,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
frame->pts =
av_rescale_q(frame->pts, filter_tb, enc->time_base) -
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
+ frame->time_base = enc->time_base;
}
early_exit:
@@ -1295,6 +1293,7 @@ static int reap_filters(int flush)
AVRational tb = av_buffersink_get_time_base(filter);
ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
AV_TIME_BASE_Q);
+ filtered_frame->time_base = tb;
if (debug_ts)
av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (5 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 07/13] fftools/ffmpeg: set AVFrame.time_base after filtering Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg: call check_recording_time() with actual frame pts Anton Khirnov
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Almost none of that function's complexity is useful for audio, it can
be replaced by a simple av_rescale_q().
---
fftools/ffmpeg.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2ee40890a9..cb65f26100 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -933,15 +933,22 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost,
static void do_audio_out(OutputFile *of, OutputStream *ost,
AVFrame *frame)
{
+ AVCodecContext *enc = ost->enc_ctx;
int ret;
- adjust_frame_pts_to_encoder_tb(of, ost, frame);
-
if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base))
return;
if (frame->pts == AV_NOPTS_VALUE)
frame->pts = ost->next_pts;
+ else {
+ int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
+ frame->pts =
+ av_rescale_q(frame->pts, frame->time_base, enc->time_base) -
+ av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
+ }
+ frame->time_base = enc->time_base;
+
ost->next_pts = frame->pts + frame->nb_samples;
ret = submit_encode_frame(of, ost, frame);
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg: call check_recording_time() with actual frame pts
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (6 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 10/13] fftools/ffmpeg: only convert video frame pts if we have a frame Anton Khirnov
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Not its estimated value that will not necessarily be used.
---
fftools/ffmpeg.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cb65f26100..e56681a461 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -936,9 +936,6 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
AVCodecContext *enc = ost->enc_ctx;
int ret;
- if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base))
- return;
-
if (frame->pts == AV_NOPTS_VALUE)
frame->pts = ost->next_pts;
else {
@@ -949,6 +946,9 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
}
frame->time_base = enc->time_base;
+ if (!check_recording_time(ost, frame->pts, frame->time_base))
+ return;
+
ost->next_pts = frame->pts + frame->nb_samples;
ret = submit_encode_frame(of, ost, frame);
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 10/13] fftools/ffmpeg: only convert video frame pts if we have a frame
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (7 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg: call check_recording_time() with actual frame pts Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 11/13] fftools/ffmpeg: drop an always-false check Anton Khirnov
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Calling adjust_frame_pts_to_encoder_tb() with a NULL frame does not
perform a meaningful action.
---
fftools/ffmpeg.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e56681a461..8f27b5ca3f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -678,7 +678,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
AVCodecContext *enc = ost->enc_ctx;
AVRational filter_tb = (AVRational){ -1, -1 };
- if (!frame || frame->pts == AV_NOPTS_VALUE || !enc)
+ if (frame->pts == AV_NOPTS_VALUE || !enc)
goto early_exit;
{
@@ -1092,12 +1092,10 @@ static void do_video_out(OutputFile *of,
int64_t nb_frames, nb0_frames, i;
double delta, delta0;
double duration = 0;
- double sync_ipts = AV_NOPTS_VALUE;
InputStream *ist = ost->ist;
AVFilterContext *filter = ost->filter->filter;
init_output_stream_wrapper(ost, next_picture, 1);
- sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
frame_rate = av_buffersink_get_frame_rate(filter);
if (frame_rate.num > 0 && frame_rate.den > 0)
@@ -1121,6 +1119,7 @@ static void do_video_out(OutputFile *of,
ost->last_nb0_frames[1],
ost->last_nb0_frames[2]);
} else {
+ double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
/* delta0 is the "drift" between the input frame (next_picture) and
* where it would fall in the output. */
delta0 = sync_ipts - ost->next_pts;
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 11/13] fftools/ffmpeg: drop an always-false check
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (8 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 10/13] fftools/ffmpeg: only convert video frame pts if we have a frame Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 12/13] fftools/ffmpeg: remove a useless inner block Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: cosmetics Anton Khirnov
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8f27b5ca3f..0128476f57 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -678,7 +678,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
AVCodecContext *enc = ost->enc_ctx;
AVRational filter_tb = (AVRational){ -1, -1 };
- if (frame->pts == AV_NOPTS_VALUE || !enc)
+ if (frame->pts == AV_NOPTS_VALUE)
goto early_exit;
{
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 12/13] fftools/ffmpeg: remove a useless inner block
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (9 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 11/13] fftools/ffmpeg: drop an always-false check Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: cosmetics Anton Khirnov
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
adjust_frame_pts_to_encoder_tb() is so small that this serves no useful
purpose.
---
fftools/ffmpeg.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0128476f57..045cc609b9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -676,17 +676,18 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
AVFrame *frame)
{
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
- AVCodecContext *enc = ost->enc_ctx;
- AVRational filter_tb = (AVRational){ -1, -1 };
+ const int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ?
+ 0 : of->start_time;
+
+ AVCodecContext *const enc = ost->enc_ctx;
+
+ AVRational tb = enc->time_base;
+ AVRational filter_tb = frame->time_base;
+ const int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
+
if (frame->pts == AV_NOPTS_VALUE)
goto early_exit;
- {
- int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
- AVRational tb = enc->time_base;
- int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
- filter_tb = frame->time_base;
-
tb.den <<= extra_bits;
float_pts =
av_rescale_q(frame->pts, filter_tb, tb) -
@@ -699,7 +700,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
av_rescale_q(frame->pts, filter_tb, enc->time_base) -
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
frame->time_base = enc->time_base;
- }
early_exit:
--
2.35.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] 13+ messages in thread
* [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: cosmetics
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
` (10 preceding siblings ...)
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 12/13] fftools/ffmpeg: remove a useless inner block Anton Khirnov
@ 2022-11-26 8:19 ` Anton Khirnov
11 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-11-26 8:19 UTC (permalink / raw)
To: ffmpeg-devel
Reindent after previous commit and break/split some lines as
appropriate.
---
fftools/ffmpeg.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 045cc609b9..771219f7df 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -688,18 +688,17 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
if (frame->pts == AV_NOPTS_VALUE)
goto early_exit;
- tb.den <<= extra_bits;
- 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 can be removed in case the fps code is changed to work with integers
- 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);
- frame->time_base = enc->time_base;
+ tb.den <<= extra_bits;
+ 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
+ // can be removed in case the fps code is changed to work with integers
+ 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);
+ frame->time_base = enc->time_base;
early_exit:
--
2.35.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] 13+ messages in thread
end of thread, other threads:[~2022-11-26 8:21 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 8:18 [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg: parse forced keyframes in of_open() Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 05/13] fftools/ffmpeg: avoid storing full forced keyframe spec Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 06/13] fftools/ffmpeg: move logging filtered frame timestamps Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 07/13] fftools/ffmpeg: set AVFrame.time_base after filtering Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg: call check_recording_time() with actual frame pts Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 10/13] fftools/ffmpeg: only convert video frame pts if we have a frame Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 11/13] fftools/ffmpeg: drop an always-false check Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 12/13] fftools/ffmpeg: remove a useless inner block Anton Khirnov
2022-11-26 8:19 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: cosmetics Anton Khirnov
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git