From 01e8a9c9e3a28f2beb41a5ee6d902797abdb74f0 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sun, 30 Mar 2014 19:05:59 +0200 Subject: encode_lavc: copy metadata to output file Closes #684 Signed-off-by: wm4 Includes some minor cosmetic changes additional to the original PR. --- common/encode.h | 4 ++++ common/encode_lavc.c | 16 +++++++++++++++- common/encode_lavc.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/encode.h b/common/encode.h index 7d6cacd86a..530805c76f 100644 --- a/common/encode.h +++ b/common/encode.h @@ -3,6 +3,8 @@ #include +#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 diff --git a/common/encode_lavc.c b/common/encode_lavc.c index 5d9853673b..39e5607e41 100644 --- a/common/encode_lavc.c +++ b/common/encode_lavc.c @@ -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; diff --git a/common/encode_lavc.h b/common/encode_lavc.h index af7f4fba3d..7a7f86cde1 100644 --- a/common/encode_lavc.h +++ b/common/encode_lavc.h @@ -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 -- cgit v1.2.3