|
Lines 168-173
Link Here
|
| 168 |
return -10.0 * log(d) / log(10); |
168 |
return -10.0 * log(d) / log(10); |
| 169 |
} |
169 |
} |
| 170 |
|
170 |
|
|
|
171 |
|
| 172 |
// Could be using GNU extension 'strchrnul' instead: |
| 173 |
static char *tc_strchrnul(const char *s, int c) { |
| 174 |
char *tmp = strchr(s, c); |
| 175 |
if (tmp == NULL) { |
| 176 |
tmp = s + strlen(s); |
| 177 |
} |
| 178 |
return tmp; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
/* START: COPIED FROM ffmpeg-0.5_p22846(ffmpeg.c, cmdutils.c) */ |
| 183 |
#include <libavcodec/opt.h> |
| 184 |
#include <libavutil/avstring.h> |
| 185 |
#include <libswscale/swscale.h> |
| 186 |
|
| 187 |
/* GLUE: */ |
| 188 |
#define FFMPEG_DATADIR lavc_param_ffmpeg_datadir |
| 189 |
|
| 190 |
/* GLUE: */ |
| 191 |
static AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB] = {NULL}; |
| 192 |
|
| 193 |
static // GLUE |
| 194 |
const char **opt_names; |
| 195 |
static int opt_name_count; |
| 196 |
|
| 197 |
static char *audio_codec_name = NULL; |
| 198 |
static char *subtitle_codec_name = NULL; |
| 199 |
static char *video_codec_name = NULL; |
| 200 |
static int audio_stream_copy = 0; |
| 201 |
static int video_stream_copy = 0; |
| 202 |
static int subtitle_stream_copy = 0; |
| 203 |
|
| 204 |
static int av_exit(int ret) |
| 205 |
{ |
| 206 |
av_free(opt_names); |
| 207 |
|
| 208 |
av_free(video_codec_name); |
| 209 |
av_free(audio_codec_name); |
| 210 |
av_free(subtitle_codec_name); |
| 211 |
|
| 212 |
exit(ret); /* not all OS-es handle main() return value */ |
| 213 |
return ret; |
| 214 |
} |
| 215 |
|
| 216 |
static void opt_codec(int *pstream_copy, char **pcodec_name, |
| 217 |
int codec_type, const char *arg) |
| 218 |
{ |
| 219 |
av_freep(pcodec_name); |
| 220 |
if (!strcmp(arg, "copy")) { |
| 221 |
*pstream_copy = 1; |
| 222 |
} else { |
| 223 |
*pcodec_name = av_strdup(arg); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
static void opt_audio_codec(const char *arg) |
| 228 |
{ |
| 229 |
opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg); |
| 230 |
} |
| 231 |
|
| 232 |
static void opt_video_codec(const char *arg) |
| 233 |
{ |
| 234 |
opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg); |
| 235 |
} |
| 236 |
|
| 237 |
static void opt_subtitle_codec(const char *arg) |
| 238 |
{ |
| 239 |
opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg); |
| 240 |
} |
| 241 |
|
| 242 |
static |
| 243 |
int opt_default(const char *opt, const char *arg){ |
| 244 |
int type; |
| 245 |
int ret= 0; |
| 246 |
const AVOption *o= NULL; |
| 247 |
int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; |
| 248 |
|
| 249 |
for(type=0; type<AVMEDIA_TYPE_NB && ret>= 0; type++){ |
| 250 |
/* GLUE: +if */ |
| 251 |
if (type == AVMEDIA_TYPE_VIDEO) { |
| 252 |
const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]); |
| 253 |
if(o2) |
| 254 |
ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o); |
| 255 |
/* GLUE: +if */ |
| 256 |
} |
| 257 |
} |
| 258 |
/* GLUE: disabling |
| 259 |
if(!o) |
| 260 |
ret = av_set_string3(avformat_opts, opt, arg, 1, &o); |
| 261 |
if(!o && sws_opts) |
| 262 |
ret = av_set_string3(sws_opts, opt, arg, 1, &o); |
| 263 |
*/ |
| 264 |
if(!o){ |
| 265 |
/* GLUE: disabling |
| 266 |
if(opt[0] == 'a') |
| 267 |
ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o); |
| 268 |
else */ if(opt[0] == 'v') |
| 269 |
ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o); |
| 270 |
/* GLUE: disabling |
| 271 |
else if(opt[0] == 's') |
| 272 |
ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o); |
| 273 |
*/ |
| 274 |
} |
| 275 |
if (o && ret < 0) { |
| 276 |
fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt); |
| 277 |
exit(1); |
| 278 |
} |
| 279 |
if (!o) { |
| 280 |
fprintf(stderr, "Unrecognized option '%s'\n", opt); |
| 281 |
exit(1); |
| 282 |
} |
| 283 |
|
| 284 |
// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL)); |
| 285 |
|
| 286 |
//FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this |
| 287 |
opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); |
| 288 |
opt_names[opt_name_count++]= o->name; |
| 289 |
|
| 290 |
/* GLUE: disabling |
| 291 |
if(avcodec_opts[0]->debug || avformat_opts->debug) |
| 292 |
av_log_set_level(AV_LOG_DEBUG); |
| 293 |
*/ |
| 294 |
return 0; |
| 295 |
} |
| 296 |
|
| 297 |
static int opt_preset(const char *opt, const char *arg) |
| 298 |
{ |
| 299 |
FILE *f=NULL; |
| 300 |
char filename[1000], tmp[1000], tmp2[1000], line[1000]; |
| 301 |
int i; |
| 302 |
const char *base[2]= { getenv("HOME"), |
| 303 |
FFMPEG_DATADIR, |
| 304 |
}; |
| 305 |
|
| 306 |
if (*opt != 'f') { |
| 307 |
for(i=!base[0]; i<2 && !f; i++){ |
| 308 |
snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg); |
| 309 |
f= fopen(filename, "r"); |
| 310 |
if(!f){ |
| 311 |
char *codec_name= *opt == 'v' ? video_codec_name : |
| 312 |
*opt == 'a' ? audio_codec_name : |
| 313 |
subtitle_codec_name; |
| 314 |
snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i], i ? "" : "/.ffmpeg", codec_name, arg); |
| 315 |
f= fopen(filename, "r"); |
| 316 |
} |
| 317 |
} |
| 318 |
} else { |
| 319 |
av_strlcpy(filename, arg, sizeof(filename)); |
| 320 |
f= fopen(filename, "r"); |
| 321 |
} |
| 322 |
|
| 323 |
if(!f){ |
| 324 |
fprintf(stderr, "File for preset '%s' not found\n", arg); |
| 325 |
av_exit(1); |
| 326 |
} |
| 327 |
|
| 328 |
while(!feof(f)){ |
| 329 |
int e= fscanf(f, "%999[^\n]\n", line) - 1; |
| 330 |
if(line[0] == '#' && !e) |
| 331 |
continue; |
| 332 |
e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2; |
| 333 |
if(e){ |
| 334 |
fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line); |
| 335 |
av_exit(1); |
| 336 |
} |
| 337 |
if(!strcmp(tmp, "acodec")){ |
| 338 |
opt_audio_codec(tmp2); |
| 339 |
}else if(!strcmp(tmp, "vcodec")){ |
| 340 |
opt_video_codec(tmp2); |
| 341 |
}else if(!strcmp(tmp, "scodec")){ |
| 342 |
opt_subtitle_codec(tmp2); |
| 343 |
}else if(opt_default(tmp, tmp2) < 0){ |
| 344 |
fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2); |
| 345 |
av_exit(1); |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
fclose(f); |
| 350 |
|
| 351 |
return 0; |
| 352 |
} |
| 353 |
/* END: COPIED FROM ffmpeg-0.5_p22846(ffmpeg.c, cmdutils.c) */ |
| 354 |
|
| 355 |
|
| 171 |
/* ------------------------------------------------------------ |
356 |
/* ------------------------------------------------------------ |
| 172 |
* |
357 |
* |
| 173 |
* init codec |
358 |
* init codec |
|
Lines 1020-1025
Link Here
|
| 1020 |
|
1205 |
|
| 1021 |
lavc_venc_context->me_method = ME_ZERO + lavc_param_vme; |
1206 |
lavc_venc_context->me_method = ME_ZERO + lavc_param_vme; |
| 1022 |
|
1207 |
|
|
|
1208 |
|
| 1209 |
/* FIXME: transcode itself contains "broken ffmpeg default settings", thus we need to override them! */ |
| 1210 |
if (lavc_param_video_preset) { |
| 1211 |
avcodec_opts[AVMEDIA_TYPE_VIDEO] = lavc_venc_context; |
| 1212 |
video_codec_name = ffmpeg_codec_name(codec->name); |
| 1213 |
|
| 1214 |
const char *preset_start = lavc_param_video_preset; |
| 1215 |
while (preset_start) { |
| 1216 |
const char *preset_end = tc_strchrnul(preset_start, ','); |
| 1217 |
char preset_name[255] = {'\0'}; |
| 1218 |
|
| 1219 |
if (strncpy(preset_name, preset_start, preset_end-preset_start) != preset_name) { |
| 1220 |
tc_log_warn(MOD_NAME, "Extracting preset name failed"); |
| 1221 |
return TC_EXPORT_ERROR; |
| 1222 |
} |
| 1223 |
|
| 1224 |
if (verbose) { |
| 1225 |
tc_log_info(MOD_NAME, "Parsing ffmpeg preset '%s'", preset_name); |
| 1226 |
} |
| 1227 |
if (opt_preset("vpre", preset_name) != 0) { |
| 1228 |
tc_log_warn(MOD_NAME, "Parsing ffmpeg preset '%s' failed", preset_name); |
| 1229 |
} |
| 1230 |
if (verbose) { |
| 1231 |
int i; |
| 1232 |
tc_log_info(MOD_NAME, "After parsing preset '%s', %i options are overridden:", preset_name, opt_name_count); |
| 1233 |
for (i=0; i < opt_name_count; i++) |
| 1234 |
tc_log_info(MOD_NAME, "-- %s", opt_names[i]); |
| 1235 |
} |
| 1236 |
|
| 1237 |
if (*preset_end != '\0') { |
| 1238 |
preset_start = preset_end+1; |
| 1239 |
} |
| 1240 |
else { |
| 1241 |
preset_start = NULL; |
| 1242 |
} |
| 1243 |
} |
| 1244 |
} |
| 1245 |
|
| 1246 |
|
| 1023 |
//-- open codec -- |
1247 |
//-- open codec -- |
| 1024 |
//---------------- |
1248 |
//---------------- |
| 1025 |
TC_LOCK_LIBAVCODEC; |
1249 |
TC_LOCK_LIBAVCODEC; |