From patchwork Thu Apr 11 15:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 48011 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a83:b0:1a7:a0dc:8de5 with SMTP id zv3csp49612pzb; Thu, 11 Apr 2024 08:42:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUaSrqUI52q95aCP0jb9QKG4jQnrhDAwZwksqxVjf0fh2Jqe79/pecpftrcQ5LWSaCba8UfZXc7S5UWNt7U7t/x50MjThlugTd3mQ== X-Google-Smtp-Source: AGHT+IGMYyEq4ZOwM3jdkJXV1RrZt8EHgtDMQfY1uMnraa6tYgjM3BWnqFDvmeve9weIGeX25O93 X-Received: by 2002:a17:906:eb0c:b0:a52:16df:59d with SMTP id mb12-20020a170906eb0c00b00a5216df059dmr70016ejb.22.1712850147259; Thu, 11 Apr 2024 08:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712850147; cv=none; d=google.com; s=arc-20160816; b=ANIxEOtINfo0ZacZIHC1P43DuFdll2EBFrS8fvnYMHmuNQuMwbjJjUw9GfTW1gFCo6 sbwrqDKeOaSSw4mWYnIwY8Z6Hba3N8sRq6s25itESqSraq0OR90qwV+wZopsL2Fwh93A K24cwOjtO14RYS0LpHwiOqjFhweRCLm4VFqLy5cazIFmXR7XM0pHt1jlstvQF2C/wpUO csoYRmwqYfBvaVvJm8tdyGoNa90IPLjpHoK9P6hv3kHqUFFiCUyVtAQJEZEdkkCne0UI qwm+Jz7IM+CM7aH9NS5nsyifN10u2f2QzbEOQCOlzk8IAvU7p/pq4yh1L22Yu0bVobco 9Ltw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:date:to:from:message-id:delivered-to; bh=Yn2uAwnZ+E8uszD965gweEf3IT7aqPtnXEIQ7Dn+aWA=; fh=vgcpdHWu4da4Dk/quIxpjcmmxLeEWfPnCXzoiCPpQLU=; b=j+q7ydycLINkadRIOjyV1fLLoODSBUiYZrD7z7d9yY7csld51neiXo9BYwADkDhdyk lUNJb473Fz0Gq23vcYRFO/JEVMvH4R9rpguZFpQN6i4WOHjXuuwocFPzZUEzRsGHxP6w a2nwmDkZNnfxhwBf3BSpyWg/mXL1xrWtrXzCcYc7CTRXGzhA2+6d2GhIHVDnXjN81sqK +GW7qAV24Gju9C4vrFaF8dzYym+hcLna59CbMiFbObODxwR2jZ5+q8I/Oi9H8UCFza3O DGDIqAWAaG5A8qs/ia03rilu4IqbN74/KzJWpCNHT6pkGuTkWp9RQCEm1bc7KEvbIEE2 X1MQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id go42-20020a1709070daa00b00a51dfabe269si871864ejc.545.2024.04.11.08.42.02; Thu, 11 Apr 2024 08:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 999C268D1C9; Thu, 11 Apr 2024 18:41:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from glom.nmugroup.com (glom.nmugroup.com [193.183.80.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF3A068C25D for ; Thu, 11 Apr 2024 18:41:51 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id 4BFB9542904D for ; Thu, 11 Apr 2024 17:41:51 +0200 (CEST) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id 04309542853E for ; Thu, 11 Apr 2024 17:41:50 +0200 (CEST) Message-ID: <2e3936bb47900fd850e4d12e5289222221cc9860.camel@haerdin.se> From: Tomas =?iso-8859-1?q?H=E4rdin?= To: ffmpeg-devel Date: Thu, 11 Apr 2024 17:41:48 +0200 User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffmpeg: Add -copystreamid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WtCY3/CgFOaQ 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 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