diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-03-16 21:52:54 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-03-16 21:53:02 +0100 |
commit | 312eb0d66f24dc123c1732176111ea1de7854b30 (patch) | |
tree | f5934ddede855d3898641dae709ec7ea27c2c3b4 | |
parent | 1904704a48b7ced8d5bb9091fe47a28b4bbe619b (diff) | |
parent | 50ff0c05b691524d1fd044a2f2eefb706932fc98 (diff) | |
download | ffmpeg-streaming-312eb0d66f24dc123c1732176111ea1de7854b30.zip ffmpeg-streaming-312eb0d66f24dc123c1732176111ea1de7854b30.tar.gz |
Merge commit '50ff0c05b691524d1fd044a2f2eefb706932fc98'
* commit '50ff0c05b691524d1fd044a2f2eefb706932fc98':
movenc: Support writing multiple trun atoms
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/movenc.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 1008708..4c76332 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3402,18 +3402,19 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVMuxContext *mov, } static int mov_write_trun_tag(AVIOContext *pb, MOVMuxContext *mov, - MOVTrack *track, int moof_size) + MOVTrack *track, int moof_size, + int first, int end) { int64_t pos = avio_tell(pb); uint32_t flags = MOV_TRUN_DATA_OFFSET; int i; - for (i = 0; i < track->entry; i++) { + for (i = first; i < end; i++) { if (get_cluster_duration(track, i) != track->default_duration) flags |= MOV_TRUN_SAMPLE_DURATION; if (track->cluster[i].size != track->default_size) flags |= MOV_TRUN_SAMPLE_SIZE; - if (i > 0 && get_sample_flags(track, &track->cluster[i]) != track->default_sample_flags) + if (i > first && get_sample_flags(track, &track->cluster[i]) != track->default_sample_flags) flags |= MOV_TRUN_SAMPLE_FLAGS; } if (!(flags & MOV_TRUN_SAMPLE_FLAGS) && track->entry > 0 && @@ -3427,18 +3428,18 @@ static int mov_write_trun_tag(AVIOContext *pb, MOVMuxContext *mov, avio_w8(pb, 0); /* version */ avio_wb24(pb, flags); - avio_wb32(pb, track->entry); /* sample count */ + avio_wb32(pb, end - first); /* sample count */ if (mov->flags & FF_MOV_FLAG_OMIT_TFHD_OFFSET && !(mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF) && !mov->first_trun) avio_wb32(pb, 0); /* Later tracks follow immediately after the previous one */ else avio_wb32(pb, moof_size + 8 + track->data_offset + - track->cluster[0].pos); /* data offset */ + track->cluster[first].pos); /* data offset */ if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) - avio_wb32(pb, get_sample_flags(track, &track->cluster[0])); + avio_wb32(pb, get_sample_flags(track, &track->cluster[first])); - for (i = 0; i < track->entry; i++) { + for (i = first; i < end; i++) { if (flags & MOV_TRUN_SAMPLE_DURATION) avio_wb32(pb, get_cluster_duration(track, i)); if (flags & MOV_TRUN_SAMPLE_SIZE) @@ -3577,13 +3578,20 @@ static int mov_write_traf_tag(AVIOContext *pb, MOVMuxContext *mov, int moof_size) { int64_t pos = avio_tell(pb); + int i, start = 0; avio_wb32(pb, 0); /* size placeholder */ ffio_wfourcc(pb, "traf"); mov_write_tfhd_tag(pb, mov, track, moof_offset); if (mov->mode != MODE_ISM) mov_write_tfdt_tag(pb, track); - mov_write_trun_tag(pb, mov, track, moof_size); + for (i = 1; i < track->entry; i++) { + if (track->cluster[i].pos != track->cluster[i - 1].pos + track->cluster[i - 1].size) { + mov_write_trun_tag(pb, mov, track, moof_size, start, i); + start = i; + } + } + mov_write_trun_tag(pb, mov, track, moof_size, start, track->entry); if (mov->mode == MODE_ISM) { mov_write_tfxd_tag(pb, track); |