1 /*****************************************************************************
2 * avcodec.h: decoder and encoder using libavcodec
3 *****************************************************************************
4 * Copyright (C) 2001-2008 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 /* VLC <-> avcodec tables */
26 int GetFfmpegCodec( vlc_fourcc_t i_fourcc, int *pi_cat,
27 int *pi_ffmpeg_codec, const char **ppsz_name );
28 int GetVlcFourcc( int i_ffmpeg_codec, int *pi_cat,
29 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
30 void GetVlcAudioFormat( vlc_fourcc_t *, unsigned *pi_bits, int i_sample_fmt );
32 unsigned GetVlcDspMask( void );
34 picture_t * DecodeVideo( decoder_t *, block_t ** );
35 block_t * DecodeAudio( decoder_t *, block_t ** );
36 subpicture_t *DecodeSubtitle( decoder_t *p_dec, block_t ** );
38 /* Video encoder module */
39 int OpenEncoder ( vlc_object_t * );
40 void CloseEncoder( vlc_object_t * );
42 /* Audio encoder module */
43 int OpenAudioEncoder ( vlc_object_t * );
44 void CloseAudioEncoder( vlc_object_t * );
46 /* Deinterlace video filter module */
47 int OpenDeinterlace( vlc_object_t * );
48 void CloseDeinterlace( vlc_object_t * );
51 int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
52 AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );
53 void EndVideoDec( decoder_t *p_dec );
56 int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
57 AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );
58 void EndAudioDec( decoder_t *p_dec );
60 /* Subtitle Decoder */
61 int InitSubtitleDec( decoder_t *p_dec, AVCodecContext *p_context,
62 AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );
63 void EndSubtitleDec( decoder_t *p_dec );
65 /* Initialize decoder */
66 int ffmpeg_OpenCodec( decoder_t *p_dec );
68 /*****************************************************************************
69 * Module descriptor help strings
70 *****************************************************************************/
71 #define DR_TEXT N_("Direct rendering")
72 /* FIXME Does somebody who knows what it does, explain */
73 #define DR_LONGTEXT N_("Direct rendering")
75 #define ERROR_TEXT N_("Error resilience")
76 #define ERROR_LONGTEXT N_( \
77 "libavcodec can do error resilience.\n" \
78 "However, with a buggy encoder (such as the ISO MPEG-4 encoder from M$) " \
79 "this can produce a lot of errors.\n" \
80 "Valid values range from 0 to 4 (0 disables all errors resilience).")
82 #define BUGS_TEXT N_("Workaround bugs")
83 #define BUGS_LONGTEXT N_( \
84 "Try to fix some bugs:\n" \
87 "4 xvid interlaced\n" \
92 "This must be the sum of the values. For example, to fix \"ac vlc\" and " \
93 "\"ump4\", enter 40.")
95 #define HURRYUP_TEXT N_("Hurry up")
96 #define HURRYUP_LONGTEXT N_( \
97 "The decoder can partially decode or skip frame(s) " \
98 "when there is not enough time. It's useful with low CPU power " \
99 "but it can produce distorted pictures.")
101 #define FAST_TEXT N_("Allow speed tricks")
102 #define FAST_LONGTEXT N_( \
103 "Allow non specification compliant speedup tricks. Faster but error-prone.")
105 #define SKIP_FRAME_TEXT N_("Skip frame (default=0)")
106 #define SKIP_FRAME_LONGTEXT N_( \
107 "Force skipping of frames to speed up decoding " \
108 "(-1=None, 0=Default, 1=B-frames, 2=P-frames, 3=B+P frames, 4=all frames)." )
110 #define SKIP_IDCT_TEXT N_("Skip idct (default=0)")
111 #define SKIP_IDCT_LONGTEXT N_( \
112 "Force skipping of idct to speed up decoding for frame types " \
113 "(-1=None, 0=Default, 1=B-frames, 2=P-frames, 3=B+P frames, 4=all frames)." )
115 #define DEBUG_TEXT N_( "Debug mask" )
116 #define DEBUG_LONGTEXT N_( "Set FFmpeg debug mask" )
118 #define CODEC_TEXT N_( "Codec name" )
119 #define CODEC_LONGTEXT N_( "Internal libavcodec codec name" )
121 /* TODO: Use a predefined list, with 0,1,2,4,7 */
122 #define VISMV_TEXT N_( "Visualize motion vectors" )
123 #define VISMV_LONGTEXT N_( \
124 "You can overlay the motion vectors (arrows showing how the images move) "\
125 "on the image. This value is a mask, based on these values:\n"\
126 "1 - visualize forward predicted MVs of P frames\n" \
127 "2 - visualize forward predicted MVs of B frames\n" \
128 "4 - visualize backward predicted MVs of B frames\n" \
129 "To visualize all vectors, the value should be 7." )
131 #define LOWRES_TEXT N_( "Low resolution decoding" )
132 #define LOWRES_LONGTEXT N_( "Only decode a low resolution version of " \
133 "the video. This requires less processing power" )
135 #define SKIPLOOPF_TEXT N_( "Skip the loop filter for H.264 decoding" )
136 #define SKIPLOOPF_LONGTEXT N_( "Skipping the loop filter (aka deblocking) " \
137 "usually has a detrimental effect on quality. However it provides a big " \
138 "speedup for high definition streams." )
140 #define HW_TEXT N_("Hardware decoding")
141 #define HW_LONGTEXT N_("This allows hardware decoding when available.")
143 #define VDA_PIX_FMT_TEXT N_("VDA output pixel format")
144 #define VDA_PIX_FMT_LONGTEXT N_("The pixel format for output image buffers.")
146 #define THREADS_TEXT N_( "Threads" )
147 #define THREADS_LONGTEXT N_( "Number of threads used for decoding, 0 meaning auto" )
152 #define ENC_CFG_PREFIX "sout-avcodec-"
154 #define ENC_KEYINT_TEXT N_( "Ratio of key frames" )
155 #define ENC_KEYINT_LONGTEXT N_( "Number of frames " \
156 "that will be coded for one key frame." )
158 #define ENC_BFRAMES_TEXT N_( "Ratio of B frames" )
159 #define ENC_BFRAMES_LONGTEXT N_( "Number of " \
160 "B frames that will be coded between two reference frames." )
162 #define ENC_VT_TEXT N_( "Video bitrate tolerance" )
163 #define ENC_VT_LONGTEXT N_( "Video bitrate tolerance in kbit/s." )
165 #define ENC_INTERLACE_TEXT N_( "Interlaced encoding" )
166 #define ENC_INTERLACE_LONGTEXT N_( "Enable dedicated " \
167 "algorithms for interlaced frames." )
169 #define ENC_INTERLACE_ME_TEXT N_( "Interlaced motion estimation" )
170 #define ENC_INTERLACE_ME_LONGTEXT N_( "Enable interlaced " \
171 "motion estimation algorithms. This requires more CPU." )
173 #define ENC_PRE_ME_TEXT N_( "Pre-motion estimation" )
174 #define ENC_PRE_ME_LONGTEXT N_( "Enable the pre-motion " \
175 "estimation algorithm.")
177 #define ENC_RC_BUF_TEXT N_( "Rate control buffer size" )
178 #define ENC_RC_BUF_LONGTEXT N_( "Rate control " \
179 "buffer size (in kbytes). A bigger buffer will allow for better rate " \
180 "control, but will cause a delay in the stream." )
182 #define ENC_RC_BUF_AGGR_TEXT N_( "Rate control buffer aggressiveness" )
183 #define ENC_RC_BUF_AGGR_LONGTEXT N_( "Rate control "\
184 "buffer aggressiveness." )
186 #define ENC_IQUANT_FACTOR_TEXT N_( "I quantization factor" )
187 #define ENC_IQUANT_FACTOR_LONGTEXT N_( \
188 "Quantization factor of I frames, compared with P frames (for instance " \
189 "1.0 => same qscale for I and P frames)." )
191 #define ENC_NOISE_RED_TEXT N_( "Noise reduction" )
192 #define ENC_NOISE_RED_LONGTEXT N_( "Enable a simple noise " \
193 "reduction algorithm to lower the encoding length and bitrate, at the " \
194 "expense of lower quality frames." )
196 #define ENC_MPEG4_MATRIX_TEXT N_( "MPEG4 quantization matrix" )
197 #define ENC_MPEG4_MATRIX_LONGTEXT N_( "Use the MPEG4 " \
198 "quantization matrix for MPEG2 encoding. This generally yields a " \
199 "better looking picture, while still retaining the compatibility with " \
200 "standard MPEG2 decoders.")
202 #define ENC_HQ_TEXT N_( "Quality level" )
203 #define ENC_HQ_LONGTEXT N_( "Quality level " \
204 "for the encoding of motions vectors (this can slow down the encoding " \
207 #define ENC_HURRYUP_TEXT N_( "Hurry up" )
208 #define ENC_HURRYUP_LONGTEXT N_( "The encoder " \
209 "can make on-the-fly quality tradeoffs if your CPU can't keep up with " \
210 "the encoding rate. It will disable trellis quantization, then the rate " \
211 "distortion of motion vectors (hq), and raise the noise reduction " \
212 "threshold to ease the encoder's task." )
214 #define ENC_QMIN_TEXT N_( "Minimum video quantizer scale" )
215 #define ENC_QMIN_LONGTEXT N_( "Minimum video " \
218 #define ENC_QMAX_TEXT N_( "Maximum video quantizer scale" )
219 #define ENC_QMAX_LONGTEXT N_( "Maximum video " \
222 #define ENC_TRELLIS_TEXT N_( "Trellis quantization" )
223 #define ENC_TRELLIS_LONGTEXT N_( "Enable trellis " \
224 "quantization (rate distortion for block coefficients)." )
226 #define ENC_QSCALE_TEXT N_( "Fixed quantizer scale" )
227 #define ENC_QSCALE_LONGTEXT N_( "A fixed video " \
228 "quantizer scale for VBR encoding (accepted values: 0.01 to 255.0)." )
230 #define ENC_STRICT_TEXT N_( "Strict standard compliance" )
231 #define ENC_STRICT_LONGTEXT N_( "Force a strict standard " \
232 "compliance when encoding (accepted values: -2 to 2)." )
234 #define ENC_LUMI_MASKING_TEXT N_( "Luminance masking" )
235 #define ENC_LUMI_MASKING_LONGTEXT N_( "Raise the quantizer for " \
236 "very bright macroblocks (default: 0.0)." )
238 #define ENC_DARK_MASKING_TEXT N_( "Darkness masking" )
239 #define ENC_DARK_MASKING_LONGTEXT N_( "Raise the quantizer for " \
240 "very dark macroblocks (default: 0.0)." )
242 #define ENC_P_MASKING_TEXT N_( "Motion masking" )
243 #define ENC_P_MASKING_LONGTEXT N_( "Raise the quantizer for " \
244 "macroblocks with a high temporal complexity (default: 0.0)." )
246 #define ENC_BORDER_MASKING_TEXT N_( "Border masking" )
247 #define ENC_BORDER_MASKING_LONGTEXT N_( "Raise the quantizer " \
248 "for macroblocks at the border of the frame (default: 0.0)." )
250 #define ENC_LUMA_ELIM_TEXT N_( "Luminance elimination" )
251 #define ENC_LUMA_ELIM_LONGTEXT N_( "Eliminates luminance blocks when " \
252 "the PSNR isn't much changed (default: 0.0). The H264 specification " \
255 #define ENC_CHROMA_ELIM_TEXT N_( "Chrominance elimination" )
256 #define ENC_CHROMA_ELIM_LONGTEXT N_( "Eliminates chrominance blocks when " \
257 "the PSNR isn't much changed (default: 0.0). The H264 specification " \
260 #define ENC_PROFILE_TEXT N_( "Specify AAC audio profile to use" )
261 #define ENC_PROFILE_LONGTEXT N_( "Specify the AAC audio profile to use " \
262 "for encoding the audio bitstream. It takes the following options: " \
263 "main, low, ssr (not supported),ltp, hev1, hev2 (default: low). " \
264 "hev1 and hev2 are currently supported only with libfdk-aac enabled libavcodec" )
266 #define AVCODEC_COMMON_MEMBERS \
269 const char *psz_namecodec; \
270 AVCodecContext *p_context; \
274 #ifndef AV_VERSION_INT
275 # define AV_VERSION_INT(a, b, c) ((a)<<16 | (b)<<8 | (c))
278 #if defined(FF_THREAD_FRAME)
279 # define HAVE_AVCODEC_MT
283 /* LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg
284 * a is the major version
285 * b and c the minor and micro versions of libav
286 * d and e the minor and micro versions of FFmpeg */
287 #define LIBAVCODEC_VERSION_CHECK( a, b, c, d, e ) \
288 (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \
289 (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) )
292 /* Uncomment it to enable compilation with vaapi/dxva2/vda (you also must change the build
294 //#define HAVE_AVCODEC_VAAPI 1
295 //#define HAVE_AVCODEC_DXVA2 1
296 //#define HAVE_AVCODEC_VDA 1
298 /* Ugly ifdefinitions to provide backwards compatibility with older ffmpeg/libav
300 #ifndef AV_CPU_FLAG_FORCE
301 # define AV_CPU_FLAG_FORCE FF_MM_FORCE
302 # define AV_CPU_FLAG_MMX FF_MM_MMX
303 # define AV_CPU_FLAG_3DNOW FF_MM_3DNOW
304 # define AV_CPU_FLAG_MMX2 FF_MM_MMX2
305 # define AV_CPU_FLAG_SSE FF_MM_SSE
306 # define AV_CPU_FLAG_SSE2 FF_MM_SSE2
307 # define AV_CPU_FLAG_SSE2SLOW FF_MM_SSE2SLOW
308 # define AV_CPU_FLAG_3DNOWEXT FF_MM_3DNOWEXT
309 # define AV_CPU_FLAG_SSE3 FF_MM_SSE3
310 # define AV_CPU_FLAG_SSE3SLOW FF_MM_SSE3SLOW
311 # define AV_CPU_FLAG_SSSE3 FF_MM_SSSE3
312 # define AV_CPU_FLAG_SSE4 FF_MM_SSE4
313 # define AV_CPU_FLAG_SSE42 FF_MM_SSE42
314 # define AV_CPU_FLAG_IWMMXT FF_MM_IWMMXT
315 # define AV_CPU_FLAG_ALTIVEC FF_MM_ALTIVEC
318 #if LIBAVCODEC_VERSION_MAJOR < 53
319 # define AVMediaType CodecType
320 # define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
321 # define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
322 # define AVMEDIA_TYPE_SUBTITLE CODEC_TYPE_SUBTITLE
323 # define AVMEDIA_TYPE_DATA CODEC_TYPE_DATA
324 # define AVMEDIA_TYPE_ATTACHMENT CODEC_TYPE_ATTACHMENT
327 #if LIBAVCODEC_VERSION_MAJOR < 54
328 # define AV_PICTURE_TYPE_B FF_B_TYPE
329 # define AV_PICTURE_TYPE_I FF_I_TYPE
330 # define AV_PICTURE_TYPE_P FF_P_TYPE
332 # define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE
333 # define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8
334 # define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16
335 # define AV_SAMPLE_FMT_S32 SAMPLE_FMT_S32
336 # define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT
337 # define AV_SAMPLE_FMT_DBL SAMPLE_FMT_DBL
339 #ifndef AV_CH_FRONT_LEFT
340 # define AV_CH_FRONT_LEFT CH_FRONT_LEFT
342 #ifndef AV_CH_FRONT_RIGHT
343 # define AV_CH_FRONT_RIGHT CH_FRONT_RIGHT
345 #ifndef AV_CH_FRONT_CENTER
346 # define AV_CH_FRONT_CENTER CH_FRONT_CENTER
348 #ifndef AV_CH_LOW_FREQUENCY
349 # define AV_CH_LOW_FREQUENCY CH_LOW_FREQUENCY
351 #ifndef AV_CH_BACK_LEFT
352 # define AV_CH_BACK_LEFT CH_BACK_LEFT
354 #ifndef AV_CH_BACK_RIGHT
355 # define AV_CH_BACK_RIGHT CH_BACK_RIGHT
357 #ifndef AV_CH_FRONT_LEFT_OF_CENTER
358 # define AV_CH_FRONT_LEFT_OF_CENTER CH_FRONT_LEFT_OF_CENTER
360 #ifndef AV_CH_FRONT_RIGHT_OF_CENTER
361 # define AV_CH_FRONT_RIGHT_OF_CENTER CH_FRONT_RIGHT_OF_CENTER
363 #ifndef AV_CH_BACK_CENTER
364 # define AV_CH_BACK_CENTER CH_BACK_CENTER
366 #ifndef AV_CH_SIDE_LEFT
367 # define AV_CH_SIDE_LEFT CH_SIDE_LEFT
369 #ifndef AV_CH_SIDE_RIGHT
370 # define AV_CH_SIDE_RIGHT CH_SIDE_RIGHT
372 #ifndef AV_CH_TOP_CENTER
373 # define AV_CH_TOP_CENTER CH_TOP_CENTER
375 #ifndef AV_CH_TOP_FRONT_LEFT
376 # define AV_CH_TOP_FRONT_LEFT CH_TOP_FRONT_LEFT
378 #ifndef AV_CH_TOP_FRONT_CENTER
379 # define AV_CH_TOP_FRONT_CENTER CH_TOP_FRONT_CENTER
381 #ifndef AV_CH_TOP_FRONT_RIGHT
382 # define AV_CH_TOP_FRONT_RIGHT CH_TOP_FRONT_RIGHT
384 #ifndef AV_CH_TOP_BACK_LEFT
385 # define AV_CH_TOP_BACK_LEFT CH_TOP_BACK_LEFT
387 #ifndef AV_CH_TOP_BACK_CENTER
388 # define AV_CH_TOP_BACK_CENTER CH_TOP_BACK_CENTER
390 #ifndef AV_CH_TOP_BACK_RIGHT
391 # define AV_CH_TOP_BACK_RIGHT CH_TOP_BACK_RIGHT
393 #ifndef AV_CH_STEREO_LEFT
394 # define AV_CH_STEREO_LEFT CH_STEREO_LEFT
396 #ifndef AV_CH_STEREO_RIGHT
397 # define AV_CH_STEREO_RIGHT CH_STEREO_RIGHT
403 #ifndef AV_PKT_FLAG_KEY
404 # define AV_PKT_FLAG_KEY PKT_FLAG_KEY