1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
<TITLE>Reading</TITLE>
<H1>Reading a file</H1>
Most users simply want read access for a player toy or something. A
good place to start is before opening the file, making sure it is
Quicktime with quicktime_check_sig().<P>
<CODE>
quicktime_check_sig("path");<P>
</CODE>
This returns 1 if it looks like a Quicktime file or 0 if it doesn't.
Then you can open the file as described in <A
HREF="qt4l_opening.html">qt4l_opening.html</A>.<P>
Next get the number of tracks for each media type in the file:<P>
<CODE>
int quicktime_video_tracks(quicktime_t *file);<BR>
int quicktime_audio_tracks(quicktime_t *file);
</CODE>
<P>
While Quicktime can store multiple video tracks, the audio track count
is a bit more complicated. Usually you'll only encounter a single
audio track. Inside the audio track is a variable number of channels.
To get the channel count call:<P>
<CODE>
int quicktime_track_channels(quicktime_t *file, int track);
</CODE>
<P>
With the track parameter set to track 0. Many routines require a
<B>track</B> parameter to specify the track to operate on. Tracks are
always numbered from 0 to the total number of tracks - 1 for the
particular media type.<P>
Audio tracks are numbered from 0 to the total number of audio tracks -
1. But like I said, you'll probably never encounter an audio track
higher than 0. Other routines you might find useful for getting audio
information are:<P>
<CODE>
long quicktime_sample_rate(quicktime_t *file, int track);<BR>
long quicktime_audio_length(quicktime_t *file, int track);<BR>
</CODE>
<P>
quicktime_audio_length gives you the total number of samples. The
sample rate is samples per second.<P>
Routines you'll never use unless you want to write a codec are:<P>
<CODE>
char* quicktime_audio_compressor(quicktime_t *file, int track);<BR>
int quicktime_audio_bits(quicktime_t *file, int track);<BR>
</CODE>
<P>
The audio compressor call returns a 4 byte array identifying the data
compression of the track. These identifiers are 4 alphanumeric
characters which go along with one of the #defines in quicktime.h. The
bits function returns the number of bits in a sample, usually
meaningless.<P>
The most interesting contents of a Quicktime file are of course the
video tracks. Quicktime stores multiple video tracks.<P>
The available queries for each video track are:<P>
<CODE>
long quicktime_video_length(quicktime_t *file, int track);<BR>
int quicktime_video_width(quicktime_t *file, int track);<BR>
int quicktime_video_height(quicktime_t *file, int track);<BR>
float quicktime_frame_rate(quicktime_t *file, int track);<BR>
long quicktime_frame_size(quicktime_t *file, long frame, int track);<BR>
int quicktime_video_depth(quicktime_t *file, int track);<BR>
quicktime_reads_cmodel(quicktime_t *file,
int colormodel,
int track);<BR>
</CODE>
<P>
Tracks are numbered 0 to the total number of tracks - 1. The video
length is in frames. The width and height are in pixels. The frame
rate is in frames per second. Depth returns the total number of bits
per pixel. The only two values Quicktime for Linux returns are 24 and
32 and the 32 bit depth is only returned when the format has an alpha
channel. There's no reason to use 16 or 8.<P>
<B>quicktime_reads_cmodel</B> allows you to determine the optimum color
model for decompression output. It requires a colormodel #define from
colormodels.h. If the codec can generate the desired colormodel
without downsampling it returns 1. If downsampling is required it
returns 0. You can assume all colormodels in colormodels.h are
supported, whether they require downsampling or not.<P>
To get the four byte compressor type for the track issue:<P>
<CODE>
char* quicktime_video_compressor(quicktime_t *file, int track);<BR>
</CODE>
<P>
Unless you get a really nihilistic file for reading, you can safely
assume the encoding scheme for track 0 of audio or video is the same
for all tracks.<P>
<A NAME="Decodingvideo">
<H1>Decoding video</H1>
The library decodes compressed video frames into a buffer in whatever
colormodel you desire but before then you should issue<P>
<CODE>
int quicktime_supported_video(quicktime_t *file, int track);<BR>
</CODE>
<P>
to find out if the data for the track can be decoded by the library.
This returns 1 if it is and 0 if it isn't supported.<P>
Then use<P>
<CODE>
<PRE>
long quicktime_decode_scaled(quicktime_t *file,
int in_x, /* Location of input frame to take picture */
int in_y,
int in_w,
int in_h,
int out_w, /* Dimensions of output frame */
int out_h,
int color_model, /* One of the color models defined above */
unsigned char **row_pointers,
int track);<BR>
</PRE>
</CODE>
<P>
to decompress a frame at the current position of the track into
**row_pointers and advance the current position. The array of rows
must have enough space allocated for the entire frame, depending on the
colormodel. Planar colormodels use only the first 3 row pointers, each
pointing to one of the planes.<P>
The decoder "sees" a region of the movie screen defined by <CODE>in_x,
in_y, in_w, in_h</CODE> and transfers it to the frame buffer defined by
<CODE>**row_pointers</CODE>. The size of the frame buffer is defined by
<CODE>out_w, out_h</CODE>.<P>
For more about the track's current position go to <A
HREF="qt4l_positioning.html">positioning</A><P>
There are other routines for reading compressed data and chunks, but
unless you want to write a codec, you'd better focus on more important
things.<P>
<A NAME="Decodingaudio">
<H1>Decoding audio</H1>
For reading audio, first use:<P>
<CODE>
int quicktime_supported_audio(quicktime_t *file, int track);<BR>
</CODE>
<P>
To determine if the audio can be decompressed by the library. This
returns 1 if it is and 0 if it isn't supported. Then use<P>
<CODE>
int quicktime_decode_audio(quicktime_t *file, int16_t *output_i, float *output_f, long samples, int channel);<BR>
</CODE>
<P>
To read a buffer's worth of samples for a single channel starting at
the current position in the track. Notice this command takes a channel
argument not a track argument. The channel argument is automatically
converted into a track and channel. Positioning information is
automatically taken from the appropriate track and advanced for all the
channels in the track.<P>
Notice the int16_t* and float* parameters. This call can
either return a buffer of int16 samples or float samples. The argument
for the data format you want should be passed a preallocated buffer big
enough to contain the sample range while the undesired format should be
passed NULL. For a buffer of float samples you would say<P>
<CODE>
result = quicktime_decode_audio(file, NULL, output_f, samples, channel);<BR>
</CODE>
<P>
For a buffer of signed int16 samples you would say<P>
<CODE>
result = quicktime_decode_audio(file, output_i, NULL, samples, channel);<BR>
</CODE>
<P>
The data format you don't want should be passed a NULL. The decoder
automatically fills the appropriate buffer. Floating point samples are
from -1 to 0 to 1.<P>
<A NAME="Readingrawvideo">
<H1>Reading raw video</H1>
<CODE>
long quicktime_read_frame(quicktime_t *file, unsigned char *video_buffer, int track);
</CODE>
<P>
<B>quicktime_read_frame</B> reads one frame worth of raw data from your
current position on the specified video track and returns the number of
bytes in the frame. You have to make sure the buffer is big enough for
the frame. A return value of 0 means error.<P>
<CODE>
long quicktime_frame_size(quicktime_t *file, long frame, int track);
</CODE>
<P>
gives up the number of bytes in the specified frame in the specified
track even if you haven't read the frame yet. Frame numbers start on
0.<P>
<A NAME="Readingkeyframes">
<H1>Accessing Keyframes</H1>
Quicktime offers very simple support for keyframes: a table of all the
keyframe numbers in a track. Many students think there's a massive
keyframe programming language in Quicktime. Really all there is is a
table.<P>
There are two things you can do with the keyframe table: insert
keyframe numbers and retrieve keyframe numbers.<P>
<CODE>
long quicktime_get_keyframe_before(quicktime_t *file, long frame, int track)
</CODE>
<P>
Gets the keyframe number before the <B>frame</B> argument. The frame
argument starts on 0.<P>
<CODE>
void quicktime_insert_keyframe(quicktime_t *file, long frame, int track)
</CODE>
<P>
Inserts a keyframe into the table. The frame argument starts on 0.<P>
<A NAME="Readingrawaudio">
<H1>Reading raw audio</H1>
This functionality is obsolete and there's no reason to use it. A
future interface may provide raw audio support but for now you're
better off writing a codec into the library.<P>
These commands are good for reading raw sample data. They should only
be used for codecs not supported in the library and only work for
interleaved, linear PCM data.<P>
<CODE>
long quicktime_read_audio(quicktime_t *file, char *audio_buffer, long samples, int track);
</CODE>
<P>
<B>quicktime_read_audio</B> requires a number of samples of raw audio data to
read. Then it reads that corresponding number of bytes on the
specified track and returns the equivalent number of bytes read or 0 if
error. The data read is PCM audio data of interleaved channels
depending on the format of the track.
Be aware that Quicktime for Linux tries to guess the number of bytes by
the codec type, so attempts to read most nonlinear codecs will crash.
|