Skip to content

Commit

Permalink
feat(encoder): copy input streams' metadata to output streams (#1284)
Browse files Browse the repository at this point in the history
* 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 <i@k4yt3x.com>
Co-authored-by: k4yt3x <i@k4yt3x.com>
  • Loading branch information
Henje and k4yt3x authored Jan 8, 2025
1 parent b1190d7 commit 8ffe1b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,21 @@ 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");
return ret;
}
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;

Expand Down

0 comments on commit 8ffe1b8

Please sign in to comment.