1 /*******************************************************************************
2  quicktime.h
3 
4  libquicktime - A library for reading and writing quicktime/avi/mp4 files.
5  http://libquicktime.sourceforge.net
6 
7  Copyright (C) 2002 Heroine Virtual Ltd.
8  Copyright (C) 2002-2011 Members of the libquicktime project.
9 
10  This library is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free
12  Software Foundation; either version 2.1 of the License, or (at your option)
13  any later version.
14 
15  This library is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along
21  with this library; if not, write to the Free Software Foundation, Inc., 51
22  Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 *******************************************************************************/
24 
25 #ifndef QUICKTIME_H
26 #define QUICKTIME_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <inttypes.h>
33 #include <stddef.h>
34 
35 #pragma GCC visibility push(default)
36 
37 /* Some public enums needed by most subsequent headers */
38 
39 typedef struct lqt_codec_info_s lqt_codec_info_t;
40 
41 
42 /**
43  * @file quicktime.h
44  * Public api header for the quicktime4linux compatibility layer.
45  */
46 
47 /** \defgroup general General
48     \brief General structures and functions
49  */
50 
51 /** \defgroup log Logging
52     \brief Message handling
53  */
54 
55 
56 /** \defgroup audio Audio
57     \brief Audio related definitions and functions
58  */
59 
60 /** \defgroup audio_decode Audio decoding
61  *  \ingroup audio
62  *  \brief Audio related definitions and functions (reading)
63  *
64  * The audio API changed a lot during the last years (causing lot of confusion), so here is the
65  * preferred way: First get the number of audio tracks with \ref quicktime_audio_tracks. Then
66  * for each track you want to decode, use \ref quicktime_supported_audio to verify that a codec
67  * is available. Then get the audio format with \ref quicktime_track_channels and \ref quicktime_sample_rate .
68  * Then use \ref lqt_decode_audio_track to decode noninterleaved channels in either 16bit integer
69  * or floating point [-1.0..1.0] format. This method will convert all internally used formats to the datatypes
70  * you want, but won't output the full precision for 24/32 bit formats. If you want the samples as raw as possible
71  * (bypassing all internal sample format conversions), use \ref lqt_get_sample_format to get the sampleformat
72  * natively used by the codec and \ref lqt_decode_audio_raw to decode it.
73  */
74 
75 /** \defgroup audio_encode Audio encoding
76  *  \ingroup audio
77  *  \brief Audio related definitions and functions (writing)
78  *
79  * The audio API changed a lot during the last years (causing lot of confusion), so here is the
80  * preferred way: Use the \ref codec_registry functions to get all supported audio encoders.
81  * Once you found a codec (i.e. a \ref lqt_codec_info_t ), call \ref lqt_add_audio_track to
82  * add the track to the file. You can repeat this procedure to add as many tracks as you like
83  * with different formats and/or codecs.
84  *
85  * Next you might want to set some compression parameters. This is done by calling \ref lqt_set_audio_parameter.
86  * Supported parameters and valid ranges are in the \ref lqt_codec_info_t.
87  *
88  * For each track, encode noninterleaved samples (either in 16bit integer
89  * or floating point [-1.0..1.0] format) with \ref lqt_encode_audio_track . In this case, libquicktime
90  * will convert your samples to the format used by the codec. This won't give the
91  * full precision when using 24/32 bit formats. If you want to pass the samples as raw as possible
92  * (bypassing all internal sample format conversions), use \ref lqt_get_sample_format to get the sampleformat
93  * natively used by the codec and \ref lqt_encode_audio_raw to encode it.
94  *
95  */
96 
97 /** \defgroup multichannel Multichannel support
98  *  \ingroup audio
99  *
100  * This is an optional API extension, which allows multichannel
101  * configuration to be saved into a file. The mechanisms used are the
102  * quicktime chan atom as well as some codec specific multichannel
103  * setups.
104  *
105  *  When decoding, simply get the channel setup with \ref lqt_get_channel_setup.
106  *  It can happen, that this function returns NULL when no specific mapping is known.
107  *
108  *  When encoding, things are more complicated. Some codecs have fixed channel
109  *  setups. After setting up an audio track, call \ref lqt_get_channel_setup to
110  *  check, if there is already a prefefined channel setup. If this is the case (i.e. if non
111  *  NULL is returned), you MUST use this  channel setup.
112  *
113  *  If there is no predefined setup (i.e. \ref lqt_get_channel_setup returns NULL after
114  *  creation of the audio track), call \ref lqt_set_channel_setup to set your desired
115  *  setup. It can happen, that libquicktime will reorder the channel setup. Thus
116  *  you need a final call to \ref lqt_get_channel_setup to know the whole truth.
117 
118 */
119 
120 /** \ingroup log
121  *  \brief Log level
122  */
123 
124 typedef enum
125   {
126     LQT_LOG_ERROR   = (1<<0),
127     LQT_LOG_WARNING = (1<<1),
128     LQT_LOG_INFO    = (1<<2),
129     LQT_LOG_DEBUG   = (1<<3),
130   } lqt_log_level_t;
131 
132 /** \ingroup log
133  *  \brief Log callback
134  *  \param level The log level
135  *  \param domain Log domain (e.g. name of the module)
136  *  \param message The message to pass
137  *  \param data Application supplied data
138  */
139 
140 typedef void (*lqt_log_callback_t)(lqt_log_level_t level,
141                                    const char * domain,
142                                    const char * message,
143                                    void * data);
144 
145 
146 /** \ingroup General
147  *  \brief File types
148  *
149  * These are bitmasks since codecs need lists of supported file formats
150  */
151 
152 typedef enum
153   {
154     LQT_FILE_NONE = 0,        /*!< Undefined or not yet set */
155     LQT_FILE_QT_OLD   = (1<<0), /*!< Old libquicktime format (without ftyp) */
156     LQT_FILE_QT       = (1<<1), /*!< New libquicktime format (ftyp = "qt  ") */
157     LQT_FILE_AVI      = (1<<2), /*!< AVI */
158     LQT_FILE_AVI_ODML = (1<<3), /*!< Opendml AVI (> 2G) */
159     LQT_FILE_MP4      = (1<<4), /*!< .mp4 (ftyp = "mp42") */
160     LQT_FILE_M4A      = (1<<5), /*!< .m4a  */
161     LQT_FILE_3GP      = (1<<6), /*!< .3gp  */
162   } lqt_file_type_t;
163 
164 
165 /** \ingroup multichannel
166  *  \brief Channel definitions
167  *
168  *  These are the channel types defined in the public API. They should
169  *  enable to support most channel configurations. Internally,
170  *  many more channel types exist. They can be added to the public part
171  *  on demand.
172  *
173  */
174 
175 typedef enum
176   {
177     LQT_CHANNEL_UNKNOWN,
178     LQT_CHANNEL_FRONT_LEFT,
179     LQT_CHANNEL_FRONT_RIGHT,
180     LQT_CHANNEL_FRONT_CENTER,
181     LQT_CHANNEL_FRONT_CENTER_LEFT,
182     LQT_CHANNEL_FRONT_CENTER_RIGHT,
183     LQT_CHANNEL_BACK_CENTER,
184     LQT_CHANNEL_BACK_LEFT,
185     LQT_CHANNEL_BACK_RIGHT,
186     LQT_CHANNEL_SIDE_LEFT,
187     LQT_CHANNEL_SIDE_RIGHT,
188     LQT_CHANNEL_LFE,
189   } lqt_channel_t;
190 
191 
192 /** \defgroup video Video
193     \brief Video related definitions and functions
194  */
195 
196 /** \defgroup video_decode Video decoding
197  * \ingroup video
198  * \brief Video related definitions and functions (reading)
199  *
200  * The video API changed a lot during the last years (causing lot of confusion), so here is the
201  * preferred way: First get the number of video tracks with \ref quicktime_video_tracks. Then
202  * for each track you want to decode, use \ref quicktime_supported_video to verify that a codec
203  * is available. Then for each track, get the frame size with \ref quicktime_video_width and
204  * \ref quicktime_video_height . The framerate is only exact when handled as a rational number.
205  * Thus, you'll need 2 functions \ref lqt_video_time_scale and \ref lqt_frame_duration .
206  * The framerate in frames/sec becomes time_scale/frame_duration. Further format information can
207  * be obtained with \ref lqt_get_pixel_aspect, \ref lqt_get_interlace_mode and \ref lqt_get_chroma_placement.
208  *
209  * A very important thing is the colormodel (see \ref color): First obtain the colormodel used natively
210  * by the codec with \ref lqt_get_cmodel. Your application might or might not support all colormodels,
211  * which exist in libquicktime. The more colormodels you can handle yourself, the better, since libquicktimes
212  * built in colormodel converter is not the best. Thus, it's the best idea to pack all colormodels you
213  * can handle yourself into an array, and call \ref lqt_get_best_colormodel to get the best colormodel. After you
214  * figured out, which colormodel you use, tell this to libquicktime with \ref lqt_set_cmodel.
215  *
216  * When decoding frames, libquicktime by default assumes, that the frames you pass to it have no padding bytes
217  * between the scanlines. Some APIs however padd scanlines to certain boundaries. If this is the case, you must
218  * tell this to libquicktime by calling \ref lqt_set_row_span and \ref lqt_set_row_span_uv (for planar formats).
219  *
220  * Then, for each frame, it's wise to get the timestamp with \ref lqt_frame_time before decoding it. This will
221  * make sure, that you'll support tracks with nonconstant framerates. The actual decoding then should happen with
222  * \ref lqt_decode_video.
223  */
224 
225 /** \defgroup video_encode Video encoding
226  *  \ingroup video
227  *  \brief Video related definitions and functions (writing)
228  *
229  * The video API changed a lot during the last years (causing lot of confusion), so here is the
230  * preferred way: Use the \ref codec_registry functions to get all supported video encoders.
231  * Once you found a codec (i.e. a \ref lqt_codec_info_t ), call \ref lqt_add_video_track to
232  * add the track to the file. You can repeat this procedure to add as many tracks as you like
233  * with different formats and/or codecs. You can pass further format parameters with \ref lqt_set_pixel_aspect.
234  *
235  * A very important thing is the colormodel (see \ref color): First obtain the colormodel used natively
236  * by the codec with \ref lqt_get_cmodel. Your application might or might not support all colormodels,
237  * which exist in libquicktime. The more colormodels you can handle yourself, the better, since libquicktimes
238  * built in colormodel converter is not the best. Thus, it's the best idea to pack all colormodels you
239  * can handle yourself into an array, and call \ref lqt_get_best_colormodel to get the best colormodel. After you
240  * figured out, which colormodel you use, tell this to libquicktime with \ref lqt_set_cmodel.
241  *
242  * Next you might want to set some compression parameters. This is done by calling \ref lqt_set_video_parameter.
243  * Supported parameters and valid ranges are in the \ref lqt_codec_info_t.
244  *
245  * Actual encoding should happen with \ref lqt_encode_video.
246  */
247 
248 /** \ingroup video
249  * \brief interlace modes
250  *
251  * This is the interlace mode of a video track. Read it with
252  * \ref lqt_get_interlace_mode .
253  */
254 
255 typedef enum
256   {
257     LQT_INTERLACE_NONE = 0, /*!< No interlacing (= progressive) */
258     LQT_INTERLACE_TOP_FIRST, /*!< Top field first */
259     LQT_INTERLACE_BOTTOM_FIRST  /*!< Bottom field first */
260   } lqt_interlace_mode_t;
261 
262 /** \ingroup video
263  * \brief Chroma placement
264  *
265  * This describes the chroma placement of a video track. Read it with
266  * \ref lqt_get_chroma_placement . Chroma placement makes only sense for
267  * YUV420 formats. For other pixelformats, it is set implicitely to
268  * LQT_CHROMA_PLACEMENT_DEFAULT.
269  */
270 
271 typedef enum
272   {
273     LQT_CHROMA_PLACEMENT_DEFAULT = 0, /*!< MPEG-1, JPEG or non 4:2:0 */
274     LQT_CHROMA_PLACEMENT_MPEG2,       /*!< MPEG-2 */
275     LQT_CHROMA_PLACEMENT_DVPAL,       /*!< DV PAL */
276   } lqt_chroma_placement_t;
277 
278 /** \ingroup audio
279  * \brief Sample format definitions for audio
280  *
281  * This defines the datatype for audio samples, which will be used by a
282  * particular codec. You'll need this, if you want to use \ref lqt_decode_audio_raw
283  * or \ref lqt_encode_audio_raw . Byte order of the data is always machine native.
284  * Endianess conversion is responsibility of the codec.
285  */
286 
287 typedef enum
288   {
289     LQT_SAMPLE_UNDEFINED = 0, /*!< If this is returned, we have an error */
290     LQT_SAMPLE_INT8,      /*!< int8_t */
291     LQT_SAMPLE_UINT8,     /*!< uint8_t */
292     LQT_SAMPLE_INT16,     /*!< int16_t */
293     LQT_SAMPLE_INT32,     /*!< int32_t */
294     LQT_SAMPLE_FLOAT,     /*!< Float (machine native) */
295     LQT_SAMPLE_DOUBLE     /*!< Double (machine native, since version 1.0.3) */
296   } lqt_sample_format_t;
297 
298 /** \ingroup general
299     \brief Quicktime handle
300 
301     Opaque file handle used both for reading and writing. In quicktime4linux, this structure is
302     public, resulting in programmers doing wrong things with it. In libquicktime, this is
303     a private structure, which is accessed exclusively by functions.
304  */
305 
306 typedef struct quicktime_s quicktime_t;
307 
308 /* This is the reference for all your library entry points. */
309 
310 /* ===== compression formats for which codecs exist ====== */
311 
312 /** \defgroup video_codecs Video codec identifiers
313  *  \brief Video codec identifiers
314  *
315  *  These definintions are for some more commonly used codecs.
316  *  They can be used as the compressor argument for \ref quicktime_set_video .
317  *  There is, however, no way to check, if a
318  *  codec is accually present on the system.
319  *  It should also be noted, that libquicktime supports more codecs, than
320  *  are listed here. For these reasons, it's strongly recommended
321  *  to use the more sophisticated codec selection mechanism via the
322  *  \ref codec_registry .
323  */
324 
325 /** \ingroup video_codecs
326  * \brief Non compatible divx
327  *
328  * Never hardcode this in an application!
329  */
330 
331 #define QUICKTIME_DIVX "DIVX"
332 
333 /** \ingroup video_codecs
334  * \brief Divx for AVI files
335  *
336  * Never hardcode this in an application!
337  */
338 
339 #define QUICKTIME_DIV3 "DIV3"
340 
341 /** \ingroup video_codecs
342  * \brief DV
343  *
344  * Never hardcode this in an application!
345  */
346 
347 #define QUICKTIME_DV "dvc "
348 /* AVID DV codec can be processed with libdv as well */
349 
350 /** \ingroup video_codecs
351  * \brief DV
352  *
353  * Never hardcode this in an application!
354  */
355 
356 #define QUICKTIME_DV_AVID "AVdv"
357 
358 /** \ingroup video_codecs
359  * \brief DV
360  *
361  * Never hardcode this in an application!
362  */
363 
364 #define QUICKTIME_DV_AVID_A "dvcp"
365 
366 /** \ingroup video_codecs
367  * \brief Uncompressed RGB.
368  *
369  * Never hardcode this in an application. There are 2 encoders with
370  * this fourcc, one for RGB and one for RGBA.
371  */
372 
373 /* RGB uncompressed.  Allows alpha */
374 #define QUICKTIME_RAW  "raw "
375 
376 /** \ingroup video_codecs
377  * \brief JPEG-Photo
378  *
379  * Might be missing if libjpeg headers aren't there during compilation.
380  */
381 
382 /* Jpeg Photo */
383 #define QUICKTIME_JPEG "jpeg"
384 
385 /* Concatenated png images.  Allows alpha */
386 
387 /** \ingroup video_codecs
388  * \brief JPEG-Photo
389  *
390  * Might be missing if libjpeg headers aren't there during compilation.
391  * There are 2 encoders, one for RGB, the other for RGBA.
392  */
393 
394 #define QUICKTIME_PNG "png "
395 
396 /** \ingroup video_codecs
397  * \brief Motion JPEG-A
398  *
399  * Might be missing if libjpeg headers aren't there during compilation.
400  * A good choice for high quality interlaced storage.
401  */
402 
403 #define QUICKTIME_MJPA "mjpa"
404 
405 /** \ingroup video_codecs
406  * \brief 8 bit Packed full-range (not video) YUV 4:2:2
407  *
408  * Should always be there, can safely be hardcoded.
409  */
410 
411 #define QUICKTIME_YUV2 "yuv2"
412 
413 /** \ingroup video_codecs
414  * \brief YUV 4:2:0
415  *
416  * Not compatible with standard quicktime.
417  */
418 
419 #define QUICKTIME_YUV4 "yuv4"
420 
421 /** \ingroup video_codecs
422  * \brief 8 bit planar YUV 4:2:0
423  *
424  * Practically no external information about this codec exists. It should
425  * always be available, but nevertheless not used.
426  */
427 
428 #define QUICKTIME_YUV420  "yv12"
429 
430 /** \ingroup video_codecs
431  * \brief 8 bit Packed YUV (video range) 4:2:2
432  *
433  * Should always be there, can safely be hardcoded.
434  */
435 
436 #define QUICKTIME_2VUY "2vuy"
437 
438 /** \ingroup video_codecs
439  * \brief 8 bit Packed YUV (video range) 4:2:2
440  *
441  * Should always be there, can safely be hardcoded.
442  */
443 
444 #define QUICKTIME_YUVS "yuvs"
445 
446 
447 /** \ingroup video_codecs
448  * \brief 8 bit Packed YUV 4:4:4
449  *
450  * Should always be there, can safely be hardcoded.
451  */
452 
453 #define QUICKTIME_V308  "v308"
454 
455 /** \ingroup video_codecs
456  * \brief 8 bit Packed YUVA 4:4:4:4
457  *
458  * Should always be there, can safely be hardcoded.
459  */
460 
461 #define QUICKTIME_V408 "v408"
462 
463 /** \ingroup video_codecs
464  * \brief 10 bit Packed YUV 4:2:2
465  *
466  * Should always be there, can safely be hardcoded.
467  */
468 
469 #define QUICKTIME_V210 "v210"
470 
471 /** \ingroup video_codecs
472  * \brief 10 bit Packed YUV 4:4:4
473  *
474  * Should always be there, can safely be hardcoded.
475  */
476 
477 #define QUICKTIME_V410 "v410"
478 
479 /* =================== Audio formats ======================= */
480 
481 /** \defgroup audio_codecs Audio codec identifiers
482  *  \brief Audio codec identifiers
483  *
484  *  These definintions are for some more commonly used codecs.
485  *  They can be used as the compressor argument for \ref quicktime_set_audio .
486  *  There is, however, no way to check, if a
487  *  codec is accually present on the system.
488  *  It should also be noted, that libquicktime supports more codecs, than
489  *  are listed here. For these reasons, it's strongly recommended
490  *  to use the more sophisticated codec selection mechanism via the
491  *  \ref codec_registry .
492  */
493 
494 /** \ingroup audio_codecs
495  * \brief Unsigned 8 bit
496  *
497  * Should always be there, can safely be hardcoded.
498  */
499 
500 #define QUICKTIME_RAWAUDIO "raw "
501 
502 /** \ingroup audio_codecs
503  * \brief IMA4
504  *
505  * Should always be there, can safely be hardcoded.
506  */
507 
508 #define QUICKTIME_IMA4 "ima4"
509 
510 /** \ingroup audio_codecs
511  * \brief Twos compliment 16 bit
512  *
513  * Should always be there, can safely be hardcoded.
514  */
515 
516 #define QUICKTIME_TWOS "twos"
517 
518 /** \ingroup audio_codecs
519  * \brief mu-law 2:1
520  *
521  * Should always be there, can safely be hardcoded.
522  */
523 
524 #define QUICKTIME_ULAW "ulaw"
525 
526 /** \ingroup audio_codecs
527  * \brief Ogg Vorbis
528  *
529  *  This depends on libvorbis and creates incompatible streams,
530  *  which won't play anywhere except libquicktime and perhaps
531  *  quicktime4linux. Never hardcode this.
532  */
533 
534 #define QUICKTIME_VORBIS "OggS"
535 
536 /** \ingroup audio_codecs
537  * \brief MP3
538  *
539  *  This depends on lame, which might or might not be there.
540  *  Never hardcode this.
541  */
542 
543 #define QUICKTIME_MP3 ".mp3"
544 
545 /* =========================== public interface ========================= // */
546 
547 /** \ingroup general
548  *  \brief Get the quicktime4linux major version
549  *
550  * This returns the major quicktime4linux version. The complete version is 2.0.0, which
551  * was the last qt4l version from which we ported code. It's not usable for detecting the
552  * libquicktime version.
553  */
554 
555   /* Get version information */
556 int quicktime_major();
557 
558 /** \ingroup general
559  *  \brief Get the quicktime4linux minor version
560  *
561  * This returns the minor quicktime4linux version. The complete version is 2.0.0, which
562  * was the last qt4l version from which we ported code. It's not usable for detecting the
563  * libquicktime version.
564  */
565 int quicktime_minor();
566 
567 /** \ingroup general
568  *  \brief Get the quicktime4linux release number
569  *
570  * This returns the release number of quicktime4linux. The complete version is 2.0.0, which
571  * was the last qt4l version from which we ported code. It's not usable for detecting the
572  * libquicktime version.
573  */
574 
575 int quicktime_release();
576 
577 /** \ingroup general
578     \brief Test file compatibility
579     \param path A path to a regular file
580     \returns 1 if the file is decodable by libquicktime.
581 
582     Check the signature of a path and return 1 is the file is likely to ba
583     decodable by libquicktime. This check might return false positives or false
584     negatives. In general it's better (although slower) to check, if \ref quicktime_open
585     return NULL or not.
586  */
587 
588 int quicktime_check_sig(char *path);
589 
590 /** \ingroup general
591     \brief Open a file
592     \param filename A path to a regular file
593     \param rd 1 for open readonly, 0 else
594     \param wr 1 for open writeonly, 0 else
595     \returns An initialized file handle or NULL if opening failed.
596 
597     Note, that files can never be opened read/write mode.
598 */
599 
600 quicktime_t* quicktime_open(const char *filename, int rd, int wr);
601 
602 /** \ingroup general
603     \brief Make a file streamable
604     \param in_path Existing non streamable file
605     \param out_path Output file
606     \returns 1 if an error occurred, 0 else
607 
608     This function makes a file streamable by placing the moov header at the beginning of the file.
609     Note that you need approximately the twice the disk-space of the file. It is recommended, that
610     this function is called only for files, which are encoded by libquicktime. Other files might not
611     be correctly written.
612 */
613 
614 int quicktime_make_streamable(char *in_path, char *out_path);
615 
616 /** \defgroup metadata Metadata support
617     \brief Metadata support
618 
619     These functions allow you to read/write the metadata of the file. Currently, only the
620     metadata in the udta atom are supported.
621 */
622 
623 /** \ingroup metadata
624     \brief Set the copyright info for the file
625     \param file A quicktime handle
626     \param string The copyright info
627 */
628 
629 void quicktime_set_copyright(quicktime_t *file, char *string);
630 
631 /** \ingroup metadata
632     \brief Set the name for the file
633     \param file A quicktime handle
634     \param string The name
635 */
636 
637 void quicktime_set_name(quicktime_t *file, char *string);
638 
639 /** \ingroup metadata
640     \brief Set info for the file
641     \param file A quicktime handle
642     \param string An info string
643 */
644 
645 void quicktime_set_info(quicktime_t *file, char *string);
646 
647 /** \ingroup metadata
648     \brief Get the copyright info from the file
649     \param file A quicktime handle
650     \returns The copyright info or NULL
651 */
652 
653 
654 char* quicktime_get_copyright(quicktime_t *file);
655 
656 /** \ingroup metadata
657     \brief Get the name from the file
658     \param file A quicktime handle
659     \returns The name or NULL
660 */
661 
662 
663 char* quicktime_get_name(quicktime_t *file);
664 
665 /** \ingroup metadata
666     \brief Get the info string from the file
667     \param file A quicktime handle
668     \returns The info string or NULL
669 */
670 
671 char* quicktime_get_info(quicktime_t *file);
672 
673 
674 /** \ingroup audio_encode
675     \brief Set up tracks in a new file after opening and before writing
676     \param file A quicktime handle
677     \param channels Number of channels
678     \param sample_rate Samplerate
679     \param bits Bits per sample
680     \param compressor Compressor to use
681 
682     Returns the number of quicktime tracks allocated. Audio is stored two channels
683     per quicktime track.
684 
685     This function is depracated and should not be used in newly written code. It won't let you
686     add individual tracks with different codecs, samplerates etc. Use \ref lqt_add_audio_track instread.
687 */
688 
689 int quicktime_set_audio(quicktime_t *file,
690 	int channels,
691 	long sample_rate,
692 	int bits,
693 	char *compressor);
694 
695 /** \ingroup video_encode
696     \brief Set the framerate for encoding
697     \param file A quicktime handle
698     \param framerate framerate
699 
700     Sets the framerate for encoding.
701 
702     This function is depracated and should not be used in newly written code.
703 */
704 
705 void quicktime_set_framerate(quicktime_t *file, double framerate);
706 
707 /** \ingroup video_encode
708     \brief Set up video tracks for encoding
709     \param file A quicktime handle
710     \param tracks Number of tracks
711     \param frame_w Frame width
712     \param frame_h Frame height
713     \param frame_rate Frame rate (in frames per second)
714     \param compressor Four character code of the compressor
715 
716     This function is depracated and should not be used in newly written code.
717     It won't allow you to set multiple video streams with different formats,
718     and passing a double framerate causes rounding errors.
719     Use \ref lqt_add_video_track instead.
720 */
721 
722 int quicktime_set_video(quicktime_t *file,
723 	int tracks,
724 	int frame_w,
725 	int frame_h,
726 	double frame_rate,
727 	char *compressor);
728 
729 /** \ingroup video_encode
730     \brief Set jpeg encoding quality
731     \param file A quicktime handle
732     \param quality Quality (0..100)
733     \param use_float Use floating point routines
734 
735     Set the jpeg encoding quality and whether to use floating point routines.
736     This should be called after creating the video track(s).
737 
738     This function is depracated and should not be used in newly written code.
739     Use \ref lqt_set_video_parameter instead.
740 */
741 
742 void quicktime_set_jpeg(quicktime_t *file, int quality, int use_float);
743 
744 /** \ingroup video_encode
745  * \brief Set a codec parameter
746  *  \param file A quicktime handle
747  *  \param key Short name of the parameter
748  *  \param value Parameter value.
749  *
750  *  For integer parameters, value must be of the type int*. For string parameters,
751  *  use char*.
752  *
753  *  This function sets the same parameter for all video AND audio streams, which is quite
754  *  idiotic. Use \ref lqt_set_audio_parameter and \ref lqt_set_video_parameter to set
755  *  codec parameters on a per stream basis.
756  */
757 
758 void quicktime_set_parameter(quicktime_t *file, char *key, void *value);
759 
760 /** \ingroup video_encode
761  *  \brief Set the depth of a video track.
762  *  \param file A quicktime handle
763  *  \param depth The depth (bits per pixel)
764  *  \param track index (starting with 0)
765  *
766  *  This function is deprecated and should never be called.
767  *  The depth is set by the codecs and there is no reason to change this.
768  *
769  */
770 void quicktime_set_depth(quicktime_t *file,
771 	int depth,
772 	int track);
773 
774 /** \ingroup video
775  * \brief Set the colormodel for en-/decoding
776  * \param file A quicktime handle
777  * \param colormodel The colormodel to use.
778  *
779  * This sets the colormodels for all video tracks at once.
780  * It's a better idea to use \ref lqt_set_cmodel instead.
781  */
782 
783 void quicktime_set_cmodel(quicktime_t *file, int colormodel);
784 
785 /** \ingroup video
786  * \brief Set the row_span for en-/decoding
787  * \param file A quicktime handle
788  * \param row_span The rowspan to use.
789  *
790  * This sets the rowspans for all video tracks at once.
791  * It's a better idea to use \ref lqt_set_row_span and
792  * \ref lqt_set_row_span_uv instead.
793  */
794 
795 void quicktime_set_row_span(quicktime_t *file, int row_span);
796 
797 /** \ingroup general
798  * \brief Close a quicktime handle and free all associated memory
799  * \param file A quicktime handle
800  */
801 
802 int quicktime_close(quicktime_t *file);
803 
804 /* get length information */
805 /* channel numbers start on 1 for audio and video */
806 
807 /** \ingroup audio_decode
808  *  \brief Get the audio length
809  *  \param file A quicktime handle
810  *  \param track index (starting with 0)
811  *  \returns The total number of uncompressed audio samples in the track
812  */
813 
814 
815 long quicktime_audio_length(quicktime_t *file, int track);
816 
817 /** \ingroup video_decode
818  *  \brief Get the video length
819  *  \param file A quicktime handle
820  *  \param track index (starting with 0)
821  *  \returns The total number of video frames in the track
822  *
823  * Note that for tracks with nonconstant framerate, you won't be able to obtain the
824  * track duration from the number of frame. If you are interested in the total playing time,
825  * use \ref lqt_video_duration
826  */
827 
828 long quicktime_video_length(quicktime_t *file, int track);
829 
830 /** \ingroup audio_decode
831  *  \brief Get the audio position
832  *  \param file A quicktime handle
833  *  \param track index (starting with 0)
834  *  \returns The number (starting with 0) of the next sample to be decoded.
835  */
836 
837   /* get position information */
838 long quicktime_audio_position(quicktime_t *file, int track);
839 
840 /** \ingroup video_decode
841  *  \brief Get the video position
842  *  \param file A quicktime handle
843  *  \param track index (starting with 0)
844  *  \returns The number (starting with 0) of the next frame to be decoded.
845  *
846  *  To get timestamps for tracks with nonconstant framerate, use \ref lqt_frame_time
847  */
848 
849 long quicktime_video_position(quicktime_t *file, int track);
850 
851 /** \ingroup video_decode
852  * \brief Get the number of video tracks
853  * \param file A quicktime handle
854  * \returns The number of video tracks
855  */
856 
857 /* get file information */
858 int quicktime_video_tracks(quicktime_t *file);
859 
860 /** \ingroup audio_decode
861  * \brief Get the number of audio tracks
862  * \param file A quicktime handle
863  * \returns The number of audio tracks
864  */
865 
866 int quicktime_audio_tracks(quicktime_t *file);
867 
868 /** \ingroup audio_decode
869  * \brief Check if a file has at least one audio track
870  * \param file A quicktime handle
871  * \returns 1 if the file has audio tracks, 0 else
872  */
873 
874 int quicktime_has_audio(quicktime_t *file);
875 
876 /** \ingroup audio_decode
877  * \brief Get the samplerate of an audio track
878  * \param file A quicktime handle
879  * \param track index (starting with 0)
880  * \returns The samplerate in Hz
881  */
882 
883 long quicktime_sample_rate(quicktime_t *file, int track);
884 
885 /** \ingroup audio_decode
886  * \brief Get the bits per sample of an audio track
887  * \param file A quicktime handle
888  * \param track index (starting with 0)
889  * \returns The bits per sample (typically 16)
890  *
891  * Don't use this function for anything else than for informational
892  * purposes. Bits per sample is meaningless for compressed codecs, and
893  * sometimes plain wrong even for uncompressed ones.
894  *
895  * To get some better informations about the resolution, a codec will
896  * deliver, use \ref lqt_get_sample_format
897  */
898 
899 int quicktime_audio_bits(quicktime_t *file, int track);
900 
901 /** \ingroup audio_decode
902  * \brief Get the number of channels of an audio track
903  * \param file A quicktime handle
904  * \param track index (starting with 0)
905  * \returns The the number of channels
906  */
907 
908 int quicktime_track_channels(quicktime_t *file, int track);
909 
910 /** \ingroup audio_decode
911  * \brief Get the four character code of an audio track
912  * \param file A quicktime handle
913  * \param track index (starting with 0)
914  * \returns The four character code (fourcc) of the track.
915  *
916  * Note, that this function might return nothing meaningful for AVI files,
917  * since AVI doesn't use four character codes for audio streams.
918  * To get more save information about the codec responsible for the stream,
919  * use \ref lqt_audio_codec_from_file .
920  */
921 
922 char* quicktime_audio_compressor(quicktime_t *file, int track);
923 
924 /** \ingroup video_decode
925  * \brief Check if a file has at least one video track
926  * \param file A quicktime handle
927  * \returns 1 if the file has video tracks, 0 else
928  */
929 
930 int quicktime_has_video(quicktime_t *file);
931 
932 /** \ingroup video_decode
933  * \brief Get the width of a video track
934  * \param file A quicktime handle
935  * \param track index (starting with 0)
936  * \returns The image width in pixels
937  */
938 
939 int quicktime_video_width(quicktime_t *file, int track);
940 
941 /** \ingroup video_decode
942  * \brief Get the height of a video track
943  * \param file A quicktime handle
944  * \param track index (starting with 0)
945  * \returns The image height in pixels
946  */
947 
948 int quicktime_video_height(quicktime_t *file, int track);
949 
950 /** \ingroup video_decode
951  * \brief Get the depth of a video track
952  * \param file A quicktime handle
953  * \param track index (starting with 0)
954  * \returns The image depth in pixels
955  *
956  * Don't use this function for anything else than for informational
957  * purposes. Depth is meaningless for compressed codecs and
958  * sometimes plain wrong even for uncompressed ones.
959  *
960  * To get some better informations about the pixel format, a codec will
961  * deliver, use \ref lqt_get_cmodel or (better) \ref lqt_get_decoder_colormodel .
962  *
963  */
964 int quicktime_video_depth(quicktime_t *file, int track);
965 
966 /** \ingroup video_decode
967  * \brief Get the framerate of a video track
968  * \param file A quicktime handle
969  * \param track index (starting with 0)
970  * \returns The framerate in frames per second.
971  *
972  * Don't use this unless A/V sync is nor important. The return value is practically
973  * random for tracks with nonconstant framerate. Even for constant framerate, the return
974  * value can never correctly resemble e.g. the NTSC framerate (30000/1001).
975  *
976  * To get the framerate as a rational number (and check if it's constant), use \ref lqt_frame_duration
977  * and \ref lqt_video_time_scale .
978  */
979 
980 double quicktime_frame_rate(quicktime_t *file, int track);
981 
982 /** \ingroup video_decode
983  * \brief Get the four character code of a video track
984  * \param file A quicktime handle
985  * \param track index (starting with 0)
986  * \returns The four character code (fourcc) of the track.
987  *
988  * To get more save information about the codec responsible for the stream,
989  * use \ref lqt_video_codec_from_file .
990  */
991 
992 char* quicktime_video_compressor(quicktime_t *file, int track);
993 
994 /* number of bytes of raw data in this frame */
995 
996 /** \ingroup video_decode
997  * \brief Get the compressed size of frame in a video track
998  * \param file A quicktime handle
999  * \param frame Frame index (starting with 0)
1000  * \param track index (starting with 0)
1001  * \returns The size in bytes of the frame
1002  *
1003  * Use this if you want to read compressed frames with \ref quicktime_read_frame
1004  */
1005 
1006 
1007 long quicktime_frame_size(quicktime_t *file, long frame, int track);
1008 
1009 /** \ingroup audio_decode
1010  *  \param file A quicktime handle
1011  *  \param quicktime_track Returns the index of the quicktime track
1012  *  \param quicktime_channel Returns the channel index inside the quicktime track
1013  *  \param channel The channel to query
1014  *
1015  * Don't use this function (see \ref lqt_decode_audio )
1016  */
1017 
1018 int quicktime_channel_location(quicktime_t *file, int *quicktime_track, int *quicktime_channel, int channel);
1019 
1020 /* file positioning */
1021 /* Remove these and see what happens :) */
1022 
1023 // int quicktime_seek_end(quicktime_t *file);
1024 
1025 /** \ingroup General
1026  *  \brief Reposition all tracks to the very beginning
1027  *  \param file A quicktime handle
1028  *  \returns Always 0
1029  *
1030  * Works (of course) only for decoding
1031  */
1032 
1033 int quicktime_seek_start(quicktime_t *file);
1034 
1035 /* set position of file descriptor relative to a track */
1036 
1037 /** \ingroup audio_decode
1038  *  \brief Seek to a specific audio position
1039  * \param file A quicktime handle
1040  * \param sample The sample position (starting with 0)
1041  * \param track index (starting with 0)
1042  *
1043  * Use this for seeking. During sequential decode calls, the position will be updated automatically
1044  */
1045 int quicktime_set_audio_position(quicktime_t *file, int64_t sample, int track);
1046 
1047 /** \ingroup video_decode
1048  *  \brief Seek to a specific video frame
1049  * \param file A quicktime handle
1050  * \param frame The frame position (starting with 0)
1051  * \param track index (starting with 0)
1052  *
1053  * Use this for seeking. During sequential decode calls, the position will be updated automatically.
1054  * If you want to support tracks with nonconmstant framerate, you should use \ref lqt_seek_video .
1055  */
1056 
1057 int quicktime_set_video_position(quicktime_t *file, int64_t frame, int track);
1058 
1059 /* ========================== Access to raw data follows. */
1060 /* write data for one quicktime track */
1061 /* the user must handle conversion to the channels in this track */
1062 int quicktime_write_audio(quicktime_t *file, uint8_t *audio_buffer, long samples, int track);
1063 
1064 /** \ingroup video_encode
1065  *  \brief Write a compressed video frame
1066  *  \param file A quicktime handle
1067  *  \param video_buffer The compressed frame
1068  *  \param bytes Bytes of the compressed frame
1069  *  \param track index (starting with 0)
1070  *
1071  *  If you get compressed video frames (e.g. from a firewire port),
1072  *  use this function to write them into a quicktime container. Before,
1073  *  you must set up the track with \ref lqt_add_video_track or, if no
1074  *  software codec is present, with \ref quicktime_set_video .
1075  */
1076 
1077 
1078 int quicktime_write_frame(quicktime_t *file, uint8_t *video_buffer, int64_t bytes, int track);
1079 
1080 /** \ingroup video_decode
1081  *  \brief Read a compressed video frame
1082  *  \param file A quicktime handle
1083  *  \param video_buffer The compressed frame
1084  *  \param track index (starting with 0)
1085  *
1086  *  Read a compressed video frame. The size of the frame can be obtained with
1087  *  \ref quicktime_frame_size . This function increments all pointers in the
1088  *  track, so you can sequentially read all frames without setting the position
1089  *  in between.
1090  */
1091 
1092 long quicktime_read_frame(quicktime_t *file, unsigned char *video_buffer, int track);
1093 
1094 /* for reading frame using a library that needs a file descriptor */
1095 /* Frame caching doesn't work here. */
1096 int quicktime_read_frame_init(quicktime_t *file, int track);
1097 int quicktime_read_frame_end(quicktime_t *file, int track);
1098 
1099 /* One keyframe table for each track */
1100 long quicktime_get_keyframe_before(quicktime_t *file, long frame, int track);
1101 void quicktime_insert_keyframe(quicktime_t *file, long frame, int track);
1102 /* Track has keyframes */
1103 int quicktime_has_keyframes(quicktime_t *file, int track);
1104 
1105 /* ===================== Access to built in codecs follows. */
1106 
1107 /* If the codec for this track is supported in the library return 1. */
1108 
1109 /** \ingroup video_decode
1110  * \brief Check if a video track is supported by libquicktime
1111  * \param file A quicktime handle
1112  * \param track index (starting with 0)
1113  * \returns 1 if a codec for this track is available, 0 else
1114  */
1115 
1116 int quicktime_supported_video(quicktime_t *file, int track);
1117 
1118 /** \ingroup audio_decode
1119  * \brief Check if an audio track is supported by libquicktime
1120  * \param file A quicktime handle
1121  * \param track index (starting with 0)
1122  * \returns 1 if a codec for this track is available, 0 else
1123  */
1124 
1125 int quicktime_supported_audio(quicktime_t *file, int track);
1126 
1127 /** \ingroup video_decode
1128  * \brief Check if a colormodel is supported for decoding
1129  * \param file A quicktime handle
1130  * \param colormodel A colormodel (see \ref color)
1131  * \param track index (starting with 0)
1132  * \returns 1 if the colormodel can be used for decoding calls, 0 if it can't.
1133  *
1134  * To let libquicktime get the best colormodel out of a list of colormodels your application
1135  * supports, use \ref lqt_get_best_colormodel instead.
1136  */
1137 
1138 int quicktime_reads_cmodel(quicktime_t *file,
1139 		int colormodel,
1140 		int track);
1141 
1142 /** \ingroup video_encode
1143  * \brief Check if a colormodel is supported for encoding
1144  * \param file A quicktime handle
1145  * \param colormodel A colormodel (see \ref color)
1146  * \param track index (starting with 0)
1147  * \returns 1 if the colormodel can be used for encoding calls, 0 if it can't.
1148  *
1149  * To let libquicktime get the best colormodel out of a list of colormodels your application
1150  * supports, use \ref lqt_get_best_colormodel instead.
1151  */
1152 
1153 int quicktime_writes_cmodel(quicktime_t *file,
1154 		int colormodel,
1155 		int track);
1156 
1157 
1158 /* Hacks for temporal codec */
1159 int quicktime_divx_is_key(unsigned char *data, long size);
1160 int quicktime_divx_write_vol(unsigned char *data_start,
1161 	int vol_width,
1162 	int vol_height,
1163 	int time_increment_resolution,
1164 	double frame_rate);
1165 int quicktime_divx_has_vol(unsigned char *data);
1166 
1167 int quicktime_div3_is_key(unsigned char *data, long size);
1168 
1169 /** \ingroup video_encode
1170  * \brief Encode a video frame
1171  * \param file A quicktime handle
1172  * \param row_pointers Frame buffer (see \ref lqt_rows_alloc )
1173  * \param track index (starting with 0)
1174  *
1175  * Encode one video frame. This works only for constant framerate streams. For nonconstant framerates,
1176  * you'll want to use \ref lqt_encode_video instead.
1177  */
1178 
1179 int quicktime_encode_video(quicktime_t *file,
1180 	unsigned char **row_pointers,
1181 	int track);
1182 
1183 /** \ingroup video_decode
1184  * \brief Decode a video frame in \ref BC_RGB888
1185  * \param file A quicktime handle
1186  * \param row_pointers Frame buffer (see \ref lqt_rows_alloc )
1187  * \param track index (starting with 0)
1188  *
1189  * Decode one video frame. All colormodels are converted to \ref BC_RGB888 automatically probably
1190  * causing lots of overhead. To decode frames in other colormodels, use \ref lqt_decode_video .
1191  */
1192 
1193 int quicktime_decode_video(quicktime_t *file,
1194 	unsigned char **row_pointers,
1195 	int track);
1196 
1197 /** \ingroup video_decode
1198  * \brief Decode aand optionally scale a video frame
1199  * \param file A quicktime handle
1200  * \param in_x Horizontal offset of the image relative to the source image
1201  * \param in_y Vertical offset of the image relative to the source image
1202  * \param in_w Image width in the source image
1203  * \param in_h Image height in the source image
1204  * \param out_w Width of output frame
1205  * \param out_h Height of output frame
1206  * \param color_model Colormodel of the output frame
1207  * \param row_pointers Frame buffer (see \ref lqt_rows_alloc )
1208  * \param track index (starting with 0)
1209  *
1210  * This function takes a subwindow of the source image (specified by in_x, in_y, in_w, in_h)
1211  * and scales it to the dimensions (out_w, out_h) of the output frame given by row_pointers. Colormodel
1212  * conversion from the stream colormodel to the color_model you pass is also done. Scaling is done
1213  * by a not very optimized nearest neighbor algorithm. To do high quality video scaling, you should use
1214  * something else.
1215  */
1216 
1217 long quicktime_decode_scaled(quicktime_t *file,
1218 	int in_x,                    /* Location of input frame to take picture */
1219 	int in_y,
1220 	int in_w,
1221 	int in_h,
1222 	int out_w,                   /* Dimensions of output frame */
1223 	int out_h,
1224 	int color_model,             /* One of the color models defined above */
1225 	unsigned char **row_pointers,
1226 	int track);
1227 
1228 /* Decode or encode audio for a single channel into the buffer. */
1229 /* Pass a buffer for the _i or the _f argument if you want int16 or float data. */
1230 /* Notice that encoding requires an array of pointers to each channel. */
1231 
1232 /** \ingroup audio_decode
1233  *  \brief Decode a number of audio samples of a single channel
1234  *  \param file A quicktime handle
1235  *  \param output_i 16 bit integer output buffer (or NULL)
1236  *  \param output_f floating point output buffer (or NULL)
1237  *  \param samples Number of samples to decode
1238  *  \param channel Channel to decode
1239  *
1240  * Never use this function: Decoding only one channel at once causes lots of internal overhead
1241  * if you need all channels anyway. In this case, \ref lqt_decode_audio_track is the better choice.
1242  * Furthermore, you won't be able to decode the full resolution
1243  * for 24 and 32 bit codecs. To decode the maximum resolution, use \ref lqt_decode_audio_raw.
1244  *
1245  * The number of actually decoded samples (and EOF) can be obtained with
1246  * \ref lqt_last_audio_position
1247  */
1248 
1249 int quicktime_decode_audio(quicktime_t *file, int16_t *output_i, float *output_f, long samples, int channel);
1250 
1251 /** \ingroup audio_encode
1252  *  \brief Encode a number of audio samples for the first track
1253  *  \param file A quicktime handle
1254  *  \param input_i 16 bit integer output buffer (or NULL)
1255  *  \param input_f floating point output buffer (or NULL)
1256  *  \param samples Number of samples to decode
1257  *
1258  * Never use this function: It won't let you encode more than one audio track. To encode
1259  * audio for multiple tracks, use \ref lqt_encode_audio_track . If you want to pass the full
1260  * resolution even for 24/32 bit audio, use \ref lqt_encode_audio_raw .
1261  */
1262 
1263 int quicktime_encode_audio(quicktime_t *file, int16_t **input_i, float **input_f, long samples);
1264 
1265 /** \ingroup general
1266  *  \brief Dump the file structures to stdout
1267  *  \param file A quicktime handle
1268  *
1269  * This is used for debugging or by the qtdump utility
1270  */
1271 
1272 int quicktime_dump(quicktime_t *file);
1273 
1274 /* Specify the number of cpus to utilize. */
1275 
1276 /** \ingroup general
1277  *  \brief Set the number of CPUs
1278  *  \param file A quicktime handle
1279  *  \param cpus Number of CPUs to use
1280  *
1281  *  Libquicktime no longer does multithreaded en-/decoding. Therefore you
1282  *  can call this function if you like, but it will have no effect :)
1283  */
1284 
1285 
1286 int quicktime_set_cpus(quicktime_t *file, int cpus);
1287 
1288 /* Specify whether to read contiguously or not. */
1289 /* preload is the number of bytes to read ahead. */
1290 /* This is no longer functional to the end user but is used to accelerate */
1291 /* reading the header internally. */
1292 void quicktime_set_preload(quicktime_t *file, int64_t preload);
1293 
1294 int64_t quicktime_byte_position(quicktime_t *file);
1295 
1296 /** \ingroup general
1297  *  \brief Write an AVI file instead of quicktime
1298  *  \param file A quicktime handle
1299  *  \param value Set this to 1. If you want quicktime, simply don't call this function.
1300  *
1301  * This function must be called AFTER all tracks are set up and BEFORE anything is encoded.
1302  */
1303 
1304 void quicktime_set_avi(quicktime_t *file, int value);
1305 
1306 #pragma GCC visibility pop
1307 
1308 
1309 #ifdef __cplusplus
1310 }
1311 #endif
1312 
1313 #endif
1314