1 <TITLE>Quicktime for Linux
</TITLE>
3 <H1>Writing a file
</H1>
6 The following commands are good for writing to a file.
<P>
8 Immediately after opening the file, set up some tracks to write with
12 quicktime_set_audio(quicktime_t *file, int channels, long sample_rate, int bits, char *compressor);
<BR>
13 quicktime_set_video(quicktime_t *file, int tracks, int frame_w, int frame_h, float frame_rate, char *compressor);
16 Don't call the audio command if you don't intend to store any audio
17 data. Likewise, don't call the video command if you're just going to
20 Notice the channels argument for audio channels but there is no
21 argument for total audio tracks. Currently the library only supports
22 writing one audio track of any number of channels.
<P>
24 If you intend to use the library's built-in compression routines
25 specify a compressor #define from quicktime.h as the compressor
26 argument. If you want to write your own compression routine, specify
27 any
4 byte identifier you want but don't expect the library to handle
28 compression. The compressor applies to all tracks of the same media
29 type, for sanity reasons.
<P>
31 Once these routines are called you can optionally call
<P>
35 void quicktime_set_parameter(quicktime_t *file, char *key, void *value);
<P>
38 to set compression parameters for the codecs. Each parameter for a
39 codec consists of a unique string and a pointer to a value. The string
40 is unique to the codec and the parameter. The value is in a specific
41 data type recognized by the parameter.
<P>
43 To set a jpeg compression quality of
80, for example, do the following:
<P>
47 quicktime_set_parameter(file,
"jpeg_quality", &quality);
<BR>
50 The data type of the value depends on the parameter. Currently the
51 best way to determine what parameters and value data types a particular
52 codec supports is to look at the codec's source code. A better way may
53 become available in the future.
<P>
55 If you don't call quicktime_set_parameter the codecs will use default
59 <H2>NOTE FOR AVI FILES
</H2><P>
61 After the above sequence and only after it, call
62 <CODE>quicktime_set_avi
</CODE> to make the library generate an AVI
70 <A NAME=
"Encodingvideo">
71 <H1>Encoding video
</H1>
73 The library generates compressed video frames from a frame buffer of
74 any colormodel in colormodels.h. First use
<P>
77 int quicktime_supported_video(quicktime_t *file, int track);
80 to find out if the codec for the track is in the library. This returns
81 1 if it is and
0 if it isn't supported. Then use
<P>
84 int quicktime_writes_cmodel(quicktime_t *file,
89 To query the library for a colormodel which doesn't require
90 downsampling to drive the codec.
<B>colormodels.h
</B> contains a set
91 of colormodel #defines which supply the colormodel argument. The
92 function returns True or False depending on whether the colormodel
93 argument is optimum. When a colormodel doesn't require downsampling it
94 returns
1. Then call
<P>
96 <CODE>quicktime_set_cmodel(quicktime_t *file, int colormodel);
</CODE><P>
98 to set the colormodel your frame buffer is in. Finally call
101 int quicktime_encode_video(quicktime_t *file, unsigned char **row_pointers, int track);
105 to compress the frame pointed to by **row_pointers, write it at the
106 current position of the track and advance the current position. The
107 return value is always
1 for failure and
0 for success. The row
108 pointers must point to rows stored in the colormodel. Planar
109 colormodels use only the first
3 row pointers, each pointing to one of
120 <A NAME=
"Encodingaudio">
121 <H1>Encoding audio
</H1>
123 The library also supports encoding certain audio codecs. Before
124 writing a buffer of samples, try
<P>
127 int quicktime_supported_audio(quicktime_t *file, int track);
131 The track argument is really hypothetical here, since you should only
132 pass
0 for it. If you get a TRUE return value, you are free to use
135 int quicktime_encode_audio(quicktime_t *file, int16_t **input_i, float **input_f, long samples);
138 to encode the sample buffer. Pass an array of buffers to either the
139 int16_t** or the float** argument, depending on what format your data
140 is in. Pass a NULL to the undesired format. The array of buffers is
141 one buffer of samples for each channel. This means all the channels
142 have to be written simultaneously. The return value is
0 on success.
146 <A NAME=
"Writingrawvideo">
147 <H1>Writing raw video
</H1>
149 For writing raw data, you need to supply a buffer of data exactly as
150 you intend the read operations to see it, with the encoding done, then
151 call one of these functions to write it. For video, specify the number
152 of bytes in the frame buffer and the track this frame belongs to.
153 Video can only be written one frame at a time.
156 int quicktime_write_frame(quicktime_t *file, unsigned char *video_buffer, long bytes, int track);
161 Now some of you are going to want to write frames directly to a file
162 descriptor using another library like libjpeg or something. For every
163 frame start by calling quicktime_write_frame_init to initialize the
167 int quicktime_write_frame_init(quicktime_t *file, int track);
170 Then write your raw, compressed data to the file descriptor given by
174 FILE* quicktime_get_fd(quicktime_t *file);
177 End the frame by calling quicktime_write_frame_end.
<P>
180 int quicktime_write_frame_end(quicktime_t *file, int track);
183 Repeat starting at quicktime_write_frame_init for every frame.
185 <A NAME=
"Writingkeyframes">
186 <H1>Writing Keyframes
</H1>
188 Quicktime offers very simple support for keyframes: a table of all the
189 keyframe numbers in a track. Many students think there's a massive
190 keyframe programming language in Quicktime. Really all there is is a
193 There are two things you can with the keyframe table: insert keyframe
194 numbers and retrieve keyframe numbers.
<P>
197 void quicktime_insert_keyframe(quicktime_t *file, long frame, int track)
201 Inserts a keyframe number corresponding to the
<B>frame
</B> argument in
204 <A NAME=
"Encodingrawaudio">
205 <H1>Writing raw audio data
</H1>
207 This functionality is obsolete due to the idiosyncracies in compressed
208 audio handling. If you want to write uncompressed audio, use the
209 <B>twos
</B> codec.
<P>
211 When you're done, call quicktime_close to close the file.
<P>
214 int quicktime_close(file);