Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Tomas Härdin" <git@haerdin.se>
To: ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] ffmpeg: Add -copystreamid
Date: Thu, 11 Apr 2024 17:41:48 +0200
Message-ID: <2e3936bb47900fd850e4d12e5289222221cc9860.camel@haerdin.se> (raw)

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

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

[-- Attachment #2: 0001-ffmpeg-Add-copystreamid.patch --]
[-- Type: text/x-patch, Size: 3068 bytes --]

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,
+        { &copy_streamid },
+        "copy input stream's streamid (MPEG-TS PID) to output stream, for all streams where -streamid is not set" },
+
     { NULL, },
 };
-- 
2.39.2


[-- Attachment #3: 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".

             reply	other threads:[~2024-04-11 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 15:41 Tomas Härdin [this message]
2024-04-11 18:28 ` Tomas Härdin
2024-04-11 22:32 ` Michael Niedermayer
2024-04-12  8:54   ` Tomas Härdin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e3936bb47900fd850e4d12e5289222221cc9860.camel@haerdin.se \
    --to=git@haerdin.se \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git