avcodec.h 11.1 KB
Newer Older
1
/*****************************************************************************
2
 * avcodec.h: decoder and encoder using libavcodec
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2001-2008 VLC authors and VideoLAN
Carlo Calabrò's avatar
Carlo Calabrò committed
5
 * $Id$
6
7
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
Sam Hocevar's avatar
Sam Hocevar committed
8
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
9
10
11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12
 * (at your option) any later version.
Sam Hocevar's avatar
Sam Hocevar committed
13
 *
14
15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
16
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
19
20
21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
23
 *****************************************************************************/

24
#include "chroma.h"
25
26
#include "avcommon.h"

27
/* VLC <-> avcodec tables */
28
29
30
31
int GetFfmpegCodec( vlc_fourcc_t i_fourcc, int *pi_cat,
                    int *pi_ffmpeg_codec, const char **ppsz_name );
int GetVlcFourcc( int i_ffmpeg_codec, int *pi_cat,
                  vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
32
vlc_fourcc_t GetVlcAudioFormat( int i_sample_fmt );
33

34
35
picture_t * DecodeVideo( decoder_t *, block_t ** );
block_t * DecodeAudio( decoder_t *, block_t ** );
36
subpicture_t *DecodeSubtitle( decoder_t *p_dec, block_t ** );
37

gbazin's avatar
   
gbazin committed
38
/* Video encoder module */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
39
40
int  OpenEncoder ( vlc_object_t * );
void CloseEncoder( vlc_object_t * );
41

gbazin's avatar
   
gbazin committed
42
/* Audio encoder module */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
43
44
int  OpenAudioEncoder ( vlc_object_t * );
void CloseAudioEncoder( vlc_object_t * );
45

46
/* Deinterlace video filter module */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
47
48
int  OpenDeinterlace( vlc_object_t * );
void CloseDeinterlace( vlc_object_t * );
hartman's avatar
hartman committed
49

Rafaël Carré's avatar
Rafaël Carré committed
50
51
52
53
54
55
56
57
58
/* Video Decoder */
int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
                  AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );
void EndVideoDec( decoder_t *p_dec );

/* Audio Decoder */
int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
                  AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );

59
60
61
62
/* Subtitle Decoder */
int InitSubtitleDec( decoder_t *p_dec, AVCodecContext *p_context,
                     AVCodec *p_codec, int i_codec_id, const char *psz_namecodec );

63
64
/* Initialize decoder */
int ffmpeg_OpenCodec( decoder_t *p_dec );
65

gbazin's avatar
   
gbazin committed
66
67
68
69
/*****************************************************************************
 * Module descriptor help strings
 *****************************************************************************/
#define DR_TEXT N_("Direct rendering")
70
/* FIXME Does somebody who knows what it does, explain */
gbazin's avatar
   
gbazin committed
71
72
73

#define ERROR_TEXT N_("Error resilience")
#define ERROR_LONGTEXT N_( \
74
    "libavcodec can do error resilience.\n" \
75
76
    "However, with a buggy encoder (such as the ISO MPEG-4 encoder from M$) " \
    "this can produce a lot of errors.\n" \
gbazin's avatar
gbazin committed
77
    "Valid values range from 0 to 4 (0 disables all errors resilience).")
gbazin's avatar
   
gbazin committed
78
79
80

#define BUGS_TEXT N_("Workaround bugs")
#define BUGS_LONGTEXT N_( \
81
    "Try to fix some bugs:\n" \
gbazin's avatar
   
gbazin committed
82
83
84
85
86
87
    "1  autodetect\n" \
    "2  old msmpeg4\n" \
    "4  xvid interlaced\n" \
    "8  ump4 \n" \
    "16 no padding\n" \
    "32 ac vlc\n" \
zorglub's avatar
zorglub committed
88
89
90
    "64 Qpel chroma.\n" \
    "This must be the sum of the values. For example, to fix \"ac vlc\" and " \
    "\"ump4\", enter 40.")
gbazin's avatar
   
gbazin committed
91
92
93

#define HURRYUP_TEXT N_("Hurry up")
#define HURRYUP_LONGTEXT N_( \
94
    "The decoder can partially decode or skip frame(s) " \
gbazin's avatar
   
gbazin committed
95
96
97
    "when there is not enough time. It's useful with low CPU power " \
    "but it can produce distorted pictures.")

98
99
100
101
#define FAST_TEXT N_("Allow speed tricks")
#define FAST_LONGTEXT N_( \
    "Allow non specification compliant speedup tricks. Faster but error-prone.")

102
103
104
105
106
107
108
#define SKIP_FRAME_TEXT N_("Skip frame (default=0)")
#define SKIP_FRAME_LONGTEXT N_( \
    "Force skipping of frames to speed up decoding " \
    "(-1=None, 0=Default, 1=B-frames, 2=P-frames, 3=B+P frames, 4=all frames)." )

#define SKIP_IDCT_TEXT N_("Skip idct (default=0)")
#define SKIP_IDCT_LONGTEXT N_( \
Christoph Miebach's avatar
Christoph Miebach committed
109
    "Force skipping of idct to speed up decoding for frame types " \
110
111
    "(-1=None, 0=Default, 1=B-frames, 2=P-frames, 3=B+P frames, 4=all frames)." )

112
113
114
#define IGNORECROP_TEXT N_("Discard cropping information")
#define IGNORECROP_LONGTEXT N_("Discard internal cropping parameters (e.g. from H.264 SPS)." )

115
#define DEBUG_TEXT N_( "Debug mask" )
116
#define DEBUG_LONGTEXT N_( "Set FFmpeg debug mask" )
117

118
119
120
#define CODEC_TEXT N_( "Codec name" )
#define CODEC_LONGTEXT N_( "Internal libavcodec codec name" )

zorglub's avatar
zorglub committed
121
/* TODO: Use a predefined list, with 0,1,2,4,7 */
gbazin's avatar
gbazin committed
122
#define VISMV_TEXT N_( "Visualize motion vectors" )
zorglub's avatar
zorglub committed
123
124
125
#define VISMV_LONGTEXT N_( \
    "You can overlay the motion vectors (arrows showing how the images move) "\
    "on the image. This value is a mask, based on these values:\n"\
gbazin's avatar
gbazin committed
126
127
    "1 - visualize forward predicted MVs of P frames\n" \
    "2 - visualize forward predicted MVs of B frames\n" \
zorglub's avatar
zorglub committed
128
129
    "4 - visualize backward predicted MVs of B frames\n" \
    "To visualize all vectors, the value should be 7." )
gbazin's avatar
gbazin committed
130

131
132
#define SKIPLOOPF_TEXT N_( "Skip the loop filter for H.264 decoding" )
#define SKIPLOOPF_LONGTEXT N_( "Skipping the loop filter (aka deblocking) " \
zorglub's avatar
zorglub committed
133
134
    "usually has a detrimental effect on quality. However it provides a big " \
    "speedup for high definition streams." )
135

136
137
138
#define HW_TEXT N_("Hardware decoding")
#define HW_LONGTEXT N_("This allows hardware decoding when available.")

139
140
141
#define VDA_PIX_FMT_TEXT N_("VDA output pixel format")
#define VDA_PIX_FMT_LONGTEXT N_("The pixel format for output image buffers.")

Laurent Aimar's avatar
Laurent Aimar committed
142
143
144
#define THREADS_TEXT N_( "Threads" )
#define THREADS_LONGTEXT N_( "Number of threads used for decoding, 0 meaning auto" )

145
146
147
/*
 * Encoder options
 */
148
#define ENC_CFG_PREFIX "sout-avcodec-"
149
150

#define ENC_KEYINT_TEXT N_( "Ratio of key frames" )
151
#define ENC_KEYINT_LONGTEXT N_( "Number of frames " \
152
153
154
  "that will be coded for one key frame." )

#define ENC_BFRAMES_TEXT N_( "Ratio of B frames" )
155
#define ENC_BFRAMES_LONGTEXT N_( "Number of " \
156
157
158
  "B frames that will be coded between two reference frames." )

#define ENC_VT_TEXT N_( "Video bitrate tolerance" )
159
#define ENC_VT_LONGTEXT N_( "Video bitrate tolerance in kbit/s." )
160

zorglub's avatar
zorglub committed
161
#define ENC_INTERLACE_TEXT N_( "Interlaced encoding" )
162
#define ENC_INTERLACE_LONGTEXT N_( "Enable dedicated " \
163
  "algorithms for interlaced frames." )
164

zorglub's avatar
zorglub committed
165
#define ENC_INTERLACE_ME_TEXT N_( "Interlaced motion estimation" )
166
#define ENC_INTERLACE_ME_LONGTEXT N_( "Enable interlaced " \
zorglub's avatar
zorglub committed
167
  "motion estimation algorithms. This requires more CPU." )
168

zorglub's avatar
zorglub committed
169
#define ENC_PRE_ME_TEXT N_( "Pre-motion estimation" )
170
171
#define ENC_PRE_ME_LONGTEXT N_( "Enable the pre-motion " \
  "estimation algorithm.")
172
173

#define ENC_RC_BUF_TEXT N_( "Rate control buffer size" )
174
#define ENC_RC_BUF_LONGTEXT N_( "Rate control " \
zorglub's avatar
zorglub committed
175
176
  "buffer size (in kbytes). A bigger buffer will allow for better rate " \
  "control, but will cause a delay in the stream." )
177

178
#define ENC_RC_BUF_AGGR_TEXT N_( "Rate control buffer aggressiveness" )
zorglub's avatar
zorglub committed
179
#define ENC_RC_BUF_AGGR_LONGTEXT N_( "Rate control "\
180
  "buffer aggressiveness." )
181

182
#define ENC_IQUANT_FACTOR_TEXT N_( "I quantization factor" )
183
184
#define ENC_IQUANT_FACTOR_LONGTEXT N_(  \
  "Quantization factor of I frames, compared with P frames (for instance " \
185
  "1.0 => same qscale for I and P frames)." )
186
187

#define ENC_NOISE_RED_TEXT N_( "Noise reduction" )
188
#define ENC_NOISE_RED_LONGTEXT N_( "Enable a simple noise " \
189
190
  "reduction algorithm to lower the encoding length and bitrate, at the " \
  "expense of lower quality frames." )
191

zorglub's avatar
zorglub committed
192
193
194
#define ENC_MPEG4_MATRIX_TEXT N_( "MPEG4 quantization matrix" )
#define ENC_MPEG4_MATRIX_LONGTEXT N_( "Use the MPEG4 " \
  "quantization matrix for MPEG2 encoding. This generally yields a " \
195
  "better looking picture, while still retaining the compatibility with " \
zorglub's avatar
zorglub committed
196
  "standard MPEG2 decoders.")
197
198

#define ENC_HQ_TEXT N_( "Quality level" )
199
#define ENC_HQ_LONGTEXT N_( "Quality level " \
200
201
  "for the encoding of motions vectors (this can slow down the encoding " \
  "very much)." )
202
203

#define ENC_HURRYUP_TEXT N_( "Hurry up" )
204
205
#define ENC_HURRYUP_LONGTEXT N_( "The encoder " \
  "can make on-the-fly quality tradeoffs if your CPU can't keep up with " \
206
  "the encoding rate. It will disable trellis quantization, then the rate " \
207
  "distortion of motion vectors (hq), and raise the noise reduction " \
208
  "threshold to ease the encoder's task." )
209
210

#define ENC_QMIN_TEXT N_( "Minimum video quantizer scale" )
zorglub's avatar
zorglub committed
211
#define ENC_QMIN_LONGTEXT N_( "Minimum video " \
212
213
214
  "quantizer scale." )

#define ENC_QMAX_TEXT N_( "Maximum video quantizer scale" )
zorglub's avatar
zorglub committed
215
#define ENC_QMAX_LONGTEXT N_( "Maximum video " \
216
217
  "quantizer scale." )

zorglub's avatar
zorglub committed
218
#define ENC_TRELLIS_TEXT N_( "Trellis quantization" )
219
#define ENC_TRELLIS_LONGTEXT N_( "Enable trellis " \
220
  "quantization (rate distortion for block coefficients)." )
gbazin's avatar
gbazin committed
221

zorglub's avatar
zorglub committed
222
#define ENC_QSCALE_TEXT N_( "Fixed quantizer scale" )
223
#define ENC_QSCALE_LONGTEXT N_( "A fixed video " \
gbazin's avatar
gbazin committed
224
225
226
  "quantizer scale for VBR encoding (accepted values: 0.01 to 255.0)." )

#define ENC_STRICT_TEXT N_( "Strict standard compliance" )
227
#define ENC_STRICT_LONGTEXT N_( "Force a strict standard " \
228
  "compliance when encoding (accepted values: -2 to 2)." )
229
230

#define ENC_LUMI_MASKING_TEXT N_( "Luminance masking" )
231
#define ENC_LUMI_MASKING_LONGTEXT N_( "Raise the quantizer for " \
232
233
234
  "very bright macroblocks (default: 0.0)." )

#define ENC_DARK_MASKING_TEXT N_( "Darkness masking" )
235
#define ENC_DARK_MASKING_LONGTEXT N_( "Raise the quantizer for " \
236
237
238
  "very dark macroblocks (default: 0.0)." )

#define ENC_P_MASKING_TEXT N_( "Motion masking" )
239
#define ENC_P_MASKING_LONGTEXT N_( "Raise the quantizer for " \
240
241
242
  "macroblocks with a high temporal complexity (default: 0.0)." )

#define ENC_BORDER_MASKING_TEXT N_( "Border masking" )
243
#define ENC_BORDER_MASKING_LONGTEXT N_( "Raise the quantizer " \
244
245
246
247
248
249
250
251
252
253
254
  "for macroblocks at the border of the frame (default: 0.0)." )

#define ENC_LUMA_ELIM_TEXT N_( "Luminance elimination" )
#define ENC_LUMA_ELIM_LONGTEXT N_( "Eliminates luminance blocks when " \
  "the PSNR isn't much changed (default: 0.0). The H264 specification " \
  "recommends -4." )

#define ENC_CHROMA_ELIM_TEXT N_( "Chrominance elimination" )
#define ENC_CHROMA_ELIM_LONGTEXT N_( "Eliminates chrominance blocks when " \
  "the PSNR isn't much changed (default: 0.0). The H264 specification " \
  "recommends 7." )
255

256
257
258
#define ENC_PROFILE_TEXT N_( "Specify AAC audio profile to use" )
#define ENC_PROFILE_LONGTEXT N_( "Specify the AAC audio profile to use " \
   "for encoding the audio bitstream. It takes the following options: " \
259
   "main, low, ssr (not supported),ltp, hev1, hev2 (default: low). " \
260
   "hev1 and hev2 are currently supported only with libfdk-aac enabled libavcodec" )
261

262
#define AVCODEC_COMMON_MEMBERS   \
263
264
    int i_cat;                  \
    int i_codec_id;             \
265
    const char *psz_namecodec;  \
266
    AVCodecContext *p_context;  \
267
268
    AVCodec        *p_codec;    \
    bool b_delayed_open;
269

270
271
272
273
#ifndef AV_VERSION_INT
#   define AV_VERSION_INT(a, b, c) ((a)<<16 | (b)<<8 | (c))
#endif

274
275
276
277
#if defined(FF_THREAD_FRAME)
#   define HAVE_AVCODEC_MT
#endif