Commit ee78b0c2 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'b75a1f98'

* commit 'b75a1f98':
  matroska: Factor out write_track from mkv_write_tracks

Conflicts:
	libavformat/matroskaenc.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 8365287e b75a1f98
......@@ -572,46 +572,59 @@ static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec,
*output_sample_rate = mp4ac.ext_sample_rate;
}
static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
AVCodecContext *codec, int native_id,
int qt_id)
static int mkv_write_native_codecprivate(AVFormatContext *s,
AVCodecContext *codec,
AVIOContext *dyn_cp)
{
AVIOContext *dyn_cp;
uint8_t *codecpriv;
int ret, codecpriv_size;
ret = avio_open_dyn_buf(&dyn_cp);
if (ret < 0)
return ret;
if (native_id) {
if (codec->codec_id == AV_CODEC_ID_VORBIS ||
codec->codec_id == AV_CODEC_ID_THEORA)
ret = put_xiph_codecpriv(s, dyn_cp, codec);
else if (codec->codec_id == AV_CODEC_ID_FLAC)
ret = put_flac_codecpriv(s, dyn_cp, codec);
else if (codec->codec_id == AV_CODEC_ID_WAVPACK)
ret = put_wv_codecpriv(dyn_cp, codec);
else if (codec->codec_id == AV_CODEC_ID_H264)
ret = ff_isom_write_avcc(dyn_cp, codec->extradata,
switch (codec->codec_id) {
case AV_CODEC_ID_VORBIS:
case AV_CODEC_ID_THEORA:
return put_xiph_codecpriv(s, dyn_cp, codec);
case AV_CODEC_ID_FLAC:
return put_flac_codecpriv(s, dyn_cp, codec);
case AV_CODEC_ID_WAVPACK:
return put_wv_codecpriv(dyn_cp, codec);
case AV_CODEC_ID_H264:
return ff_isom_write_avcc(dyn_cp, codec->extradata,
codec->extradata_size);
else if (codec->codec_id == AV_CODEC_ID_HEVC)
ret = ff_isom_write_hvcc(dyn_cp, codec->extradata,
case AV_CODEC_ID_HEVC:
return ff_isom_write_hvcc(dyn_cp, codec->extradata,
codec->extradata_size, 0);
else if (codec->codec_id == AV_CODEC_ID_ALAC) {
case AV_CODEC_ID_ALAC:
if (codec->extradata_size < 36) {
av_log(s, AV_LOG_ERROR,
"Invalid extradata found, ALAC expects a 36-byte "
"QuickTime atom.");
ret = AVERROR_INVALIDDATA;
return AVERROR_INVALIDDATA;
} else
avio_write(dyn_cp, codec->extradata + 12,
codec->extradata_size - 12);
} else if (codec->codec_id == AV_CODEC_ID_PRORES &&
break;
default:
if (codec->codec_id == AV_CODEC_ID_PRORES &&
ff_codec_get_id(ff_codec_movvideo_tags, codec->codec_tag) == AV_CODEC_ID_PRORES) {
avio_wl32(dyn_cp, codec->codec_tag);
} else if (codec->extradata_size && codec->codec_id != AV_CODEC_ID_TTA)
avio_write(dyn_cp, codec->extradata, codec->extradata_size);
}
return 0;
}
static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
AVCodecContext *codec, int native_id,
int qt_id)
{
AVIOContext *dyn_cp;
uint8_t *codecpriv;
int ret, codecpriv_size;
ret = avio_open_dyn_buf(&dyn_cp);
if (ret < 0)
return ret;
if (native_id) {
ret = mkv_write_native_codecprivate(s, codec, dyn_cp);
} else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (qt_id) {
if (!codec->codec_tag)
......@@ -667,23 +680,9 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
return ret;
}
static int mkv_write_tracks(AVFormatContext *s)
static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
int i, AVIOContext *pb, int default_stream_exists)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *pb = s->pb;
ebml_master tracks;
int i, j, ret, default_stream_exists = 0;
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));
if (ret < 0)
return ret;
tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0);
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
}
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
AVCodecContext *codec = st->codec;
ebml_master subinfo, track;
......@@ -694,6 +693,7 @@ static int mkv_write_tracks(AVFormatContext *s)
int output_sample_rate = 0;
int display_width_div = 1;
int display_height_div = 1;
int j, ret;
AVDictionaryEntry *tag;
// ms precision is the de-facto standard timescale for mkv files
......@@ -701,7 +701,7 @@ static int mkv_write_tracks(AVFormatContext *s)
if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
mkv->have_attachments = 1;
continue;
return 0;
}
if (!bit_depth && codec->codec_id != AV_CODEC_ID_ADPCM_G726)
......@@ -919,6 +919,30 @@ static int mkv_write_tracks(AVFormatContext *s)
}
end_ebml_master(pb, track);
return 0;
}
static int mkv_write_tracks(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *pb = s->pb;
ebml_master tracks;
int i, ret, default_stream_exists = 0;
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));
if (ret < 0)
return ret;
tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0);
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
}
for (i = 0; i < s->nb_streams; i++) {
ret = mkv_write_track(s, mkv, i, pb, default_stream_exists);
if (ret < 0)
return ret;
}
end_ebml_master(pb, tracks);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment