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>
This commit is contained in:
Michael Niedermayer 2011-11-29 04:03:22 +01:00
parent 4dcd1a3145
commit fc09bf57a6
17 changed files with 66 additions and 40 deletions

View File

@ -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;

View File

@ -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

View File

@ -1,4 +1,4 @@
b25bcc7ec3f5c19cdfc01a6bbd32edb8 *./tests/data/acodec/alac.m4a
389386 ./tests/data/acodec/alac.m4a
b7a590dd346b2fbaf49421c72a4a84bd *./tests/data/acodec/alac.m4a
389130 ./tests/data/acodec/alac.m4a
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/alac.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400

View File

@ -6,16 +6,16 @@ stddev: 101.67 PSNR: 56.19 MAXDIFF: 515 bytes: 1058400/ 1058400
529258 ./tests/data/acodec/pcm_mulaw.wav
7ae8c3fc804bd574006fd547fe28980c *./tests/data/pcm.acodec.out.wav
stddev: 103.38 PSNR: 56.04 MAXDIFF: 644 bytes: 1058400/ 1058400
760f85fb9f4e8aba326fb44ae84c9507 *./tests/data/acodec/pcm_s8.mov
530837 ./tests/data/acodec/pcm_s8.mov
b78d2a30df75af08ecf86f201281fec2 *./tests/data/acodec/pcm_s8.mov
529793 ./tests/data/acodec/pcm_s8.mov
651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm.acodec.out.wav
stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400
70fecbae732f81143a560c7315eda49a *./tests/data/acodec/pcm_u8.wav
529246 ./tests/data/acodec/pcm_u8.wav
651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm.acodec.out.wav
stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400
a4e18d1ca9ef5b8132a84d43625ddc47 *./tests/data/acodec/pcm_s16be.mov
1060037 ./tests/data/acodec/pcm_s16be.mov
9686b93d1439fc2df991a004ab0298f4 *./tests/data/acodec/pcm_s16be.mov
1058993 ./tests/data/acodec/pcm_s16be.mov
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/acodec/pcm_s16le.wav
@ -30,16 +30,16 @@ c4f51bf32fad2f7af8ea5beedb56168b *./tests/data/acodec/pcm_s16le.mkv
1060638 ./tests/data/acodec/pcm_s16le.mkv
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
971d2d2633e41a0326fe2d04a2d0350f *./tests/data/acodec/pcm_s24be.mov
1589237 ./tests/data/acodec/pcm_s24be.mov
22c5c3df0a4765e28c205a4fb95b3cdc *./tests/data/acodec/pcm_s24be.mov
1588193 ./tests/data/acodec/pcm_s24be.mov
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
a85380fb79b0d4fff38e24ac1e34bb94 *./tests/data/acodec/pcm_s24le.wav
1587668 ./tests/data/acodec/pcm_s24le.wav
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
fc4f4e3e195bbde037ed31021d229f12 *./tests/data/acodec/pcm_s32be.mov
2118437 ./tests/data/acodec/pcm_s32be.mov
b36ac7a1b4fc28248a565a676e555bd1 *./tests/data/acodec/pcm_s32be.mov
2117393 ./tests/data/acodec/pcm_s32be.mov
64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm.acodec.out.wav
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
da6ed80f4f40f0082577dea80827e014 *./tests/data/acodec/pcm_s32le.wav

View File

@ -1,3 +1,3 @@
2e2529d01dbe42e4dd63580a351898f5 *./tests/data/lavf/lavf.mov
357681 ./tests/data/lavf/lavf.mov
6706bb7887aa828a0a734552c3d9fc40 *./tests/data/lavf/lavf.mov
357749 ./tests/data/lavf/lavf.mov
./tests/data/lavf/lavf.mov CRC=0x2f6a9b26

View File

@ -1,4 +1,4 @@
34949ea38da2cf6a8406ad600ad95cfa *./tests/data/vsynth1/dnxhd-1080i.mov
3031875 ./tests/data/vsynth1/dnxhd-1080i.mov
b0c02b4f7ce6b57668e54970443f9a42 *./tests/data/vsynth1/dnxhd-1080i.mov
3031859 ./tests/data/vsynth1/dnxhd-1080i.mov
0c651e840f860592f0d5b66030d9fa32 *./tests/data/dnxhd_1080i.vsynth1.out.yuv
stddev: 6.29 PSNR: 32.15 MAXDIFF: 64 bytes: 760320/ 7603200

View File

@ -1,4 +1,4 @@
d2405fd9e350854a161f48bc63f49253 *./tests/data/vsynth1/odivx.mp4
540156 ./tests/data/vsynth1/odivx.mp4
859c8b545c1c702343d201836833ce23 *./tests/data/vsynth1/odivx.mp4
539960 ./tests/data/vsynth1/odivx.mp4
8828a375448dc5c2215163ba70656f89 *./tests/data/mpeg4.vsynth1.out.yuv
stddev: 7.97 PSNR: 30.10 MAXDIFF: 105 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
1864aa1cb7370fe682f3f392dc771960 *./tests/data/vsynth1/prores.mov
5022955 ./tests/data/vsynth1/prores.mov
6484056f2f99410c20a0d987d0255a1d *./tests/data/vsynth1/prores.mov
5022759 ./tests/data/vsynth1/prores.mov
a2e2d1d45341a94ff994d1d92629f778 *./tests/data/prores.vsynth1.out.yuv
stddev: 2.47 PSNR: 40.27 MAXDIFF: 31 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
d14041925ce5ec5001dc519276b1a1ab *./tests/data/vsynth1/qtrle.mov
15263232 ./tests/data/vsynth1/qtrle.mov
92a24c3cb16de8352db01e094c2cab9a *./tests/data/vsynth1/qtrle.mov
15263036 ./tests/data/vsynth1/qtrle.mov
93695a27c24a61105076ca7b1f010bbd *./tests/data/qtrle.vsynth1.out.yuv
stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
0544350c00f33f21e29b5edd965c3f03 *./tests/data/vsynth1/qtrlegray.mov
5113428 ./tests/data/vsynth1/qtrlegray.mov
54651e32f751432fad61acb364de80f5 *./tests/data/vsynth1/qtrlegray.mov
5113232 ./tests/data/vsynth1/qtrlegray.mov
29def4aed035ed65d3a89f7d382fccbe *./tests/data/qtrlegray.vsynth1.out.yuv
stddev: 25.95 PSNR: 19.85 MAXDIFF: 122 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
595fc4e38734521356b60e67b813f0fa *./tests/data/vsynth1/svq1.mov
1334367 ./tests/data/vsynth1/svq1.mov
e3257e307140bf1c2e117f4ed6131c1c *./tests/data/vsynth1/svq1.mov
1334171 ./tests/data/vsynth1/svq1.mov
9cc35c54b2c77d36bd7e308b393c1f81 *./tests/data/svq1.vsynth1.out.yuv
stddev: 9.58 PSNR: 28.50 MAXDIFF: 210 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
995e433cd076e3c1534fa73181744a84 *./tests/data/vsynth2/dnxhd-1080i.mov
3031875 ./tests/data/vsynth2/dnxhd-1080i.mov
4841132b013b373862ee5b9c4dc7592c *./tests/data/vsynth2/dnxhd-1080i.mov
3031859 ./tests/data/vsynth2/dnxhd-1080i.mov
3c559af629ae0a8fb1a9a0e4b4da7733 *./tests/data/dnxhd_1080i.vsynth2.out.yuv
stddev: 1.31 PSNR: 45.77 MAXDIFF: 23 bytes: 760320/ 7603200

View File

@ -1,4 +1,4 @@
2e3bf184668d4807ae6df0bdceba487b *./tests/data/vsynth2/odivx.mp4
119809 ./tests/data/vsynth2/odivx.mp4
f11f53931a1374acff6c04a21517809c *./tests/data/vsynth2/odivx.mp4
119613 ./tests/data/vsynth2/odivx.mp4
90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.vsynth2.out.yuv
stddev: 5.34 PSNR: 33.57 MAXDIFF: 83 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
1160bb646bd365536951fadd96880d3c *./tests/data/vsynth2/prores.mov
2844194 ./tests/data/vsynth2/prores.mov
179b4f654de017fa74b8eaab93d9d2cb *./tests/data/vsynth2/prores.mov
2843998 ./tests/data/vsynth2/prores.mov
b5844025c0f4c7c37db702c3213db232 *./tests/data/prores.vsynth2.out.yuv
stddev: 1.31 PSNR: 45.77 MAXDIFF: 11 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
d8c1604dc46d9aa4ec0385e6722c6989 *./tests/data/vsynth2/qtrle.mov
14798419 ./tests/data/vsynth2/qtrle.mov
998aa370cb23634272c64cc4ae759a9d *./tests/data/vsynth2/qtrle.mov
14798223 ./tests/data/vsynth2/qtrle.mov
98d0e2854731472c5bf13d8638502d0a *./tests/data/qtrle.vsynth2.out.yuv
stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
55c6e5af44ece0621d1d4c91b282a544 *./tests/data/vsynth2/qtrlegray.mov
5111417 ./tests/data/vsynth2/qtrlegray.mov
19ffbb5fe258dc96fa345b9fbbf7ba51 *./tests/data/vsynth2/qtrlegray.mov
5111221 ./tests/data/vsynth2/qtrlegray.mov
f63b5ebdfdba750e547c25131b0a3fd1 *./tests/data/qtrlegray.vsynth2.out.yuv
stddev: 19.42 PSNR: 22.36 MAXDIFF: 72 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
7f9fbe4890bc1df67867bf03803dca48 *./tests/data/vsynth2/svq1.mov
766851 ./tests/data/vsynth2/svq1.mov
fdb06a9800712a0bf6941847afcbca57 *./tests/data/vsynth2/svq1.mov
766655 ./tests/data/vsynth2/svq1.mov
aa03471dac3f49455a33a2b19fda1098 *./tests/data/svq1.vsynth2.out.yuv
stddev: 3.23 PSNR: 37.93 MAXDIFF: 61 bytes: 7603200/ 7603200