annotate movenc.c @ 2737:1e7edb0c6cfc libavformat

Add support for reading WM/Year tag Patch by: patrice bensoussan a free d fr
author andoma
date Wed, 14 Nov 2007 07:31:25 +0000
parents 09eb62fa2a0e
children d52c718e83f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * MOV, 3GP, MP4 muxer
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
3 * Copyright (c) 2003 Thomas Raivio.
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
4 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
5 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
6 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
7 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
12 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
16 * Lesser General Public License for more details.
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
17 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 890
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
21 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
22 #include "avformat.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
23 #include "riff.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
24 #include "avio.h"
1216
fec0a3d5408f move common code from mov.c and movenc.c to isom.c
bcoudurier
parents: 1172
diff changeset
25 #include "isom.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
26
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
27 #undef NDEBUG
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
28 #include <assert.h>
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
29
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
30 #define MOV_INDEX_CLUSTER_SIZE 16384
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
31 #define globalTimescale 1000
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
32
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
33 #define MODE_MP4 0
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
34 #define MODE_MOV 1
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
35 #define MODE_3GP 2
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
36 #define MODE_PSP 3 // example working PSP command line:
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
37 // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
38 #define MODE_3G2 4
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
39
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
40 typedef struct MOVIentry {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
41 unsigned int flags, size;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
42 uint64_t pos;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
43 unsigned int samplesInChunk;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
44 char key_frame;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
45 unsigned int entries;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
46 int64_t cts;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
47 int64_t dts;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
48 } MOVIentry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
49
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
50 typedef struct MOVIndex {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
51 int mode;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
52 int entry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
53 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
54 long time;
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
55 int64_t trackDuration;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
56 long sampleCount;
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
57 long sampleSize;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
58 int hasKeyframes;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
59 int hasBframes;
890
1e49bfea0ffb finally found what those >138 codes were... crappy compressed 5bit ascii. this gets them correctly, and adds setting track lang in movenc too.
mmu_man
parents: 887
diff changeset
60 int language;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
61 int trackID;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
62 int tag;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
63 AVCodecContext *enc;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
64
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
65 int vosLen;
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
66 uint8_t *vosData;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
67 MOVIentry *cluster;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
68 int audio_vbr;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
69 } MOVTrack;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
70
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
71 typedef struct MOVContext {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
72 int mode;
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
73 int64_t time;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
74 int nb_streams;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
75 offset_t mdat_pos;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
76 uint64_t mdat_size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
77 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
78 MOVTrack tracks[MAX_STREAMS];
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
79 } MOVContext;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
80
2165
eac986610f47 misc typo fixes
diego
parents: 2164
diff changeset
81 //FIXME support 64 bit variant with wide placeholders
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
82 static offset_t updateSize (ByteIOContext *pb, offset_t pos)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
83 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
84 offset_t curpos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
85 url_fseek(pb, pos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
86 put_be32(pb, curpos - pos); /* rewrite size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
87 url_fseek(pb, curpos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
88
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
89 return curpos - pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
90 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
91
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
92 /* Chunk offset atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
93 static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
94 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
95 int i;
910
d92e6d673ef5 gcc 2.95 fix
banan
parents: 909
diff changeset
96 int mode64 = 0; // use 32 bit size variant if possible
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
97 offset_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
98 put_be32(pb, 0); /* size */
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
99 if (pos > UINT32_MAX) {
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
100 mode64 = 1;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
101 put_tag(pb, "co64");
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
102 } else
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
103 put_tag(pb, "stco");
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
104 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
105 put_be32(pb, track->entry); /* entry count */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
106 for (i=0; i<track->entry; i++) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
107 if(mode64 == 1)
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
108 put_be64(pb, track->cluster[i].pos);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
109 else
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
110 put_be32(pb, track->cluster[i].pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
111 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
112 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
113 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
114
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
115 /* Sample size atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
116 static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
117 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
118 int equalChunks = 1;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
119 int i, j, entries = 0, tst = -1, oldtst = -1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
120
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
121 offset_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
122 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
123 put_tag(pb, "stsz");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
124 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
125
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
126 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
127 tst = track->cluster[i].size/track->cluster[i].entries;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
128 if(oldtst != -1 && tst != oldtst) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
129 equalChunks = 0;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
130 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
131 oldtst = tst;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
132 entries += track->cluster[i].entries;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
133 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
134 if (equalChunks) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
135 int sSize = track->cluster[0].size/track->cluster[0].entries;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
136 put_be32(pb, sSize); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
137 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
138 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
139 else {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
140 put_be32(pb, 0); // sample size
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
141 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
142 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
143 for ( j=0; j<track->cluster[i].entries; j++) {
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
144 put_be32(pb, track->cluster[i].size /
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
145 track->cluster[i].entries);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
146 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
147 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
148 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
149 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
150 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
151
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
152 /* Sample to chunk atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
153 static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
154 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
155 int index = 0, oldval = -1, i;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
156 offset_t entryPos, curpos;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
157
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
158 offset_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
159 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
160 put_tag(pb, "stsc");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
161 put_be32(pb, 0); // version & flags
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
162 entryPos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
163 put_be32(pb, track->entry); // entry count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
164 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
165 if(oldval != track->cluster[i].samplesInChunk)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
166 {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
167 put_be32(pb, i+1); // first chunk
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
168 put_be32(pb, track->cluster[i].samplesInChunk); // samples per chunk
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
169 put_be32(pb, 0x1); // sample description index
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
170 oldval = track->cluster[i].samplesInChunk;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
171 index++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
172 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
173 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
174 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
175 url_fseek(pb, entryPos, SEEK_SET);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
176 put_be32(pb, index); // rewrite size
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
177 url_fseek(pb, curpos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
178
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
179 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
180 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
181
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
182 /* Sync sample atom */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
183 static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
184 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
185 offset_t curpos, entryPos;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
186 int i, index = 0;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
187 offset_t pos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
188 put_be32(pb, 0); // size
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
189 put_tag(pb, "stss");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
190 put_be32(pb, 0); // version & flags
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
191 entryPos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
192 put_be32(pb, track->entry); // entry count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
193 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
194 if(track->cluster[i].key_frame == 1) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
195 put_be32(pb, i+1);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
196 index++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
197 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
198 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
199 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
200 url_fseek(pb, entryPos, SEEK_SET);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
201 put_be32(pb, index); // rewrite size
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
202 url_fseek(pb, curpos, SEEK_SET);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
203 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
204 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
205
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
206 static int mov_write_amr_tag(ByteIOContext *pb, MOVTrack *track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
207 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
208 put_be32(pb, 0x11); /* size */
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
209 if (track->mode == MODE_MOV) put_tag(pb, "samr");
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
210 else put_tag(pb, "damr");
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
211 put_tag(pb, "FFMP");
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
212 put_byte(pb, 0); /* decoder version */
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
213
1153
6cb1c11cc363 10l, all modes is 0x81FF
bcoudurier
parents: 1152
diff changeset
214 put_be16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
215 put_byte(pb, 0x00); /* Mode change period (no restriction) */
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
216 put_byte(pb, 0x01); /* Frames per sample */
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
217 return 0x11;
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
218 }
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
219
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
220 static int mov_write_enda_tag(ByteIOContext *pb)
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
221 {
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
222 put_be32(pb, 10);
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
223 put_tag(pb, "enda");
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
224 put_be16(pb, 1); /* little endian */
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
225 return 10;
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
226 }
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
227
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
228 static unsigned int descrLength(unsigned int len)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
229 {
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
230 int i;
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
231 for(i=1; len>>(7*i); i++);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
232 return len + 1 + i;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
233 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
234
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
235 static void putDescr(ByteIOContext *pb, int tag, unsigned int size)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
236 {
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
237 int i= descrLength(size) - size - 2;
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
238 put_byte(pb, tag);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
239 for(; i>0; i--)
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
240 put_byte(pb, (size>>(7*i)) | 0x80);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
241 put_byte(pb, size & 0x7F);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
242 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
243
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
244 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
245 {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
246 offset_t pos = url_ftell(pb);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
247 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
248
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
249 put_be32(pb, 0); // size
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
250 put_tag(pb, "esds");
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
251 put_be32(pb, 0); // Version
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
252
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
253 // ES descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
254 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
255 descrLength(1));
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
256 put_be16(pb, track->trackID);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
257 put_byte(pb, 0x00); // flags (= no flags)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
258
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
259 // DecoderConfig descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
260 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
261
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
262 // Object type indication
1948
80d330650d35 cosmectics, mov -> mp4
bcoudurier
parents: 1937
diff changeset
263 put_byte(pb, codec_get_tag(ff_mp4_obj_type, track->enc->codec_id));
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
264
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
265 // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
266 // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
267 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
268 put_byte(pb, 0x15); // flags (= Audiostream)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
269 else
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
270 put_byte(pb, 0x11); // flags (= Visualstream)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
271
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
272 put_byte(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
273 put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
274
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
275 put_be32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
276 if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
277 put_be32(pb, 0); // vbr
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
278 else
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
279 put_be32(pb, track->enc->rc_max_rate); // avg bitrate
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
280
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
281 if (track->vosLen)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
282 {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
283 // DecoderSpecific info descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
284 putDescr(pb, 0x05, track->vosLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
285 put_buffer(pb, track->vosData, track->vosLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
286 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
287
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
288
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
289 // SL descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
290 putDescr(pb, 0x06, 1);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
291 put_byte(pb, 0x02);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
292 return updateSize (pb, pos);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
293 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
294
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
295 static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
296 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
297 offset_t pos = url_ftell(pb);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
298
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
299 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
300 put_tag(pb, "wave");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
301
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
302 put_be32(pb, 12); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
303 put_tag(pb, "frma");
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
304 put_le32(pb, track->tag);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
305
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
306 if (track->enc->codec_id == CODEC_ID_AAC) {
1125
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
307 /* useless atom needed by mplayer, ipod, not needed by quicktime */
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
308 put_be32(pb, 12); /* size */
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
309 put_tag(pb, "mp4a");
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
310 put_be32(pb, 0);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
311 mov_write_esds_tag(pb, track);
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
312 } else if (track->enc->codec_id == CODEC_ID_PCM_S24LE ||
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
313 track->enc->codec_id == CODEC_ID_PCM_S32LE) {
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
314 mov_write_enda_tag(pb);
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
315 } else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
316 mov_write_amr_tag(pb, track);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
317 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
318
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
319 put_be32(pb, 8); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
320 put_be32(pb, 0); /* null tag */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
321
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
322 return updateSize (pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
323 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
324
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
325 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
326 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
327 offset_t pos = url_ftell(pb);
1438
76ae91843087 simplify
bcoudurier
parents: 1437
diff changeset
328 int version = track->mode == MODE_MOV &&
76ae91843087 simplify
bcoudurier
parents: 1437
diff changeset
329 (track->audio_vbr ||
76ae91843087 simplify
bcoudurier
parents: 1437
diff changeset
330 track->enc->codec_id == CODEC_ID_PCM_S32LE ||
76ae91843087 simplify
bcoudurier
parents: 1437
diff changeset
331 track->enc->codec_id == CODEC_ID_PCM_S24LE);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
332
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
333 put_be32(pb, 0); /* size */
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
334 put_le32(pb, track->tag); // store it byteswapped
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
335 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
336 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
337 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
338
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
339 /* SoundDescription */
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
340 put_be16(pb, version); /* Version */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
341 put_be16(pb, 0); /* Revision level */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
342 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
343
1849
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
344 if (track->mode == MODE_MOV) {
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
345 put_be16(pb, track->enc->channels);
1850
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
346 if (track->enc->codec_id == CODEC_ID_PCM_U8 ||
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
347 track->enc->codec_id == CODEC_ID_PCM_S8)
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
348 put_be16(pb, 8); /* bits per sample */
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
349 else
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
350 put_be16(pb, 16);
1849
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
351 put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
352 } else { /* reserved for mp4/3gp */
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
353 put_be16(pb, 2);
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
354 put_be16(pb, 16);
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
355 put_be16(pb, 0);
acd6287f79e1 deobfuscate, clearly split mov case
bcoudurier
parents: 1843
diff changeset
356 }
505
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
357
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
358 put_be16(pb, 0); /* packet size (= 0) */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
359 put_be16(pb, track->timescale); /* Time scale */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
360 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
361
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
362 if(version == 1) { /* SoundDescription V1 extended info */
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
363 put_be32(pb, track->enc->frame_size); /* Samples per packet */
1150
c8edab114cc3 vbr requires version=1 and samplesize=0 per QT spec
michael
parents: 1147
diff changeset
364 put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
365 put_be32(pb, track->sampleSize); /* Bytes per frame */
1125
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
366 put_be32(pb, 2); /* Bytes per sample */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
367 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
368
1084
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
369 if(track->mode == MODE_MOV &&
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
370 (track->enc->codec_id == CODEC_ID_AAC ||
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
371 track->enc->codec_id == CODEC_ID_AMR_NB ||
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
372 track->enc->codec_id == CODEC_ID_PCM_S24LE ||
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
373 track->enc->codec_id == CODEC_ID_PCM_S32LE))
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
374 mov_write_wave_tag(pb, track);
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
375 else if(track->enc->codec_id == CODEC_ID_AAC)
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
376 mov_write_esds_tag(pb, track);
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
377 else if(track->enc->codec_id == CODEC_ID_AMR_NB)
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
378 mov_write_amr_tag(pb, track);
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
379
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
380 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
381 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
382
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
383 static int mov_write_d263_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
384 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
385 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
386 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
387 put_tag(pb, "FFMP");
1240
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
388 put_byte(pb, 0); /* decoder version */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
389 /* FIXME use AVCodecContext level/profile, when encoder will set values */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
390 put_byte(pb, 0xa); /* level */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
391 put_byte(pb, 0); /* profile */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
392 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
393 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
394
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
395 /* TODO: No idea about these values */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
396 static int mov_write_svq3_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
397 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
398 put_be32(pb, 0x15);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
399 put_tag(pb, "SMI ");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
400 put_tag(pb, "SEQH");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
401 put_be32(pb, 0x5);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
402 put_be32(pb, 0xe2c0211d);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
403 put_be32(pb, 0xc0000000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
404 put_byte(pb, 0);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
405 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
406 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
407
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
408 static uint8_t *avc_find_startcode( uint8_t *p, uint8_t *end )
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
409 {
2233
886efa933499 kill harmless 64-bit pointer cast warning
mru
parents: 2165
diff changeset
410 uint8_t *a = p + 4 - ((long)p & 3);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
411
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
412 for( end -= 3; p < a && p < end; p++ ) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
413 if( p[0] == 0 && p[1] == 0 && p[2] == 1 )
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
414 return p;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
415 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
416
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
417 for( end -= 3; p < end; p += 4 ) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
418 uint32_t x = *(uint32_t*)p;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
419 // if( (x - 0x01000100) & (~x) & 0x80008000 ) // little endian
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
420 // if( (x - 0x00010001) & (~x) & 0x00800080 ) // big endian
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
421 if( (x - 0x01010101) & (~x) & 0x80808080 ) { // generic
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
422 if( p[1] == 0 ) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
423 if( p[0] == 0 && p[2] == 1 )
1088
e7fd91082489 fix avc nal parsing
bcoudurier
parents: 1085
diff changeset
424 return p-1;
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
425 if( p[2] == 0 && p[3] == 1 )
1088
e7fd91082489 fix avc nal parsing
bcoudurier
parents: 1085
diff changeset
426 return p;
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
427 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
428 if( p[3] == 0 ) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
429 if( p[2] == 0 && p[4] == 1 )
1088
e7fd91082489 fix avc nal parsing
bcoudurier
parents: 1085
diff changeset
430 return p+1;
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
431 if( p[4] == 0 && p[5] == 1 )
1088
e7fd91082489 fix avc nal parsing
bcoudurier
parents: 1085
diff changeset
432 return p+2;
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
433 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
434 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
435 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
436
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
437 for( end += 3; p < end; p++ ) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
438 if( p[0] == 0 && p[1] == 0 && p[2] == 1 )
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
439 return p;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
440 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
441
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
442 return end + 3;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
443 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
444
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
445 static void avc_parse_nal_units(uint8_t **buf, int *size)
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
446 {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
447 ByteIOContext pb;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
448 uint8_t *p = *buf;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
449 uint8_t *end = p + *size;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
450 uint8_t *nal_start, *nal_end;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
451
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
452 url_open_dyn_buf(&pb);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
453 nal_start = avc_find_startcode(p, end);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
454 while (nal_start < end) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
455 while(!*(nal_start++));
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
456 nal_end = avc_find_startcode(nal_start, end);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
457 put_be32(&pb, nal_end - nal_start);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
458 put_buffer(&pb, nal_start, nal_end - nal_start);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
459 nal_start = nal_end;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
460 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
461 av_freep(buf);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
462 *size = url_close_dyn_buf(&pb, buf);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
463 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
464
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
465 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track)
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
466 {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
467 offset_t pos = url_ftell(pb);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
468
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
469 put_be32(pb, 0);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
470 put_tag(pb, "avcC");
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
471 if (track->vosLen > 6) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
472 /* check for h264 start code */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1565
diff changeset
473 if (AV_RB32(track->vosData) == 0x00000001) {
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
474 uint8_t *buf, *end;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
475 uint32_t sps_size=0, pps_size=0;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
476 uint8_t *sps=0, *pps=0;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
477
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
478 avc_parse_nal_units(&track->vosData, &track->vosLen);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
479 buf = track->vosData;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
480 end = track->vosData + track->vosLen;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
481
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
482 /* look for sps and pps */
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
483 while (buf < end) {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
484 unsigned int size;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
485 uint8_t nal_type;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1565
diff changeset
486 size = AV_RB32(buf);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
487 nal_type = buf[4] & 0x1f;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
488 if (nal_type == 7) { /* SPS */
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
489 sps = buf + 4;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
490 sps_size = size;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
491 } else if (nal_type == 8) { /* PPS */
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
492 pps = buf + 4;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
493 pps_size = size;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
494 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
495 buf += size + 4;
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
496 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
497 assert(sps);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
498 assert(pps);
1056
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
499
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
500 put_byte(pb, 1); /* version */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
501 put_byte(pb, sps[1]); /* profile */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
502 put_byte(pb, sps[2]); /* profile compat */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
503 put_byte(pb, sps[3]); /* level */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
504 put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
505 put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */
4af4c74a4548 get avcC profile and level indication from sps (from handbrake)
bcoudurier
parents: 1055
diff changeset
506
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
507 put_be16(pb, sps_size);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
508 put_buffer(pb, sps, sps_size);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
509 put_byte(pb, 1); /* number of pps */
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
510 put_be16(pb, pps_size);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
511 put_buffer(pb, pps, pps_size);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
512 } else {
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
513 put_buffer(pb, track->vosData, track->vosLen);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
514 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
515 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
516 return updateSize(pb, pos);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
517 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
518
2588
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
519 /* also used by all avid codecs (dv, imx, meridien) and their variants */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
520 static int mov_write_avid_tag(ByteIOContext *pb, MOVTrack *track)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
521 {
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
522 int i;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
523 put_be32(pb, 24); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
524 put_tag(pb, "ACLR");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
525 put_tag(pb, "ACLR");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
526 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
527 put_be32(pb, 1); /* yuv 1 / rgb 2 ? */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
528 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
529
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
530 put_be32(pb, 24); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
531 put_tag(pb, "APRG");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
532 put_tag(pb, "APRG");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
533 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
534 put_be32(pb, 1); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
535 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
536
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
537 put_be32(pb, 120); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
538 put_tag(pb, "ARES");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
539 put_tag(pb, "ARES");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
540 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
541 put_be32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
542 put_be32(pb, track->enc->width);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
543 /* values below are based on samples created with quicktime and avid codecs */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
544 if (track->vosData[5] & 2) { // interlaced
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
545 put_be32(pb, track->enc->height/2);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
546 put_be32(pb, 2); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
547 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
548 put_be32(pb, 4); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
549 } else {
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
550 put_be32(pb, track->enc->height);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
551 put_be32(pb, 1); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
552 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
553 put_be32(pb, 5); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
554 }
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
555 /* padding */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
556 for (i = 0; i < 10; i++)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
557 put_be64(pb, 0);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
558
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
559 /* extra padding for stsd needed */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
560 put_be32(pb, 0);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
561 return 0;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
562 }
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
563
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
564 static int mov_find_video_codec_tag(AVFormatContext *s, MOVTrack *track)
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
565 {
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
566 int tag = track->enc->codec_tag;
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
567 if (!tag) {
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
568 if (track->enc->codec_id == CODEC_ID_DVVIDEO) {
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
569 if (track->enc->height == 480) { /* NTSC */
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
570 if (track->enc->pix_fmt == PIX_FMT_YUV422P)
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
571 tag = MKTAG('d', 'v', '5', 'n');
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
572 else
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
573 tag = MKTAG('d', 'v', 'c', ' ');
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
574 } else { /* assume PAL */
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
575 if (track->enc->pix_fmt == PIX_FMT_YUV422P)
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
576 tag = MKTAG('d', 'v', '5', 'p');
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
577 else if (track->enc->pix_fmt == PIX_FMT_YUV420P)
1026
3cf3b7a81b26 dvcpro is 411p in fact
bcoudurier
parents: 1007
diff changeset
578 tag = MKTAG('d', 'v', 'c', 'p');
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
579 else
1026
3cf3b7a81b26 dvcpro is 411p in fact
bcoudurier
parents: 1007
diff changeset
580 tag = MKTAG('d', 'v', 'p', 'p');
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
581 }
1241
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
582 } else if (track->enc->codec_id == CODEC_ID_H263) {
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
583 if (track->mode == MODE_MOV)
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
584 tag = MKTAG('h', '2', '6', '3');
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
585 else
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
586 tag = MKTAG('s', '2', '6', '3');
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
587 } else {
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
588 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
589 }
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
590 }
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
591 // if no mac fcc found, try with Microsoft tags
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
592 if (!tag) {
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
593 tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
594 if (tag) {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
595 av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n");
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
596 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
597 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
598 assert(tag);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
599 return tag;
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
600 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
601
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
602 static int mov_find_audio_codec_tag(AVFormatContext *s, MOVTrack *track)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
603 {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
604 int tag = track->enc->codec_tag;
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
605 if (!tag) {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
606 tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
607 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
608 // if no mac fcc found, try with Microsoft tags
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
609 if (!tag) {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
610 int ms_tag = codec_get_tag(codec_wav_tags, track->enc->codec_id);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
611 if (ms_tag) {
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
612 tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
613 av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n");
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
614 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
615 }
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
616 assert(tag);
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
617 return tag;
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
618 }
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
619
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
620 static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
621 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
622 offset_t pos = url_ftell(pb);
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
623 char compressor_name[32];
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
624
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
625 put_be32(pb, 0); /* size */
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
626 put_le32(pb, track->tag); // store it byteswapped
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
627 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
628 put_be16(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
629 put_be16(pb, 1); /* Data-reference index */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
630
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
631 put_be16(pb, 0); /* Codec stream version */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
632 put_be16(pb, 0); /* Codec stream revision (=0) */
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
633 if (track->mode == MODE_MOV) {
1239
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
634 put_tag(pb, "FFMP"); /* Vendor */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
635 if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
636 put_be32(pb, 0); /* Temporal Quality */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
637 put_be32(pb, 0x400); /* Spatial Quality = lossless*/
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
638 } else {
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
639 put_be32(pb, 0x200); /* Temporal Quality = normal */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
640 put_be32(pb, 0x200); /* Spatial Quality = normal */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
641 }
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
642 } else {
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
643 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
644 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
645 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
646 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
647 put_be16(pb, track->enc->width); /* Video width */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
648 put_be16(pb, track->enc->height); /* Video height */
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
649 put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
650 put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
651 put_be32(pb, 0); /* Data size (= 0) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
652 put_be16(pb, 1); /* Frame count (= 1) */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
653
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
654 memset(compressor_name,0,32);
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
655 /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
656 if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name)
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
657 strncpy(compressor_name,track->enc->codec->name,31);
664
76d0af843707 don't crash on null codec; by matthieu castet <castet DOT matthieu AT free DOT fr>
mmu_man
parents: 663
diff changeset
658 put_byte(pb, strlen(compressor_name));
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
659 put_buffer(pb, compressor_name, 31);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
660
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
661 put_be16(pb, 0x18); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
662 put_be16(pb, 0xffff); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
663 if(track->enc->codec_id == CODEC_ID_MPEG4)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
664 mov_write_esds_tag(pb, track);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
665 else if(track->enc->codec_id == CODEC_ID_H263)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
666 mov_write_d263_tag(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
667 else if(track->enc->codec_id == CODEC_ID_SVQ3)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
668 mov_write_svq3_tag(pb);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
669 else if(track->enc->codec_id == CODEC_ID_H264)
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
670 mov_write_avcc_tag(pb, track);
2588
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
671 else if(track->enc->codec_id == CODEC_ID_DNXHD)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
672 mov_write_avid_tag(pb, track);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
673
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
674 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
675 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
676
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
677 static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
678 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
679 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
680 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
681 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
682 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
683 put_be32(pb, 1); /* entry count */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
684 if (track->enc->codec_type == CODEC_TYPE_VIDEO)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
685 mov_write_video_tag(pb, track);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
686 else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
687 mov_write_audio_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
688 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
689 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
690
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
691 static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack* track)
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
692 {
2045
aa5e56700fdf cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents: 1948
diff changeset
693 MOV_stts_t *ctts_entries;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
694 uint32_t entries = 0;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
695 uint32_t atom_size;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
696 int i;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
697
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
698 ctts_entries = av_malloc((track->entry + 1) * sizeof(*ctts_entries)); /* worst case */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
699 ctts_entries[0].count = 1;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
700 ctts_entries[0].duration = track->cluster[0].cts;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
701 for (i=1; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
702 if (track->cluster[i].cts == ctts_entries[entries].duration) {
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
703 ctts_entries[entries].count++; /* compress */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
704 } else {
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
705 entries++;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
706 ctts_entries[entries].duration = track->cluster[i].cts;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
707 ctts_entries[entries].count = 1;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
708 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
709 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
710 entries++; /* last one */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
711 atom_size = 16 + (entries * 8);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
712 put_be32(pb, atom_size); /* size */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
713 put_tag(pb, "ctts");
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
714 put_be32(pb, 0); /* version & flags */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
715 put_be32(pb, entries); /* entry count */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
716 for (i=0; i<entries; i++) {
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
717 put_be32(pb, ctts_entries[i].count);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
718 put_be32(pb, ctts_entries[i].duration);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
719 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
720 av_free(ctts_entries);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
721 return atom_size;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
722 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
723
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
724 /* Time to sample atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
725 static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
726 {
2045
aa5e56700fdf cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents: 1948
diff changeset
727 MOV_stts_t *stts_entries;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
728 uint32_t entries = -1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
729 uint32_t atom_size;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
730 int i;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
731
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
732 if (track->enc->codec_type == CODEC_TYPE_AUDIO && !track->audio_vbr) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
733 stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
734 stts_entries[0].count = track->sampleCount;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
735 stts_entries[0].duration = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
736 entries = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
737 } else {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
738 stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
739 for (i=0; i<track->entry; i++) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
740 int64_t duration = i + 1 == track->entry ?
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
741 track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
742 track->cluster[i+1].dts - track->cluster[i].dts;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
743 if (i && duration == stts_entries[entries].duration) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
744 stts_entries[entries].count++; /* compress */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
745 } else {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
746 entries++;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
747 stts_entries[entries].duration = duration;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
748 stts_entries[entries].count = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
749 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
750 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
751 entries++; /* last one */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
752 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
753 atom_size = 16 + (entries * 8);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
754 put_be32(pb, atom_size); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
755 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
756 put_be32(pb, 0); /* version & flags */
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
757 put_be32(pb, entries); /* entry count */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
758 for (i=0; i<entries; i++) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
759 put_be32(pb, stts_entries[i].count);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
760 put_be32(pb, stts_entries[i].duration);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
761 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
762 av_free(stts_entries);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
763 return atom_size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
764 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
765
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
766 static int mov_write_dref_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
767 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
768 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
769 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
770 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
771 put_be32(pb, 1); /* entry count */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
772
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
773 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
774 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
775 put_be32(pb, 1); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
776
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
777 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
778 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
779
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
780 static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
781 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
782 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
783 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
784 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
785 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
786 mov_write_stts_tag(pb, track);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
787 if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
1054
b38a08b0cd12 dont write stss atom if keyframes only
bcoudurier
parents: 1053
diff changeset
788 track->hasKeyframes < track->entry)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
789 mov_write_stss_tag(pb, track);
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
790 if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
791 track->hasBframes)
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
792 mov_write_ctts_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
793 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
794 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
795 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
796 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
797 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
798
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
799 static int mov_write_dinf_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
800 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
801 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
802 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
803 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
804 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
805 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
806 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
807
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
808 static int mov_write_smhd_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
809 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
810 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
811 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
812 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
813 put_be16(pb, 0); /* reserved (balance, normally = 0) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
814 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
815 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
816 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
817
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
818 static int mov_write_vmhd_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
819 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
820 put_be32(pb, 0x14); /* size (always 0x14) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
821 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
822 put_be32(pb, 0x01); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
823 put_be64(pb, 0); /* reserved (graphics mode = copy) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
824 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
825 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
826
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
827 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
828 {
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1112
diff changeset
829 const char *descr, *hdlr, *hdlr_type;
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
830 offset_t pos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
831
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
832 if (!track) { /* no media --> data handler */
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
833 hdlr = "dhlr";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
834 hdlr_type = "url ";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
835 descr = "DataHandler";
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
836 } else {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
837 hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
838 if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
839 hdlr_type = "vide";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
840 descr = "VideoHandler";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
841 } else {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
842 hdlr_type = "soun";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
843 descr = "SoundHandler";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
844 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
845 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
846
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
847 put_be32(pb, 0); /* size */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
848 put_tag(pb, "hdlr");
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
849 put_be32(pb, 0); /* Version & flags */
400
62e4ea840c52 * fixing 10l in movenc.c + updating regression patterns.
romansh
parents: 399
diff changeset
850 put_buffer(pb, hdlr, 4); /* handler */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
851 put_tag(pb, hdlr_type); /* handler type */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
852 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
853 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
854 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
855 put_byte(pb, strlen(descr)); /* string counter */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
856 put_buffer(pb, descr, strlen(descr)); /* handler description */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
857 return updateSize(pb, pos);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
858 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
859
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
860 static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
861 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
862 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
863 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
864 put_tag(pb, "minf");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
865 if(track->enc->codec_type == CODEC_TYPE_VIDEO)
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
866 mov_write_vmhd_tag(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
867 else
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
868 mov_write_smhd_tag(pb);
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
869 if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
870 mov_write_hdlr_tag(pb, NULL);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
871 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
872 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
873 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
874 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
875
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
876 static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
877 {
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
878 int version = track->trackDuration < INT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
879
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
880 (version == 1) ? put_be32(pb, 44) : put_be32(pb, 32); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
881 put_tag(pb, "mdhd");
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
882 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
883 put_be24(pb, 0); /* flags */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
884 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
885 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
886 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
887 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
888 put_be32(pb, track->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
889 put_be32(pb, track->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
890 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
891 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
892 (version == 1) ? put_be64(pb, track->trackDuration) : put_be32(pb, track->trackDuration); /* duration */
890
1e49bfea0ffb finally found what those >138 codes were... crappy compressed 5bit ascii. this gets them correctly, and adds setting track lang in movenc too.
mmu_man
parents: 887
diff changeset
893 put_be16(pb, track->language); /* language */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
894 put_be16(pb, 0); /* reserved (quality) */
2102
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
895
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
896 if(version!=0 && track->mode == MODE_MOV){
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
897 av_log(NULL, AV_LOG_ERROR,
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
898 "FATAL error, file duration too long for timebase, this file will not be\n"
2106
aurel
parents: 2102
diff changeset
899 "playable with quicktime. Choose a different timebase or a different\n"
2102
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
900 "container format\n");
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
901 }
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
902
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
903 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
904 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
905
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
906 static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
907 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
908 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
909 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
910 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
911 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
912 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
913 mov_write_minf_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
914 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
915 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
916
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
917 static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
918 {
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
919 int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
920 int version = duration < INT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
921
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
922 (version == 1) ? put_be32(pb, 104) : put_be32(pb, 92); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
923 put_tag(pb, "tkhd");
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
924 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
925 put_be24(pb, 0xf); /* flags (track enabled) */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
926 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
927 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
928 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
929 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
930 put_be32(pb, track->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
931 put_be32(pb, track->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
932 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
933 put_be32(pb, track->trackID); /* track-id */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
934 put_be32(pb, 0); /* reserved */
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
935 (version == 1) ? put_be64(pb, duration) : put_be32(pb, duration);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
936
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
937 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
938 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
939 put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
940 /* Volume, only for audio */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
941 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
942 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
943 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
944 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
945 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
946
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
947 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
948 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
949 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
950 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
951 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
952 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
953 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
954 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
955 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
956 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
957
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
958 /* Track width and height, for visual only */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
959 if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
960 double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
961 if( !sample_aspect_ratio ) sample_aspect_ratio = 1;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
962 put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
963 put_be32(pb, track->enc->height*0x10000);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
964 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
965 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
966 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
967 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
968 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
969 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
970 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
971
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
972 // This box seems important for the psp playback ... without it the movie seems to hang
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
973 static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
974 {
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
975 put_be32(pb, 0x24); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
976 put_tag(pb, "edts");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
977 put_be32(pb, 0x1c); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
978 put_tag(pb, "elst");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
979 put_be32(pb, 0x0);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
980 put_be32(pb, 0x1);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
981
761
805598adf3e9 round duration up in mov
michael
parents: 743
diff changeset
982 put_be32(pb, av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP)); /* duration ... doesn't seem to effect psp */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
983
1250
0492aa3dffc9 set elst start time to first pts
bcoudurier
parents: 1241
diff changeset
984 put_be32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
985 put_be32(pb, 0x00010000);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
986 return 0x24;
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
987 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
988
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
989 // goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
990 static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
991 {
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
992 put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
993 put_tag(pb, "uuid");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
994 put_tag(pb, "USMT");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
995 put_be32(pb, 0x21d24fce);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
996 put_be32(pb, 0xbb88695c);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
997 put_be32(pb, 0xfac9c740);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
998 put_be32(pb, 0x1c); // another size here!
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
999 put_tag(pb, "MTDT");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1000 put_be32(pb, 0x00010012);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1001 put_be32(pb, 0x0a);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1002 put_be32(pb, 0x55c40000);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1003 put_be32(pb, 0x1);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1004 put_be32(pb, 0x0);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1005 return 0x34;
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1006 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1007
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1008 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1009 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1010 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1011 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1012 put_tag(pb, "trak");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1013 mov_write_tkhd_tag(pb, track);
1007
5fe94e61fdaa create edts atom when muxing B frames, needed to compute cts
bcoudurier
parents: 1006
diff changeset
1014 if (track->mode == MODE_PSP || track->hasBframes)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1015 mov_write_edts_tag(pb, track); // PSP Movies require edts box
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1016 mov_write_mdia_tag(pb, track);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1017 if (track->mode == MODE_PSP)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1018 mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1019 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1020 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1021
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 677
diff changeset
1022 #if 0
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1023 /* TODO: Not sorted out, but not necessary either */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1024 static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1025 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1026 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1027 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1028 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1029 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1030 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1031 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1032 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1033 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1034 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1035 }
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 677
diff changeset
1036 #endif
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1037
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1038 static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1039 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1040 int maxTrackID = 1, i;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1041 int64_t maxTrackLenTemp, maxTrackLen = 0;
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1042 int version;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1043
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1044 for (i=0; i<mov->nb_streams; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1045 if(mov->tracks[i].entry > 0) {
761
805598adf3e9 round duration up in mov
michael
parents: 743
diff changeset
1046 maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration, globalTimescale, mov->tracks[i].timescale, AV_ROUND_UP);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1047 if(maxTrackLen < maxTrackLenTemp)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1048 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1049 if(maxTrackID < mov->tracks[i].trackID)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1050 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1051 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1052 }
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1053
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1054 version = maxTrackLen < UINT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1055 (version == 1) ? put_be32(pb, 120) : put_be32(pb, 108); /* size */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1056 put_tag(pb, "mvhd");
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1057 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1058 put_be24(pb, 0); /* flags */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1059 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1060 put_be64(pb, mov->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1061 put_be64(pb, mov->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1062 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1063 put_be32(pb, mov->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1064 put_be32(pb, mov->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1065 }
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1066 put_be32(pb, mov->timescale); /* timescale */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1067 (version == 1) ? put_be64(pb, maxTrackLen) : put_be32(pb, maxTrackLen); /* duration of longest track */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1068
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1069 put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1070 put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1071 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1072 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1073 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1074
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1075 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1076 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1077 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1078 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1079 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1080 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1081 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1082 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1083 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1084 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1085
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1086 put_be32(pb, 0); /* reserved (preview time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1087 put_be32(pb, 0); /* reserved (preview duration) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1088 put_be32(pb, 0); /* reserved (poster time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1089 put_be32(pb, 0); /* reserved (selection time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1090 put_be32(pb, 0); /* reserved (selection duration) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1091 put_be32(pb, 0); /* reserved (current time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1092 put_be32(pb, maxTrackID+1); /* Next track id */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1093 return 0x6c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1094 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1095
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1096 static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1097 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1098 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1099 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1100 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1101 put_tag(pb, "hdlr");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1102 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1103 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1104 put_tag(pb, "mdir");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1105 put_tag(pb, "appl");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1106 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1107 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1108 put_be16(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1109 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1110 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1111
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1112 /* helper function to write a data tag with the specified string as data */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1113 static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int long_style)
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1114 {
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1115 if(long_style){
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1116 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1117 put_be32(pb, 0); /* size */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1118 put_tag(pb, "data");
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1119 put_be32(pb, 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1120 put_be32(pb, 0);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1121 put_buffer(pb, data, strlen(data));
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1122 return updateSize(pb, pos);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1123 }else{
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1124 put_be16(pb, strlen(data)); /* string length */
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1125 put_be16(pb, 0);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1126 put_buffer(pb, data, strlen(data));
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1127 return strlen(data) + 4;
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1128 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1129 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1130
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1112
diff changeset
1131 static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int long_style){
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1132 int size = 0;
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1133 if ( value && value[0] ) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1134 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1135 put_be32(pb, 0); /* size */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1136 put_tag(pb, name);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1137 mov_write_string_data_tag(pb, value, long_style);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1138 size= updateSize(pb, pos);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1139 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1140 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1141 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1142
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1143 /* iTunes year */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1144 static int mov_write_day_tag(ByteIOContext *pb, int year, int long_style)
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1145 {
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1146 if(year){
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1147 char year_str[5];
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1148 snprintf(year_str, sizeof(year_str), "%04d", year);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1149 return mov_write_string_tag(pb, "\251day", year_str, long_style);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1150 }else
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1151 return 0;
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1152 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1153
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1154 /* iTunes track number */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1155 static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1156 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1157 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1158 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1159 if ( s->track ) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1160 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1161 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1162 put_tag(pb, "trkn");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1163 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1164 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1165 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1166 put_tag(pb, "data");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1167 put_be32(pb, 0); // 8 bytes empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1168 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1169 put_be16(pb, 0); // empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1170 put_be16(pb, s->track); // track number
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1171 put_be16(pb, 0); // total track number
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1172 put_be16(pb, 0); // empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1173 updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1174 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1175 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1176 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1177 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1178 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1179
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1180 /* iTunes meta data list */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1181 static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1182 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1183 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1184 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1185 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1186 put_tag(pb, "ilst");
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1187 mov_write_string_tag(pb, "\251nam", s->title , 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1188 mov_write_string_tag(pb, "\251ART", s->author , 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1189 mov_write_string_tag(pb, "\251wrt", s->author , 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1190 mov_write_string_tag(pb, "\251alb", s->album , 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1191 mov_write_day_tag(pb, s->year ,1);
1095
bf797dc4828e dont write LAVF_ID if bitexact and any meta tag is set
michael
parents: 1094
diff changeset
1192 if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
bf797dc4828e dont write LAVF_ID if bitexact and any meta tag is set
michael
parents: 1094
diff changeset
1193 mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 1);
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1194 mov_write_string_tag(pb, "\251cmt", s->comment , 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1195 mov_write_string_tag(pb, "\251gen", s->genre , 1);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1196 mov_write_trkn_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1197 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1198 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1199
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1200 /* iTunes meta data tag */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1201 static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1202 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1203 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1204 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1205
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1206 // only save meta tag if required
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1207 if ( s->title[0] || s->author[0] || s->album[0] || s->year ||
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1208 s->comment[0] || s->genre[0] || s->track ) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1209 offset_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1210 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1211 put_tag(pb, "meta");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1212 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1213 mov_write_itunes_hdlr_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1214 mov_write_ilst_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1215 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1216 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1217 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1218 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1219
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1220 static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1221 AVFormatContext *s)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1222 {
2668
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1223 int i, req = 0;
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1224
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1225 /* Requirements */
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1226 for (i=0; i<mov->nb_streams; i++) {
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1227 if(mov->tracks[i].entry <= 0) continue;
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1228 if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1229 mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1230 req = 1;
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1231 break;
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1232 }
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1233 }
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1234
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1235 if (s->title[0] || s->author[0] || s->album[0] || s->year ||
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1236 s->comment[0] || s->genre[0] || s->track ||
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1237 (mov->mode == MODE_MOV &&
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1238 ((mov->tracks[0].enc && !mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT) || req))) {
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1239 offset_t pos = url_ftell(pb);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1240
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1241 put_be32(pb, 0); /* size */
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1242 put_tag(pb, "udta");
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1243
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1244 /* iTunes meta data */
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1245 mov_write_meta_tag(pb, mov, s);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1246
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1247 if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1248 /* Requirements */
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1249 if (req)
2616
ccb37555090a indentation
bcoudurier
parents: 2588
diff changeset
1250 mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0);
ccb37555090a indentation
bcoudurier
parents: 2588
diff changeset
1251
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1252 mov_write_string_tag(pb, "\251nam", s->title , 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1253 mov_write_string_tag(pb, "\251aut", s->author , 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1254 mov_write_string_tag(pb, "\251alb", s->album , 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1255 mov_write_day_tag(pb, s->year, 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1256 if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1257 mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1258 mov_write_string_tag(pb, "\251des", s->comment , 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1259 mov_write_string_tag(pb, "\251gen", s->genre , 0);
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1260 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1261
2669
09eb62fa2a0e Cosmetics: indentation.
benoit
parents: 2668
diff changeset
1262 return updateSize(pb, pos);
2668
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1263 }
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1264
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1265 return 0;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1266 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1267
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1268 static int utf8len(uint8_t *b){
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1269 int len=0;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1270 int val;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1271 while(*b){
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1272 GET_UTF8(val, *b++, return -1;)
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1273 len++;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1274 }
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1275 return len;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1276 }
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1277
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1278 static int ascii_to_wc (ByteIOContext *pb, uint8_t *b)
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1279 {
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1280 int val;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1281 while(*b){
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1282 GET_UTF8(val, *b++, return -1;)
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1283 put_be16(pb, val);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1284 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1285 put_be16(pb, 0x00);
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1286 return 0;
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1287 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1288
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1112
diff changeset
1289 static uint16_t language_code (const char *str)
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1290 {
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1291 return ((((str[0]-0x60) & 0x1F)<<10) + (((str[1]-0x60) & 0x1F)<<5) + ((str[2]-0x60) & 0x1F));
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1292 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1293
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1294 static int mov_write_uuidusmt_tag (ByteIOContext *pb, AVFormatContext *s)
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1295 {
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1296 size_t len, size;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1297 offset_t pos, curpos;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1298
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1299 size = 0;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1300 if (s->title[0]) {
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1301 pos = url_ftell(pb);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1302 put_be32(pb, 0); /* size placeholder*/
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1303 put_tag(pb, "uuid");
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1304 put_tag(pb, "USMT");
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1305 put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1306 put_be32(pb, 0xbb88695c );
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1307 put_be32(pb, 0xfac9c740 );
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1308 size += 24;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1309
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1310 put_be32(pb, 0); /* size placeholder*/
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1311 put_tag(pb, "MTDT");
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1312 put_be16(pb, 4);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1313 size += 10;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1314
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1315 // ?
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1316 put_be16(pb, 0x0C); /* size */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1317 put_be32(pb, 0x0B); /* type */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1318 put_be16(pb, language_code("und")); /* language */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1319 put_be16(pb, 0x0); /* ? */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1320 put_be16(pb, 0x021C); /* data */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1321 size += 12;
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1322
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1323 // Encoder
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1324 len = utf8len(LIBAVCODEC_IDENT)+1;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1325 if(len<=0)
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1326 goto not_utf8;
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1327 put_be16(pb, len*2+10); /* size */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1328 put_be32(pb, 0x04); /* type */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1329 put_be16(pb, language_code("eng")); /* language */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1330 put_be16(pb, 0x01); /* ? */
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1331 ascii_to_wc(pb, LIBAVCODEC_IDENT);
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1332 size += len*2+10;
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1333
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1334 // Title
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1335 len = utf8len(s->title)+1;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1336 if(len<=0)
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1337 goto not_utf8;
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1338 put_be16(pb, len*2+10); /* size */
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1339 put_be32(pb, 0x01); /* type */
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1340 put_be16(pb, language_code("eng")); /* language */
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1341 put_be16(pb, 0x01); /* ? */
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1342 ascii_to_wc (pb, s->title);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1343 size += len*2+10;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1344
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1345 // Date
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1346 // snprintf(dt,32,"%04d/%02d/%02d %02d:%02d:%02d",t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday,t_st->tm_hour,t_st->tm_min,t_st->tm_sec);
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1347 len = utf8len("2006/04/01 11:11:11")+1;
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1348 if(len<=0)
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1349 goto not_utf8;
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1350 put_be16(pb, len*2+10); /* size */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1351 put_be32(pb, 0x03); /* type */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1352 put_be16(pb, language_code("und")); /* language */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1353 put_be16(pb, 0x01); /* ? */
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1354 ascii_to_wc (pb, "2006/04/01 11:11:11");
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1355 size += len*2+10;
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1356
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1357 // size
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1358 curpos = url_ftell(pb);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1359 url_fseek(pb, pos, SEEK_SET);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1360 put_be32(pb, size);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1361 url_fseek(pb, pos+24, SEEK_SET);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1362 put_be32(pb, size-24);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1363 url_fseek(pb, curpos, SEEK_SET);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1364 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1365
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1366 return size;
1462
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1367 not_utf8:
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1368 av_log(s, AV_LOG_ERROR, "not utf8\n");
e5e2d80a859c utf8 title support for psp (untested)
michael
parents: 1441
diff changeset
1369 return -1;
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1370 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1371
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1372 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1373 AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1374 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1375 int i;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1376 offset_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1377 put_be32(pb, 0); /* size placeholder*/
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1378 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1379 mov->timescale = globalTimescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1380
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1381 for (i=0; i<mov->nb_streams; i++) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1382 if(mov->tracks[i].entry <= 0) continue;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1383
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1384 mov->tracks[i].time = mov->time;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1385 mov->tracks[i].trackID = i+1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1386 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1387
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1388 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1389 //mov_write_iods_tag(pb, mov);
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1390 for (i=0; i<mov->nb_streams; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1391 if(mov->tracks[i].entry > 0) {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1392 mov_write_trak_tag(pb, &(mov->tracks[i]));
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1393 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1394 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1395
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1396 if (mov->mode == MODE_PSP)
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1397 mov_write_uuidusmt_tag(pb, s);
2617
0b993d441969 dont write udta atom for 3gp/3g2 for now, current written atoms (ilst) are itunes specific
bcoudurier
parents: 2616
diff changeset
1398 else if (mov->mode != MODE_3GP && mov->mode != MODE_3G2)
1441
ad3b03b7b142 reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents: 1438
diff changeset
1399 mov_write_udta_tag(pb, mov, s);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1400
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1401 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1402 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1403
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 1123
diff changeset
1404 static int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1405 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1406 put_be32(pb, 8); // placeholder for extended size field (64 bit)
1273
07137c477f09 wide atom is only defined in mov, use free for mp4/3gp
bcoudurier
parents: 1250
diff changeset
1407 put_tag(pb, mov->mode == MODE_MOV ? "wide" : "free");
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1408
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1409 mov->mdat_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1410 put_be32(pb, 0); /* size placeholder*/
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1411 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1412 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1413 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1414
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1415 /* TODO: This needs to be more general */
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1416 static void mov_write_ftyp_tag (ByteIOContext *pb, AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1417 {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1418 MOVContext *mov = s->priv_data;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1419
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1420 put_be32(pb, 0x14 ); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1421 put_tag(pb, "ftyp");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1422
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1423 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1424 put_tag(pb, "3gp4");
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1425 else if ( mov->mode == MODE_3G2 )
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1426 put_tag(pb, "3g2a");
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1427 else if ( mov->mode == MODE_PSP )
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1428 put_tag(pb, "MSNV");
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1429 else if ( mov->mode == MODE_MP4 )
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1430 put_tag(pb, "isom");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1431 else
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1432 put_tag(pb, "qt ");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1433
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1434 put_be32(pb, 0x200 );
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1435
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1436 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1437 put_tag(pb, "3gp4");
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1438 else if ( mov->mode == MODE_3G2 )
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1439 put_tag(pb, "3g2a");
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1440 else if ( mov->mode == MODE_PSP )
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1441 put_tag(pb, "MSNV");
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1442 else if ( mov->mode == MODE_MP4 )
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1443 put_tag(pb, "mp41");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1444 else
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1445 put_tag(pb, "qt ");
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1446 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1447
665
47d5b20c9aba fix segfault by matthieu castet <castet DOT matthieu AT free DOT fr>
mmu_man
parents: 664
diff changeset
1448 static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1449 {
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1450 AVCodecContext *VideoCodec = s->streams[0]->codec;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1451 AVCodecContext *AudioCodec = s->streams[1]->codec;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1452 int AudioRate = AudioCodec->sample_rate;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1453 int FrameRate = ((VideoCodec->time_base.den) * (0x10000))/ (VideoCodec->time_base.num);
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1454 int audio_kbitrate= AudioCodec->bit_rate / 1000;
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1455 int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate);
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1456
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1457 put_be32(pb, 0x94 ); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1458 put_tag(pb, "uuid");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1459 put_tag(pb, "PROF");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1460
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1461 put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1462 put_be32(pb, 0xbb88695c );
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1463 put_be32(pb, 0xfac9c740 );
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1464
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1465 put_be32(pb, 0x0 ); /* ? */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1466 put_be32(pb, 0x3 ); /* 3 sections ? */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1467
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1468 put_be32(pb, 0x14 ); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1469 put_tag(pb, "FPRF");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1470 put_be32(pb, 0x0 ); /* ? */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1471 put_be32(pb, 0x0 ); /* ? */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1472 put_be32(pb, 0x0 ); /* ? */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1473
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1474 put_be32(pb, 0x2c ); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1475 put_tag(pb, "APRF"); /* audio */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1476 put_be32(pb, 0x0 );
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1477 put_be32(pb, 0x2 ); /* TrackID */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1478 put_tag(pb, "mp4a");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1479 put_be32(pb, 0x20f );
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1480 put_be32(pb, 0x0 );
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1481 put_be32(pb, audio_kbitrate);
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1482 put_be32(pb, audio_kbitrate);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1483 put_be32(pb, AudioRate );
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1484 put_be32(pb, AudioCodec->channels );
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1485
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1486 put_be32(pb, 0x34 ); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1487 put_tag(pb, "VPRF"); /* video */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1488 put_be32(pb, 0x0 );
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1489 put_be32(pb, 0x1 ); /* TrackID */
1050
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1490 if (VideoCodec->codec_id == CODEC_ID_H264) {
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1491 put_tag(pb, "avc1");
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1492 put_be16(pb, 0x014D );
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1493 put_be16(pb, 0x0015 );
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1494 } else {
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1495 put_tag(pb, "mp4v");
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1496 put_be16(pb, 0x0000 );
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1497 put_be16(pb, 0x0103 );
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1498 }
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1499 put_be32(pb, 0x0 );
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1500 put_be32(pb, video_kbitrate);
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1501 put_be32(pb, video_kbitrate);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1502 put_be32(pb, FrameRate);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1503 put_be32(pb, FrameRate);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1504 put_be16(pb, VideoCodec->width);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1505 put_be16(pb, VideoCodec->height);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1506 put_be32(pb, 0x010001); /* ? */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1507 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1508
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1509 static int mov_write_header(AVFormatContext *s)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1510 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1511 ByteIOContext *pb = &s->pb;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1512 MOVContext *mov = s->priv_data;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1513 int i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1514
2091
659c9e8f558c print and return error if output is non seekable
bcoudurier
parents: 2045
diff changeset
1515 if (url_is_streamed(&s->pb)) {
659c9e8f558c print and return error if output is non seekable
bcoudurier
parents: 2045
diff changeset
1516 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
659c9e8f558c print and return error if output is non seekable
bcoudurier
parents: 2045
diff changeset
1517 return -1;
659c9e8f558c print and return error if output is non seekable
bcoudurier
parents: 2045
diff changeset
1518 }
659c9e8f558c print and return error if output is non seekable
bcoudurier
parents: 2045
diff changeset
1519
987
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1520 /* Default mode == MP4 */
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1521 mov->mode = MODE_MP4;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1522
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1523 if (s->oformat != NULL) {
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1524 if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1525 else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3G2;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1526 else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1527 else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1528
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1529 mov_write_ftyp_tag(pb,s);
987
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1530 if ( mov->mode == MODE_PSP ) {
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1531 if ( s->nb_streams != 2 ) {
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1532 av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1533 return -1;
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1534 }
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1535 mov_write_uuidprof_tag(pb,s);
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1536 }
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1537 }
955d23ed733f compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 971
diff changeset
1538
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1539 for(i=0; i<s->nb_streams; i++){
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1540 AVStream *st= s->streams[i];
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1541 MOVTrack *track= &mov->tracks[i];
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1542
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1543 track->enc = st->codec;
1241
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
1544 track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV);
11fbe0326131 use correct tag for h263 in mov
bcoudurier
parents: 1240
diff changeset
1545 track->mode = mov->mode;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1546 if(st->codec->codec_type == CODEC_TYPE_VIDEO){
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1547 track->tag = mov_find_video_codec_tag(s, track);
1292
6042770198c6 move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents: 1273
diff changeset
1548 track->timescale = st->codec->time_base.den;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1549 av_set_pts_info(st, 64, 1, st->codec->time_base.den);
2149
d5e89ef58c3b warn user if video codec timebase is very high
bcoudurier
parents: 2106
diff changeset
1550 if (track->timescale > 100000)
d5e89ef58c3b warn user if video codec timebase is very high
bcoudurier
parents: 2106
diff changeset
1551 av_log(NULL, AV_LOG_WARNING,
d5e89ef58c3b warn user if video codec timebase is very high
bcoudurier
parents: 2106
diff changeset
1552 "WARNING codec timebase is very high. If duration is too long,\n"
d5e89ef58c3b warn user if video codec timebase is very high
bcoudurier
parents: 2106
diff changeset
1553 "file may not be playable by quicktime. Specify a shorter timebase\n"
d5e89ef58c3b warn user if video codec timebase is very high
bcoudurier
parents: 2106
diff changeset
1554 "or choose different container.\n");
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1555 }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1556 track->tag = mov_find_audio_codec_tag(s, track);
1292
6042770198c6 move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents: 1273
diff changeset
1557 track->timescale = st->codec->sample_rate;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1558 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
1937
4997738b316c treat frame_size > 1 as compressed audio
bcoudurier
parents: 1850
diff changeset
1559 if(!st->codec->frame_size){
1564
35ab31b4dfa6 check codec frame size directly and only for audio
bcoudurier
parents: 1462
diff changeset
1560 av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
35ab31b4dfa6 check codec frame size directly and only for audio
bcoudurier
parents: 1462
diff changeset
1561 return -1;
1937
4997738b316c treat frame_size > 1 as compressed audio
bcoudurier
parents: 1850
diff changeset
1562 }else if(st->codec->frame_size > 1){ /* assume compressed audio */
4997738b316c treat frame_size > 1 as compressed audio
bcoudurier
parents: 1850
diff changeset
1563 track->audio_vbr = 1;
4997738b316c treat frame_size > 1 as compressed audio
bcoudurier
parents: 1850
diff changeset
1564 }else{
4997738b316c treat frame_size > 1 as compressed audio
bcoudurier
parents: 1850
diff changeset
1565 track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
1564
35ab31b4dfa6 check codec frame size directly and only for audio
bcoudurier
parents: 1462
diff changeset
1566 }
1292
6042770198c6 move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents: 1273
diff changeset
1567 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1568 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1569
1055
faa09c43a3d6 write mdat in write_header avoid check in write_packet
bcoudurier
parents: 1054
diff changeset
1570 mov_write_mdat_tag(pb, mov);
faa09c43a3d6 write mdat in write_header avoid check in write_packet
bcoudurier
parents: 1054
diff changeset
1571 mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1572 mov->nb_streams = s->nb_streams;
1055
faa09c43a3d6 write mdat in write_header avoid check in write_packet
bcoudurier
parents: 1054
diff changeset
1573
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1574 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1575
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1576 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1577 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1578
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1579 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1580 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1581 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1582 ByteIOContext *pb = &s->pb;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1583 MOVTrack *trk = &mov->tracks[pkt->stream_index];
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1584 AVCodecContext *enc = trk->enc;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1585 unsigned int samplesInChunk = 0;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1586 int size= pkt->size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1587
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1588 if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1589 if (!size) return 0; /* Discard 0 sized packets */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1590
1154
322bb8541a9e typo fix
bcoudurier
parents: 1153
diff changeset
1591 if (enc->codec_id == CODEC_ID_AMR_NB) {
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1592 /* We must find out how many AMR blocks there are in one packet */
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1593 static uint16_t packed_size[16] =
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1594 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1595 int len = 0;
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1596
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1597 while (len < size && samplesInChunk < 100) {
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1598 len += packed_size[(pkt->data[len] >> 3) & 0x0F];
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1599 samplesInChunk++;
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1600 }
1151
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1601 if(samplesInChunk > 1){
2546
ramiro
parents: 2233
diff changeset
1602 av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n");
1151
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1603 return -1;
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1604 }
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1605 } else if (trk->sampleSize)
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1606 samplesInChunk = size/trk->sampleSize;
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1607 else
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1608 samplesInChunk = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1609
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1610 /* copy extradata if it exists */
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1611 if (trk->vosLen == 0 && enc->extradata_size > 0) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1612 trk->vosLen = enc->extradata_size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1613 trk->vosData = av_malloc(trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1614 memcpy(trk->vosData, enc->extradata, trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1615 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1616
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1617 if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1618 /* from x264 or from bytestream h264 */
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1619 /* nal reformating needed */
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1620 avc_parse_nal_units(&pkt->data, &pkt->size);
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1621 assert(pkt->size);
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1622 size = pkt->size;
2588
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1623 } else if (enc->codec_id == CODEC_ID_DNXHD && !trk->vosLen) {
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1624 /* copy frame header to create needed atoms */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1625 if (size < 640)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1626 return -1;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1627 trk->vosLen = 640;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1628 trk->vosData = av_malloc(trk->vosLen);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
1629 memcpy(trk->vosData, pkt->data, 640);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
1630 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
1631
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1632 if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1633 trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster));
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1634 if (!trk->cluster)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1635 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1636 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1637
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1638 trk->cluster[trk->entry].pos = url_ftell(pb);
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1639 trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1640 trk->cluster[trk->entry].size = size;
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1641 trk->cluster[trk->entry].entries = samplesInChunk;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1642 trk->cluster[trk->entry].dts = pkt->dts;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1643 trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1644
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1645 if(enc->codec_type == CODEC_TYPE_VIDEO) {
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
1646 if (pkt->dts != pkt->pts)
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
1647 trk->hasBframes = 1;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1648 trk->cluster[trk->entry].cts = pkt->pts - pkt->dts;
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1649 trk->cluster[trk->entry].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1650 if(trk->cluster[trk->entry].key_frame)
1054
b38a08b0cd12 dont write stss atom if keyframes only
bcoudurier
parents: 1053
diff changeset
1651 trk->hasKeyframes++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1652 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1653 trk->entry++;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1654 trk->sampleCount += samplesInChunk;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1655 mov->mdat_size += size;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1656
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1657 put_buffer(pb, pkt->data, size);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1658
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1659 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1660 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1661 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1662
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1663 static int mov_write_trailer(AVFormatContext *s)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1664 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1665 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1666 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1667 int res = 0;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1668 int i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1669
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1670 offset_t moov_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1671
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1672 /* Write size of mdat tag */
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1673 if (mov->mdat_size+8 <= UINT32_MAX) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1674 url_fseek(pb, mov->mdat_pos, SEEK_SET);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1675 put_be32(pb, mov->mdat_size+8);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1676 } else {
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1677 /* overwrite 'wide' placeholder atom */
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1678 url_fseek(pb, mov->mdat_pos - 8, SEEK_SET);
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1679 put_be32(pb, 1); /* special value: real atom size will be 64 bit value after tag field */
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1680 put_tag(pb, "mdat");
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1681 put_be64(pb, mov->mdat_size+16);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1682 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1683 url_fseek(pb, moov_pos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1684
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1685 mov_write_moov_tag(pb, mov, s);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1686
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1687 for (i=0; i<mov->nb_streams; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1688 av_freep(&mov->tracks[i].cluster);
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1689
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
1690 if( mov->tracks[i].vosLen ) av_free( mov->tracks[i].vosData );
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
1691
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1692 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1693
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1694 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1695
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1696 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1697 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1698
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1699 #ifdef CONFIG_MOV_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1700 AVOutputFormat mov_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1701 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1702 "mov format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1703 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1704 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1705 sizeof(MOVContext),
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1706 CODEC_ID_AAC,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
1707 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1708 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1709 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1710 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
1711 .flags = AVFMT_GLOBALHEADER,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1712 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1713 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1714 #ifdef CONFIG_TGP_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1715 AVOutputFormat tgp_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1716 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1717 "3gp format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1718 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1719 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1720 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1721 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1722 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1723 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1724 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1725 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
1726 .flags = AVFMT_GLOBALHEADER,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1727 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1728 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1729 #ifdef CONFIG_MP4_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1730 AVOutputFormat mp4_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1731 "mp4",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1732 "mp4 format",
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1733 "application/mp4",
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1734 "mp4,m4a",
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1735 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1736 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1737 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1738 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1739 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1740 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
1741 .flags = AVFMT_GLOBALHEADER,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1742 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1743 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1744 #ifdef CONFIG_PSP_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1745 AVOutputFormat psp_muxer = {
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1746 "psp",
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1747 "psp mp4 format",
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1748 NULL,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1749 "mp4,psp",
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1750 sizeof(MOVContext),
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1751 CODEC_ID_AAC,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1752 CODEC_ID_MPEG4,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1753 mov_write_header,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1754 mov_write_packet,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1755 mov_write_trailer,
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1756 .flags = AVFMT_GLOBALHEADER,
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1757 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1758 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1759 #ifdef CONFIG_TG2_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1760 AVOutputFormat tg2_muxer = {
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1761 "3g2",
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1762 "3gp2 format",
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1763 NULL,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1764 "3g2",
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1765 sizeof(MOVContext),
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1766 CODEC_ID_AMR_NB,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1767 CODEC_ID_H263,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1768 mov_write_header,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1769 mov_write_packet,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1770 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
1771 .flags = AVFMT_GLOBALHEADER,
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
1772 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1773 #endif