summaryrefslogtreecommitdiff
path: root/libavformat/dashenc.c
diff options
context:
space:
mode:
authorTimo Rothenpieler <timo@rothenpieler.org>2015-03-04 22:48:43 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-03-05 10:33:03 +0100
commitf5668e614bdccc19a3b3e3d3d67f7c7778526908 (patch)
tree7c1b2985310f77065a03e194b29f405da7062c1a /libavformat/dashenc.c
parent63ea3a86b7ce7c4f6dca40387fb948a9bb9b2b9b (diff)
avformat/dashenc: Update extradata for mov muxer
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/dashenc.c')
-rw-r--r--libavformat/dashenc.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 25c699e5d5..92b7d6c773 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -72,7 +72,6 @@ typedef struct OutputStream {
int bit_rate;
char bandwidth_str[64];
- int codec_str_extradata_size;
char codec_str[100];
} OutputStream;
@@ -503,12 +502,6 @@ static int write_manifest(AVFormatContext *s, int final)
if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO)
continue;
- if (os->codec_str_extradata_size != st->codec->extradata_size) {
- memset(os->codec_str, 0, sizeof(os->codec_str));
- set_codec_str(s, st->codec, os->codec_str, sizeof(os->codec_str));
- os->codec_str_extradata_size = st->codec->extradata_size;
- }
-
avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/mp4\" codecs=\"%s\"%s width=\"%d\" height=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codec->width, st->codec->height);
output_segment_list(&c->streams[i], out, c);
avio_printf(out, "\t\t\t</Representation>\n");
@@ -524,12 +517,6 @@ static int write_manifest(AVFormatContext *s, int final)
if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO)
continue;
- if (os->codec_str_extradata_size != st->codec->extradata_size) {
- memset(os->codec_str, 0, sizeof(os->codec_str));
- set_codec_str(s, st->codec, os->codec_str, sizeof(os->codec_str));
- os->codec_str_extradata_size = st->codec->extradata_size;
- }
-
avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/mp4\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n", i, os->codec_str, os->bandwidth_str, st->codec->sample_rate);
avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", st->codec->channels);
output_segment_list(&c->streams[i], out, c);
@@ -664,8 +651,7 @@ static int dash_write_header(AVFormatContext *s)
else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
c->has_audio = 1;
- set_codec_str(s, s->streams[i]->codec, os->codec_str, sizeof(os->codec_str));
- os->codec_str_extradata_size = s->streams[i]->codec->extradata_size;
+ set_codec_str(s, st->codec, os->codec_str, sizeof(os->codec_str));
os->first_pts = AV_NOPTS_VALUE;
os->max_pts = AV_NOPTS_VALUE;
os->segment_index = 1;
@@ -750,6 +736,29 @@ static void find_index_range(AVFormatContext *s, const char *full_path,
*index_length = AV_RB32(&buf[0]);
}
+static int update_stream_extradata(AVFormatContext *s, OutputStream *os,
+ AVCodecContext *codec)
+{
+ uint8_t *extradata;
+
+ if (os->ctx->streams[0]->codec->extradata_size || !codec->extradata_size)
+ return 0;
+
+ extradata = av_malloc(codec->extradata_size);
+
+ if (!extradata)
+ return AVERROR(ENOMEM);
+
+ memcpy(extradata, codec->extradata, codec->extradata_size);
+
+ os->ctx->streams[0]->codec->extradata = extradata;
+ os->ctx->streams[0]->codec->extradata_size = codec->extradata_size;
+
+ set_codec_str(s, codec, os->codec_str, sizeof(os->codec_str));
+
+ return 0;
+}
+
static int dash_flush(AVFormatContext *s, int final, int stream)
{
DASHContext *c = s->priv_data;
@@ -853,6 +862,10 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t seg_end_duration = (os->segment_index) * (int64_t) c->min_seg_duration;
int ret;
+ ret = update_stream_extradata(s, os, st->codec);
+ if (ret < 0)
+ return ret;
+
// If forcing the stream to start at 0, the mp4 muxer will set the start
// timestamps to 0. Do the same here, to avoid mismatches in duration/timestamps.
if (os->first_pts == AV_NOPTS_VALUE &&