From patchwork Sun Jul 31 21:51:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 37057 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp2154539pzb; Sun, 31 Jul 2022 14:52:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Un3pLbF3KiwHLa98KfHjCF+P6M4j8KwqV2mgR8O6eqE35hoZIdGCt6TSjXOPT26EtB7S1 X-Received: by 2002:a05:6402:2b97:b0:43d:75b3:7d10 with SMTP id fj23-20020a0564022b9700b0043d75b37d10mr5002475edb.397.1659304353816; Sun, 31 Jul 2022 14:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659304353; cv=none; d=google.com; s=arc-20160816; b=SWJUHyMuZ197hfOdJ3BGtM8QwO4rSy1wLNMIdRPcMx3rGH0H6DKXMqAv7lhMlkIlAY Hb2NSVqSBT+R7YVBF59REn34lgqQmmJiyZ41Bh86Vgo4LzKZHKb5CaQmpkw4DttGcTmk qC7ipeu6a70B6u/CPuTBVZ0e4JB5EHnYr/uGqh3yx8KpGzEgMTOGy6ne68uhADxZuVnU PblXBmplprt75UnftRqkm0vcXJb66QR2pbL+Q/KgUzak9aQoRno5x1EBhJ28HYSZ2EuZ js01vwkVpa9hJLVykf4Q5cjViYG3xcjLnUlG+E2KMdDqyYZw4hZo7mkjH62pBgnfkSm0 OYUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=2qjJ1Banw3A8gVTAUQx81xJ8yuaD4CA/4drNIoa15Rs=; b=zs7WmQAch2GuyXMPo/4HEylM/YBxWkXz047jvDa1o+feEgMY2jEicRaL/X3LiqV6mq waP2z3vTWKlvkc1SPD7Unk544+Yfwb6bSg4KbHgazrN8Ih60Ey99cf4z+ul6VbZpiLEg SCG7UjrimL0G4w4z+gP9pqwjiQi1LxhHHiqsr2t1nCk7870lGOihxnUmjDoFkz1o1IEU HjR/jSPYneIGhupqZYKpkdN7/Cx/i0VcpfqK5aPrLW7uR2nF8U6azSX1MQyexcwXIitv BeOLRv85cKyjECaSwbut3+g3IRwDDqQNH4WhzjGmArLojAENGKlB0nMJu0cKuOYF5/Cz fYug== 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 bm19-20020a0564020b1300b0043cbacc60e0si5495151edb.388.2022.07.31.14.52.32; Sun, 31 Jul 2022 14:52:33 -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 0D27B68BA20; Mon, 1 Aug 2022 00:52:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C2C8068B6AF for ; Mon, 1 Aug 2022 00:52:21 +0300 (EEST) Received: by mail-pl1-f170.google.com with SMTP id q22so707899plr.9 for ; Sun, 31 Jul 2022 14:52:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XM2UXxU5EegCNant95bYClt2JTDEq3QmOTsLl423MCQ=; b=YKJsbiJBQdpVpiqGkPa5oYED87eeaaVn2hyDRhPj0IQCbv+VNzunP9DZZB0DaJCi4y vdcs6MWzZrt/Gg21xmC2HO8UJM5r2CORK+EPHjyN+9SuFDTITV8eaH8YdUGJWm50SJ+W jtW3WqtLf7c2bQxPtzIF7k6//oGLzrQVTOuzcyyZyVTl2fW10e9BDmyCSrD2rsnE3rWS hYg8AlXkOz5NyIxUQqHUJmZ7d5XG3AXn0EtYJpn9hKLecxV/8Uz8tofUZG4ukYglQaGb NX5A8yT+uRCTc/RVGe/1I9EyOg7/DZXpT/PF5fYj+PdwbzVP++xtLl1u3PquZ+Cocz4a furg== X-Gm-Message-State: ACgBeo13UtckStPWjyCdomHDRuFQeemhZiqYzhceEvhiKihUYiuY65ds K9qIrPIG3h9gnKXbn9c/NFVRKBlTf5A= X-Received: by 2002:a17:902:b709:b0:16d:be4:40f8 with SMTP id d9-20020a170902b70900b0016d0be440f8mr13869348pls.41.1659304338978; Sun, 31 Jul 2022 14:52:18 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id n3-20020a1709026a8300b0016b81679c31sm7775784plk.213.2022.07.31.14.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 14:52:18 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Sun, 31 Jul 2022 14:52:00 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jul 2022 14:51:56 -0700 Message-Id: <20220731215157.22022-1-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy() 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lkOx9W9rWjMX From: Pierre-Anthony Lemieux As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html. Note that ff_stream_params_copy() does not copy: * the index field * the attached_pic if its size is 0 Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299514.html --- libavformat/avformat.c | 40 ++++++++++++++++++++++++++++++++++++++++ libavformat/fifo.c | 2 +- libavformat/internal.h | 12 ++++++++++++ libavformat/mux.h | 9 --------- libavformat/mux_utils.c | 28 ---------------------------- libavformat/segment.c | 2 +- libavformat/tee.c | 2 +- libavformat/webm_chunk.c | 2 +- 8 files changed, 56 insertions(+), 41 deletions(-) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 30d6ea6a49..242187c359 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -235,6 +235,46 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src) return 0; } +int ff_stream_params_copy(AVStream *dst, const AVStream *src) +{ + int ret; + + dst->id = src->id; + dst->time_base = src->time_base; + dst->start_time = src->start_time; + dst->duration = src->duration; + dst->nb_frames = src->nb_frames; + dst->disposition = src->disposition; + dst->discard = src->discard; + dst->sample_aspect_ratio = src->sample_aspect_ratio; + dst->avg_frame_rate = src->avg_frame_rate; + dst->event_flags = src->event_flags; + dst->r_frame_rate = src->r_frame_rate; + dst->pts_wrap_bits = src->pts_wrap_bits; + + av_dict_free(&dst->metadata); + ret = av_dict_copy(&dst->metadata, src->metadata, 0); + if (ret < 0) + return ret; + + ret = avcodec_parameters_copy(dst->codecpar, src->codecpar); + if (ret < 0) + return ret; + + ret = ff_stream_side_data_copy(dst, src); + if (ret < 0) + return ret; + + av_packet_unref(&dst->attached_pic); + if (src->attached_pic.size > 0) { + ret = av_packet_ref(&dst->attached_pic, &src->attached_pic); + if (ret < 0) + return ret; + } + + return 0; +} + AVProgram *av_new_program(AVFormatContext *ac, int id) { AVProgram *program = NULL; diff --git a/libavformat/fifo.c b/libavformat/fifo.c index ead2bdc5cf..fef116d040 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const AVOutputFormat *oformat, if (!st) return AVERROR(ENOMEM); - ret = ff_stream_encode_params_copy(st, avf->streams[i]); + ret = ff_stream_params_copy(st, avf->streams[i]); if (ret < 0) return ret; } diff --git a/libavformat/internal.h b/libavformat/internal.h index b6b8fbf56f..87a00bbae3 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -625,6 +625,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags); */ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src); +/** + * Copy all stream parameters from source to destination stream, with the + * exception of: + * * the index field, which is usually set by avformat_new_stream() + * * the attached_pic field, if attached_pic.size is 0 or less + * + * @param dst pointer to destination AVStream + * @param src pointer to source AVStream + * @return >=0 on success, AVERROR code on error + */ +int ff_stream_params_copy(AVStream *dst, const AVStream *src); + /** * Wrap ffurl_move() and log if error happens. * diff --git a/libavformat/mux.h b/libavformat/mux.h index c01da82194..1bfcaf795f 100644 --- a/libavformat/mux.h +++ b/libavformat/mux.h @@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size) */ int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options); -/** - * Copy encoding parameters from source to destination stream - * - * @param dst pointer to destination AVStream - * @param src pointer to source AVStream - * @return >=0 on success, AVERROR code on error - */ -int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src); - /** * Parse creation_time in AVFormatContext metadata if exists and warn if the * parsing fails. diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c index eb8ea3d560..2fa2ab5b0f 100644 --- a/libavformat/mux_utils.c +++ b/libavformat/mux_utils.c @@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **op return 0; } -int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) -{ - int ret; - - dst->id = src->id; - dst->time_base = src->time_base; - dst->nb_frames = src->nb_frames; - dst->disposition = src->disposition; - dst->sample_aspect_ratio = src->sample_aspect_ratio; - dst->avg_frame_rate = src->avg_frame_rate; - dst->r_frame_rate = src->r_frame_rate; - - av_dict_free(&dst->metadata); - ret = av_dict_copy(&dst->metadata, src->metadata, 0); - if (ret < 0) - return ret; - - ret = avcodec_parameters_copy(dst->codecpar, src->codecpar); - if (ret < 0) - return ret; - - ret = ff_stream_side_data_copy(dst, src); - if (ret < 0) - return ret; - - return 0; -} - int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds) { AVDictionaryEntry *entry; diff --git a/libavformat/segment.c b/libavformat/segment.c index fa435d9f32..a8f3e94714 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -169,7 +169,7 @@ static int segment_mux_init(AVFormatContext *s) if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - ret = ff_stream_encode_params_copy(st, ist); + ret = ff_stream_params_copy(st, ist); if (ret < 0) return ret; opar = st->codecpar; diff --git a/libavformat/tee.c b/libavformat/tee.c index f1f2a9d2a5..dbfad604d0 100644 --- a/libavformat/tee.c +++ b/libavformat/tee.c @@ -289,7 +289,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) goto end; } - ret = ff_stream_encode_params_copy(st2, st); + ret = ff_stream_params_copy(st2, st); if (ret < 0) goto end; } diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index d69db3a004..39f21fce7a 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -94,7 +94,7 @@ static int webm_chunk_init(AVFormatContext *s) if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - if ((ret = ff_stream_encode_params_copy(st, ost)) < 0) + if ((ret = ff_stream_params_copy(st, ost)) < 0) return ret; if (wc->http_method) From patchwork Sun Jul 31 21:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 37058 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp2154562pzb; Sun, 31 Jul 2022 14:52:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vhjOkpmVIROqrLyCSIO5FA5MunQP3lxNDwtk5x0ZMyIwdcDV5DKVkONW833DJNZsx9EA4F X-Received: by 2002:a17:907:7347:b0:730:5e9:8160 with SMTP id dq7-20020a170907734700b0073005e98160mr10156105ejc.630.1659304361287; Sun, 31 Jul 2022 14:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659304361; cv=none; d=google.com; s=arc-20160816; b=qMw1J8RKg5ERg4JRtJIeKpUhYPFibVxqC4r+8TEpGu9mzs4UTjRkVBavWTLBV9If5N EhcKhQ9b6/EC6NdMkoBIpoIrPaI5jToxV3W1BtHOEavHVY//HZR4nQ0P2rrzF1UqrNGJ 59X/sM+SdmMadqmNnPDruCCGnb8HGJY6YPosxEPtqE8au0GNK7/ml/baSPg138x3LwSH EtNKov8LeqEAy8EIwmIxcVK2J57kWezNCuvozfIrj/RCD7rLBH5Y2DkFk3e0lO4d1C1w cBJLd+vOwifGfENtrx0YkRjTa5DEHdQ0yXdWlpK4t5Fa+yXoSu8uW9IFjqurvUtBX92C 05gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=9zCbXpHXmd755OeulNl9APs93akbkNU9xfuPlY7hEj8=; b=Ge6YXKw+Ewg+vodjWL98Qie0za/6sfHhsiK6UozTmTnW99S+BtnI07Kq7DV54SBquT Qk8T7m2PCIu62paJp90Ub2l49L2H/DW1B6cSLN05/XIX0lPfN3iKhxAYuD2FLj4ipUh1 TuLj6WNxfIhoG3ShO/GUOI1MzMQxlhiJRUBNJ4hSxxkLzuja6AJod2uGMIumjputAFOl 6Ws8lnX4edfVTjxEIPVPWJjSqvNpedJJpwumaL2Va2pwvondnbENcK5bGylO4o2wRPMe 8hiWWZx04irofl5fBhBhS2r0aMy/SzVHc8B5zxeq68OYytHvtnRHyGmHPAdt2pKBLpQ/ rhXg== 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 ga22-20020a170906b85600b007301b3b8e11si7317777ejb.613.2022.07.31.14.52.41; Sun, 31 Jul 2022 14:52:41 -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 199D068B92F; Mon, 1 Aug 2022 00:52:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6CF0B68B92F for ; Mon, 1 Aug 2022 00:52:24 +0300 (EEST) Received: by mail-pl1-f171.google.com with SMTP id x23so223302pll.7 for ; Sun, 31 Jul 2022 14:52:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FwKvxwrA3NOseZ5HpVCRZiIp+AR0Ge1Jb7rvqD7EFTM=; b=SSVBLd/fqjz9zSG/jgfPwmvfeeCgnsCSVs/pKt1kiQWu0F3dUebibqO+L8/n1KiWw9 J8gNBFsnK1I9/9Qm3saq/wRWRgwJNgtFuDA4WbYTVSFjPS7/HkPZSMg2Y6cE7HHe2r3E ItYI6tV9D/HjX4w5oNN3eisPDYUdDJ6d3REZXf5lPpQgs0uIcQ++ijZJ0/TbSnKOU31E J8x9NpaOwyC3qIYyUTjs0HznaYXVZk2NBbeop7RnhqiyeYKS/kn9Nosc24IckwtXedYP w15j2xYVgS+SsMZ6+V2Y8Hxq9VoPaMxDeyeClt/o1oYv2MG8mn98TJSYq5agO184/x6B /9Dg== X-Gm-Message-State: ACgBeo1drC6AyS41NgnuQ0YvAAZFlnCqjJxVkdaEVC6AzPYsVK15YMQk oB8pMQfyUgkGCt2t8+LYffYLCaB3+jA= X-Received: by 2002:a17:90a:1d4f:b0:1f3:10f2:155c with SMTP id u15-20020a17090a1d4f00b001f310f2155cmr15817845pju.25.1659304342349; Sun, 31 Jul 2022 14:52:22 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id o6-20020a17090a4b4600b001f239783e3dsm10079440pjl.34.2022.07.31.14.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 14:52:22 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Sun, 31 Jul 2022 14:52:04 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jul 2022 14:51:57 -0700 Message-Id: <20220731215157.22022-2-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220731215157.22022-1-pal@sandflow.com> References: <20220731215157.22022-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 2/2] avformat/imfdec: preserve stream information 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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jciQMlScSXP2 From: Pierre-Anthony Lemieux As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not currently preserve stream information such as language in the case of audio streams. --- libavformat/imfdec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 71dfb26958..4cd6a56a09 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -579,12 +579,15 @@ static int set_context_streams_from_tracks(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Could not create stream\n"); return AVERROR(ENOMEM); } - asset_stream->id = i; - ret = avcodec_parameters_copy(asset_stream->codecpar, first_resource_stream->codecpar); + + ret = ff_stream_params_copy(asset_stream, first_resource_stream); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n"); return ret; } + + asset_stream->id = i; + asset_stream->nb_frames = 0; avpriv_set_pts_info(asset_stream, first_resource_stream->pts_wrap_bits, first_resource_stream->time_base.num,