From 63b10983876077fd0e2b41c21a3c188b8557c602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Thu, 11 Apr 2024 16:52:33 +0200 Subject: [PATCH] ffmpeg: Add -copystreamid This causes streamid's to be copied from all input streams to all output streams. Individual streams' streamid can still be set explicitly with -streamid. --- doc/ffmpeg.texi | 10 ++++++++++ fftools/ffmpeg.h | 1 + fftools/ffmpeg_mux_init.c | 4 ++++ fftools/ffmpeg_opt.c | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index e996ab945f..ef61b7118d 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -2096,6 +2096,16 @@ an output mpegts file: ffmpeg -i inurl -streamid 0:33 -streamid 1:36 out.ts @end example +@item -copystreamid +Copy streamid's (PIDs) from input streams to output streams for all streams in all output files. +Can be overridden with -streamid on a per-stream basis. + +For example, to remux an input MPEG-TS file, copying all PIDs except the PID of stream 3, +and setting the PID of stream 3 to 0x123: +@example +ffmpeg -i in.ts -map 0 -c copy -copystreamid -streamid 3:0x123 -y out.ts +@end + @item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{input/output,per-stream}) Apply bitstream filters to matching streams. The filters are applied to each packet as it is received from the demuxer (when used as an input option) or diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 885a7c0c10..e0f8e4d87d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -685,6 +685,7 @@ extern int64_t stats_period; extern int stdin_interaction; extern AVIOContext *progress_avio; extern float max_error_rate; +extern int copy_streamid; extern char *filter_nbthreads; extern int filter_complex_nbthreads; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6d8bd5bcdf..8268595a18 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1073,6 +1073,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ost = &ms->ost; + if (ist && copy_streamid) + ost->st->id = ist->st->id; + + // override -copystreamid if -streamid explicitly set if (o->streamid) { AVDictionaryEntry *e; char idx[16], *p; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 6526e8e3e8..5b4b29d259 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -77,6 +77,7 @@ int filter_complex_nbthreads = 0; int vstats_version = 2; int auto_conversion_filters = 1; int64_t stats_period = 500000; +int copy_streamid = 0; static int file_overwrite = 0; @@ -1902,5 +1903,9 @@ const OptionDef options[] = { "set video sync method globally; deprecated, use -fps_mode", "" }, #endif + { "copystreamid", OPT_TYPE_BOOL, OPT_EXPERT, + { ©_streamid }, + "copy input stream's streamid (MPEG-TS PID) to output stream, for all streams where -streamid is not set" }, + { NULL, }, }; -- 2.39.2