avformat/dashenc: Update extradata for mov muxer

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/121/merge
Timo Rothenpieler 10 years ago committed by Michael Niedermayer
parent 63ea3a86b7
commit f5668e614b
  1. 43
      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 &&

Loading…
Cancel
Save