summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-11-29 04:03:22 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-11-29 04:51:47 +0100
commitfc09bf57a60d4c4a6d339b204b3282337067c06d (patch)
treeef4e1cd353c5139689a181e4ba9fdef5c5816f5a /libavformat
parent4dcd1a3145dd93602b86a44ebc07d98ca2a30ab6 (diff)
movenc: Write file with minimal number of chunks for the given interleaving.
Reviewed-by: Baptiste Coudurier <baptiste.coudurier@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/movenc.c31
-rw-r--r--libavformat/movenc.h3
2 files changed, 30 insertions, 4 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index efa0b92cad..d72ac4d714 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -81,8 +81,10 @@ static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track)
} else
ffio_wfourcc(pb, "stco");
avio_wb32(pb, 0); /* version & flags */
- avio_wb32(pb, track->entry); /* entry count */
+ avio_wb32(pb, track->chunkCount); /* entry count */
for (i=0; i<track->entry; i++) {
+ if(!track->cluster[i].chunkNum)
+ continue;
if(mode64 == 1)
avio_wb64(pb, track->cluster[i].pos);
else
@@ -140,11 +142,11 @@ static int mov_write_stsc_tag(AVIOContext *pb, MOVTrack *track)
ffio_wfourcc(pb, "stsc");
avio_wb32(pb, 0); // version & flags
entryPos = avio_tell(pb);
- avio_wb32(pb, track->entry); // entry count
+ avio_wb32(pb, track->chunkCount); // entry count
for (i=0; i<track->entry; i++) {
- if(oldval != track->cluster[i].samplesInChunk)
+ if(oldval != track->cluster[i].samplesInChunk && track->cluster[i].chunkNum)
{
- avio_wb32(pb, i+1); // first chunk
+ avio_wb32(pb, track->cluster[i].chunkNum); // first chunk
avio_wb32(pb, track->cluster[i].samplesInChunk); // samples per chunk
avio_wb32(pb, 0x1); // sample description index
oldval = track->cluster[i].samplesInChunk;
@@ -1805,6 +1807,24 @@ static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s)
return 0;
}
+static void build_chunks(MOVTrack *trk)
+{
+ int i;
+ MOVIentry *chunk= &trk->cluster[0];
+ chunk->chunkNum= 1;
+ trk->chunkCount= 1;
+ for(i=1; i<trk->entry; i++){
+ if(chunk->pos + chunk->chunkSize == trk->cluster[i].pos){
+ chunk->chunkSize += trk->cluster[i].size;
+ chunk->samplesInChunk += trk->cluster[i].entries;
+ }else{
+ trk->cluster[i].chunkNum = chunk->chunkNum+1;
+ chunk=&trk->cluster[i];
+ trk->chunkCount++;
+ }
+ }
+}
+
static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
AVFormatContext *s)
{
@@ -1818,6 +1838,8 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
mov->tracks[i].time = mov->time;
mov->tracks[i].trackID = i+1;
+
+ build_chunks(&mov->tracks[i]);
}
if (mov->chapter_track)
@@ -2070,6 +2092,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
trk->cluster[trk->entry].pos = avio_tell(pb) - size;
trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
+ trk->cluster[trk->entry].chunkSize =
trk->cluster[trk->entry].size = size;
trk->cluster[trk->entry].entries = samplesInChunk;
trk->cluster[trk->entry].dts = pkt->dts;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 1aa23fa1a9..b022f48b87 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -43,6 +43,8 @@ typedef struct MOVIentry {
unsigned int size;
uint64_t pos;
unsigned int samplesInChunk;
+ unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
+ uint64_t chunkSize;
unsigned int entries;
int cts;
int64_t dts;
@@ -73,6 +75,7 @@ typedef struct MOVIndex {
int64_t trackDuration;
long sampleCount;
long sampleSize;
+ long chunkCount;
int hasKeyframes;
#define MOV_TRACK_CTTS 0x0001
#define MOV_TRACK_STPS 0x0002