📄 qt4l_reading.html
字号:
<TITLE>Reading</TITLE><H1>Reading a file</H1>Most users simply want read access for a player toy or something. Agood place to start is before opening the file, making sure it isQuicktime 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 <AHREF="opening.html">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 countis a bit more complicated. Usually you'll only encounter a singleaudio 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 arealways numbered from 0 to the total number of tracks - 1 for theparticular 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 trackhigher than 0. Other routines you might find useful for getting audioinformation 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. Thesample 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 datacompression of the track. These identifiers are 4 alphanumericcharacters which go along with one of the #defines in quicktime.h. Thebits function returns the number of bits in a sample, usuallymeaningless.<P>The most interesting contents of a Quicktime file are of course thevideo 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 videolength is in frames. The width and height are in pixels. The framerate is in frames per second. Depth returns the total number of bitsper pixel. The only two values Quicktime for Linux returns are 24 and32 and the 32 bit depth is only returned when the format has an alphachannel. There's no reason to use 16 or 8.<P><B>quicktime_reads_cmodel</B> allows you to determine the optimum colormodel for decompression output. It requires a colormodel #define fromcolormodels.h. If the codec can generate the desired colormodelwithout downsampling it returns 1. If downsampling is required itreturns 0. You can assume all colormodels in colormodels.h aresupported, 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 safelyassume the encoding scheme for track 0 of audio or video is the samefor all tracks.<P><A NAME="Decodingvideo"><H1>Decoding video</H1>The library decodes compressed video frames into a buffer in whatevercolormodel 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 rowsmust have enough space allocated for the entire frame, depending on thecolormodel. Planar colormodels use only the first 3 row pointers, eachpointing 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 <AHREF="positioning.html">positioning</A><P>There are other routines for reading compressed data and chunks, butunless you want to write a codec, you'd better focus on more importantthings.<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. Thisreturns 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 atthe current position in the track. Notice this command takes a channelargument not a track argument. The channel argument is automaticallyconverted into a track and channel. Positioning information isautomatically taken from the appropriate track and advanced for all thechannels in the track.<P>Notice the int16_t* and float* parameters. This call caneither return a buffer of int16 samples or float samples. The argumentfor the data format you want should be passed a preallocated buffer bigenough to contain the sample range while the undesired format should bepassed 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 decoderautomatically fills the appropriate buffer. Floating point samples arefrom -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 yourcurrent position on the specified video track and returns the number ofbytes in the frame. You have to make sure the buffer is big enough forthe 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 specifiedtrack even if you haven't read the frame yet. Frame numbers start on0.<P><A NAME="Readingkeyframes"><H1>Accessing Keyframes</H1>Quicktime offers very simple support for keyframes: a table of all thekeyframe numbers in a track. Many students think there's a massivekeyframe programming language in Quicktime. Really all there is is atable.<P>There are two things you can do with the keyframe table: insertkeyframe 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 frameargument 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. Afuture interface may provide raw audio support but for now you'rebetter off writing a codec into the library.<P>These commands are good for reading raw sample data. They should onlybe used for codecs not supported in the library and only work forinterleaved, 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 toread. Then it reads that corresponding number of bytes on thespecified track and returns the equivalent number of bytes read or 0 iferror. The data read is PCM audio data of interleaved channelsdepending on the format of the track.Be aware that Quicktime for Linux tries to guess the number of bytes bythe codec type, so attempts to read most nonlinear codecs will crash.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -