Message ID | 2e3936bb47900fd850e4d12e5289222221cc9860.camel@haerdin.se |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] ffmpeg: Add -copystreamid | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | fail | Make failed |
andriy/make_x86 | fail | Make failed |
tor 2024-04-11 klockan 17:41 +0200 skrev Tomas Härdin: > Hi > > Patch attached allows preserving PIDs when remuxing MPEG-TS. James > suggested we could generalize this to allow copying from specific > streams, but I think if we want to handle a more general case then it > would be better to handle streamid via metadata. > > Passes FATE. Come to think of it, I may need the ability to copy PID from a specific stream after all. Or more correctly, to replace the audio in an MPEG-TS stream but keep all the other streams the same, and keeping the PIDs. I'll see what I can come up with.. /Tomas
On Thu, Apr 11, 2024 at 05:41:48PM +0200, Tomas Härdin wrote: > Hi > > Patch attached allows preserving PIDs when remuxing MPEG-TS. James > suggested we could generalize this to allow copying from specific > streams, but I think if we want to handle a more general case then it > would be better to handle streamid via metadata. > > Passes FATE. > > /Tomas > doc/ffmpeg.texi | 10 ++++++++++ > fftools/ffmpeg.h | 1 + > fftools/ffmpeg_mux_init.c | 4 ++++ > fftools/ffmpeg_opt.c | 5 +++++ > 4 files changed, 20 insertions(+) > a926f3ca3c894dfa1dc91d479d32278ab7863bfa 0001-ffmpeg-Add-copystreamid.patch > From 63b10983876077fd0e2b41c21a3c188b8557c602 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se> > 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(+) rm doc/ffmpeg.pod doc/ffmpeg-all.1 ; make -j32 doc/ffmpeg-all.1 doc/ffmpeg.pod rm: cannot remove 'doc/ffmpeg-all.1': No such file or directory MAN doc/ffmpeg-all.1 POD doc/ffmpeg.pod @example ended by @end table at line 2502 doc/Makefile:88: recipe for target 'doc/ffmpeg.pod' failed make: *** [doc/ffmpeg.pod] Error 255 make: *** Waiting for unfinished jobs.... pod2man: unable to format doc/ffmpeg-all.pod doc/Makefile:98: recipe for target 'doc/ffmpeg-all.1' failed make: *** [doc/ffmpeg-all.1] Error 1 [...]
fre 2024-04-12 klockan 00:32 +0200 skrev Michael Niedermayer: > On Thu, Apr 11, 2024 at 05:41:48PM +0200, Tomas Härdin wrote: > > Hi > > > > Patch attached allows preserving PIDs when remuxing MPEG-TS. James > > suggested we could generalize this to allow copying from specific > > streams, but I think if we want to handle a more general case then > > it > > would be better to handle streamid via metadata. > > > > Passes FATE. > > > > /Tomas > > > doc/ffmpeg.texi | 10 ++++++++++ > > fftools/ffmpeg.h | 1 + > > fftools/ffmpeg_mux_init.c | 4 ++++ > > fftools/ffmpeg_opt.c | 5 +++++ > > 4 files changed, 20 insertions(+) > > a926f3ca3c894dfa1dc91d479d32278ab7863bfa 0001-ffmpeg-Add- > > copystreamid.patch > > From 63b10983876077fd0e2b41c21a3c188b8557c602 Mon Sep 17 00:00:00 > > 2001 > > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se> > > 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(+) > > rm doc/ffmpeg.pod doc/ffmpeg-all.1 ; make -j32 doc/ffmpeg-all.1 > doc/ffmpeg.pod > rm: cannot remove 'doc/ffmpeg-all.1': No such file or directory > MAN doc/ffmpeg-all.1 > POD doc/ffmpeg.pod > @example ended by @end table at line 2502 Right, should be @end example. Wrote the doc after running FATE. No matter, I have another solution in the works. /Tomas
From 63b10983876077fd0e2b41c21a3c188b8557c602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se> 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