api_usage.html

来自「这个库实现了录象功能」· HTML 代码 · 共 724 行 · 第 1/3 页

HTML
724
字号
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html><head>  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">  <meta name="GENERATOR" content="Mozilla/4.75 [de] (X11; U; Linux 2.4.14 i686) [Netscape]"></head><body text="#000000" bgcolor="#ffffff" link="#0000ee" vlink="#551a8b" alink="#ff0000"><center><h1>Libquicktime API usage<br></h1></center><center><br><div style="text-align: left;"><a href="#1._API_Conventions">1. APIconventions</a><br><a href="#2._OpeningClosing">2. Opening/Closing</a><br><a href="#3._Reading_quicktime_files">3. Reading</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.1_Getting_audio_stream_information">3.1Getting audio information</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.2_Decoding_audio">3.2 Decoding audio</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.3_Audio_seeking">3.3 Audio seeking</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.4_Getting_video_information">3.4Getting video information</a><span style="font-weight: bold;"><br>&nbsp;&nbsp;&nbsp; </span><a href="#3.5_Decoding_video">3.5 Decodingvideo</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.6_Video_seeking">3.6 Video seeking</a><br>&nbsp;&nbsp;&nbsp; <a href="#3.7_Global_information">3.7 Globalinformation</a><br><a href="#4._Writing_Quicktime_files">4. Writing</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.1_Setting_metadata">4.1 Setting metadata</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.2_Setting_up_tracks">4.2 Setting uptracks</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.3_Setting_codec_parameters">4.3 Settingcodec parameters</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.4_Making_an_AVI">4.4 Making an AVI</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.5_Encoding_audio">4.5 Encoding audio</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.6_Encoding_video">4.6 Encoding video</a><br>&nbsp;&nbsp;&nbsp; <a href="#4.7_Making_streamable_Quicktime">4.7Making streamable quicktime</a><br><a href="#5._Colormodels">5. Colormodels</a><br><a href="#6._Codec_registry_interface">6. Codec registry interface</a><br></div></center><h3><a name="1._API_Conventions"></a>&nbsp;1. API Conventions<br></h3>The libquicktime API is kept quite similar to the quicktime4linux API.All libquicktime specific extensions are prefixed with lqt_ or LQT_.Libquicktime makes however, a bit more use of enums. In this file, somenot recommended functions are not documented. Brave people mightconsult the files <span style="font-family: monospace;">&lt;quicktime/quicktime.h&gt;</span>and <span style="font-family: monospace;">&lt;quicktime/lqt.h&gt;</span>for the whole truth.<br><h3><a name="2._OpeningClosing"></a>2. Opening/Closing</h3>To open a Quicktime or sufficiently compatible AVI file, use:<br><br><code></code><span style="font-family: monospace;">quicktime_t*quicktime_open(const char *filename, int rd, int wr);</span><br><br>This returns an opaque pointer type quicktime_t* or NULL if the filecould not be opened. The returned handle is the first argument for mostlibquicktime functions. The arguments <span style="font-family: monospace;">rd</span> and <span style="font-family: monospace;">wr</span> specify if the filewill be opened for reading or writing. Only one of both can be TRUE.After you are done with it, close the handle with<br><br><span style="font-family: monospace;">int quicktime_close(quicktime_t*file);</span><br><h3><a name="3._Reading_quicktime_files"></a>3. Reading quicktime files</h3><h4><a name="3.1_Getting_audio_stream_information"></a>3.1 Gettingaudio information</h4>First, get the number of audio streams with:<br><br><span style="font-family: monospace;">intquicktime_audio_tracks(quicktime_t *file);</span><br><br>Then, for each track, call:<br><br><span style="font-family: monospace;">intquicktime_track_channels(quicktime_t *file, int track);</span><br style="font-family: monospace;"><span style="font-family: monospace;">longquicktime_sample_rate(quicktime_t *file, int track);<br>long quicktime_audio_length(quicktime_t *file, int track);<br style="font-family: monospace;"></span><span style="font-family: monospace;">intquicktime_audio_bits(quicktime_t *file, int track);</span><br><br>to get channel count, the samplerate, length (in samples) and bits persample. The lastvalue is for information purposes only. While the audio format isalways available from the quicktime container, it can happen, that thecodec isn't supported by libquicktime. To make sure, that an audiotrack can be decoded, check if the return value of<br><br><span style="font-family: monospace;">intquicktime_supported_audio(quicktime_t *file, int track)</span>;<br><br>is nonzero. Then, before you decode the first samples, you can set somecodec parameters. This works exactly the same way as for encoding (see <a href="#4.3_Setting_codec_parameters">Setting codec parameters</a>).<br><h4><a name="3.2_Decoding_audio"></a>3.2 Decoding audio</h4>There are 3 functions for decoding audio. The most recommended one is:<br><br><span style="font-family: monospace;">intlqt_decode_audio_track(quicktime_t *file, int16_t **output_i, float**output_f, long samples, int track);</span><br><br><span style="font-family: monospace;">output_i</span> and <span style="font-family: monospace;">output_f</span> are pointers to arrayswhere the samples for the channels will be copied. Either of botharrays can be NULL.Single channel arrays can also be NULL if some channels are not ofinterest.<br>The quicktime4linux API (unlike ours) hides the concept of an audiotrack from the user. To resemble this behaviour, there is a function:<br><br><span style="font-family: monospace;">int lqt_decode_audio(quicktime_t*file, int16_t **output_i, float **output_f, long samples);</span><br><br>It decodes all channels of all tracks at once. Finally, there is thequicktime4linux approach (for compatibility reasons):<br><br><span style="font-family: monospace;">intquicktime_decode_audio(quicktime_t *file, int16_t *output_i, float*output_f, long samples, int channel);</span><br><br>It's not recommended, because if you need more than one channel, youmust seek backwards between the decode calls.<br>After decoding, you can use<br><br><span style="font-family: monospace;">int64_tlqt_last_audio_position(quicktime_t * file, int track);</span><br><br>It returns the REAL sample position of the stream. You can use this tocheck, if you decoded fewer samples than you wanted. In this case, EOFis reached.<br><h4><a name="3.3_Audio_seeking"></a>3.3 Audio seeking</h4>To set an audio stream to a specified position, use:<br><br><span style="font-family: monospace;">intquicktime_set_audio_position(quicktime_t *file, int64_t sample, inttrack);</span><br><br>Subsequent decode calls will then start from the specified sampleposition. Seeking is sample-accurate except for AVI files withcompressed audio due to file format weaknesses.<br><h4><a name="3.4_Getting_video_information"></a>3.4 Getting videoinformation</h4>First, get the number of video tracks with:<br><br><span style="font-family: monospace;">intquicktime_video_tracks(quicktime_t *file);<span style="font-weight: bold;"><br><br></span></span>For each track, get the video format with:<span style="font-weight: bold;"><br><br></span><span style="font-family: monospace;">intquicktime_video_width(quicktime_t *file, int track);</span><br style="font-family: monospace;"><span style="font-family: monospace;">intquicktime_video_height(quicktime_t *file, int track);</span><br style="font-family: monospace;"><span style="font-family: monospace;">intlqt_video_time_scale(quicktime_t * file, int track);</span><span style="font-weight: bold;"><br></span><span style="font-family: monospace;">doublequicktime_frame_rate(quicktime_t *file, int track);<br>long quicktime_video_length(quicktime_t *file, int track);<br>int64_t lqt_video_duration(quicktime_t * file, int track);<br>int quicktime_video_depth(quicktime_t *file, int track);<br><br></span>The last function is for information only. You can either usethe framerate (and <span style="font-family: monospace;">quicktime_video_length</span>)for your synchronization or the timescale (and <span style="font-family: monospace;">lqt_video_duration</span>). Thetimescale method has the advantage, that you make no roundingerrors and can synchronize tracks with nonconstant framerates. Whilethe video format is always available from the quicktimecontainer, it can happen, that the codec isn't supported bylibquicktime. To make sure, that a video track can be decoded, checkif the return value of<br><br><span style="font-family: monospace;">intquicktime_supported_video(quicktime_t *file, int track)</span>;<br><br>is nonzero. Then, before you decode the first frame, you can set somecodecparameters. This works exactly the same way as for encoding (see <a href="file:///home/pix/Src/Libquicktime/libquicktime/doc/api_usage.html#4.3_Setting_codec_parameters">Settingcodec parameters</a>).<h4><a name="3.5_Decoding_video"></a>3.5 Decoding video</h4>After you figured out the proper colormodel (see <a href="#5._Colormodels">colormodels</a>) and before decoding the firstframe, call:<br><br><span style="font-family: monospace;">lqt_set_cmodel(<span style="font-family: monospace;">quicktime_t *file, int track, intcolormodel);</span><br></span><br>Furthermore, you might have planar video frames (e.g. XVideo images)which have padded scanlines. To tell this to the library, use:<br><br><span style="font-family: monospace;">void lqt_set_row_span(quicktime_t*file, int track, int row_span);</span><br style="font-family: monospace;"><span style="font-family: monospace;">voidlqt_set_row_span_uv(quicktime_t *file, int track, int row_span_uv);</span><br><br>The first one sets the byte offsets between the scane lines for theluminance plane, the second one is for the chrominance planes. Then,youcan get the timestamp and duration of the NEXT frame to be decoded with:<br><br><span style="font-family: monospace;">int64_tlqt_frame_time(quicktime_t * file, int track);</span><br><br>The unit are timescale tics. Finally, decode the frame with:<br><br><span style="font-family: monospace;">int lqt_decode_video(quicktime_t*file, unsigned char **row_pointers, int track);</span><br><br><span style="font-family: monospace;">row_pointers</span> points to thescanline beginnings for packed formats andto the planes for planar formats. Alternatively, you can use:<br><br><span style="font-family: monospace;">longquicktime_decode_scaled(quicktime_t *file,</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int in_x,&nbsp; /* Location of input frame to take picture */</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int in_y,</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int in_w,</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int in_h,</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?