📄 codecs.html
字号:
<!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 dynamic codec interface</h1></center> <center>Programmed in 2002 by Burkhard Plaum (gmerlin_at_users.sourceforge.net)</center> <p><a href="#user">1 Notes for application users</a> <br><a href="#app_hacker">2 API extensions for application programmers</a> <br><a href="#codec_hacker">3. API for Codec developers</a> <br> <a href="#codec_intro">3.1 Introduction</a> <br> <a href="#new_delete">3.2 Creating and deleting codecs</a> <br> <a href="#codecinfo">3.3 Presenting ourselves to the outerworld</a> <br> <a href="#passing">3.4 Passing codecs to libquicktime</a> <br> <a href="#encode_video">3.5 Encoding video</a> <br> <a href="#decode_video">3.6 Decoding video</a> <br> <a href="#encoding_audio">3.7 Encoding audio</a> <br> <a href="#decode_audio">3.8 Decoding audio</a> </p><h3> <a name="user"></a>1. Notes for application users</h3> Libquicktime has dynamic codecs, which are installed in <prefix>/lib/libquicktime. Here, prefix is the same prefix, you used, when you compiled libquicktime (/usr/local by default). If you installed a binary package, you will find the plugins in /usr/lib/libquicktime. The plugin directory is currently hardcodedin the library and can only be changed by recompiling. <p>When your application tries to open a quicktime file with libquicktime, it will first search for the file .libquicktime_codecs in your home directory. Then it scans the plugin directory for files lqt_*.so. (The prefix lqt_ waschoosen, to prevent confusion with regular shared libraries). </p><p>For all dynamic plugins, it checks, if they are in the database (.libquicktime_codecs). If they are not there, or if the dynamic plugin is younger, than the database entry, libquicktime opens the plugin and reads the information (name, capabilities of each codec etc) from the plugin. If the database entry however is still valid, the information is taken from the database to avoid the time consuming loading of the plugin. After the whole directory is scanned, the .libquicktime_plugins file is written with the updated codec data. </p><p>With this mechanism, you will always have the new codecs enabled automatically when you start a new libquicktime application. If your application supports it, you can even register new codecs without restarting the program (See below,how application programmers can implement this feature). </p><h3> <a name="app_hacker"></a>2. API extensions for application programmers</h3> <b>2.1 Maintaining the registry</b> <p>Libquicktime has a codec registry (see above) defined in a private linked list. It allows applications to build configuration dialogs for codecs dynamicallyat runtime depending on the codecs, the user has installed. This is necessaryfor the separate distribution of libquicktime codecs. </p>The registry is initialized automatically by the first access to codecinformations, with the exception of the non thread save functions (see below).If you want to access the registry with the non thread save functions beforeyour application openend the first file, call:<br><br><tt>lqt_registry_init();</tt><br><br>If you want to enable newly installed codecs without restarting your application,destroy the registry with:<br><br><tt>lqt_registry_destroy();</tt><br><br>and call lqt_registry_inif() to rebuild it again. By default, the file .libquicktime_codecsis written once each time the registry is initialized. If you want to writethe file at a time of your choice, call:<br><br><tt>lqt_registry_write();</tt><br><br>Libquicktime also has an (not completely finished) API extension for handlingdefault values for codec parameters. To store a certain default value fora codec in the registry, use:<br><br><tt>void lqt_set_default_parameter(lqt_codec_type type, int encode,</tt><tt><br></tt><tt> const char * codec_name,</tt><tt><br></tt><tt> const char * parameter_name,</tt><tt><br></tt><tt> lqt_parameter_value_t * val);</tt><br><br>Remember that you need to call lqt_registry_write() to save the new defaultvalue permanently.<br><p><b>2.2 The codec info structure</b> </p><p>The structure for all codec data is defined as follows: </p><p><tt>struct lqt_codec_info_s</tt> <br><tt> {</tt> <br><tt> /* These are set by the plugins */</tt> <br><tt> </tt> <br><tt> char * name; /* Nameof the codec */</tt> <br><tt> char * long_name; /* Long name of the codec */</tt> <br><tt> char * description; /* Description */</tt><tt></tt> </p><p><tt> lqt_codec_type type;</tt> <br><tt> lqt_codec_direction direction;</tt> <br><tt> </tt> <br><tt> int num_fourccs; /* Fourccs, this codec canhandle */</tt> <br><tt> char ** fourccs;</tt> <br><tt> </tt> <br><tt> int num_encoding_parameters;</tt> <br><tt> lqt_parameter_info_t * encoding_parameters;</tt><tt></tt> </p><p><tt> int num_decoding_parameters;</tt> <br><tt> lqt_parameter_info_t * decoding_parameters;</tt><tt></tt> </p><p><tt> /* Colormodels this codec can handle */</tt> <br><tt> </tt> <br><tt> int num_encoding_colormodels;</tt> <br><tt> int * encoding_colormodels;</tt><tt></tt> </p><p><tt> /*</tt> <br><tt> * Colormodel for decoding.</tt> <br><tt> * Must be set to LQT_COLORMODEL_NONE if the streamcolormodel</tt> <br><tt> * must be obtained at runtime by the codec</tt> <br><tt> */</tt> <br><tt> </tt> <br><tt> int decoding_colormodel;</tt> <br><tt> </tt> <br><tt> /* The following members are set by libquicktime */</tt> <br><tt> </tt> <br><tt> char * module_filename; /* Filename of the module */</tt> <br><tt> int module_index; /* Index inside the module */</tt> <br><tt> </tt> <br><tt> uint32_t file_time; /*File modification time */</tt> <br><tt> </tt> <br><tt> struct lqt_codec_info_s * next; /* For chaining */</tt> <br><tt> };</tt><tt></tt> </p><p><tt>typedef struct lqt_codec_info_s lqt_codec_info_t;</tt><b></b> </p><p>Most of these members are self explaining. The only thicky thing are thecolormodels. They indicate the the native colormodels of the codec, whichcan be read and written directly without colorspace conversion. A codec canhave more than one native colormodel (e.g. the png codec supports RGB aswell as RGBA), but in this case the best decoding colormodel depends on theother stream parameters (e.g. on the video depth for png). <br>If a codec supports more colormodels, it has all of them in the encoding_colormodels array. The application can then choose one these, if a file is written. Inthis case, the decoding_colormodel is set to LQT_COLORMODEL_NONE. This indicates,that libquicktime will try to get the stream colormodel from the codec ifthe file is open (see below). <br>In most cases, however, there will be only one native colormodel, so therewill be only one encoding colormodel, and the decoding colormodel will beknown at compile time. <br>The next pointer should not be used by applications. To simplify the accessto the data, all codec informations are passed as NULL terminated arraysto the outer world. </p><p>You can get the encoding and decoding parameters in the parameter_info_t structure: </p><p><tt>typedef struct</tt> <br><tt> {</tt> <br><tt> char * name; /* Parameter name (tobe passed to quicktime_set_parameter() ) */</tt> <br><tt> char * real_name; /* Other name (for making dialogs) */</tt> <br><tt> </tt> <br><tt> lqt_parameter_type_t type; /* LQT_INT, LQT_STRING or LQT_STRINGLIST */</tt> <br><tt> </tt> <br><tt> lqt_parameter_value_t val_default;</tt><tt></tt> </p><p><tt> /*</tt> <br><tt> * Minimum and maximum values:</tt> <br><tt> * These are only valid for numeric types andif val_min < val_max</tt> <br><tt> */</tt><tt></tt> </p><p><tt> int val_min;</tt> <br><tt> int val_max;</tt><tt></tt> </p><p><tt> /*</tt> <br><tt> * Possible options (only valid for LQT_STRINGLIST)</tt> <br><tt> */</tt> <br><tt> </tt> <br><tt> int num_stringlist_options;</tt> <br><tt> char ** stringlist_options;</tt> <br><tt> </tt> <br><tt> } lqt_parameter_info_t;</tt> <br><tt></tt> </p><p>The minimum and maximum values are only valid for integer parameters andif val_min < val_max. If integer parameters have a minimum of 0 and amaximum of 1, they should be considered as boolean (applications will makea check button instead of a slider for this). The stringlist is for enumeratedtypes, the possible options are in stringlist_options. </p><p>lqt_parameter_value_t is a union, which can carry values of different datatypes: </p><p><tt>typedef union</tt> <br><tt> {</tt> <br><tt> int val_int;</tt> <br><tt> char * val_string;</tt> <br><tt> } lqt_parameter_value_t;</tt><b></b> </p><p><b>2.3 Getting codec informations (the easy way):</b> </p><p>If you can make sure, that no quicktime files are openend or closed, whileanother thread rebuilds the registry, you can access the registry directly.Note, that these won't initialize the registry automatically. Get the numberof audio- and videocodecs with: </p><p><tt> int lqt_get_num_audio_codecs();</tt> </p><p><tt> int lqt_get_num_video_codecs();</tt> </p><p>For each codec index (starting with zero), you can obtain an info structure with: </p><p><tt> const lqt_codec_info_t * lqt_get_audio_codec_info(int index);</tt> </p><p><tt> const lqt_codec_info_t * lqt_get_video_codec_info(int index);</tt> </p><p>These functions bypass the locking machanism of the registry and return pointers to the internal data. </p><p><b>2.4 Getting codec informations (the harder way):</b> </p><p>There is another group of registry access functions, which lock the registry,copy the informations into the return value and unlock the registry. Theyare thread save, but you must free the retruned data expicitly. All thesefunctions return a NULL terminated lqt_codec_info_t* array, even ifthey retrun always only one codec. <br>For getting any combination of audio/video en/decoders, use: </p><p><tt>lqt_codec_info_t ** lqt_query_registry(int audio, int video, int encode,int decode);</tt> </p><p>You can use it to show the commanline user a list of supported codecs orfor building dialogs. To find a codec by it's individual name, use: </p><p><tt>lqt_codec_info_t ** lqt_find_audio_codec_by_name(const char * name);</tt><tt></tt> </p><p><tt>lqt_codec_info_t ** lqt_find_video_codec_by_name(const char * name);</tt><tt></tt> </p><p>If you want to know something about the codecs of an open quicktime file,use: </p><p><tt>lqt_codec_info_t ** lqt_audio_codec_from_file(quicktime_t *, int track);</tt><tt></tt> </p><p><tt>lqt_codec_info_t ** lqt_video_codec_from_file(quicktime_t *, int track);</tt><tt></tt> </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -