diff options
author | Anton Khirnov <anton@khirnov.net> | 2024-09-10 12:10:31 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-09-26 18:25:21 +0200 |
commit | 7f7fe2a10bda086c595bc191145f2390e9781726 (patch) | |
tree | 16f6b5c0d2a8aafcd25318ba5e1e6d4255f67517 /fftools | |
parent | 6525fe4e773b054bc4d48fd06208262a8040e592 (diff) | |
download | ffmpeg-7f7fe2a10bda086c595bc191145f2390e9781726.tar.gz |
fftools/ffmpeg_enc: move set_encoder_id() to ffmpeg_mux_init
This code uses no encoder properties or state besides its name, and is
mostly muxer logic, and thus belongs more properly into the muxer.
The results of several test change due to different metadata tag order
(the "encoder" tag is now set first).
Diffstat (limited to 'fftools')
-rw-r--r-- | fftools/ffmpeg_enc.c | 29 | ||||
-rw-r--r-- | fftools/ffmpeg_mux_init.c | 31 |
2 files changed, 28 insertions, 32 deletions
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 499d6ea1f3..1be0a37353 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -161,31 +161,6 @@ static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx, return 0; } -static int set_encoder_id(OutputFile *of, OutputStream *ost) -{ - const char *cname = ost->enc_ctx->codec->name; - uint8_t *encoder_string; - int encoder_string_len; - - if (av_dict_get(ost->st->metadata, "encoder", NULL, 0)) - return 0; - - encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(cname) + 2; - encoder_string = av_mallocz(encoder_string_len); - if (!encoder_string) - return AVERROR(ENOMEM); - - if (!of->bitexact && !ost->bitexact) - av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); - else - av_strlcpy(encoder_string, "Lavc ", encoder_string_len); - av_strlcat(encoder_string, cname, encoder_string_len); - av_dict_set(&ost->st->metadata, "encoder", encoder_string, - AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); - - return 0; -} - int enc_open(void *opaque, const AVFrame *frame) { OutputStream *ost = opaque; @@ -224,10 +199,6 @@ int enc_open(void *opaque, const AVFrame *frame) } } - ret = set_encoder_id(of, ost); - if (ret < 0) - return ret; - if (ist) dec = ist->decoder; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 47d745aa65..bf2c0b8f67 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1140,6 +1140,28 @@ fail: return ret; } +static int set_encoder_id(OutputStream *ost, const AVCodec *codec) +{ + const char *cname = codec->name; + uint8_t *encoder_string; + int encoder_string_len; + + encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(cname) + 2; + encoder_string = av_mallocz(encoder_string_len); + if (!encoder_string) + return AVERROR(ENOMEM); + + if (!ost->file->bitexact && !ost->bitexact) + av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); + else + av_strlcpy(encoder_string, "Lavc ", encoder_string_len); + av_strlcat(encoder_string, cname, encoder_string_len); + av_dict_set(&ost->st->metadata, "encoder", encoder_string, + AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); + + return 0; +} + static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, InputStream *ist, OutputFilter *ofilter, const ViewSpecifier *vs, OutputStream **post) @@ -1406,6 +1428,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT); } + if (enc) { + ret = set_encoder_id(ost, enc); + if (ret < 0) + return ret; + } + opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base); if (time_base) { AVRational q; @@ -2981,9 +3009,6 @@ static int copy_meta(Muxer *mux, const OptionsContext *o) if (!ost->ist) /* this is true e.g. for attached files */ continue; av_dict_copy(&ost->st->metadata, ost->ist->st->metadata, AV_DICT_DONT_OVERWRITE); - if (ost->enc_ctx) { - av_dict_set(&ost->st->metadata, "encoder", NULL, 0); - } } return 0; |