From 8ffe1b84bd2d2d22228397df5b200b90446d2e7e Mon Sep 17 00:00:00 2001 From: Henje Date: Wed, 8 Jan 2025 21:39:43 +0100 Subject: [PATCH] feat(encoder): copy input streams' metadata to output streams (#1284) * feat(encoder): copy language tag for audio and subtitle streams Containers with audio streams for different languages use a tag to signal which track contains which language. This information is saved in the metadata object of a stream and needs to be copied in addition to the codec properties. * feat(encoder): copy input streams' metadata to output streams --------- Signed-off-by: k4yt3x Co-authored-by: k4yt3x --- CHANGELOG.md | 1 + src/encoder.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d5a47..3d3f5ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Multi-versioning to critical functions to enhance performance in generic architecture builds. +- The feature to copy input streams' metadata to the output streams (#1282). ### Changed diff --git a/src/encoder.cpp b/src/encoder.cpp index 6974397..1ddce69 100644 --- a/src/encoder.cpp +++ b/src/encoder.cpp @@ -225,7 +225,7 @@ int Encoder::init( return AVERROR_UNKNOWN; } - // Copy codec parameters from input to output + // Copy codec parameters from the input stream to the output stream ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar); if (ret < 0) { logger()->error("Failed to copy codec parameters"); @@ -233,6 +233,13 @@ int Encoder::init( } out_stream->codecpar->codec_tag = 0; + // Copy all metadata from the input stream to the output stream + AVDictionaryEntry* tag = nullptr; + while ((tag = av_dict_get(in_stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)) != + nullptr) { + av_dict_set(&out_stream->metadata, tag->key, tag->value, 0); + } + // Copy time base out_stream->time_base = in_stream->time_base;