* [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs out of open_output_file()
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg_opt: move adding metadata " Anton Khirnov
` (22 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_opt.c | 135 ++++++++++++++++++++++---------------------
1 file changed, 70 insertions(+), 65 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 0d5323ea73..ccab98406e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2784,6 +2784,75 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o)
}
}
+static void of_add_programs(AVFormatContext *oc, const OptionsContext *o)
+{
+ /* process manually set programs */
+ for (int i = 0; i < o->nb_program; i++) {
+ const char *p = o->program[i].u.str;
+ int progid = i+1;
+ AVProgram *program;
+
+ while(*p) {
+ const char *p2 = av_get_token(&p, ":");
+ const char *to_dealloc = p2;
+ char *key;
+ if (!p2)
+ break;
+
+ if(*p) p++;
+
+ key = av_get_token(&p2, "=");
+ if (!key || !*p2) {
+ av_freep(&to_dealloc);
+ av_freep(&key);
+ break;
+ }
+ p2++;
+
+ if (!strcmp(key, "program_num"))
+ progid = strtol(p2, NULL, 0);
+ av_freep(&to_dealloc);
+ av_freep(&key);
+ }
+
+ program = av_new_program(oc, progid);
+
+ p = o->program[i].u.str;
+ while(*p) {
+ const char *p2 = av_get_token(&p, ":");
+ const char *to_dealloc = p2;
+ char *key;
+ if (!p2)
+ break;
+ if(*p) p++;
+
+ key = av_get_token(&p2, "=");
+ if (!key) {
+ av_log(NULL, AV_LOG_FATAL,
+ "No '=' character in program string %s.\n",
+ p2);
+ exit_program(1);
+ }
+ if (!*p2)
+ exit_program(1);
+ p2++;
+
+ if (!strcmp(key, "title")) {
+ av_dict_set(&program->metadata, "title", p2, 0);
+ } else if (!strcmp(key, "program_num")) {
+ } else if (!strcmp(key, "st")) {
+ int st_num = strtol(p2, NULL, 0);
+ av_program_add_stream_index(oc, progid, st_num);
+ } else {
+ av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
+ exit_program(1);
+ }
+ av_freep(&to_dealloc);
+ av_freep(&key);
+ }
+ }
+}
+
static int open_output_file(OptionsContext *o, const char *filename)
{
AVFormatContext *oc;
@@ -3073,71 +3142,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
}
}
- /* process manually set programs */
- for (i = 0; i < o->nb_program; i++) {
- const char *p = o->program[i].u.str;
- int progid = i+1;
- AVProgram *program;
-
- while(*p) {
- const char *p2 = av_get_token(&p, ":");
- const char *to_dealloc = p2;
- char *key;
- if (!p2)
- break;
-
- if(*p) p++;
-
- key = av_get_token(&p2, "=");
- if (!key || !*p2) {
- av_freep(&to_dealloc);
- av_freep(&key);
- break;
- }
- p2++;
-
- if (!strcmp(key, "program_num"))
- progid = strtol(p2, NULL, 0);
- av_freep(&to_dealloc);
- av_freep(&key);
- }
-
- program = av_new_program(oc, progid);
-
- p = o->program[i].u.str;
- while(*p) {
- const char *p2 = av_get_token(&p, ":");
- const char *to_dealloc = p2;
- char *key;
- if (!p2)
- break;
- if(*p) p++;
-
- key = av_get_token(&p2, "=");
- if (!key) {
- av_log(NULL, AV_LOG_FATAL,
- "No '=' character in program string %s.\n",
- p2);
- exit_program(1);
- }
- if (!*p2)
- exit_program(1);
- p2++;
-
- if (!strcmp(key, "title")) {
- av_dict_set(&program->metadata, "title", p2, 0);
- } else if (!strcmp(key, "program_num")) {
- } else if (!strcmp(key, "st")) {
- int st_num = strtol(p2, NULL, 0);
- av_program_add_stream_index(oc, progid, st_num);
- } else {
- av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
- exit_program(1);
- }
- av_freep(&to_dealloc);
- av_freep(&key);
- }
- }
+ of_add_programs(oc, o);
/* process manually set metadata */
for (i = 0; i < o->nb_metadata; i++) {
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg_opt: move adding metadata out of open_output_file()
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs " Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_hw: stop logging to the decoder context Anton Khirnov
` (21 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_opt.c | 125 ++++++++++++++++++++++---------------------
1 file changed, 63 insertions(+), 62 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index ccab98406e..aa240107dc 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2853,12 +2853,73 @@ static void of_add_programs(AVFormatContext *oc, const OptionsContext *o)
}
}
+static void of_add_metadata(AVFormatContext *oc, const OptionsContext *o)
+{
+ for (int i = 0; i < o->nb_metadata; i++) {
+ AVDictionary **m;
+ char type, *val;
+ const char *stream_spec;
+ int index = 0, ret = 0;
+
+ val = strchr(o->metadata[i].u.str, '=');
+ if (!val) {
+ av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
+ o->metadata[i].u.str);
+ exit_program(1);
+ }
+ *val++ = 0;
+
+ parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
+ if (type == 's') {
+ for (int j = 0; j < oc->nb_streams; j++) {
+ OutputStream *ost = output_streams[nb_output_streams - oc->nb_streams + j];
+ if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
+ if (!strcmp(o->metadata[i].u.str, "rotate")) {
+ char *tail;
+ double theta = av_strtod(val, &tail);
+ if (!*tail) {
+ ost->rotate_overridden = 1;
+ ost->rotate_override_value = theta;
+ }
+ } else {
+ av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
+ }
+ } else if (ret < 0)
+ exit_program(1);
+ }
+ } else {
+ switch (type) {
+ case 'g':
+ m = &oc->metadata;
+ break;
+ case 'c':
+ if (index < 0 || index >= oc->nb_chapters) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->chapters[index]->metadata;
+ break;
+ case 'p':
+ if (index < 0 || index >= oc->nb_programs) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
+ exit_program(1);
+ }
+ m = &oc->programs[index]->metadata;
+ break;
+ default:
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
+ exit_program(1);
+ }
+ av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
+ }
+ }
+}
+
static int open_output_file(OptionsContext *o, const char *filename)
{
AVFormatContext *oc;
int i, j, err;
OutputFile *of;
- OutputStream *ost;
AVDictionary *unused_opts = NULL, *format_opts = NULL;
const AVDictionaryEntry *e = NULL;
@@ -3143,67 +3204,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
}
of_add_programs(oc, o);
-
- /* process manually set metadata */
- for (i = 0; i < o->nb_metadata; i++) {
- AVDictionary **m;
- char type, *val;
- const char *stream_spec;
- int index = 0, j, ret = 0;
-
- val = strchr(o->metadata[i].u.str, '=');
- if (!val) {
- av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
- o->metadata[i].u.str);
- exit_program(1);
- }
- *val++ = 0;
-
- parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
- if (type == 's') {
- for (j = 0; j < oc->nb_streams; j++) {
- ost = output_streams[nb_output_streams - oc->nb_streams + j];
- if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
- if (!strcmp(o->metadata[i].u.str, "rotate")) {
- char *tail;
- double theta = av_strtod(val, &tail);
- if (!*tail) {
- ost->rotate_overridden = 1;
- ost->rotate_override_value = theta;
- }
- } else {
- av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
- }
- } else if (ret < 0)
- exit_program(1);
- }
- }
- else {
- switch (type) {
- case 'g':
- m = &oc->metadata;
- break;
- case 'c':
- if (index < 0 || index >= oc->nb_chapters) {
- av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
- exit_program(1);
- }
- m = &oc->chapters[index]->metadata;
- break;
- case 'p':
- if (index < 0 || index >= oc->nb_programs) {
- av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
- exit_program(1);
- }
- m = &oc->programs[index]->metadata;
- break;
- default:
- av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
- exit_program(1);
- }
- av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
- }
- }
+ of_add_metadata(oc, o);
err = set_dispositions(of, oc);
if (err < 0) {
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_hw: stop logging to the decoder context
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_opt: move adding programs " Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg_opt: move adding metadata " Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: stop accessing the decoder context unnecessarily Anton Khirnov
` (20 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Only the decoder itself should do that. Use NULL as is done by all other
logging code in ffmpeg.
---
fftools/ffmpeg_hw.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index 14e702bd92..8acfeaf08f 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -339,7 +339,7 @@ int hw_device_setup_for_decode(InputStream *ist)
if (ist->hwaccel_id == HWACCEL_AUTO) {
ist->hwaccel_device_type = dev->type;
} else if (ist->hwaccel_device_type != dev->type) {
- av_log(ist->dec_ctx, AV_LOG_ERROR, "Invalid hwaccel device "
+ av_log(NULL, AV_LOG_ERROR, "Invalid hwaccel device "
"specified for decoder: device %s of type %s is not "
"usable with hwaccel %s.\n", dev->name,
av_hwdevice_get_type_name(dev->type),
@@ -390,7 +390,7 @@ int hw_device_setup_for_decode(InputStream *ist)
type = config->device_type;
dev = hw_device_get_by_type(type);
if (dev) {
- av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto "
+ av_log(NULL, AV_LOG_INFO, "Using auto "
"hwaccel type %s with existing device %s.\n",
av_hwdevice_get_type_name(type), dev->name);
}
@@ -408,12 +408,12 @@ int hw_device_setup_for_decode(InputStream *ist)
continue;
}
if (ist->hwaccel_device) {
- av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto "
+ av_log(NULL, AV_LOG_INFO, "Using auto "
"hwaccel type %s with new device created "
"from %s.\n", av_hwdevice_get_type_name(type),
ist->hwaccel_device);
} else {
- av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto "
+ av_log(NULL, AV_LOG_INFO, "Using auto "
"hwaccel type %s with new default device.\n",
av_hwdevice_get_type_name(type));
}
@@ -421,7 +421,7 @@ int hw_device_setup_for_decode(InputStream *ist)
if (dev) {
ist->hwaccel_device_type = type;
} else {
- av_log(ist->dec_ctx, AV_LOG_INFO, "Auto hwaccel "
+ av_log(NULL, AV_LOG_INFO, "Auto hwaccel "
"disabled: no device found.\n");
ist->hwaccel_id = HWACCEL_NONE;
return 0;
@@ -429,7 +429,7 @@ int hw_device_setup_for_decode(InputStream *ist)
}
if (!dev) {
- av_log(ist->dec_ctx, AV_LOG_ERROR, "No device available "
+ av_log(NULL, AV_LOG_ERROR, "No device available "
"for decoder: device type %s needed for codec %s.\n",
av_hwdevice_get_type_name(type), ist->dec->name);
return err;
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: stop accessing the decoder context unnecessarily
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (2 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_hw: stop logging to the decoder context Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg_opt: drop redundant decoder selection Anton Khirnov
` (19 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
The same information is available from AVStream.codecpar. This will
allow to stop allocating a decoder unless decoding is actually
performed.
---
fftools/ffmpeg.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4746742c02..62ff1a98df 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1495,7 +1495,7 @@ static void print_final_stats(int64_t total_size)
for (j = 0; j < f->nb_streams; j++) {
InputStream *ist = input_streams[f->ist_index + j];
- enum AVMediaType type = ist->dec_ctx->codec_type;
+ enum AVMediaType type = ist->st->codecpar->codec_type;
total_size += ist->data_size;
total_packets += ist->nb_packets;
@@ -1915,11 +1915,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
if (pkt->dts == AV_NOPTS_VALUE) {
opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase);
} else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
- int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size);
+ int duration = av_get_audio_frame_duration2(ist->st->codecpar, pkt->size);
if(!duration)
- duration = ist->dec_ctx->frame_size;
+ duration = ist->st->codecpar->frame_size;
opkt->dts = av_rescale_delta(ist->st->time_base, pkt->dts,
- (AVRational){1, ist->dec_ctx->sample_rate}, duration,
+ (AVRational){1, ist->st->codecpar->sample_rate}, duration,
&ist->filter_in_rescale_delta_last, ost->mux_timebase);
/* dts will be set immediately afterwards to what pts is now */
opkt->pts = opkt->dts - ost_tb_start_time;
@@ -2394,6 +2394,7 @@ static int send_filter_eof(InputStream *ist)
/* pkt = NULL means EOF (needed to flush decoder buffers) */
static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
{
+ const AVCodecParameters *par = ist->st->codecpar;
int ret = 0, i;
int repeating = 0;
int eof_reached = 0;
@@ -2426,7 +2427,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
if (pkt && pkt->dts != AV_NOPTS_VALUE) {
ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
- if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
+ if (par->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
ist->next_pts = ist->pts = ist->dts;
}
@@ -2440,7 +2441,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
ist->pts = ist->next_pts;
ist->dts = ist->next_dts;
- switch (ist->dec_ctx->codec_type) {
+ switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output,
&decode_failed);
@@ -2537,12 +2538,12 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
/* handle stream copy */
if (!ist->decoding_needed && pkt) {
ist->dts = ist->next_dts;
- switch (ist->dec_ctx->codec_type) {
+ switch (par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
av_assert1(pkt->duration >= 0);
- if (ist->dec_ctx->sample_rate) {
- ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) /
- ist->dec_ctx->sample_rate;
+ if (par->sample_rate) {
+ ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
+ par->sample_rate;
} else {
ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
}
@@ -4000,7 +4001,8 @@ static int process_input(int file_index)
if (debug_ts) {
av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s "
"next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
- ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type),
+ ifile->ist_index + pkt->stream_index,
+ av_get_media_type_string(ist->st->codecpar->codec_type),
av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q),
av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q),
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base),
@@ -4076,8 +4078,8 @@ static int process_input(int file_index)
pkt->dts *= ist->ts_scale;
pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
- if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
- ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
+ if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
+ ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) &&
pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts
&& (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) {
int64_t delta = pkt_dts - ifile->last_ts;
@@ -4114,8 +4116,8 @@ static int process_input(int file_index)
disable_discontinuity_correction = 0;
}
- if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
- ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
+ if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
+ ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) &&
pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
!disable_discontinuity_correction) {
int64_t delta = pkt_dts - ist->next_dts;
@@ -4128,7 +4130,7 @@ static int process_input(int file_index)
"timestamp discontinuity for stream #%d:%d "
"(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
ist->file_index, ist->st->index, ist->st->id,
- av_get_media_type_string(ist->dec_ctx->codec_type),
+ av_get_media_type_string(ist->st->codecpar->codec_type),
delta, ifile->ts_offset);
pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
if (pkt->pts != AV_NOPTS_VALUE)
@@ -4157,7 +4159,8 @@ static int process_input(int file_index)
if (debug_ts) {
av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
- ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type),
+ ifile->ist_index + pkt->stream_index,
+ av_get_media_type_string(ist->st->codecpar->codec_type),
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base),
av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base),
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg_opt: drop redundant decoder selection
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (3 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: stop accessing the decoder context unnecessarily Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy Anton Khirnov
` (18 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
A decoder is already selected above, in choose_decoder().
---
fftools/ffmpeg_opt.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index aa240107dc..12cde4b617 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1078,9 +1078,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
switch (par->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- if(!ist->dec)
- ist->dec = avcodec_find_decoder(par->codec_id);
-
// avformat_find_stream_info() doesn't set this for us anymore.
ist->dec_ctx->framerate = st->avg_frame_rate;
@@ -1104,8 +1101,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
case AVMEDIA_TYPE_DATA:
case AVMEDIA_TYPE_SUBTITLE: {
char *canvas_size = NULL;
- if(!ist->dec)
- ist->dec = avcodec_find_decoder(par->codec_id);
MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
if (canvas_size &&
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (4 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg_opt: drop redundant decoder selection Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-04 12:40 ` Michael Niedermayer
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg: remove OutputStream.encoding_needed Anton Khirnov
` (17 subsequent siblings)
23 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
There are currently three possible modes for an output stream:
1) The stream is produced by encoding output from some filtergraph. This
is true when ost->enc_ctx != NULL, or equivalently when
ost->encoding_needed != 0.
2) The stream is produced by copying some input stream's packets. This
is true when ost->enc_ctx == NULL && ost->source_index >= 0.
3) The stream is produced by attaching some file directly. This is true
when ost->enc_ctx == NULL && ost->source_index < 0.
OutputStream.stream_copy is currently used to identify case 2), and
sometimes to confusingly (or even incorrectly) identify case 1). Remove
it, replacing its usage with checking enc_ctx/source_index values.
---
fftools/ffmpeg.c | 23 +++++++++--------------
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
3 files changed, 21 insertions(+), 36 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 62ff1a98df..0a1dc5bb3b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1566,9 +1566,7 @@ static void print_final_stats(int64_t total_size)
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
{
AVBPrint buf, buf_script;
- OutputStream *ost;
int64_t total_size = of_filesize(output_files[0]);
- AVCodecContext *enc;
int vid, i;
double bitrate;
double speed;
@@ -1600,11 +1598,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
for (i = 0; i < nb_output_streams; i++) {
- float q = -1;
- ost = output_streams[i];
- enc = ost->enc_ctx;
- if (!ost->stream_copy)
- q = ost->quality / (float) FF_QP2LAMBDA;
+ const OutputStream * const ost = output_streams[i];
+ const AVCodecContext * const enc = ost->enc_ctx;
+ const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1;
if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
av_bprintf(&buf, "q=%2.1f ", q);
@@ -3258,7 +3254,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
// 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);
- } else if (ost->stream_copy) {
+ } else if (ost->source_index >= 0) {
ret = init_output_stream_streamcopy(ost);
if (ret < 0)
return ret;
@@ -3343,7 +3339,7 @@ static int transcode_init(void)
* known after the encoder is initialized.
*/
for (i = 0; i < nb_output_streams; i++) {
- if (!output_streams[i]->stream_copy &&
+ if (output_streams[i]->enc_ctx &&
(output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))
continue;
@@ -3417,9 +3413,7 @@ static int transcode_init(void)
av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
ost->sync_ist->file_index,
ost->sync_ist->st->index);
- if (ost->stream_copy)
- av_log(NULL, AV_LOG_INFO, " (copy)");
- else {
+ if (ost->enc_ctx) {
const AVCodec *in_codec = input_streams[ost->source_index]->dec;
const AVCodec *out_codec = ost->enc;
const char *decoder_name = "?";
@@ -3449,7 +3443,8 @@ static int transcode_init(void)
av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",
in_codec_name, decoder_name,
out_codec_name, encoder_name);
- }
+ } else
+ av_log(NULL, AV_LOG_INFO, " (copy)");
av_log(NULL, AV_LOG_INFO, "\n");
}
@@ -3959,7 +3954,7 @@ static int process_input(int file_index)
OutputStream *ost = output_streams[j];
if (ost->source_index == ifile->ist_index + i &&
- (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) {
+ (!ost->enc_ctx || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) {
OutputFile *of = output_files[ost->file_index];
output_packet(of, ost->pkt, ost, 1);
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6417db03bd..713de42e2b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -540,7 +540,6 @@ typedef struct OutputStream {
char *apad;
OSTFinished finished; /* no more packets should be written for this stream */
int unavailable; /* true if the steram is unavailable (possibly temporarily) */
- int stream_copy;
// init_output_stream() has been called for this stream
// The encoder and the bitstream filters have been initialized and the stream
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 12cde4b617..784209e770 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1555,16 +1555,13 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o
avcodec_get_name(ost->st->codecpar->codec_id));
return AVERROR_ENCODER_NOT_FOUND;
}
- } else if (!strcmp(codec_name, "copy"))
- ost->stream_copy = 1;
- else {
+ } else if (strcmp(codec_name, "copy")) {
ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
ost->st->codecpar->codec_id = ost->enc->id;
}
- ost->encoding_needed = !ost->stream_copy;
+ ost->encoding_needed = !!ost->enc;
} else {
/* no encoding supported for other media types */
- ost->stream_copy = 1;
ost->encoding_needed = 0;
}
@@ -1898,7 +1895,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *video_enc = ost->enc_ctx;
const char *p = NULL;
char *frame_size = NULL;
@@ -2087,9 +2084,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
ost->last_frame = av_frame_alloc();
if (!ost->last_frame)
exit_program(1);
- }
-
- if (ost->stream_copy)
+ } else
check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
return ost;
@@ -2107,7 +2102,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *audio_enc = ost->enc_ctx;
int channels = 0;
char *layout = NULL;
@@ -2186,9 +2181,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
}
}
#endif
- }
-
- if (ost->stream_copy)
+ } else
check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
return ost;
@@ -2199,7 +2192,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int
OutputStream *ost;
ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
exit_program(1);
}
@@ -2212,7 +2205,7 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc,
OutputStream *ost;
ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
exit_program(1);
}
@@ -2223,7 +2216,6 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc,
static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
{
OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
- ost->stream_copy = 1;
ost->finished = 1;
return ost;
}
@@ -2236,7 +2228,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc,
ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
st = ost->st;
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *subtitle_enc = ost->enc_ctx;
char *frame_size = NULL;
@@ -2401,7 +2393,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
ofilter->ost = ost;
ofilter->format = -1;
- if (ost->stream_copy) {
+ if (!ost->enc_ctx) {
av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
"which is fed from a complex filtergraph. Filtering and streamcopy "
"cannot be used together.\n", ost->file_index, ost->index);
@@ -2768,7 +2760,6 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o)
memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
ost = new_attachment_stream(o, oc, -1);
- ost->stream_copy = 0;
ost->attachment_filename = o->attachments[i];
ost->st->codecpar->extradata = attachment;
ost->st->codecpar->extradata_size = len;
@@ -3068,7 +3059,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
exit_program(1);
}
}
- } else if (ost->stream_copy && ost->source_index >= 0) {
+ } else if (ost->source_index >= 0) {
InputStream *ist = input_streams[ost->source_index];
ist->processing_needed = 1;
}
@@ -3193,7 +3184,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
continue;
ist = input_streams[output_streams[i]->source_index];
av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
- if (!output_streams[i]->stream_copy) {
+ if (output_streams[i]->enc_ctx) {
av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
}
}
--
2.34.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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy Anton Khirnov
@ 2022-08-04 12:40 ` Michael Niedermayer
2022-08-04 12:54 ` Andreas Rheinhardt
` (2 more replies)
0 siblings, 3 replies; 35+ messages in thread
From: Michael Niedermayer @ 2022-08-04 12:40 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2179 bytes --]
On Wed, Aug 03, 2022 at 03:58:26PM +0200, Anton Khirnov wrote:
> There are currently three possible modes for an output stream:
> 1) The stream is produced by encoding output from some filtergraph. This
> is true when ost->enc_ctx != NULL, or equivalently when
> ost->encoding_needed != 0.
> 2) The stream is produced by copying some input stream's packets. This
> is true when ost->enc_ctx == NULL && ost->source_index >= 0.
> 3) The stream is produced by attaching some file directly. This is true
> when ost->enc_ctx == NULL && ost->source_index < 0.
>
> OutputStream.stream_copy is currently used to identify case 2), and
> sometimes to confusingly (or even incorrectly) identify case 1). Remove
> it, replacing its usage with checking enc_ctx/source_index values.
> ---
> fftools/ffmpeg.c | 23 +++++++++--------------
> fftools/ffmpeg.h | 1 -
> fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
> 3 files changed, 21 insertions(+), 36 deletions(-)
seems to break build with shared libs:
CC fftools/ffmpeg.o
src/fftools/ffmpeg.c:405:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
struct sigaction action = {0};
^
{}
src/fftools/ffmpeg.c:1612:37: error: address argument to atomic operation must be a pointer to non-const _Atomic type ('const atomic_uint_least64_t *' (aka 'const _Atomic(uint_least64_t) *') invalid)
uint64_t frame_number = atomic_load(&ost->packets_written);
^ ~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-6.0/lib/clang/6.0.0/include/stdatomic.h:134:29: note: expanded from macro 'atomic_load'
#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
^ ~~~~~~
1 warning and 1 error generated.
src/ffbuild/common.mak:81: recipe for target 'fftools/ffmpeg.o' failed
make: *** [fftools/ffmpeg.o] Error 1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
[-- 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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-04 12:40 ` Michael Niedermayer
@ 2022-08-04 12:54 ` Andreas Rheinhardt
2022-08-04 14:37 ` Anton Khirnov
2022-08-06 4:26 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2 siblings, 0 replies; 35+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 12:54 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Aug 03, 2022 at 03:58:26PM +0200, Anton Khirnov wrote:
>> There are currently three possible modes for an output stream:
>> 1) The stream is produced by encoding output from some filtergraph. This
>> is true when ost->enc_ctx != NULL, or equivalently when
>> ost->encoding_needed != 0.
>> 2) The stream is produced by copying some input stream's packets. This
>> is true when ost->enc_ctx == NULL && ost->source_index >= 0.
>> 3) The stream is produced by attaching some file directly. This is true
>> when ost->enc_ctx == NULL && ost->source_index < 0.
>>
>> OutputStream.stream_copy is currently used to identify case 2), and
>> sometimes to confusingly (or even incorrectly) identify case 1). Remove
>> it, replacing its usage with checking enc_ctx/source_index values.
>> ---
>> fftools/ffmpeg.c | 23 +++++++++--------------
>> fftools/ffmpeg.h | 1 -
>> fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
>> 3 files changed, 21 insertions(+), 36 deletions(-)
>
> seems to break build with shared libs:
>
> CC fftools/ffmpeg.o
> src/fftools/ffmpeg.c:405:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
> struct sigaction action = {0};
> ^
> {}
> src/fftools/ffmpeg.c:1612:37: error: address argument to atomic operation must be a pointer to non-const _Atomic type ('const atomic_uint_least64_t *' (aka 'const _Atomic(uint_least64_t) *') invalid)
> uint64_t frame_number = atomic_load(&ost->packets_written);
> ^ ~~~~~~~~~~~~~~~~~~~~~
> /usr/lib/llvm-6.0/lib/clang/6.0.0/include/stdatomic.h:134:29: note: expanded from macro 'atomic_load'
> #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
> ^ ~~~~~~
> 1 warning and 1 error generated.
> src/ffbuild/common.mak:81: recipe for target 'fftools/ffmpeg.o' failed
> make: *** [fftools/ffmpeg.o] Error 1
>
> [...]
>
This has nothing to do with shared libs. It is just that C11 defines
atomic_load in such a way that it does not allow a pointer to const
atomic; presumably because atomic types might be emulated via mutexes in
which case even a read involves a write.
- Andreas
_______________________________________________
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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-04 12:40 ` Michael Niedermayer
2022-08-04 12:54 ` Andreas Rheinhardt
@ 2022-08-04 14:37 ` Anton Khirnov
2022-08-04 14:51 ` Andreas Rheinhardt
2022-08-06 4:26 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2022-08-04 14:37 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Andreas Rheinhardt (2022-08-04 14:54:41)
> Michael Niedermayer:
> > On Wed, Aug 03, 2022 at 03:58:26PM +0200, Anton Khirnov wrote:
> >> There are currently three possible modes for an output stream:
> >> 1) The stream is produced by encoding output from some filtergraph. This
> >> is true when ost->enc_ctx != NULL, or equivalently when
> >> ost->encoding_needed != 0.
> >> 2) The stream is produced by copying some input stream's packets. This
> >> is true when ost->enc_ctx == NULL && ost->source_index >= 0.
> >> 3) The stream is produced by attaching some file directly. This is true
> >> when ost->enc_ctx == NULL && ost->source_index < 0.
> >>
> >> OutputStream.stream_copy is currently used to identify case 2), and
> >> sometimes to confusingly (or even incorrectly) identify case 1). Remove
> >> it, replacing its usage with checking enc_ctx/source_index values.
> >> ---
> >> fftools/ffmpeg.c | 23 +++++++++--------------
> >> fftools/ffmpeg.h | 1 -
> >> fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
> >> 3 files changed, 21 insertions(+), 36 deletions(-)
> >
> > seems to break build with shared libs:
> >
> > CC fftools/ffmpeg.o
> > src/fftools/ffmpeg.c:405:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
> > struct sigaction action = {0};
> > ^
> > {}
> > src/fftools/ffmpeg.c:1612:37: error: address argument to atomic operation must be a pointer to non-const _Atomic type ('const atomic_uint_least64_t *' (aka 'const _Atomic(uint_least64_t) *') invalid)
> > uint64_t frame_number = atomic_load(&ost->packets_written);
> > ^ ~~~~~~~~~~~~~~~~~~~~~
> > /usr/lib/llvm-6.0/lib/clang/6.0.0/include/stdatomic.h:134:29: note: expanded from macro 'atomic_load'
> > #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
> > ^ ~~~~~~
> > 1 warning and 1 error generated.
> > src/ffbuild/common.mak:81: recipe for target 'fftools/ffmpeg.o' failed
> > make: *** [fftools/ffmpeg.o] Error 1
> >
> > [...]
> >
>
> This has nothing to do with shared libs. It is just that C11 defines
> atomic_load in such a way that it does not allow a pointer to const
> atomic; presumably because atomic types might be emulated via mutexes in
> which case even a read involves a write.
I don't even get a warning with gcc 11 or clang 13.
--
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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-04 14:37 ` Anton Khirnov
@ 2022-08-04 14:51 ` Andreas Rheinhardt
0 siblings, 0 replies; 35+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 14:51 UTC (permalink / raw)
To: ffmpeg-devel
Anton Khirnov:
> Quoting Andreas Rheinhardt (2022-08-04 14:54:41)
>> Michael Niedermayer:
>>> On Wed, Aug 03, 2022 at 03:58:26PM +0200, Anton Khirnov wrote:
>>>> There are currently three possible modes for an output stream:
>>>> 1) The stream is produced by encoding output from some filtergraph. This
>>>> is true when ost->enc_ctx != NULL, or equivalently when
>>>> ost->encoding_needed != 0.
>>>> 2) The stream is produced by copying some input stream's packets. This
>>>> is true when ost->enc_ctx == NULL && ost->source_index >= 0.
>>>> 3) The stream is produced by attaching some file directly. This is true
>>>> when ost->enc_ctx == NULL && ost->source_index < 0.
>>>>
>>>> OutputStream.stream_copy is currently used to identify case 2), and
>>>> sometimes to confusingly (or even incorrectly) identify case 1). Remove
>>>> it, replacing its usage with checking enc_ctx/source_index values.
>>>> ---
>>>> fftools/ffmpeg.c | 23 +++++++++--------------
>>>> fftools/ffmpeg.h | 1 -
>>>> fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
>>>> 3 files changed, 21 insertions(+), 36 deletions(-)
>>>
>>> seems to break build with shared libs:
>>>
>>> CC fftools/ffmpeg.o
>>> src/fftools/ffmpeg.c:405:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
>>> struct sigaction action = {0};
>>> ^
>>> {}
>>> src/fftools/ffmpeg.c:1612:37: error: address argument to atomic operation must be a pointer to non-const _Atomic type ('const atomic_uint_least64_t *' (aka 'const _Atomic(uint_least64_t) *') invalid)
>>> uint64_t frame_number = atomic_load(&ost->packets_written);
>>> ^ ~~~~~~~~~~~~~~~~~~~~~
>>> /usr/lib/llvm-6.0/lib/clang/6.0.0/include/stdatomic.h:134:29: note: expanded from macro 'atomic_load'
>>> #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
>>> ^ ~~~~~~
>>> 1 warning and 1 error generated.
>>> src/ffbuild/common.mak:81: recipe for target 'fftools/ffmpeg.o' failed
>>> make: *** [fftools/ffmpeg.o] Error 1
>>>
>>> [...]
>>>
>>
>> This has nothing to do with shared libs. It is just that C11 defines
>> atomic_load in such a way that it does not allow a pointer to const
>> atomic; presumably because atomic types might be emulated via mutexes in
>> which case even a read involves a write.
>
> I don't even get a warning with gcc 11 or clang 13.
>
Yes, same for me (this is meant literally:
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298360.html). Maybe
the spec has been modified since then:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1807.htm and
https://en.cppreference.com/w/c/atomic/atomic_load indicate this.
- Andreas
_______________________________________________
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] 35+ messages in thread
* [FFmpeg-devel] [PATCH] fftools/ffmpeg: remove OutputStream.stream_copy
2022-08-04 12:40 ` Michael Niedermayer
2022-08-04 12:54 ` Andreas Rheinhardt
2022-08-04 14:37 ` Anton Khirnov
@ 2022-08-06 4:26 ` Anton Khirnov
2 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-06 4:26 UTC (permalink / raw)
To: ffmpeg-devel
There are currently three possible modes for an output stream:
1) The stream is produced by encoding output from some filtergraph. This
is true when ost->enc_ctx != NULL, or equivalently when
ost->encoding_needed != 0.
2) The stream is produced by copying some input stream's packets. This
is true when ost->enc_ctx == NULL && ost->source_index >= 0.
3) The stream is produced by attaching some file directly. This is true
when ost->enc_ctx == NULL && ost->source_index < 0.
OutputStream.stream_copy is currently used to identify case 2), and
sometimes to confusingly (or even incorrectly) identify case 1). Remove
it, replacing its usage with checking enc_ctx/source_index values.
---
fftools/ffmpeg.c | 23 +++++++++--------------
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_opt.c | 33 ++++++++++++---------------------
3 files changed, 21 insertions(+), 36 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 62ff1a98df..cf61706ac0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1566,9 +1566,7 @@ static void print_final_stats(int64_t total_size)
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
{
AVBPrint buf, buf_script;
- OutputStream *ost;
int64_t total_size = of_filesize(output_files[0]);
- AVCodecContext *enc;
int vid, i;
double bitrate;
double speed;
@@ -1600,11 +1598,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
for (i = 0; i < nb_output_streams; i++) {
- float q = -1;
- ost = output_streams[i];
- enc = ost->enc_ctx;
- if (!ost->stream_copy)
- q = ost->quality / (float) FF_QP2LAMBDA;
+ OutputStream * const ost = output_streams[i];
+ const AVCodecContext * const enc = ost->enc_ctx;
+ const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1;
if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
av_bprintf(&buf, "q=%2.1f ", q);
@@ -3258,7 +3254,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
// 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);
- } else if (ost->stream_copy) {
+ } else if (ost->source_index >= 0) {
ret = init_output_stream_streamcopy(ost);
if (ret < 0)
return ret;
@@ -3343,7 +3339,7 @@ static int transcode_init(void)
* known after the encoder is initialized.
*/
for (i = 0; i < nb_output_streams; i++) {
- if (!output_streams[i]->stream_copy &&
+ if (output_streams[i]->enc_ctx &&
(output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
output_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))
continue;
@@ -3417,9 +3413,7 @@ static int transcode_init(void)
av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
ost->sync_ist->file_index,
ost->sync_ist->st->index);
- if (ost->stream_copy)
- av_log(NULL, AV_LOG_INFO, " (copy)");
- else {
+ if (ost->enc_ctx) {
const AVCodec *in_codec = input_streams[ost->source_index]->dec;
const AVCodec *out_codec = ost->enc;
const char *decoder_name = "?";
@@ -3449,7 +3443,8 @@ static int transcode_init(void)
av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",
in_codec_name, decoder_name,
out_codec_name, encoder_name);
- }
+ } else
+ av_log(NULL, AV_LOG_INFO, " (copy)");
av_log(NULL, AV_LOG_INFO, "\n");
}
@@ -3959,7 +3954,7 @@ static int process_input(int file_index)
OutputStream *ost = output_streams[j];
if (ost->source_index == ifile->ist_index + i &&
- (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) {
+ (!ost->enc_ctx || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) {
OutputFile *of = output_files[ost->file_index];
output_packet(of, ost->pkt, ost, 1);
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6417db03bd..713de42e2b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -540,7 +540,6 @@ typedef struct OutputStream {
char *apad;
OSTFinished finished; /* no more packets should be written for this stream */
int unavailable; /* true if the steram is unavailable (possibly temporarily) */
- int stream_copy;
// init_output_stream() has been called for this stream
// The encoder and the bitstream filters have been initialized and the stream
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 12cde4b617..784209e770 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1555,16 +1555,13 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o
avcodec_get_name(ost->st->codecpar->codec_id));
return AVERROR_ENCODER_NOT_FOUND;
}
- } else if (!strcmp(codec_name, "copy"))
- ost->stream_copy = 1;
- else {
+ } else if (strcmp(codec_name, "copy")) {
ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
ost->st->codecpar->codec_id = ost->enc->id;
}
- ost->encoding_needed = !ost->stream_copy;
+ ost->encoding_needed = !!ost->enc;
} else {
/* no encoding supported for other media types */
- ost->stream_copy = 1;
ost->encoding_needed = 0;
}
@@ -1898,7 +1895,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *video_enc = ost->enc_ctx;
const char *p = NULL;
char *frame_size = NULL;
@@ -2087,9 +2084,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
ost->last_frame = av_frame_alloc();
if (!ost->last_frame)
exit_program(1);
- }
-
- if (ost->stream_copy)
+ } else
check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
return ost;
@@ -2107,7 +2102,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *audio_enc = ost->enc_ctx;
int channels = 0;
char *layout = NULL;
@@ -2186,9 +2181,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
}
}
#endif
- }
-
- if (ost->stream_copy)
+ } else
check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
return ost;
@@ -2199,7 +2192,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int
OutputStream *ost;
ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
exit_program(1);
}
@@ -2212,7 +2205,7 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc,
OutputStream *ost;
ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
exit_program(1);
}
@@ -2223,7 +2216,6 @@ static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc,
static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
{
OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
- ost->stream_copy = 1;
ost->finished = 1;
return ost;
}
@@ -2236,7 +2228,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc,
ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
st = ost->st;
- if (!ost->stream_copy) {
+ if (ost->enc_ctx) {
AVCodecContext *subtitle_enc = ost->enc_ctx;
char *frame_size = NULL;
@@ -2401,7 +2393,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
ofilter->ost = ost;
ofilter->format = -1;
- if (ost->stream_copy) {
+ if (!ost->enc_ctx) {
av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
"which is fed from a complex filtergraph. Filtering and streamcopy "
"cannot be used together.\n", ost->file_index, ost->index);
@@ -2768,7 +2760,6 @@ static void of_add_attachments(AVFormatContext *oc, OptionsContext *o)
memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
ost = new_attachment_stream(o, oc, -1);
- ost->stream_copy = 0;
ost->attachment_filename = o->attachments[i];
ost->st->codecpar->extradata = attachment;
ost->st->codecpar->extradata_size = len;
@@ -3068,7 +3059,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
exit_program(1);
}
}
- } else if (ost->stream_copy && ost->source_index >= 0) {
+ } else if (ost->source_index >= 0) {
InputStream *ist = input_streams[ost->source_index];
ist->processing_needed = 1;
}
@@ -3193,7 +3184,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
continue;
ist = input_streams[output_streams[i]->source_index];
av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
- if (!output_streams[i]->stream_copy) {
+ if (output_streams[i]->enc_ctx) {
av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
}
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg: remove OutputStream.encoding_needed
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (5 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: remove OutputStream.stream_copy Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: remove OutputStream.sync_ist Anton Khirnov
` (16 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
It is unnecessary, as it is always exactly equivalent to !!ost->enc_ctx
---
fftools/ffmpeg.c | 10 +++++-----
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_opt.c | 8 ++------
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0a1dc5bb3b..6124197580 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1536,7 +1536,7 @@ static void print_final_stats(int64_t total_size)
av_log(NULL, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ",
i, j, av_get_media_type_string(type));
- if (ost->encoding_needed) {
+ if (ost->enc_ctx) {
av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
ost->frames_encoded);
if (type == AVMEDIA_TYPE_AUDIO)
@@ -1788,7 +1788,7 @@ static void flush_encoders(void)
AVCodecContext *enc = ost->enc_ctx;
OutputFile *of = output_files[ost->file_index];
- if (!ost->encoding_needed)
+ if (!enc)
continue;
// Try to enable encoding with no input frames.
@@ -2359,7 +2359,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
- if (!check_output_constraints(ist, ost) || !ost->encoding_needed
+ if (!check_output_constraints(ist, ost) || !ost->enc_ctx
|| ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
continue;
@@ -2568,7 +2568,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
- if (!check_output_constraints(ist, ost) || ost->encoding_needed ||
+ if (!check_output_constraints(ist, ost) || ost->enc_ctx ||
(!pkt && no_eof))
continue;
@@ -3137,7 +3137,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
OutputFile *of = output_files[ost->file_index];
int ret = 0;
- if (ost->encoding_needed) {
+ if (ost->enc_ctx) {
const AVCodec *codec = ost->enc;
AVCodecContext *dec = NULL;
InputStream *ist;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 713de42e2b..69e4758a2d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -464,7 +464,6 @@ typedef struct OutputStream {
int index; /* stream index in the output file */
int source_index; /* InputStream index */
AVStream *st; /* stream in the output file */
- int encoding_needed; /* true if encoding needed for this stream */
/* number of frames emitted by the video-encoding sync code */
int64_t vsync_frame_number;
/* input pts and corresponding output pts
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 784209e770..ffa320da87 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1559,10 +1559,6 @@ static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *o
ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
ost->st->codecpar->codec_id = ost->enc->id;
}
- ost->encoding_needed = !!ost->enc;
- } else {
- /* no encoding supported for other media types */
- ost->encoding_needed = 0;
}
return 0;
@@ -2433,7 +2429,7 @@ static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_si
int limit_frames = 0, limit_frames_av_enc = 0;
#define IS_AV_ENC(ost, type) \
- (ost->encoding_needed && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))
+ (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))
#define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT)
for (int i = 0; i < oc->nb_streams; i++) {
@@ -3043,7 +3039,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
for (i = of->ost_index; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
- if (ost->encoding_needed && ost->source_index >= 0) {
+ if (ost->enc_ctx && ost->source_index >= 0) {
InputStream *ist = input_streams[ost->source_index];
ist->decoding_needed |= DECODING_FOR_OST;
ist->processing_needed = 1;
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: remove OutputStream.sync_ist
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (6 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg: remove OutputStream.encoding_needed Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: deprecate specifying a sync stream with -map Anton Khirnov
` (15 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
It is not actually used for anything.
---
fftools/ffmpeg.c | 4 ----
fftools/ffmpeg.h | 1 -
fftools/ffmpeg_opt.c | 18 ++++++------------
3 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6124197580..47f9a6137f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3409,10 +3409,6 @@ static int transcode_init(void)
input_streams[ost->source_index]->st->index,
ost->file_index,
ost->index);
- if (ost->sync_ist != input_streams[ost->source_index])
- av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
- ost->sync_ist->file_index,
- ost->sync_ist->st->index);
if (ost->enc_ctx) {
const AVCodec *in_codec = input_streams[ost->source_index]->dec;
const AVCodec *out_codec = ost->enc;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 69e4758a2d..b7d62957f8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -468,7 +468,6 @@ typedef struct OutputStream {
int64_t vsync_frame_number;
/* input pts and corresponding output pts
for A/V sync */
- struct InputStream *sync_ist; /* input stream to sync against */
int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
/* pts of the first frame encoded for this stream, used for limiting
* recording time */
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index ffa320da87..0cd807c9c8 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1757,7 +1757,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->source_index = source_index;
if (source_index >= 0) {
- ost->sync_ist = input_streams[source_index];
input_streams[source_index]->discard = 0;
input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
}
@@ -2650,7 +2649,6 @@ static void map_manual(OutputFile *of, AVFormatContext *oc,
OptionsContext *o, const StreamMap *map)
{
InputStream *ist;
- OutputStream *ost;
if (map->disabled)
return;
@@ -2695,16 +2693,15 @@ loop_end:
if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
return;
- ost = NULL;
switch (ist->st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
- case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
- case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
- case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
- case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
+ case AVMEDIA_TYPE_VIDEO: new_video_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_AUDIO: new_audio_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_DATA: new_data_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(o, oc, src_idx); break;
case AVMEDIA_TYPE_UNKNOWN:
if (copy_unknown_streams) {
- ost = new_unknown_stream (o, oc, src_idx);
+ new_unknown_stream (o, oc, src_idx);
break;
}
default:
@@ -2719,9 +2716,6 @@ loop_end:
exit_program(1);
}
}
- if (ost)
- ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
- + map->sync_stream_index];
}
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: deprecate specifying a sync stream with -map
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (7 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: remove OutputStream.sync_ist Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 11/25] doc/ffmpeg: update -map documentation Anton Khirnov
` (14 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
It has not had any effect whatsoever for over 10 years.
---
doc/ffmpeg.texi | 6 ++----
fftools/ffmpeg.h | 3 +--
fftools/ffmpeg_opt.c | 41 +++++++----------------------------------
3 files changed, 10 insertions(+), 40 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 2fb0bc8ffa..20747ebb8e 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1411,14 +1411,12 @@ Set the size of the canvas used to render subtitles.
@section Advanced options
@table @option
-@item -map [-]@var{input_file_id}[:@var{stream_specifier}][?][,@var{sync_file_id}[:@var{stream_specifier}]] | @var{[linklabel]} (@emph{output})
+@item -map [-]@var{input_file_id}[:@var{stream_specifier}][?] | @var{[linklabel]} (@emph{output})
Designate one or more input streams as a source for the output file. Each input
stream is identified by the input file index @var{input_file_id} and
the input stream index @var{input_stream_id} within the input
-file. Both indices start at 0. If specified,
-@var{sync_file_id}:@var{stream_specifier} sets which input stream
-is used as a presentation sync reference.
+file. Both indices start at 0.
The first @code{-map} option on the command line specifies the
source for output stream 0, the second @code{-map} option specifies
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b7d62957f8..6b09846825 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -52,6 +52,7 @@
// deprecated features
#define FFMPEG_OPT_PSNR 1
#define FFMPEG_OPT_MAP_CHANNEL 1
+#define FFMPEG_OPT_MAP_SYNC 1
enum VideoSyncMethod {
VSYNC_AUTO = -1,
@@ -81,8 +82,6 @@ typedef struct StreamMap {
int disabled; /* 1 is this mapping is disabled by a negative map */
int file_index;
int stream_index;
- int sync_file_index;
- int sync_stream_index;
char *linklabel; /* name of an output link, for mapping lavfi outputs */
} StreamMap;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 0cd807c9c8..bd3a34960c 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -415,9 +415,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
OptionsContext *o = optctx;
StreamMap *m = NULL;
int i, negative = 0, file_idx, disabled = 0;
- int sync_file_idx = -1, sync_stream_idx = 0;
- char *p, *sync;
- char *map;
+#if FFMPEG_OPT_MAP_SYNC
+ char *sync;
+#endif
+ char *map, *p;
char *allow_unused;
if (*arg == '-') {
@@ -428,33 +429,13 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
if (!map)
return AVERROR(ENOMEM);
+#if FFMPEG_OPT_MAP_SYNC
/* parse sync stream first, just pick first matching stream */
if (sync = strchr(map, ',')) {
*sync = 0;
- sync_file_idx = strtol(sync + 1, &sync, 0);
- if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
- av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
- exit_program(1);
- }
- if (*sync)
- sync++;
- for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
- if (check_stream_specifier(input_files[sync_file_idx]->ctx,
- input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
- sync_stream_idx = i;
- break;
- }
- if (i == input_files[sync_file_idx]->nb_streams) {
- av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
- "match any streams.\n", arg);
- exit_program(1);
- }
- if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
- av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
- "stream.\n", arg);
- exit_program(1);
- }
+ av_log(NULL, AV_LOG_WARNING, "Specifying a sync stream is deprecated and has no effect\n");
}
+#endif
if (map[0] == '[') {
@@ -499,14 +480,6 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
m->file_index = file_idx;
m->stream_index = i;
-
- if (sync_file_idx >= 0) {
- m->sync_file_index = sync_file_idx;
- m->sync_stream_index = sync_stream_idx;
- } else {
- m->sync_file_index = file_idx;
- m->sync_stream_index = i;
- }
}
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 11/25] doc/ffmpeg: update -map documentation
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (8 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: deprecate specifying a sync stream with -map Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg: drop a superfluous stack variable Anton Khirnov
` (13 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Make it match reality (current text was not updated for stream
specifiers), extend and clarify the text.
---
doc/ffmpeg.texi | 58 +++++++++++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 19 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 20747ebb8e..42440d93b4 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1413,14 +1413,16 @@ Set the size of the canvas used to render subtitles.
@table @option
@item -map [-]@var{input_file_id}[:@var{stream_specifier}][?] | @var{[linklabel]} (@emph{output})
-Designate one or more input streams as a source for the output file. Each input
-stream is identified by the input file index @var{input_file_id} and
-the input stream index @var{input_stream_id} within the input
-file. Both indices start at 0.
+Create one or more streams in the output file. This option has two forms for
+specifying the data source(s): the first selects one or more streams from some
+input file (specified with @code{-i}), the second takes an output from some
+complex filtergraph (specified with @code{-filter_complex} or
+@code{-filter_complex_script}).
-The first @code{-map} option on the command line specifies the
-source for output stream 0, the second @code{-map} option specifies
-the source for output stream 1, etc.
+In the first form, an output stream is created for every stream from the input
+file with the index @var{input_file_id}. If @var{stream_specifier} is given,
+only those streams that match the specifier are used (see the
+@ref{Stream specifiers} section for the @var{stream_specifier} syntax).
A @code{-} character before the stream identifier creates a "negative" mapping.
It disables matching streams from already created mappings.
@@ -1434,39 +1436,56 @@ An alternative @var{[linklabel]} form will map outputs from complex filter
graphs (see the @option{-filter_complex} option) to the output file.
@var{linklabel} must correspond to a defined output link label in the graph.
-For example, to map ALL streams from the first input file to output
+This option may be specified multiple times, each adding more streams to the
+output file. Any given input stream may also be mapped any number of times as a
+source for different output streams, e.g. in order to use different encoding
+options and/or filters. The streams are created in the output in the same order
+in which the @code{-map} options are given on the commandline.
+
+Using this option disables the default mappings for this output file.
+
+Examples:
+
+@table @emph
+
+@item map everything
+To map ALL streams from the first input file to output
@example
ffmpeg -i INPUT -map 0 output
@end example
-For example, if you have two audio streams in the first input file,
-these streams are identified by "0:0" and "0:1". You can use
-@code{-map} to select which streams to place in an output file. For
-example:
+@item select specific stream
+If you have two audio streams in the first input file, these streams are
+identified by @var{0:0} and @var{0:1}. You can use @code{-map} to select which
+streams to place in an output file. For example:
@example
ffmpeg -i INPUT -map 0:1 out.wav
@end example
-will map the input stream in @file{INPUT} identified by "0:1" to
-the (single) output stream in @file{out.wav}.
+will map the second input stream in @file{INPUT} to the (single) output stream
+in @file{out.wav}.
-For example, to select the stream with index 2 from input file
-@file{a.mov} (specified by the identifier "0:2"), and stream with
-index 6 from input @file{b.mov} (specified by the identifier "1:6"),
-and copy them to the output file @file{out.mov}:
+@item create multiple streams
+To select the stream with index 2 from input file @file{a.mov} (specified by the
+identifier @var{0:2}), and stream with index 6 from input @file{b.mov}
+(specified by the identifier @var{1:6}), and copy them to the output file
+@file{out.mov}:
@example
ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov
@end example
+@item create multiple streams 2
To select all video and the third audio stream from an input file:
@example
ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT
@end example
+@item negative map
To map all the streams except the second audio, use negative mappings
@example
ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT
@end example
+@item optional map
To map the video and audio streams from the first input, and using the
trailing @code{?}, ignore the audio mapping if no audio streams exist in
the first input:
@@ -1474,12 +1493,13 @@ the first input:
ffmpeg -i INPUT -map 0:v -map 0:a? OUTPUT
@end example
+@item map by language
To pick the English audio stream:
@example
ffmpeg -i INPUT -map 0:m:language:eng OUTPUT
@end example
-Note that using this option disables the default mappings for this output file.
+@end table
@item -ignore_unknown
Ignore input streams with unknown type instead of failing if copying
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg: drop a superfluous stack variable
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (9 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 11/25] doc/ffmpeg: update -map documentation Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg: store the input file index in InputFile Anton Khirnov
` (12 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 47f9a6137f..f12364fe0a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3904,16 +3904,14 @@ static int process_input(int file_index)
return ret;
}
if (ret < 0 && ifile->loop) {
- AVCodecContext *avctx;
for (i = 0; i < ifile->nb_streams; i++) {
ist = input_streams[ifile->ist_index + i];
- avctx = ist->dec_ctx;
if (ist->processing_needed) {
ret = process_input_packet(ist, NULL, 1);
if (ret>0)
return 0;
if (ist->decoding_needed)
- avcodec_flush_buffers(avctx);
+ avcodec_flush_buffers(ist->dec_ctx);
}
}
free_input_thread(file_index);
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg: store the input file index in InputFile
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (10 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg: drop a superfluous stack variable Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: always read input in a thread Anton Khirnov
` (11 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Use it to simplify some code and fix two off-by-one errors.
Similar to what was previously done for OutputFile.
---
fftools/ffmpeg.h | 2 ++
fftools/ffmpeg_opt.c | 9 +++++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6b09846825..23b249780b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -408,6 +408,8 @@ typedef struct InputStream {
} InputStream;
typedef struct InputFile {
+ int index;
+
AVFormatContext *ctx;
int eof_reached; /* true if eof reached */
int eagain; /* true if last read attempt returned EAGAIN */
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index bd3a34960c..25aa9aaff5 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1383,6 +1383,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
f = ALLOC_ARRAY_ELEM(input_files, nb_input_files);
f->ctx = ic;
+ f->index = nb_input_files - 1;
f->ist_index = nb_input_streams - ic->nb_streams;
f->start_time = o->start_time;
f->recording_time = o->recording_time;
@@ -1398,11 +1399,11 @@ static int open_input_file(OptionsContext *o, const char *filename)
f->readrate = o->readrate ? o->readrate : 0.0;
if (f->readrate < 0.0f) {
- av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", nb_input_files, f->readrate);
+ av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate);
exit_program(1);
}
if (f->readrate && f->rate_emu) {
- av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", nb_input_files, f->readrate);
+ av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate);
f->rate_emu = 0;
}
@@ -1435,7 +1436,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
"input file #%d (%s) is not a decoding option.\n", e->key,
- option->help ? option->help : "", nb_input_files - 1,
+ option->help ? option->help : "", f->index,
filename);
exit_program(1);
}
@@ -1445,7 +1446,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
"likely reason is either wrong type (e.g. a video option with "
"no video streams) or that it is a private option of some decoder "
"which was not actually used for any stream.\n", e->key,
- option->help ? option->help : "", nb_input_files - 1, filename);
+ option->help ? option->help : "", f->index, filename);
}
av_dict_free(&unused_opts);
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: always read input in a thread
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (11 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg: store the input file index in InputFile Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: drop a write-only variable Anton Khirnov
` (10 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
This will be required by the following architecture changes.
---
fftools/ffmpeg.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f12364fe0a..7ba1f2a8cf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3713,10 +3713,8 @@ static int init_input_thread(int i)
int ret;
InputFile *f = input_files[i];
- if (f->thread_queue_size < 0)
- f->thread_queue_size = (nb_input_files > 1 ? 8 : 0);
- if (!f->thread_queue_size)
- return 0;
+ if (f->thread_queue_size <= 0)
+ f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
if (f->ctx->pb ? !f->ctx->pb->seekable :
strcmp(f->ctx->iformat->name, "lavfi"))
@@ -3747,13 +3745,6 @@ static int init_input_threads(void)
return 0;
}
-static int get_input_packet_mt(InputFile *f, AVPacket **pkt)
-{
- return av_thread_message_queue_recv(f->in_thread_queue, pkt,
- f->non_blocking ?
- AV_THREAD_MESSAGE_NONBLOCK : 0);
-}
-
static int get_input_packet(InputFile *f, AVPacket **pkt)
{
if (f->readrate || f->rate_emu) {
@@ -3775,10 +3766,9 @@ static int get_input_packet(InputFile *f, AVPacket **pkt)
}
}
- if (f->thread_queue_size)
- return get_input_packet_mt(f, pkt);
- *pkt = f->pkt;
- return av_read_frame(f->ctx, *pkt);
+ return av_thread_message_queue_recv(f->in_thread_queue, pkt,
+ f->non_blocking ?
+ AV_THREAD_MESSAGE_NONBLOCK : 0);
}
static int got_eagain(void)
@@ -4162,10 +4152,7 @@ static int process_input(int file_index)
process_input_packet(ist, pkt, 0);
discard_packet:
- if (ifile->thread_queue_size)
- av_packet_free(&pkt);
- else
- av_packet_unref(pkt);
+ av_packet_free(&pkt);
return 0;
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: drop a write-only variable
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (12 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: always read input in a thread Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: move the input thread into its own file Anton Khirnov
` (9 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 1 -
fftools/ffmpeg.h | 1 -
2 files changed, 2 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7ba1f2a8cf..a377e776c7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3696,7 +3696,6 @@ static void free_input_thread(int i)
av_packet_free(&pkt);
pthread_join(f->thread, NULL);
- f->joined = 1;
av_thread_message_queue_free(&f->in_thread_queue);
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 23b249780b..fc082bfbea 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -437,7 +437,6 @@ typedef struct InputFile {
AVThreadMessageQueue *in_thread_queue;
pthread_t thread; /* thread reading from this file */
int non_blocking; /* reading packets from the thread should not block */
- int joined; /* the thread has been joined */
int thread_queue_size; /* maximum number of queued packets */
} InputFile;
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: move the input thread into its own file
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (13 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: drop a write-only variable Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: drop the 'h' key handling Anton Khirnov
` (8 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
It will contain more demuxing-specific code in the future.
---
fftools/Makefile | 1 +
fftools/ffmpeg.c | 110 ---------------------------------
fftools/ffmpeg.h | 5 ++
fftools/ffmpeg_demux.c | 136 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 142 insertions(+), 110 deletions(-)
create mode 100644 fftools/ffmpeg_demux.c
diff --git a/fftools/Makefile b/fftools/Makefile
index 6285e6eacb..5907f5c57e 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -10,6 +10,7 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
OBJS-ffmpeg += \
+ fftools/ffmpeg_demux.o \
fftools/ffmpeg_filter.o \
fftools/ffmpeg_hw.o \
fftools/ffmpeg_mux.o \
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a377e776c7..0a94b0d05a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -161,8 +161,6 @@ static struct termios oldtty;
static int restore_tty;
#endif
-static void free_input_threads(void);
-
/* sub2video hack:
Convert subtitles to video with alpha to insert them in filter graphs.
This is a temporary solution until libavfilter gets real subtitles support.
@@ -3636,114 +3634,6 @@ static int check_keyboard_interaction(int64_t cur_time)
return 0;
}
-static void *input_thread(void *arg)
-{
- InputFile *f = arg;
- AVPacket *pkt = f->pkt, *queue_pkt;
- unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
- int ret = 0;
-
- while (1) {
- ret = av_read_frame(f->ctx, pkt);
-
- if (ret == AVERROR(EAGAIN)) {
- av_usleep(10000);
- continue;
- }
- if (ret < 0) {
- av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
- break;
- }
- queue_pkt = av_packet_alloc();
- if (!queue_pkt) {
- av_packet_unref(pkt);
- av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM));
- break;
- }
- av_packet_move_ref(queue_pkt, pkt);
- ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
- if (flags && ret == AVERROR(EAGAIN)) {
- flags = 0;
- ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
- av_log(f->ctx, AV_LOG_WARNING,
- "Thread message queue blocking; consider raising the "
- "thread_queue_size option (current value: %d)\n",
- f->thread_queue_size);
- }
- if (ret < 0) {
- if (ret != AVERROR_EOF)
- av_log(f->ctx, AV_LOG_ERROR,
- "Unable to send packet to main thread: %s\n",
- av_err2str(ret));
- av_packet_free(&queue_pkt);
- av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
- break;
- }
- }
-
- return NULL;
-}
-
-static void free_input_thread(int i)
-{
- InputFile *f = input_files[i];
- AVPacket *pkt;
-
- if (!f || !f->in_thread_queue)
- return;
- av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
- while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
- av_packet_free(&pkt);
-
- pthread_join(f->thread, NULL);
- av_thread_message_queue_free(&f->in_thread_queue);
-}
-
-static void free_input_threads(void)
-{
- int i;
-
- for (i = 0; i < nb_input_files; i++)
- free_input_thread(i);
-}
-
-static int init_input_thread(int i)
-{
- int ret;
- InputFile *f = input_files[i];
-
- if (f->thread_queue_size <= 0)
- f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
-
- if (f->ctx->pb ? !f->ctx->pb->seekable :
- strcmp(f->ctx->iformat->name, "lavfi"))
- f->non_blocking = 1;
- ret = av_thread_message_queue_alloc(&f->in_thread_queue,
- f->thread_queue_size, sizeof(f->pkt));
- if (ret < 0)
- return ret;
-
- if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
- av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
- av_thread_message_queue_free(&f->in_thread_queue);
- return AVERROR(ret);
- }
-
- return 0;
-}
-
-static int init_input_threads(void)
-{
- int i, ret;
-
- for (i = 0; i < nb_input_files; i++) {
- ret = init_input_thread(i);
- if (ret < 0)
- return ret;
- }
- return 0;
-}
-
static int get_input_packet(InputFile *f, AVPacket **pkt)
{
if (f->readrate || f->rate_emu) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fc082bfbea..81356fd566 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -710,4 +710,9 @@ int64_t of_filesize(OutputFile *of);
AVChapter * const *
of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
+int init_input_threads(void);
+int init_input_thread(int i);
+void free_input_threads(void);
+void free_input_thread(int i);
+
#endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
new file mode 100644
index 0000000000..2629af5950
--- /dev/null
+++ b/fftools/ffmpeg_demux.c
@@ -0,0 +1,136 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "ffmpeg.h"
+
+#include "libavutil/error.h"
+#include "libavutil/time.h"
+#include "libavutil/thread.h"
+#include "libavutil/threadmessage.h"
+
+#include "libavcodec/packet.h"
+
+#include "libavformat/avformat.h"
+
+static void *input_thread(void *arg)
+{
+ InputFile *f = arg;
+ AVPacket *pkt = f->pkt, *queue_pkt;
+ unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
+ int ret = 0;
+
+ while (1) {
+ ret = av_read_frame(f->ctx, pkt);
+
+ if (ret == AVERROR(EAGAIN)) {
+ av_usleep(10000);
+ continue;
+ }
+ if (ret < 0) {
+ av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+ break;
+ }
+ queue_pkt = av_packet_alloc();
+ if (!queue_pkt) {
+ av_packet_unref(pkt);
+ av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM));
+ break;
+ }
+ av_packet_move_ref(queue_pkt, pkt);
+ ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
+ if (flags && ret == AVERROR(EAGAIN)) {
+ flags = 0;
+ ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
+ av_log(f->ctx, AV_LOG_WARNING,
+ "Thread message queue blocking; consider raising the "
+ "thread_queue_size option (current value: %d)\n",
+ f->thread_queue_size);
+ }
+ if (ret < 0) {
+ if (ret != AVERROR_EOF)
+ av_log(f->ctx, AV_LOG_ERROR,
+ "Unable to send packet to main thread: %s\n",
+ av_err2str(ret));
+ av_packet_free(&queue_pkt);
+ av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+ break;
+ }
+ }
+
+ return NULL;
+}
+
+void free_input_thread(int i)
+{
+ InputFile *f = input_files[i];
+ AVPacket *pkt;
+
+ if (!f || !f->in_thread_queue)
+ return;
+ av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
+ while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
+ av_packet_free(&pkt);
+
+ pthread_join(f->thread, NULL);
+ av_thread_message_queue_free(&f->in_thread_queue);
+}
+
+void free_input_threads(void)
+{
+ int i;
+
+ for (i = 0; i < nb_input_files; i++)
+ free_input_thread(i);
+}
+
+int init_input_thread(int i)
+{
+ int ret;
+ InputFile *f = input_files[i];
+
+ if (f->thread_queue_size <= 0)
+ f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
+
+ if (f->ctx->pb ? !f->ctx->pb->seekable :
+ strcmp(f->ctx->iformat->name, "lavfi"))
+ f->non_blocking = 1;
+ ret = av_thread_message_queue_alloc(&f->in_thread_queue,
+ f->thread_queue_size, sizeof(f->pkt));
+ if (ret < 0)
+ return ret;
+
+ if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
+ av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
+ av_thread_message_queue_free(&f->in_thread_queue);
+ return AVERROR(ret);
+ }
+
+ return 0;
+}
+
+int init_input_threads(void)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_input_files; i++) {
+ ret = init_input_thread(i);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: drop the 'h' key handling
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (14 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: move the input thread into its own file Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: handle dumping input packets in input_thread() Anton Khirnov
` (7 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
This undocumented feature runtime-enables dumping input packets. I can
think of no reasonable real-world use case that cannot also be
accomplished in a different way. Keeping this functionality would
interfere with the following commit moving it to the input thread (then
setting the variable would require locking or atomics, which would be
unnecessarily complicated for a feature that probably nobody uses).
---
fftools/ffmpeg.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0a94b0d05a..3911db1948 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3537,15 +3537,6 @@ static int check_keyboard_interaction(int64_t cur_time)
if (key == '+') av_log_set_level(av_log_get_level()+10);
if (key == '-') av_log_set_level(av_log_get_level()-10);
if (key == 's') qp_hist ^= 1;
- if (key == 'h'){
- if (do_hex_dump){
- do_hex_dump = do_pkt_dump = 0;
- } else if(do_pkt_dump){
- do_hex_dump = 1;
- } else
- do_pkt_dump = 1;
- av_log_set_level(AV_LOG_DEBUG);
- }
if (key == 'c' || key == 'C'){
char buf[4096], target[64], command[256], arg[256] = {0};
double time;
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: handle dumping input packets in input_thread()
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (15 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: drop the 'h' key handling Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread Anton Khirnov
` (6 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
This is a more appropriate place for this.
---
fftools/ffmpeg.c | 4 ----
fftools/ffmpeg_demux.c | 6 ++++++
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3911db1948..1393ca9c1e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3831,10 +3831,6 @@ static int process_input(int file_index)
reset_eagain();
- if (do_pkt_dump) {
- av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump,
- is->streams[pkt->stream_index]);
- }
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
if (pkt->stream_index >= ifile->nb_streams) {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 2629af5950..f9bd6d47fe 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -45,6 +45,12 @@ static void *input_thread(void *arg)
av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
break;
}
+
+ if (do_pkt_dump) {
+ av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump,
+ f->ctx->streams[pkt->stream_index]);
+ }
+
queue_pkt = av_packet_alloc();
if (!queue_pkt) {
av_packet_unref(pkt);
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (16 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: handle dumping input packets in input_thread() Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 18:47 ` Andreas Rheinhardt
2022-08-04 8:20 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c Anton Khirnov
` (5 subsequent siblings)
23 siblings, 2 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
This avoids a potential race with the demuxer adding new streams. It is
also more efficient, since we no longer do inter-thread transfers of
packets that will be just discarded.
---
fftools/ffmpeg.c | 22 ----------------------
fftools/ffmpeg_demux.c | 23 +++++++++++++++++++++++
2 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1393ca9c1e..37f52f0208 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3277,21 +3277,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
return ret;
}
-static void report_new_stream(int input_index, AVPacket *pkt)
-{
- InputFile *file = input_files[input_index];
- AVStream *st = file->ctx->streams[pkt->stream_index];
-
- if (pkt->stream_index < file->nb_streams_warn)
- return;
- av_log(file->ctx, AV_LOG_WARNING,
- "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
- av_get_media_type_string(st->codecpar->codec_type),
- input_index, pkt->stream_index,
- pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
- file->nb_streams_warn = pkt->stream_index + 1;
-}
-
static int transcode_init(void)
{
int ret = 0, i, j, k;
@@ -3831,13 +3816,6 @@ static int process_input(int file_index)
reset_eagain();
- /* the following test is needed in case new streams appear
- dynamically in stream : we ignore them */
- if (pkt->stream_index >= ifile->nb_streams) {
- report_new_stream(file_index, pkt);
- goto discard_packet;
- }
-
ist = input_streams[ifile->ist_index + pkt->stream_index];
ist->data_size += pkt->size;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index f9bd6d47fe..66cb6ebd5f 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -20,6 +20,7 @@
#include "libavutil/error.h"
#include "libavutil/time.h"
+#include "libavutil/timestamp.h"
#include "libavutil/thread.h"
#include "libavutil/threadmessage.h"
@@ -27,6 +28,20 @@
#include "libavformat/avformat.h"
+static void report_new_stream(InputFile *file, AVPacket *pkt)
+{
+ AVStream *st = file->ctx->streams[pkt->stream_index];
+
+ if (pkt->stream_index < file->nb_streams_warn)
+ return;
+ av_log(file->ctx, AV_LOG_WARNING,
+ "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
+ av_get_media_type_string(st->codecpar->codec_type),
+ file->index, pkt->stream_index,
+ pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
+ file->nb_streams_warn = pkt->stream_index + 1;
+}
+
static void *input_thread(void *arg)
{
InputFile *f = arg;
@@ -51,6 +66,14 @@ static void *input_thread(void *arg)
f->ctx->streams[pkt->stream_index]);
}
+ /* the following test is needed in case new streams appear
+ dynamically in stream : we ignore them */
+ if (pkt->stream_index >= f->nb_streams) {
+ report_new_stream(f, pkt);
+ av_packet_unref(pkt);
+ continue;
+ }
+
queue_pkt = av_packet_alloc();
if (!queue_pkt) {
av_packet_unref(pkt);
--
2.34.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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread Anton Khirnov
@ 2022-08-03 18:47 ` Andreas Rheinhardt
2022-08-04 8:20 ` Anton Khirnov
1 sibling, 0 replies; 35+ messages in thread
From: Andreas Rheinhardt @ 2022-08-03 18:47 UTC (permalink / raw)
To: ffmpeg-devel
Anton Khirnov:
> This avoids a potential race with the demuxer adding new streams. It is
> also more efficient, since we no longer do inter-thread transfers of
> packets that will be just discarded.
> ---
> fftools/ffmpeg.c | 22 ----------------------
> fftools/ffmpeg_demux.c | 23 +++++++++++++++++++++++
> 2 files changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 1393ca9c1e..37f52f0208 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -3277,21 +3277,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
> return ret;
> }
>
> -static void report_new_stream(int input_index, AVPacket *pkt)
> -{
> - InputFile *file = input_files[input_index];
> - AVStream *st = file->ctx->streams[pkt->stream_index];
> -
> - if (pkt->stream_index < file->nb_streams_warn)
> - return;
> - av_log(file->ctx, AV_LOG_WARNING,
> - "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
> - av_get_media_type_string(st->codecpar->codec_type),
> - input_index, pkt->stream_index,
> - pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
> - file->nb_streams_warn = pkt->stream_index + 1;
> -}
> -
> static int transcode_init(void)
> {
> int ret = 0, i, j, k;
> @@ -3831,13 +3816,6 @@ static int process_input(int file_index)
>
> reset_eagain();
>
> - /* the following test is needed in case new streams appear
> - dynamically in stream : we ignore them */
> - if (pkt->stream_index >= ifile->nb_streams) {
> - report_new_stream(file_index, pkt);
> - goto discard_packet;
> - }
> -
> ist = input_streams[ifile->ist_index + pkt->stream_index];
>
> ist->data_size += pkt->size;
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index f9bd6d47fe..66cb6ebd5f 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -20,6 +20,7 @@
>
> #include "libavutil/error.h"
> #include "libavutil/time.h"
> +#include "libavutil/timestamp.h"
> #include "libavutil/thread.h"
> #include "libavutil/threadmessage.h"
>
> @@ -27,6 +28,20 @@
>
> #include "libavformat/avformat.h"
>
> +static void report_new_stream(InputFile *file, AVPacket *pkt)
> +{
> + AVStream *st = file->ctx->streams[pkt->stream_index];
Missing const on st and pkt.
> +
> + if (pkt->stream_index < file->nb_streams_warn)
> + return;
> + av_log(file->ctx, AV_LOG_WARNING,
> + "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
> + av_get_media_type_string(st->codecpar->codec_type),
> + file->index, pkt->stream_index,
> + pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
> + file->nb_streams_warn = pkt->stream_index + 1;
> +}
> +
> static void *input_thread(void *arg)
> {
> InputFile *f = arg;
> @@ -51,6 +66,14 @@ static void *input_thread(void *arg)
> f->ctx->streams[pkt->stream_index]);
> }
>
> + /* the following test is needed in case new streams appear
> + dynamically in stream : we ignore them */
> + if (pkt->stream_index >= f->nb_streams) {
> + report_new_stream(f, pkt);
> + av_packet_unref(pkt);
> + continue;
> + }
> +
> queue_pkt = av_packet_alloc();
> if (!queue_pkt) {
> av_packet_unref(pkt);
_______________________________________________
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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread Anton Khirnov
2022-08-03 18:47 ` Andreas Rheinhardt
@ 2022-08-04 8:20 ` Anton Khirnov
2022-08-04 8:23 ` Nicolas George
1 sibling, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2022-08-04 8:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Andreas Rheinhardt (2022-08-03 20:47:36)
> Missing const on st
src/fftools/ffmpeg_demux.c:41:46: warning: passing argument 3 of ‘av_ts_make_time_string’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
41 | pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
> and pkt.
can do
--
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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread
2022-08-04 8:20 ` Anton Khirnov
@ 2022-08-04 8:23 ` Nicolas George
2022-08-04 8:25 ` Andreas Rheinhardt
0 siblings, 1 reply; 35+ messages in thread
From: Nicolas George @ 2022-08-04 8:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 399 bytes --]
Anton Khirnov (12022-08-04):
> src/fftools/ffmpeg_demux.c:41:46: warning: passing argument 3 of ‘av_ts_make_time_string’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 41 | pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
av_ts_make_time_string() should have const on its *tb argument. Good
catch.
Regards,
--
Nicolas George
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 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] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread
2022-08-04 8:23 ` Nicolas George
@ 2022-08-04 8:25 ` Andreas Rheinhardt
2022-08-04 8:29 ` Nicolas George
0 siblings, 1 reply; 35+ messages in thread
From: Andreas Rheinhardt @ 2022-08-04 8:25 UTC (permalink / raw)
To: ffmpeg-devel
Nicolas George:
> Anton Khirnov (12022-08-04):
>> src/fftools/ffmpeg_demux.c:41:46: warning: passing argument 3 of ‘av_ts_make_time_string’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
>> 41 | pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
>
> av_ts_make_time_string() should have const on its *tb argument. Good
> catch.
>
Or the timebase should be passed by value (as is commonly done elsewhere).
- Andreas
_______________________________________________
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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (17 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg: report new streams from the input thread Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move seek_to_start() " Anton Khirnov
` (4 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Also rename it to use the ifile_* namespace.
---
fftools/ffmpeg.c | 30 ++----------------------------
fftools/ffmpeg.h | 1 +
fftools/ffmpeg_demux.c | 26 ++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 37f52f0208..497a847101 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3610,32 +3610,6 @@ static int check_keyboard_interaction(int64_t cur_time)
return 0;
}
-static int get_input_packet(InputFile *f, AVPacket **pkt)
-{
- if (f->readrate || f->rate_emu) {
- int i;
- int64_t file_start = copy_ts * (
- (f->ctx->start_time != AV_NOPTS_VALUE ? f->ctx->start_time * !start_at_zero : 0) +
- (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
- );
- float scale = f->rate_emu ? 1.0 : f->readrate;
- for (i = 0; i < f->nb_streams; i++) {
- InputStream *ist = input_streams[f->ist_index + i];
- int64_t stream_ts_offset, pts, now;
- if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue;
- stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
- pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
- now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset;
- if (pts > now)
- return AVERROR(EAGAIN);
- }
- }
-
- return av_thread_message_queue_recv(f->in_thread_queue, pkt,
- f->non_blocking ?
- AV_THREAD_MESSAGE_NONBLOCK : 0);
-}
-
static int got_eagain(void)
{
int i;
@@ -3752,7 +3726,7 @@ static int process_input(int file_index)
int disable_discontinuity_correction = copy_ts;
is = ifile->ctx;
- ret = get_input_packet(ifile, &pkt);
+ ret = ifile_get_packet(ifile, &pkt);
if (ret == AVERROR(EAGAIN)) {
ifile->eagain = 1;
@@ -3777,7 +3751,7 @@ static int process_input(int file_index)
if (ret < 0)
av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n");
else
- ret = get_input_packet(ifile, &pkt);
+ ret = ifile_get_packet(ifile, &pkt);
if (ret == AVERROR(EAGAIN)) {
ifile->eagain = 1;
return ret;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 81356fd566..f983d077d9 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -710,6 +710,7 @@ int64_t of_filesize(OutputFile *of);
AVChapter * const *
of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
+int ifile_get_packet(InputFile *f, AVPacket **pkt);
int init_input_threads(void);
int init_input_thread(int i);
void free_input_threads(void);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 66cb6ebd5f..1e95be349c 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -163,3 +163,29 @@ int init_input_threads(void)
}
return 0;
}
+
+int ifile_get_packet(InputFile *f, AVPacket **pkt)
+{
+ if (f->readrate || f->rate_emu) {
+ int i;
+ int64_t file_start = copy_ts * (
+ (f->ctx->start_time != AV_NOPTS_VALUE ? f->ctx->start_time * !start_at_zero : 0) +
+ (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
+ );
+ float scale = f->rate_emu ? 1.0 : f->readrate;
+ for (i = 0; i < f->nb_streams; i++) {
+ InputStream *ist = input_streams[f->ist_index + i];
+ int64_t stream_ts_offset, pts, now;
+ if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue;
+ stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
+ pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
+ now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset;
+ if (pts > now)
+ return AVERROR(EAGAIN);
+ }
+ }
+
+ return av_thread_message_queue_recv(f->in_thread_queue, pkt,
+ f->non_blocking ?
+ AV_THREAD_MESSAGE_NONBLOCK : 0);
+}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move seek_to_start() to ffmpeg_demux.c
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (18 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg: move -stream_loop handling to the demuxer thread Anton Khirnov
` (3 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Reduces the diff in the following commit.
---
fftools/ffmpeg.c | 79 ------------------------------------------
fftools/ffmpeg.h | 1 +
fftools/ffmpeg_demux.c | 79 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 79 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 497a847101..90e25973d3 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3628,85 +3628,6 @@ static void reset_eagain(void)
output_streams[i]->unavailable = 0;
}
-// set duration to max(tmp, duration) in a proper time base and return duration's time_base
-static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base,
- AVRational time_base)
-{
- int ret;
-
- if (!*duration) {
- *duration = tmp;
- return tmp_time_base;
- }
-
- ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base);
- if (ret < 0) {
- *duration = tmp;
- return tmp_time_base;
- }
-
- return time_base;
-}
-
-static int seek_to_start(InputFile *ifile, AVFormatContext *is)
-{
- InputStream *ist;
- AVCodecContext *avctx;
- int i, ret, has_audio = 0;
- int64_t duration = 0;
-
- ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
- if (ret < 0)
- return ret;
-
- for (i = 0; i < ifile->nb_streams; i++) {
- ist = input_streams[ifile->ist_index + i];
- avctx = ist->dec_ctx;
-
- /* duration is the length of the last frame in a stream
- * when audio stream is present we don't care about
- * last video frame length because it's not defined exactly */
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples)
- has_audio = 1;
- }
-
- for (i = 0; i < ifile->nb_streams; i++) {
- ist = input_streams[ifile->ist_index + i];
- avctx = ist->dec_ctx;
-
- if (has_audio) {
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) {
- AVRational sample_rate = {1, avctx->sample_rate};
-
- duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base);
- } else {
- continue;
- }
- } else {
- if (ist->framerate.num) {
- duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
- } else if (ist->st->avg_frame_rate.num) {
- duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base);
- } else {
- duration = 1;
- }
- }
- if (!ifile->duration)
- ifile->time_base = ist->st->time_base;
- /* the total duration of the stream, max_pts - min_pts is
- * the duration of the stream without the last frame */
- if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration)
- duration += ist->max_pts - ist->min_pts;
- ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base,
- ifile->time_base);
- }
-
- if (ifile->loop > 0)
- ifile->loop--;
-
- return ret;
-}
-
/*
* Return
* - 0 -- one packet was read and processed
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f983d077d9..2a9c34eb93 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -715,5 +715,6 @@ int init_input_threads(void);
int init_input_thread(int i);
void free_input_threads(void);
void free_input_thread(int i);
+int seek_to_start(InputFile *ifile, AVFormatContext *is);
#endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1e95be349c..ff9313b040 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -42,6 +42,85 @@ static void report_new_stream(InputFile *file, AVPacket *pkt)
file->nb_streams_warn = pkt->stream_index + 1;
}
+// set duration to max(tmp, duration) in a proper time base and return duration's time_base
+static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base,
+ AVRational time_base)
+{
+ int ret;
+
+ if (!*duration) {
+ *duration = tmp;
+ return tmp_time_base;
+ }
+
+ ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base);
+ if (ret < 0) {
+ *duration = tmp;
+ return tmp_time_base;
+ }
+
+ return time_base;
+}
+
+int seek_to_start(InputFile *ifile, AVFormatContext *is)
+{
+ InputStream *ist;
+ AVCodecContext *avctx;
+ int i, ret, has_audio = 0;
+ int64_t duration = 0;
+
+ ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < ifile->nb_streams; i++) {
+ ist = input_streams[ifile->ist_index + i];
+ avctx = ist->dec_ctx;
+
+ /* duration is the length of the last frame in a stream
+ * when audio stream is present we don't care about
+ * last video frame length because it's not defined exactly */
+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples)
+ has_audio = 1;
+ }
+
+ for (i = 0; i < ifile->nb_streams; i++) {
+ ist = input_streams[ifile->ist_index + i];
+ avctx = ist->dec_ctx;
+
+ if (has_audio) {
+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) {
+ AVRational sample_rate = {1, avctx->sample_rate};
+
+ duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base);
+ } else {
+ continue;
+ }
+ } else {
+ if (ist->framerate.num) {
+ duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
+ } else if (ist->st->avg_frame_rate.num) {
+ duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base);
+ } else {
+ duration = 1;
+ }
+ }
+ if (!ifile->duration)
+ ifile->time_base = ist->st->time_base;
+ /* the total duration of the stream, max_pts - min_pts is
+ * the duration of the stream without the last frame */
+ if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration)
+ duration += ist->max_pts - ist->min_pts;
+ ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base,
+ ifile->time_base);
+ }
+
+ if (ifile->loop > 0)
+ ifile->loop--;
+
+ return ret;
+}
+
static void *input_thread(void *arg)
{
InputFile *f = arg;
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg: move -stream_loop handling to the demuxer thread
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (19 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move seek_to_start() " Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_demux: factorize signalling end of demuxing Anton Khirnov
` (2 subsequent siblings)
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
-stream_loop is currently handled by destroying the demuxer thread,
seeking, then recreating it anew. This is very messy and conflicts with
the future goal of moving each major ffmpeg component into its own
thread.
Handle -stream_loop directly in the demuxer thread. Looping requires the
demuxer to know the duration of the file, which takes into account the
duration of the last decoded audio frame (if any). Use a thread message
queue to communicate this information from the main thread to the
demuxer thread.
---
fftools/ffmpeg.c | 61 ++++++++-------
fftools/ffmpeg.h | 23 +++++-
fftools/ffmpeg_demux.c | 166 +++++++++++++++++++++++++----------------
3 files changed, 158 insertions(+), 92 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 90e25973d3..0218f330b9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3628,6 +3628,37 @@ static void reset_eagain(void)
output_streams[i]->unavailable = 0;
}
+static void decode_flush(InputFile *ifile)
+{
+ for (int i = 0; i < ifile->nb_streams; i++) {
+ InputStream *ist = input_streams[ifile->ist_index + i];
+ int ret;
+
+ if (!ist->processing_needed)
+ continue;
+
+ do {
+ ret = process_input_packet(ist, NULL, 1);
+ } while (ret > 0);
+
+ if (ist->decoding_needed) {
+ /* report last frame duration to the demuxer thread */
+ if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ LastFrameDuration dur;
+
+ dur.stream_idx = i;
+ dur.duration = av_rescale_q(ist->nb_samples,
+ (AVRational){ 1, ist->dec_ctx->sample_rate},
+ ist->st->time_base);
+
+ av_thread_message_queue_send(ifile->audio_duration_queue, &dur, 0);
+ }
+
+ avcodec_flush_buffers(ist->dec_ctx);
+ }
+ }
+}
+
/*
* Return
* - 0 -- one packet was read and processed
@@ -3641,7 +3672,7 @@ static int process_input(int file_index)
AVFormatContext *is;
InputStream *ist;
AVPacket *pkt;
- int ret, thread_ret, i, j;
+ int ret, i, j;
int64_t duration;
int64_t pkt_dts;
int disable_discontinuity_correction = copy_ts;
@@ -3653,30 +3684,10 @@ static int process_input(int file_index)
ifile->eagain = 1;
return ret;
}
- if (ret < 0 && ifile->loop) {
- for (i = 0; i < ifile->nb_streams; i++) {
- ist = input_streams[ifile->ist_index + i];
- if (ist->processing_needed) {
- ret = process_input_packet(ist, NULL, 1);
- if (ret>0)
- return 0;
- if (ist->decoding_needed)
- avcodec_flush_buffers(ist->dec_ctx);
- }
- }
- free_input_thread(file_index);
- ret = seek_to_start(ifile, is);
- thread_ret = init_input_thread(file_index);
- if (thread_ret < 0)
- return thread_ret;
- if (ret < 0)
- av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n");
- else
- ret = ifile_get_packet(ifile, &pkt);
- if (ret == AVERROR(EAGAIN)) {
- ifile->eagain = 1;
- return ret;
- }
+ if (ret == 1) {
+ /* the input file is looped: flush the decoders */
+ decode_flush(ifile);
+ return AVERROR(EAGAIN);
}
if (ret < 0) {
if (ret != AVERROR_EOF) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 2a9c34eb93..aa97f35310 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -407,6 +407,11 @@ typedef struct InputStream {
int got_output;
} InputStream;
+typedef struct LastFrameDuration {
+ int stream_idx;
+ int64_t duration;
+} LastFrameDuration;
+
typedef struct InputFile {
int index;
@@ -438,6 +443,11 @@ typedef struct InputFile {
pthread_t thread; /* thread reading from this file */
int non_blocking; /* reading packets from the thread should not block */
int thread_queue_size; /* maximum number of queued packets */
+
+ /* when looping the input file, this queue is used by decoders to report
+ * the last frame duration back to the demuxer thread */
+ AVThreadMessageQueue *audio_duration_queue;
+ int audio_duration_queue_size;
} InputFile;
enum forced_keyframes_const {
@@ -710,11 +720,18 @@ int64_t of_filesize(OutputFile *of);
AVChapter * const *
of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
+/**
+ * Get next input packet from the demuxer.
+ *
+ * @param pkt the packet is written here when this function returns 0
+ * @return
+ * - 0 when a packet has been read successfully
+ * - 1 when stream end was reached, but the stream is looped;
+ * caller should flush decoders and read from this demuxer again
+ * - a negative error code on failure
+ */
int ifile_get_packet(InputFile *f, AVPacket **pkt);
int init_input_threads(void);
-int init_input_thread(int i);
void free_input_threads(void);
-void free_input_thread(int i);
-int seek_to_start(InputFile *ifile, AVFormatContext *is);
#endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index ff9313b040..e02d2d9656 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -28,6 +28,11 @@
#include "libavformat/avformat.h"
+typedef struct DemuxMsg {
+ AVPacket *pkt;
+ int looping;
+} DemuxMsg;
+
static void report_new_stream(InputFile *file, AVPacket *pkt)
{
AVStream *st = file->ctx->streams[pkt->stream_index];
@@ -42,61 +47,54 @@ static void report_new_stream(InputFile *file, AVPacket *pkt)
file->nb_streams_warn = pkt->stream_index + 1;
}
-// set duration to max(tmp, duration) in a proper time base and return duration's time_base
-static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base,
- AVRational time_base)
+static void ifile_duration_update(InputFile *f, InputStream *ist,
+ int64_t last_duration)
{
- int ret;
-
- if (!*duration) {
- *duration = tmp;
- return tmp_time_base;
+ /* the total duration of the stream, max_pts - min_pts is
+ * the duration of the stream without the last frame */
+ if (ist->max_pts > ist->min_pts &&
+ ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration)
+ last_duration += ist->max_pts - ist->min_pts;
+
+ if (!f->duration ||
+ av_compare_ts(f->duration, f->time_base,
+ last_duration, ist->st->time_base) < 0) {
+ f->duration = last_duration;
+ f->time_base = ist->st->time_base;
}
-
- ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base);
- if (ret < 0) {
- *duration = tmp;
- return tmp_time_base;
- }
-
- return time_base;
}
-int seek_to_start(InputFile *ifile, AVFormatContext *is)
+static int seek_to_start(InputFile *ifile)
{
+ AVFormatContext *is = ifile->ctx;
InputStream *ist;
- AVCodecContext *avctx;
- int i, ret, has_audio = 0;
- int64_t duration = 0;
+ int ret;
ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
if (ret < 0)
return ret;
- for (i = 0; i < ifile->nb_streams; i++) {
- ist = input_streams[ifile->ist_index + i];
- avctx = ist->dec_ctx;
-
+ if (ifile->audio_duration_queue_size) {
/* duration is the length of the last frame in a stream
* when audio stream is present we don't care about
* last video frame length because it's not defined exactly */
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples)
- has_audio = 1;
- }
+ int got_durations = 0;
- for (i = 0; i < ifile->nb_streams; i++) {
- ist = input_streams[ifile->ist_index + i];
- avctx = ist->dec_ctx;
+ while (got_durations < ifile->audio_duration_queue_size) {
+ LastFrameDuration dur;
+ ret = av_thread_message_queue_recv(ifile->audio_duration_queue, &dur, 0);
+ if (ret < 0)
+ return ret;
+ got_durations++;
- if (has_audio) {
- if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) {
- AVRational sample_rate = {1, avctx->sample_rate};
+ ist = input_streams[ifile->ist_index + dur.stream_idx];
+ ifile_duration_update(ifile, ist, dur.duration);
+ }
+ } else {
+ for (int i = 0; i < ifile->nb_streams; i++) {
+ int64_t duration = 0;
+ ist = input_streams[ifile->ist_index + i];
- duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base);
- } else {
- continue;
- }
- } else {
if (ist->framerate.num) {
duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
} else if (ist->st->avg_frame_rate.num) {
@@ -104,15 +102,9 @@ int seek_to_start(InputFile *ifile, AVFormatContext *is)
} else {
duration = 1;
}
+
+ ifile_duration_update(ifile, ist, duration);
}
- if (!ifile->duration)
- ifile->time_base = ist->st->time_base;
- /* the total duration of the stream, max_pts - min_pts is
- * the duration of the stream without the last frame */
- if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration)
- duration += ist->max_pts - ist->min_pts;
- ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base,
- ifile->time_base);
}
if (ifile->loop > 0)
@@ -124,11 +116,13 @@ int seek_to_start(InputFile *ifile, AVFormatContext *is)
static void *input_thread(void *arg)
{
InputFile *f = arg;
- AVPacket *pkt = f->pkt, *queue_pkt;
+ AVPacket *pkt = f->pkt;
unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
int ret = 0;
while (1) {
+ DemuxMsg msg = { NULL };
+
ret = av_read_frame(f->ctx, pkt);
if (ret == AVERROR(EAGAIN)) {
@@ -136,6 +130,18 @@ static void *input_thread(void *arg)
continue;
}
if (ret < 0) {
+ if (f->loop) {
+ /* signal looping to the consumer thread */
+ msg.looping = 1;
+ ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0);
+ if (ret >= 0)
+ ret = seek_to_start(f);
+ if (ret >= 0)
+ continue;
+
+ /* fallthrough to the error path */
+ }
+
av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
break;
}
@@ -153,17 +159,17 @@ static void *input_thread(void *arg)
continue;
}
- queue_pkt = av_packet_alloc();
- if (!queue_pkt) {
+ msg.pkt = av_packet_alloc();
+ if (!msg.pkt) {
av_packet_unref(pkt);
av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM));
break;
}
- av_packet_move_ref(queue_pkt, pkt);
- ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
+ av_packet_move_ref(msg.pkt, pkt);
+ ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags);
if (flags && ret == AVERROR(EAGAIN)) {
flags = 0;
- ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
+ ret = av_thread_message_queue_send(f->in_thread_queue, &msg, flags);
av_log(f->ctx, AV_LOG_WARNING,
"Thread message queue blocking; consider raising the "
"thread_queue_size option (current value: %d)\n",
@@ -174,7 +180,7 @@ static void *input_thread(void *arg)
av_log(f->ctx, AV_LOG_ERROR,
"Unable to send packet to main thread: %s\n",
av_err2str(ret));
- av_packet_free(&queue_pkt);
+ av_packet_free(&msg.pkt);
av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
break;
}
@@ -183,19 +189,20 @@ static void *input_thread(void *arg)
return NULL;
}
-void free_input_thread(int i)
+static void free_input_thread(int i)
{
InputFile *f = input_files[i];
- AVPacket *pkt;
+ DemuxMsg msg;
if (!f || !f->in_thread_queue)
return;
av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
- while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
- av_packet_free(&pkt);
+ while (av_thread_message_queue_recv(f->in_thread_queue, &msg, 0) >= 0)
+ av_packet_free(&msg.pkt);
pthread_join(f->thread, NULL);
av_thread_message_queue_free(&f->in_thread_queue);
+ av_thread_message_queue_free(&f->audio_duration_queue);
}
void free_input_threads(void)
@@ -206,7 +213,7 @@ void free_input_threads(void)
free_input_thread(i);
}
-int init_input_thread(int i)
+static int init_input_thread(int i)
{
int ret;
InputFile *f = input_files[i];
@@ -218,17 +225,38 @@ int init_input_thread(int i)
strcmp(f->ctx->iformat->name, "lavfi"))
f->non_blocking = 1;
ret = av_thread_message_queue_alloc(&f->in_thread_queue,
- f->thread_queue_size, sizeof(f->pkt));
+ f->thread_queue_size, sizeof(DemuxMsg));
if (ret < 0)
return ret;
+ if (f->loop) {
+ int nb_audio_dec = 0;
+
+ for (int i = 0; i < f->nb_streams; i++) {
+ InputStream *ist = input_streams[f->ist_index + i];
+ nb_audio_dec += !!(ist->decoding_needed &&
+ ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO);
+ }
+
+ if (nb_audio_dec) {
+ ret = av_thread_message_queue_alloc(&f->audio_duration_queue,
+ nb_audio_dec, sizeof(LastFrameDuration));
+ if (ret < 0)
+ goto fail;
+ f->audio_duration_queue_size = nb_audio_dec;
+ }
+ }
+
if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
- av_thread_message_queue_free(&f->in_thread_queue);
- return AVERROR(ret);
+ ret = AVERROR(ret);
+ goto fail;
}
return 0;
+fail:
+ av_thread_message_queue_free(&f->in_thread_queue);
+ return ret;
}
int init_input_threads(void)
@@ -245,6 +273,9 @@ int init_input_threads(void)
int ifile_get_packet(InputFile *f, AVPacket **pkt)
{
+ DemuxMsg msg;
+ int ret;
+
if (f->readrate || f->rate_emu) {
int i;
int64_t file_start = copy_ts * (
@@ -264,7 +295,14 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
}
}
- return av_thread_message_queue_recv(f->in_thread_queue, pkt,
- f->non_blocking ?
- AV_THREAD_MESSAGE_NONBLOCK : 0);
+ ret = av_thread_message_queue_recv(f->in_thread_queue, &msg,
+ f->non_blocking ?
+ AV_THREAD_MESSAGE_NONBLOCK : 0);
+ if (ret < 0)
+ return ret;
+ if (msg.looping)
+ return 1;
+
+ *pkt = msg.pkt;
+ return 0;
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_demux: factorize signalling end of demuxing
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (20 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg: move -stream_loop handling to the demuxer thread Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_demux: do not store demux packet in the context Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg: move handling corrupt packets to the input thread Anton Khirnov
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_demux.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index e02d2d9656..be734be581 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -18,6 +18,7 @@
#include "ffmpeg.h"
+#include "libavutil/avassert.h"
#include "libavutil/error.h"
#include "libavutil/time.h"
#include "libavutil/timestamp.h"
@@ -142,7 +143,6 @@ static void *input_thread(void *arg)
/* fallthrough to the error path */
}
- av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
break;
}
@@ -162,7 +162,7 @@ static void *input_thread(void *arg)
msg.pkt = av_packet_alloc();
if (!msg.pkt) {
av_packet_unref(pkt);
- av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM));
+ ret = AVERROR(ENOMEM);
break;
}
av_packet_move_ref(msg.pkt, pkt);
@@ -181,11 +181,13 @@ static void *input_thread(void *arg)
"Unable to send packet to main thread: %s\n",
av_err2str(ret));
av_packet_free(&msg.pkt);
- av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
break;
}
}
+ av_assert0(ret < 0);
+ av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+
return NULL;
}
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_demux: do not store demux packet in the context
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (21 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_demux: factorize signalling end of demuxing Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg: move handling corrupt packets to the input thread Anton Khirnov
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Its use is local to input_thread().
---
fftools/ffmpeg.c | 1 -
fftools/ffmpeg.h | 2 --
fftools/ffmpeg_demux.c | 11 ++++++++++-
fftools/ffmpeg_opt.c | 3 ---
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0218f330b9..a9eda3c33e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -593,7 +593,6 @@ static void ffmpeg_cleanup(int ret)
free_input_threads();
for (i = 0; i < nb_input_files; i++) {
avformat_close_input(&input_files[i]->ctx);
- av_packet_free(&input_files[i]->pkt);
av_freep(&input_files[i]);
}
for (i = 0; i < nb_input_streams; i++) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index aa97f35310..2ac7cbe522 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -437,8 +437,6 @@ typedef struct InputFile {
float readrate;
int accurate_seek;
- AVPacket *pkt;
-
AVThreadMessageQueue *in_thread_queue;
pthread_t thread; /* thread reading from this file */
int non_blocking; /* reading packets from the thread should not block */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index be734be581..af54ea3de1 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -117,10 +117,16 @@ static int seek_to_start(InputFile *ifile)
static void *input_thread(void *arg)
{
InputFile *f = arg;
- AVPacket *pkt = f->pkt;
+ AVPacket *pkt;
unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
int ret = 0;
+ pkt = av_packet_alloc();
+ if (!pkt) {
+ ret = AVERROR(ENOMEM);
+ goto finish;
+ }
+
while (1) {
DemuxMsg msg = { NULL };
@@ -185,9 +191,12 @@ static void *input_thread(void *arg)
}
}
+finish:
av_assert0(ret < 0);
av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+ av_packet_free(&pkt);
+
return NULL;
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 25aa9aaff5..97f14b2a5b 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1407,9 +1407,6 @@ static int open_input_file(OptionsContext *o, const char *filename)
f->rate_emu = 0;
}
- f->pkt = av_packet_alloc();
- if (!f->pkt)
- exit_program(1);
f->thread_queue_size = o->thread_queue_size;
/* check if all codec options have been used */
--
2.34.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] 35+ messages in thread
* [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg: move handling corrupt packets to the input thread
2022-08-03 13:58 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() Anton Khirnov
` (22 preceding siblings ...)
2022-08-03 13:58 ` [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_demux: do not store demux packet in the context Anton Khirnov
@ 2022-08-03 13:58 ` Anton Khirnov
23 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2022-08-03 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 7 -------
fftools/ffmpeg_demux.c | 11 +++++++++++
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a9eda3c33e..09a4d20028 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3729,13 +3729,6 @@ static int process_input(int file_index)
if (ist->discard)
goto discard_packet;
- if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
- av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
- "%s: corrupt input packet in stream %d\n", is->url, pkt->stream_index);
- if (exit_on_error)
- exit_program(1);
- }
-
if (debug_ts) {
av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s "
"next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index af54ea3de1..097a6e3d1d 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -165,6 +165,17 @@ static void *input_thread(void *arg)
continue;
}
+ if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
+ av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
+ "%s: corrupt input packet in stream %d\n",
+ f->ctx->url, pkt->stream_index);
+ if (exit_on_error) {
+ av_packet_unref(pkt);
+ ret = AVERROR_INVALIDDATA;
+ break;
+ }
+ }
+
msg.pkt = av_packet_alloc();
if (!msg.pkt) {
av_packet_unref(pkt);
--
2.34.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] 35+ messages in thread