1 Fix build with ffmpeg-2.0.
2 Fix segfaults introduced by wrong usage of the av_dict API.
3 Fix forgotten parts in the libav9 patch.
4
5 Index: transcode-1.1.7/encode/encode_lavc.c
6 ===================================================================
7 --- transcode-1.1.7.orig/encode/encode_lavc.c
8 +++ transcode-1.1.7/encode/encode_lavc.c
9 @@ -74,6 +74,9 @@ struct tclavcconfigdata_ {
10 int lmin;
11 int lmax;
12 int me_method;
13 + int luma_elim_threshold;
14 + int chroma_elim_threshold;
15 + int quantizer_noise_shaping;
16
17 /* same as above for flags */
18 struct {
19 @@ -114,7 +117,7 @@ struct tclavcprivatedata_ {
20
21 AVFrame ff_venc_frame;
22 AVCodecContext ff_vcontext;
23 - AVDictionary ** ff_opts;
24 + AVDictionary * ff_opts;
25
26 AVCodec *ff_vcodec;
27
28 @@ -165,6 +168,7 @@ static const TCCodecID tc_lavc_codecs_ou
29 TC_CODEC_ERROR
30 };
31
32 +#if LIBAVCODEC_VERSION_MAJOR < 55
33 static const enum CodecID tc_lavc_internal_codecs[] = {
34 CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO, CODEC_ID_MPEG4,
35 CODEC_ID_H263I, CODEC_ID_H263P,
36 @@ -177,6 +181,20 @@ static const enum CodecID tc_lavc_intern
37 CODEC_ID_MSMPEG4V2, CODEC_ID_MSMPEG4V3,
38 CODEC_ID_NONE
39 };
40 +#else
41 +static const enum AVCodecID tc_lavc_internal_codecs[] = {
42 + AV_CODEC_ID_MPEG1VIDEO, AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_MPEG4,
43 + AV_CODEC_ID_H263I, AV_CODEC_ID_H263P,
44 + AV_CODEC_ID_H264,
45 + AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2,
46 + AV_CODEC_ID_RV10,
47 + AV_CODEC_ID_HUFFYUV, AV_CODEC_ID_FFV1,
48 + AV_CODEC_ID_DVVIDEO,
49 + AV_CODEC_ID_MJPEG, AV_CODEC_ID_LJPEG,
50 + AV_CODEC_ID_MSMPEG4V2, AV_CODEC_ID_MSMPEG4V3,
51 + AV_CODEC_ID_NONE
52 +};
53 +#endif
54
55 static const TCFormatID tc_lavc_formats[] = { TC_FORMAT_ERROR };
56
57 @@ -938,7 +956,11 @@ static int tc_lavc_settings_from_vob(TCL
58 static void tc_lavc_config_defaults(TCLavcPrivateData *pd)
59 {
60 /* first of all reinitialize lavc data */
61 +#if LIBAVCODEC_VERSION_MAJOR < 55
62 avcodec_get_context_defaults(&pd->ff_vcontext);
63 +#else
64 + avcodec_get_context_defaults3(&pd->ff_vcontext, NULL);
65 +#endif
66
67 pd->confdata.thread_count = 1;
68
69 @@ -976,8 +998,8 @@ static void tc_lavc_config_defaults(TCLa
70 pd->ff_vcontext.mpeg_quant = 0;
71 pd->ff_vcontext.rc_initial_cplx = 0.0;
72 pd->ff_vcontext.rc_qsquish = 1.0;
73 - pd->ff_vcontext.luma_elim_threshold = 0;
74 - pd->ff_vcontext.chroma_elim_threshold = 0;
75 + pd->confdata.luma_elim_threshold = 0;
76 + pd->confdata.chroma_elim_threshold = 0;
77 pd->ff_vcontext.strict_std_compliance = 0;
78 pd->ff_vcontext.dct_algo = FF_DCT_AUTO;
79 pd->ff_vcontext.idct_algo = FF_IDCT_AUTO;
80 @@ -1001,7 +1023,7 @@ static void tc_lavc_config_defaults(TCLa
81 pd->ff_vcontext.intra_quant_bias = FF_DEFAULT_QUANT_BIAS;
82 pd->ff_vcontext.inter_quant_bias = FF_DEFAULT_QUANT_BIAS;
83 pd->ff_vcontext.noise_reduction = 0;
84 - pd->ff_vcontext.quantizer_noise_shaping = 0;
85 + pd->confdata.quantizer_noise_shaping = 0;
86 pd->ff_vcontext.flags = 0;
87 }
88
89 @@ -1033,7 +1055,6 @@ static void tc_lavc_dispatch_settings(TC
90
91 pd->ff_vcontext.flags = 0;
92 SET_FLAG(pd, mv0);
93 - SET_FLAG(pd, cbp);
94 SET_FLAG(pd, qpel);
95 SET_FLAG(pd, naq);
96 SET_FLAG(pd, ilme);
97 @@ -1060,17 +1081,29 @@ static void tc_lavc_dispatch_settings(TC
98 pd->ff_vcontext.flags |= CODEC_FLAG_INTERLACED_ME;
99 }
100 if (pd->confdata.flags.alt) {
101 - av_dict_set(pd->ff_opts, "alternate_scan", "1", 0);
102 + av_dict_set(&(pd->ff_opts), "alternate_scan", "1", 0);
103 }
104 if (pd->confdata.flags.vdpart) {
105 - av_dict_set(pd->ff_opts, "data_partitioning", "1", 0);
106 + av_dict_set(&(pd->ff_opts), "data_partitioning", "1", 0);
107 }
108 if (pd->confdata.flags.umv) {
109 - av_dict_set(pd->ff_opts, "umv", "1", 0);
110 + av_dict_set(&(pd->ff_opts), "umv", "1", 0);
111 }
112 if (pd->confdata.flags.aiv) {
113 - av_dict_set(pd->ff_opts, "aiv", "1", 0);
114 + av_dict_set(&(pd->ff_opts), "aiv", "1", 0);
115 }
116 + if (pd->confdata.flags.cbp) {
117 + av_dict_set(&(pd->ff_opts), "mpv_flags", "+cbp_rd", 0);
118 + }
119 +
120 + char buf[1024];
121 +#define set_dict_opt(val, opt) \
122 + snprintf(buf, sizeof(buf), "%i", pd->confdata.val);\
123 + av_dict_set(&(pd->ff_opts), opt, buf, 0)
124 +
125 + set_dict_opt(luma_elim_threshold, "luma_elim_threshold");
126 + set_dict_opt(chroma_elim_threshold, "chroma_elim_threshold");
127 + set_dict_opt(quantizer_noise_shaping, "quantizer_noise_shaping");
128 }
129
130 #undef SET_FLAG
131 @@ -1155,8 +1188,8 @@ static int tc_lavc_read_config(TCLavcPri
132 { "vrc_init_cplx", PCTX(rc_initial_cplx), TCCONF_TYPE_FLOAT, TCCONF_FLAG_RANGE, 0.0, 9999999.0 },
133 // { "vrc_init_occupancy", }, // not yet supported
134 { "vqsquish", PCTX(rc_qsquish), TCCONF_TYPE_FLOAT, TCCONF_FLAG_RANGE, 0.0, 99.0 },
135 - { "vlelim", PCTX(luma_elim_threshold), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -99, 99 },
136 - { "vcelim", PCTX(chroma_elim_threshold), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -99, 99 },
137 + { "vlelim", PAUX(luma_elim_threshold), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -99, 99 },
138 + { "vcelim", PAUX(chroma_elim_threshold), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -99, 99 },
139 { "vstrict", PCTX(strict_std_compliance), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -99, 99 },
140 { "vpsize", PCTX(rtp_payload_size), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 100000000 },
141 { "dct", PCTX(dct_algo), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 10 },
142 @@ -1182,12 +1215,12 @@ static int tc_lavc_read_config(TCLavcPri
143 { "ibias", PCTX(intra_quant_bias), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -512, 512 },
144 { "pbias", PCTX(inter_quant_bias), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, -512, 512 },
145 { "nr", PCTX(noise_reduction), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 1000000},
146 - { "qns", PCTX(quantizer_noise_shaping), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 3 },
147 + { "qns", PAUX(quantizer_noise_shaping), TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 3 },
148 { "inter_matrix_file", inter_matrix_file, TCCONF_TYPE_STRING, 0, 0, 0 },
149 { "intra_matrix_file", intra_matrix_file, TCCONF_TYPE_STRING, 0, 0, 0 },
150
151 { "mv0", PAUX(flags.mv0), TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_MV0 },
152 - { "cbp", PAUX(flags.cbp), TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CBP_RD },
153 + { "cbp", PAUX(flags.cbp), TCCONF_TYPE_FLAG, 0, 0, 1 },
154 { "qpel", PAUX(flags.qpel), TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QPEL },
155 { "alt", PAUX(flags.alt), TCCONF_TYPE_FLAG, 0, 0, 1 },
156 { "ilme", PAUX(flags.ilme), TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_INTERLACED_ME },
157 @@ -1350,6 +1383,8 @@ static int tc_lavc_configure(TCModuleIns
158
159 pd = self->userdata;
160
161 + pd->ff_opts = NULL;
162 +
163 pd->flush_flag = vob->encoder_flush;
164
165 /* FIXME: move into core? */
166 @@ -1402,7 +1437,7 @@ static int tc_lavc_configure(TCModuleIns
167 }
168
169 TC_LOCK_LIBAVCODEC;
170 - ret = avcodec_open2(&pd->ff_vcontext, pd->ff_vcodec, pd->ff_opts);
171 + ret = avcodec_open2(&pd->ff_vcontext, pd->ff_vcodec, &(pd->ff_opts));
172 TC_UNLOCK_LIBAVCODEC;
173
174 if (ret < 0) {
175 Index: transcode-1.1.7/export/export_ffmpeg.c
176 ===================================================================
177 --- transcode-1.1.7.orig/export/export_ffmpeg.c
178 +++ transcode-1.1.7/export/export_ffmpeg.c
179 @@ -122,7 +122,7 @@ static uint8_t *img_buffer =
180 static AVFrame *lavc_convert_frame = NULL;
181
182 static AVCodec *lavc_venc_codec = NULL;
183 -static AVDictionary **lavc_venc_opts = NULL;
184 +static AVDictionary *lavc_venc_opts = NULL;
185 static AVFrame *lavc_venc_frame = NULL;
186 static AVCodecContext *lavc_venc_context;
187 static avi_t *avifile = NULL;
188 @@ -486,7 +486,7 @@ MOD_init
189 codec->name, codec->fourCC, codec->comments);
190 }
191
192 - lavc_venc_context = avcodec_alloc_context();
193 + lavc_venc_context = avcodec_alloc_context3(lavc_venc_codec);
194 lavc_venc_frame = avcodec_alloc_frame();
195
196 lavc_convert_frame= avcodec_alloc_frame();
197 @@ -838,8 +838,13 @@ MOD_init
198 lavc_venc_context->rc_strategy = lavc_param_vrc_strategy;
199 lavc_venc_context->b_frame_strategy = lavc_param_vb_strategy;
200 lavc_venc_context->b_quant_offset = lavc_param_vb_qoffset;
201 - lavc_venc_context->luma_elim_threshold= lavc_param_luma_elim_threshold;
202 - lavc_venc_context->chroma_elim_threshold= lavc_param_chroma_elim_threshold;
203 +
204 + char buf[1024];
205 +#define set_dict_opt(val, opt) \
206 + snprintf(buf, sizeof(buf), "%i", val); \
207 + av_dict_set(&lavc_venc_opts, opt, buf, 0)
208 + set_dict_opt(lavc_param_luma_elim_threshold, "luma_elim_threshold");
209 + set_dict_opt(lavc_param_chroma_elim_threshold, "chroma_elim_threshold");
210 lavc_venc_context->rtp_payload_size = lavc_param_packet_size;
211 #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
212 if (lavc_param_packet_size)
213 @@ -870,7 +875,7 @@ MOD_init
214 lavc_venc_context->context_model = lavc_param_context;
215 lavc_venc_context->scenechange_threshold= lavc_param_sc_threshold;
216 lavc_venc_context->noise_reduction = lavc_param_noise_reduction;
217 - lavc_venc_context->inter_threshold = lavc_param_inter_threshold;
218 + set_dict_opt(lavc_param_inter_threshold, "inter_threshold");
219 lavc_venc_context->intra_dc_precision = lavc_param_intra_dc_precision;
220 lavc_venc_context->skip_top = lavc_param_skip_top;
221 lavc_venc_context->skip_bottom = lavc_param_skip_bottom;
222 @@ -1066,9 +1071,11 @@ MOD_init
223 lavc_venc_context->flags |= lavc_param_trunc;
224 lavc_venc_context->flags |= lavc_param_aic;
225 lavc_venc_context->flags |= lavc_param_v4mv;
226 - lavc_venc_context->flags |= lavc_param_cbp;
227 + if(lavc_param_cbp)
228 + av_dict_set(&lavc_venc_opts, "mpv_flags", "+cbp_rd", 0);
229 lavc_venc_context->flags |= lavc_param_mv0;
230 - lavc_venc_context->flags |= lavc_param_qp_rd;
231 + if(lavc_param_qp_rd)
232 + av_dict_set(&lavc_venc_opts, "mpv_flags", "+qp_rd", 0);
233 lavc_venc_context->flags |= lavc_param_ilme;
234 #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
235 lavc_venc_context->flags |= lavc_param_trell;
236 @@ -1238,29 +1245,29 @@ MOD_init
237 }
238
239 if (lavc_param_scan_offset) {
240 - av_dict_set(lavc_venc_opts, "scan_offset", "1", 0);
241 + av_dict_set(&lavc_venc_opts, "scan_offset", "1", 0);
242 }
243
244 if (lavc_param_ss) {
245 - av_dict_set(lavc_venc_opts, "structured_slices", "1", 0);
246 + av_dict_set(&lavc_venc_opts, "structured_slices", "1", 0);
247 }
248
249 if (lavc_param_alt) {
250 - av_dict_set(lavc_venc_opts, "alternate_scan", "1", 0);
251 + av_dict_set(&lavc_venc_opts, "alternate_scan", "1", 0);
252 }
253
254 if (lavc_param_umv) {
255 - av_dict_set(lavc_venc_opts, "umv", "1", 0);
256 + av_dict_set(&lavc_venc_opts, "umv", "1", 0);
257 }
258
259 if (lavc_param_data_partitioning) {
260 - av_dict_set(lavc_venc_opts, "vdpart", "1", 0);
261 + av_dict_set(&lavc_venc_opts, "vdpart", "1", 0);
262 }
263
264 //-- open codec --
265 //----------------
266 TC_LOCK_LIBAVCODEC;
267 - ret = avcodec_open2(lavc_venc_context, lavc_venc_codec, lavc_venc_opts);
268 + ret = avcodec_open2(lavc_venc_context, lavc_venc_codec, &lavc_venc_opts);
269 TC_UNLOCK_LIBAVCODEC;
270 if (ret < 0) {
271 tc_log_warn(MOD_NAME, "could not open FFMPEG codec");
272 Index: transcode-1.1.7/export/ffmpeg_cfg.c
273 ===================================================================
274 --- transcode-1.1.7.orig/export/ffmpeg_cfg.c
275 +++ transcode-1.1.7/export/ffmpeg_cfg.c
276 @@ -214,10 +214,10 @@ TCConfigEntry lavcopts_conf[]={
277 {"context", &lavc_param_context, TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 10},
278 {"intra_matrix", &lavc_param_intra_matrix, TCCONF_TYPE_STRING, 0, 0, 0},
279 {"inter_matrix", &lavc_param_inter_matrix, TCCONF_TYPE_STRING, 0, 0, 0},
280 - {"cbp", &lavc_param_cbp, TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CBP_RD},
281 + {"cbp", &lavc_param_cbp, TCCONF_TYPE_FLAG, 0, 0, 1},
282 {"mv0", &lavc_param_mv0, TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_MV0},
283 {"nr", &lavc_param_noise_reduction, TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 0, 1000000},
284 - {"qprd", &lavc_param_qp_rd, TCCONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QP_RD},
285 + {"qprd", &lavc_param_qp_rd, TCCONF_TYPE_FLAG, 0, 0, 1},
286 {"threads", &lavc_param_threads, TCCONF_TYPE_INT, TCCONF_FLAG_RANGE, 1, 16},
287 {"ss", &lavc_param_ss, TCCONF_TYPE_FLAG, 0, 0, 1},
288 {"svcd_sof", &lavc_param_scan_offset, TCCONF_TYPE_FLAG, 0, 0, 1},
289 Index: transcode-1.1.7/export/aud_aux.c
290 ===================================================================
291 --- transcode-1.1.7.orig/export/aud_aux.c
292 +++ transcode-1.1.7/export/aud_aux.c
293 @@ -346,7 +346,7 @@ static int tc_audio_init_ffmpeg(vob_t *v
294
295 //-- set parameters (bitrate, channels and sample-rate) --
296 //--------------------------------------------------------
297 - avcodec_get_context_defaults(&mpa_ctx);
298 + avcodec_get_context_defaults3(&mpa_ctx, mpa_codec);
299 #if LIBAVCODEC_VERSION_MAJOR < 53
300 mpa_ctx.codec_type = CODEC_TYPE_AUDIO;
301 #else
302 @@ -359,7 +359,7 @@ static int tc_audio_init_ffmpeg(vob_t *v
303 //-- open codec --
304 //----------------
305 TC_LOCK_LIBAVCODEC;
306 - ret = avcodec_open(&mpa_ctx, mpa_codec);
307 + ret = avcodec_open2(&mpa_ctx, mpa_codec, NULL);
308 TC_UNLOCK_LIBAVCODEC;
309 if (ret < 0) {
310 tc_warn("tc_audio_init_ffmpeg: could not open %s codec !",
311 Index: transcode-1.1.7/import/import_ffmpeg.c
312 ===================================================================
313 --- transcode-1.1.7.orig/import/import_ffmpeg.c
314 +++ transcode-1.1.7/import/import_ffmpeg.c
315 @@ -302,7 +302,7 @@ do_avi:
316
317 // Set these to the expected values so that ffmpeg's decoder can
318 // properly detect interlaced input.
319 - lavc_dec_context = avcodec_alloc_context();
320 + lavc_dec_context = avcodec_alloc_context3(lavc_dec_codec);
321 if (lavc_dec_context == NULL) {
322 tc_log_error(MOD_NAME, "Could not allocate enough memory.");
323 return TC_IMPORT_ERROR;
324 @@ -344,7 +344,7 @@ do_avi:
325 }
326
327 TC_LOCK_LIBAVCODEC;
328 - ret = avcodec_open(lavc_dec_context, lavc_dec_codec);
329 + ret = avcodec_open2(lavc_dec_context, lavc_dec_codec, NULL);
330 TC_UNLOCK_LIBAVCODEC;
331 if (ret < 0) {
332 tc_log_warn(MOD_NAME, "Could not initialize the '%s' codec.",
|