mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 12:17:12 +00:00
encode_lavc: copy metadata to output file
Closes #684 Signed-off-by: wm4 <wm4@nowhere> Includes some minor cosmetic changes additional to the original PR.
This commit is contained in:
parent
239dc2851a
commit
01e8a9c9e3
@ -3,6 +3,8 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "demux/demux.h"
|
||||
|
||||
struct mpv_global;
|
||||
struct mp_log;
|
||||
struct encode_lavc_context;
|
||||
@ -17,6 +19,8 @@ void encode_lavc_discontinuity(struct encode_lavc_context *ctx);
|
||||
bool encode_lavc_showhelp(struct mp_log *log, struct encode_output_conf *options);
|
||||
int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position);
|
||||
void encode_lavc_expect_stream(struct encode_lavc_context *ctx, int mt);
|
||||
void encode_lavc_set_metadata(struct encode_lavc_context *ctx,
|
||||
struct mp_tags *metadata);
|
||||
void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps);
|
||||
void encode_lavc_set_audio_pts(struct encode_lavc_context *ctx, double pts);
|
||||
bool encode_lavc_didfail(struct encode_lavc_context *ctx); // check if encoding failed
|
||||
|
@ -244,10 +244,15 @@ struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options,
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void encode_lavc_set_metadata(struct encode_lavc_context *ctx,
|
||||
struct mp_tags *metadata)
|
||||
{
|
||||
ctx->metadata = metadata;
|
||||
}
|
||||
|
||||
int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
{
|
||||
AVDictionaryEntry *de;
|
||||
unsigned i;
|
||||
|
||||
if (ctx->header_written < 0)
|
||||
return 0;
|
||||
@ -257,6 +262,7 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
CHECK_FAIL(ctx, 0);
|
||||
|
||||
if (ctx->expect_video) {
|
||||
unsigned i;
|
||||
for (i = 0; i < ctx->avc->nb_streams; ++i)
|
||||
if (ctx->avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
|
||||
break;
|
||||
@ -267,6 +273,7 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
}
|
||||
}
|
||||
if (ctx->expect_audio) {
|
||||
unsigned i;
|
||||
for (i = 0; i < ctx->avc->nb_streams; ++i)
|
||||
if (ctx->avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
|
||||
break;
|
||||
@ -296,6 +303,13 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
MP_INFO(ctx, "Opening muxer: %s [%s]\n",
|
||||
ctx->avc->oformat->long_name, ctx->avc->oformat->name);
|
||||
|
||||
if (ctx->metadata) {
|
||||
for (int i = 0; i < ctx->metadata->num_keys; i++) {
|
||||
av_dict_set(&ctx->avc->metadata,
|
||||
ctx->metadata->keys[i], ctx->metadata->values[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (avformat_write_header(ctx->avc, &ctx->foptions) < 0) {
|
||||
encode_lavc_fail(ctx, "could not write header\n");
|
||||
return 0;
|
||||
|
@ -38,6 +38,7 @@ struct encode_lavc_context {
|
||||
struct mpv_global *global;
|
||||
struct encode_output_conf *options;
|
||||
struct mp_log *log;
|
||||
struct mp_tags *metadata;
|
||||
|
||||
// All entry points must be guarded with the lock. Functions called by
|
||||
// the playback core lock this automatically, but ao_lavc.c and vo_lavc.c
|
||||
|
@ -1272,6 +1272,10 @@ goto_reopen_demuxer: ;
|
||||
encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_VIDEO);
|
||||
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_AUDIO])
|
||||
encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_AUDIO);
|
||||
if (mpctx->encode_lavc_ctx) {
|
||||
encode_lavc_set_metadata(mpctx->encode_lavc_ctx,
|
||||
mpctx->demuxer->metadata);
|
||||
}
|
||||
#endif
|
||||
|
||||
reinit_video_chain(mpctx);
|
||||
|
Loading…
Reference in New Issue
Block a user