aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/ffmenc.c
diff options
context:
space:
mode:
authorLukasz Marek <lukasz.m.luki2@gmail.com>2014-11-10 23:22:59 +0100
committerLukasz Marek <lukasz.m.luki2@gmail.com>2014-11-16 01:13:38 +0100
commit6690d4c3f53bd46144f3c13afcc77bcca3f7bb0b (patch)
tree3cec9602849c3d034a150a00603e0e7872d39250 /libavformat/ffmenc.c
parentbee5844ddd4efc771a85caf6168d79abe42769a2 (diff)
downloadffmpeg-6690d4c3f53bd46144f3c13afcc77bcca3f7bb0b.tar.gz
lavf/ffm: store/restore private codec context
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Diffstat (limited to 'libavformat/ffmenc.c')
-rw-r--r--libavformat/ffmenc.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
index eb809eb64c..e0885e7012 100644
--- a/libavformat/ffmenc.c
+++ b/libavformat/ffmenc.c
@@ -23,6 +23,7 @@
#include "libavutil/intfloat.h"
#include "libavutil/avassert.h"
#include "libavutil/parseutils.h"
+#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
#include "ffm.h"
@@ -93,6 +94,32 @@ static void write_header_chunk(AVIOContext *pb, AVIOContext *dpb, unsigned id)
av_free(dyn_buf);
}
+static int ffm_write_header_codec_private_ctx(AVIOContext *pb, AVCodecContext *ctx, int type)
+{
+ AVIOContext *tmp;
+ char *buf = NULL;
+ int ret;
+ const AVCodec *enc = ctx->codec ? ctx->codec : avcodec_find_encoder(ctx->codec_id);
+
+ if (!enc)
+ return AVERROR(EINVAL);
+ if (ctx->priv_data && enc->priv_class && enc->priv_data_size) {
+ if ((ret = av_opt_serialize(ctx->priv_data, AV_OPT_FLAG_ENCODING_PARAM | type,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',')) < 0)
+ return ret;
+ if (buf && strlen(buf)) {
+ if (avio_open_dyn_buf(&tmp) < 0) {
+ av_free(buf);
+ return AVERROR(ENOMEM);
+ }
+ avio_put_str(tmp, buf);
+ write_header_chunk(pb, tmp, MKBETAG('C', 'P', 'R', 'V'));
+ }
+ av_free(buf);
+ }
+ return 0;
+}
+
static int ffm_write_header(AVFormatContext *s)
{
FFMContext *ffm = s->priv_data;
@@ -100,10 +127,10 @@ static int ffm_write_header(AVFormatContext *s)
AVStream *st;
AVIOContext *pb = s->pb;
AVCodecContext *codec;
- int bit_rate, i;
+ int bit_rate, i, ret;
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
- int ret = av_parse_time(&ffm->start_time, t->value, 0);
+ ret = av_parse_time(&ffm->start_time, t->value, 0);
if (ret < 0)
return ret;
}
@@ -197,12 +224,16 @@ static int ffm_write_header(AVFormatContext *s)
avio_wb32(pb, codec->max_qdiff);
avio_wb32(pb, codec->refs);
write_header_chunk(s->pb, pb, MKBETAG('S', 'T', 'V', 'I'));
+ if ((ret = ffm_write_header_codec_private_ctx(s->pb, codec, AV_OPT_FLAG_VIDEO_PARAM)) < 0)
+ return ret;
break;
case AVMEDIA_TYPE_AUDIO:
avio_wb32(pb, codec->sample_rate);
avio_wl16(pb, codec->channels);
avio_wl16(pb, codec->frame_size);
write_header_chunk(s->pb, pb, MKBETAG('S', 'T', 'A', 'U'));
+ if ((ret = ffm_write_header_codec_private_ctx(s->pb, codec, AV_OPT_FLAG_AUDIO_PARAM)) < 0)
+ return ret;
break;
default:
return -1;