45 #include "libavformat/avformat.h"
47 #include "libavcodec/avcodec.h"
49 #include "libavfilter/avfilter.h"
51 #include "libavutil/avassert.h"
52 #include "libavutil/avstring.h"
53 #include "libavutil/avutil.h"
54 #include "libavutil/channel_layout.h"
55 #include "libavutil/intreadwrite.h"
56 #include "libavutil/fifo.h"
57 #include "libavutil/mathematics.h"
58 #include "libavutil/opt.h"
59 #include "libavutil/parseutils.h"
60 #include "libavutil/pixdesc.h"
61 #include "libavutil/pixfmt.h"
63 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
65 #define SPECIFIER_OPT_FMT_str "%s"
66 #define SPECIFIER_OPT_FMT_i "%i"
67 #define SPECIFIER_OPT_FMT_i64 "%"PRId64
68 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
69 #define SPECIFIER_OPT_FMT_f "%f"
70 #define SPECIFIER_OPT_FMT_dbl "%lf"
72 static const char *
const opt_name_codec_names[] = {
"c",
"codec",
"acodec",
"vcodec",
"scodec",
"dcodec", NULL};
117 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
119 char namestr[128] = "";\
120 const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
121 for (i = 0; opt_name_##name[i]; i++)\
122 av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
123 av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
124 namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
127 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
129 int i, ret, matches = 0;\
131 for (i = 0; i < o->nb_ ## name; i++) {\
132 char *spec = o->name[i].specifier;\
133 if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
134 outvar = o->name[i].u.type;\
141 WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
144 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
147 for (i = 0; i < o->nb_ ## name; i++) {\
148 char *spec = o->name[i].specifier;\
149 if (!strcmp(spec, mediatype))\
150 outvar = o->name[i].u.type;\
155 #if CONFIG_VIDEOTOOLBOX
218 void *dst = (uint8_t*)o + po->
u.
off;
222 int i, *count = (
int*)(so + 1);
223 for (i = 0; i < *count; i++) {
224 av_freep(&(*so)[i].specifier);
226 av_freep(&(*so)[i].u.str);
245 memset(o, 0,
sizeof(*o));
260 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
262 av_log(NULL,
AV_LOG_STDERR,
"Hardware acceleration methods:\n");
263 while ((type = av_hwdevice_iterate_types(type)) !=
264 AV_HWDEVICE_TYPE_NONE)
265 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
273 AVDictionaryEntry *e = NULL;
274 AVDictionary *ret = NULL;
276 while ((e = av_dict_get(dict,
"", e, AV_DICT_IGNORE_SUFFIX))) {
277 char *p = strchr(e->key,
':');
281 av_dict_set(&ret, e->key, e->value, 0);
290 const AVOption opts[] = {
291 {
"abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, (double)INT64_MAX, .unit =
"flags" },
296 const AVClass
class = {
298 .item_name = av_default_item_name,
300 .version = LIBAVUTIL_VERSION_INT,
302 const AVClass *pclass = &
class;
304 return av_opt_eval_flags(&pclass, &opts[0], arg, &
abort_on_flags);
311 if (user_stats_period <= 0) {
312 av_log(NULL, AV_LOG_ERROR,
"stats_period %s must be positive.\n", arg);
313 return AVERROR(EINVAL);
317 av_log(NULL, AV_LOG_INFO,
"ffmpeg stats and -progress period set to %s.\n", arg);
322 int opt_sameq(
void *optctx,
const char *opt,
const char *arg)
324 av_log(NULL, AV_LOG_ERROR,
"Option '%s' was removed. "
325 "If you are looking for an option to preserve the quality (which is not "
326 "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
328 return AVERROR(EINVAL);
333 av_log(NULL, AV_LOG_WARNING,
"This option is deprecated, use -channel.\n");
339 av_log(NULL, AV_LOG_WARNING,
"This option is deprecated, use -standard.\n");
367 int opt_map(
void *optctx,
const char *opt,
const char *arg)
371 int i, negative = 0, file_idx, disabled = 0;
372 int sync_file_idx = -1, sync_stream_idx = 0;
381 map = av_strdup(arg);
383 return AVERROR(ENOMEM);
386 if ((sync = strchr(map,
','))) {
388 sync_file_idx = strtol(sync + 1, &sync, 0);
390 av_log(NULL, AV_LOG_FATAL,
"Invalid sync file index: %d.\n", sync_file_idx);
402 av_log(NULL, AV_LOG_FATAL,
"Sync stream specification in map %s does not "
403 "match any streams.\n", arg);
407 av_log(NULL, AV_LOG_FATAL,
"Sync stream specification in map %s matches a disabled input "
416 const char *c = map + 1;
421 av_log(NULL, AV_LOG_ERROR,
"Invalid output link label: %s.\n", map);
425 if ((allow_unused = strchr(map,
'?')))
427 file_idx = strtol(map, &p, 0);
429 av_log(NULL, AV_LOG_FATAL,
"Invalid input file index: %d.\n", file_idx);
439 *p ==
':' ? p + 1 : p) > 0)
445 *p ==
':' ? p + 1 : p) <= 0)
457 if (sync_file_idx >= 0) {
469 av_log(NULL, AV_LOG_VERBOSE,
"Stream map '%s' matches no streams; ignoring.\n", arg);
470 }
else if (disabled) {
471 av_log(NULL, AV_LOG_FATAL,
"Stream map '%s' matches disabled streams.\n"
472 "To ignore this, add a trailing '?' to the map.\n", arg);
475 av_log(NULL, AV_LOG_FATAL,
"Stream map '%s' matches no streams.\n"
476 "To ignore this, add a trailing '?' to the map.\n", arg);
485 int opt_attach(
void *optctx,
const char *opt,
const char *arg)
501 mapchan = av_strdup(arg);
503 return AVERROR(ENOMEM);
519 n = sscanf(arg,
"%d.%d.%d:%d.%d",
523 if (n != 3 && n != 5) {
524 av_log(NULL, AV_LOG_FATAL,
"Syntax error, mapchan usage: "
525 "[file.stream.channel|-1][:syncfile:syncstream]\n");
534 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid input file index: %d\n",
540 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid input file stream index #%d.%d\n",
545 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
546 av_log(NULL, AV_LOG_FATAL,
"mapchan: stream #%d.%d is not an audio stream.\n",
551 if ((allow_unused = strchr(mapchan,
'?')))
556 av_log(NULL, AV_LOG_VERBOSE,
"mapchan: invalid audio channel #%d.%d.%d\n",
559 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid audio channel #%d.%d.%d\n"
560 "To ignore this, add a trailing '?' to the map_channel.\n",
578 int opt_vaapi_device(
void *optctx,
const char *opt,
const char *arg)
580 const char *prefix =
"vaapi:";
583 tmp = av_asprintf(
"%s%s", prefix, arg);
585 return AVERROR(ENOMEM);
594 if (!strcmp(arg,
"list")) {
595 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
596 av_log(NULL,
AV_LOG_STDERR,
"Supported hardware device types:\n");
597 while ((type = av_hwdevice_iterate_types(type)) !=
598 AV_HWDEVICE_TYPE_NONE)
599 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
610 av_log(NULL, AV_LOG_ERROR,
"Only one filter device can be used.\n");
611 return AVERROR(EINVAL);
615 av_log(NULL, AV_LOG_ERROR,
"Invalid filter device %s.\n", arg);
616 return AVERROR(EINVAL);
636 if (*(++arg) && *arg !=
':') {
637 av_log(NULL, AV_LOG_FATAL,
"Invalid metadata specifier %s.\n", arg);
640 *stream_spec = *arg ==
':' ? arg + 1 :
"";
645 *index = strtol(++arg, NULL, 0);
648 av_log(NULL, AV_LOG_FATAL,
"Invalid metadata type %c.\n", *arg);
657 AVDictionary **meta_in = NULL;
658 AVDictionary **meta_out = NULL;
660 char type_in, type_out;
661 const char *istream_spec = NULL, *ostream_spec = NULL;
662 int idx_in = 0, idx_out = 0;
668 if (type_out ==
'g' || !*outspec)
670 if (type_out ==
's' || !*outspec)
672 if (type_out ==
'c' || !*outspec)
677 if (type_in ==
'g' || type_out ==
'g')
679 if (type_in ==
's' || type_out ==
's')
681 if (type_in ==
'c' || type_out ==
'c')
688 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
689 if ((index) < 0 || (index) >= (nb_elems)) {\
690 av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
695 #define SET_DICT(type, meta, context, index)\
698 meta = &context->metadata;\
701 METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
702 meta = &context->chapters[index]->metadata;\
705 METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
706 meta = &context->programs[index]->metadata;\
710 default: av_assert0(0);\
713 SET_DICT(type_in, meta_in, ic, idx_in);
714 SET_DICT(type_out, meta_out, oc, idx_out);
717 if (type_in ==
's') {
718 for (i = 0; i < ic->nb_streams; i++) {
720 meta_in = &ic->streams[i]->metadata;
726 av_log(NULL, AV_LOG_FATAL,
"Stream specifier %s does not match any streams.\n", istream_spec);
731 if (type_out ==
's') {
732 for (i = 0; i < oc->nb_streams; i++) {
734 meta_out = &oc->streams[i]->metadata;
735 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
740 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
750 struct tm time = *gmtime((time_t*)&recording_timestamp);
751 if (!strftime(buf,
sizeof(buf),
"creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
755 av_log(NULL, AV_LOG_WARNING,
"%s is deprecated, set the 'creation_time' metadata "
756 "tag instead.\n", opt);
762 const AVCodecDescriptor *desc;
763 const char *codec_string = encoder ?
"encoder" :
"decoder";
767 avcodec_find_encoder_by_name(name) :
768 avcodec_find_decoder_by_name(name);
770 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
771 codec = encoder ? avcodec_find_encoder(desc->id) :
772 avcodec_find_decoder(desc->id);
774 av_log(NULL, AV_LOG_VERBOSE,
"Matched %s '%s' for codec '%s'.\n",
775 codec_string, codec->name, desc->name);
779 av_log(NULL, AV_LOG_FATAL,
"Unknown %s '%s'\n", codec_string, name);
782 if (codec->type != type) {
783 av_log(NULL, AV_LOG_FATAL,
"Invalid %s type '%s'\n", codec_string, name);
791 char *codec_name = NULL;
796 st->codecpar->codec_id = codec->id;
799 return avcodec_find_decoder(st->codecpar->codec_id);
808 for (i = 0; i < ic->nb_streams; i++) {
809 AVStream *st = ic->streams[i];
810 AVCodecParameters *par = st->codecpar;
812 char *framerate = NULL, *hwaccel_device = NULL;
813 const char *hwaccel = NULL;
814 char *hwaccel_output_format = NULL;
815 char *codec_tag = NULL;
817 char *discard_str = NULL;
818 const AVClass *cc = avcodec_get_class();
819 const AVOption *discard_opt = av_opt_find(&cc,
"skip_frame", NULL, 0, 0);
830 st->discard = AVDISCARD_ALL;
843 uint32_t tag = strtol(codec_tag, &next, 0);
845 tag = AV_RL32(codec_tag);
846 st->codecpar->codec_tag = tag;
858 if ((o->
video_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
859 (o->
audio_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
861 (o->
data_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
864 if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->
user_set_discard) < 0) {
865 av_log(NULL, AV_LOG_ERROR,
"Error parsing discard %s.\n",
872 ist->
dec_ctx = avcodec_alloc_context3(ist->
dec);
874 av_log(NULL, AV_LOG_ERROR,
"Error allocating the decoder context.\n");
878 ret = avcodec_parameters_to_context(ist->
dec_ctx, par);
880 av_log(NULL, AV_LOG_ERROR,
"Error initializing the decoder context.\n");
885 ist->
dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
887 switch (par->codec_type) {
888 case AVMEDIA_TYPE_VIDEO:
890 ist->
dec = avcodec_find_decoder(par->codec_id);
893 ist->
dec_ctx->framerate = st->avg_frame_rate;
896 if (framerate && av_parse_video_rate(&ist->
framerate,
898 av_log(NULL, AV_LOG_ERROR,
"Error parsing framerate %s.\n",
908 hwaccel_output_format, ic, st);
910 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel,
"cuvid")) {
911 av_log(NULL, AV_LOG_WARNING,
912 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
913 "with old commandlines. This behaviour is DEPRECATED and will be removed "
914 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
916 }
else if (hwaccel_output_format) {
919 av_log(NULL, AV_LOG_FATAL,
"Unrecognised hwaccel output "
920 "format: %s", hwaccel_output_format);
928 if (!strcmp(hwaccel,
"nvdec") || !strcmp(hwaccel,
"cuvid"))
931 if (!strcmp(hwaccel,
"none"))
933 else if (!strcmp(hwaccel,
"auto"))
936 enum AVHWDeviceType type;
939 if (!strcmp(
hwaccels[i].name, hwaccel)) {
946 type = av_hwdevice_find_type_by_name(hwaccel);
947 if (type != AV_HWDEVICE_TYPE_NONE) {
954 av_log(NULL, AV_LOG_FATAL,
"Unrecognized hwaccel: %s.\n",
956 av_log(NULL, AV_LOG_FATAL,
"Supported hwaccels: ");
957 type = AV_HWDEVICE_TYPE_NONE;
958 while ((type = av_hwdevice_iterate_types(type)) !=
959 AV_HWDEVICE_TYPE_NONE)
960 av_log(NULL, AV_LOG_FATAL,
"%s ",
961 av_hwdevice_get_type_name(type));
962 av_log(NULL, AV_LOG_FATAL,
"\n");
969 if (hwaccel_device) {
978 case AVMEDIA_TYPE_AUDIO:
983 case AVMEDIA_TYPE_DATA:
984 case AVMEDIA_TYPE_SUBTITLE: {
985 char *canvas_size = NULL;
987 ist->
dec = avcodec_find_decoder(par->codec_id);
991 av_parse_video_size(&ist->
dec_ctx->width, &ist->
dec_ctx->height, canvas_size) < 0) {
992 av_log(NULL, AV_LOG_FATAL,
"Invalid canvas size: %s.\n", canvas_size);
997 case AVMEDIA_TYPE_ATTACHMENT:
998 case AVMEDIA_TYPE_UNKNOWN:
1004 ret = avcodec_parameters_from_context(par, ist->
dec_ctx);
1006 av_log(NULL, AV_LOG_ERROR,
"Error initializing the decoder context.\n");
1014 const char *proto_name = avio_find_protocol_name(filename);
1017 fprintf(stderr,
"Error, both -y and -n supplied. Exiting.\n");
1022 if (proto_name && !strcmp(proto_name,
"file") && avio_check(filename, 0) == 0) {
1024 fprintf(stderr,
"File '%s' already exists. Overwrite ? [y/N] ", filename);
1027 signal(SIGINT, SIG_DFL);
1029 av_log(NULL, AV_LOG_FATAL,
"Not overwriting - exiting\n");
1035 av_log(NULL, AV_LOG_FATAL,
"File '%s' already exists. Exiting.\n", filename);
1041 if (proto_name && !strcmp(proto_name,
"file")) {
1044 if (file->
ctx->iformat->flags & AVFMT_NOFILE)
1046 if (!strcmp(filename, file->
ctx->url)) {
1047 av_log(NULL, AV_LOG_FATAL,
"Output %s same as Input #%d - exiting\n", filename, i);
1048 av_log(NULL, AV_LOG_WARNING,
"FFmpeg cannot edit existing files in-place.\n");
1058 AVIOContext *out = NULL;
1059 AVDictionaryEntry *e;
1061 if (!st->codecpar->extradata_size) {
1062 av_log(NULL, AV_LOG_WARNING,
"No extradata to dump in stream #%d:%d.\n",
1066 if (!*filename && (e = av_dict_get(st->metadata,
"filename", NULL, 0)))
1067 filename = e->value;
1069 av_log(NULL, AV_LOG_FATAL,
"No filename specified and no 'filename' tag"
1076 if ((ret =
avio_open2(&out, filename, AVIO_FLAG_WRITE, &
int_cb, NULL)) < 0) {
1077 av_log(NULL, AV_LOG_FATAL,
"Could not open file %s for writing.\n",
1082 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
1090 AVFormatContext *ic;
1091 AVInputFormat *file_iformat = NULL;
1094 AVDictionary *unused_opts = NULL;
1095 AVDictionaryEntry *e = NULL;
1096 char * video_codec_name = NULL;
1097 char * audio_codec_name = NULL;
1098 char *subtitle_codec_name = NULL;
1099 char * data_codec_name = NULL;
1100 int scan_all_pmts_set = 0;
1104 av_log(NULL, AV_LOG_WARNING,
"-t and -to cannot be used together; using -t.\n");
1110 av_log(NULL, AV_LOG_ERROR,
"-to value smaller than -ss; aborting.\n");
1118 if (!(file_iformat = av_find_input_format(o->
format))) {
1119 av_log(NULL, AV_LOG_FATAL,
"Unknown input format: '%s'\n", o->
format);
1124 if (!strcmp(filename,
"-"))
1128 strcmp(filename,
"/dev/stdin");
1131 ic = avformat_alloc_context();
1143 if (file_iformat && file_iformat->priv_class &&
1144 av_opt_find(&file_iformat->priv_class,
"channels", NULL, 0,
1145 AV_OPT_SEARCH_FAKE_OBJ)) {
1152 if (file_iformat && file_iformat->priv_class &&
1153 av_opt_find(&file_iformat->priv_class,
"framerate", NULL, 0,
1154 AV_OPT_SEARCH_FAKE_OBJ)) {
1170 if (video_codec_name)
1172 if (audio_codec_name)
1174 if (subtitle_codec_name)
1175 ic->subtitle_codec =
find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1176 if (data_codec_name)
1179 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1180 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1181 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1182 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1184 ic->flags |= AVFMT_FLAG_NONBLOCK;
1186 ic->flags |= AVFMT_FLAG_BITEXACT;
1187 ic->interrupt_callback =
int_cb;
1189 if (!av_dict_get(o->
g->
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1190 av_dict_set(&o->
g->
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
1191 scan_all_pmts_set = 1;
1197 if (err == AVERROR_PROTOCOL_NOT_FOUND)
1198 av_log(NULL, AV_LOG_ERROR,
"Did you mean file:%s?\n", filename);
1201 if (scan_all_pmts_set)
1202 av_dict_set(&o->
g->
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1207 for (i = 0; i < ic->nb_streams; i++)
1212 int orig_nb_streams = ic->nb_streams;
1216 ret = avformat_find_stream_info(ic, opts);
1218 for (i = 0; i < orig_nb_streams; i++)
1219 av_dict_free(&opts[i]);
1223 av_log(NULL, AV_LOG_FATAL,
"%s: could not find codec parameters\n", filename);
1224 if (ic->nb_streams == 0) {
1232 av_log(NULL, AV_LOG_WARNING,
"Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1238 av_log(NULL, AV_LOG_ERROR,
"-sseof value must be negative; aborting\n");
1241 if (ic->duration > 0) {
1244 av_log(NULL, AV_LOG_WARNING,
"-sseof value seeks to before start of file %s; ignored\n", filename);
1248 av_log(NULL, AV_LOG_WARNING,
"Cannot use -sseof, duration of %s not known\n", filename);
1253 timestamp += ic->start_time;
1257 int64_t seek_timestamp = timestamp;
1259 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1260 int dts_heuristic = 0;
1261 for (i=0; i<ic->nb_streams; i++) {
1262 const AVCodecParameters *par = ic->streams[i]->codecpar;
1263 if (par->video_delay) {
1268 if (dts_heuristic) {
1269 seek_timestamp -= 3*AV_TIME_BASE / 23;
1272 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1274 av_log(NULL, AV_LOG_WARNING,
"%s: could not seek to position %0.3f\n",
1275 filename, (
double)timestamp / AV_TIME_BASE);
1286 f = av_mallocz(
sizeof(*f));
1311 while ((e = av_dict_get(
input_streams[i]->decoder_opts,
"", e,
1312 AV_DICT_IGNORE_SUFFIX)))
1313 av_dict_set(&unused_opts, e->key, NULL, 0);
1317 while ((e = av_dict_get(unused_opts,
"", e, AV_DICT_IGNORE_SUFFIX))) {
1318 const AVClass *
class = avcodec_get_class();
1319 const AVOption *option = av_opt_find(&
class, e->key, NULL, 0,
1320 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1321 const AVClass *fclass = avformat_get_class();
1322 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1323 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1324 if (!option || foption)
1328 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1329 av_log(NULL, AV_LOG_ERROR,
"Codec AVOption %s (%s) specified for "
1330 "input file #%d (%s) is not a decoding option.\n", e->key,
1336 av_log(NULL, AV_LOG_WARNING,
"Codec AVOption %s (%s) specified for "
1337 "input file #%d (%s) has not been used for any stream. The most "
1338 "likely reason is either wrong type (e.g. a video option with "
1339 "no video streams) or that it is a private option of some decoder "
1340 "which was not actually used for any stream.\n", e->key,
1343 av_dict_free(&unused_opts);
1348 for (j = 0; j < ic->nb_streams; j++) {
1349 AVStream *st = ic->streams[j];
1367 if (avio_open_dyn_buf(&line) < 0) {
1368 av_log(NULL, AV_LOG_FATAL,
"Could not alloc buffer for reading preset.\n");
1372 while ((c = avio_r8(s)) && c !=
'\n')
1375 avio_close_dyn_buf(line, &buf);
1383 char filename[1000];
1384 const char *base[3] = { getenv(
"AVCONV_DATADIR"),
1389 for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1393 snprintf(filename,
sizeof(filename),
"%s%s/%s-%s.avpreset", base[i],
1394 i != 1 ?
"" :
"/.avconv", codec_name, preset_name);
1398 snprintf(filename,
sizeof(filename),
"%s%s/%s.avpreset", base[i],
1399 i != 1 ?
"" :
"/.avconv", preset_name);
1408 enum AVMediaType type = ost->
st->codecpar->codec_type;
1409 char *codec_name = NULL;
1411 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1414 ost->
st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1415 NULL, ost->
st->codecpar->codec_type);
1416 ost->
enc = avcodec_find_encoder(ost->
st->codecpar->codec_id);
1418 av_log(NULL, AV_LOG_FATAL,
"Automatic encoder selection failed for "
1419 "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1420 "probably disabled. Please choose an encoder manually.\n",
1422 avcodec_get_name(ost->
st->codecpar->codec_id));
1423 return AVERROR_ENCODER_NOT_FOUND;
1425 }
else if (!strcmp(codec_name,
"copy"))
1429 ost->
st->codecpar->codec_id = ost->
enc->id;
1444 AVStream *st = avformat_new_stream(oc, NULL);
1445 int idx = oc->nb_streams - 1, ret = 0;
1446 const char *bsfs = NULL, *time_base = NULL;
1447 char *next, *codec_tag = NULL;
1452 av_log(NULL, AV_LOG_FATAL,
"Could not alloc stream.\n");
1460 if (!(ost = av_mallocz(
sizeof(*ost))))
1468 st->codecpar->codec_type = type;
1472 av_log(NULL, AV_LOG_FATAL,
"Error selecting an encoder for stream "
1477 ost->
enc_ctx = avcodec_alloc_context3(ost->
enc);
1479 av_log(NULL, AV_LOG_ERROR,
"Error allocating the encoding context.\n");
1482 ost->
enc_ctx->codec_type = type;
1484 ost->
ref_par = avcodec_parameters_alloc();
1486 av_log(NULL, AV_LOG_ERROR,
"Error allocating the encoding parameters.\n");
1491 AVIOContext *s = NULL;
1492 char *buf = NULL, *arg = NULL, *preset = NULL;
1502 if (!buf[0] || buf[0] ==
'#') {
1506 if (!(arg = strchr(buf,
'='))) {
1507 av_log(NULL, AV_LOG_FATAL,
"Invalid line found in the preset file.\n");
1511 av_dict_set(&ost->
encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1513 }
while (!s->eof_reached);
1517 av_log(NULL, AV_LOG_FATAL,
1518 "Preset %s specified for stream %d:%d, but could not be opened.\n",
1528 ost->
enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1533 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1534 q.num <= 0 || q.den <= 0) {
1535 av_log(NULL, AV_LOG_FATAL,
"Invalid time base: %s\n", time_base);
1544 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1546 av_log(NULL, AV_LOG_FATAL,
"Invalid time base: %s\n", time_base);
1556 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1557 av_log(NULL, AV_LOG_WARNING,
"Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1566 if (bsfs && *bsfs) {
1567 ret = av_bsf_list_parse_str(bsfs, &ost->
bsf_ctx);
1569 av_log(NULL, AV_LOG_ERROR,
"Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1576 uint32_t tag = strtol(codec_tag, &next, 0);
1578 tag = AV_RL32(codec_tag);
1579 ost->
st->codecpar->codec_tag =
1580 ost->
enc_ctx->codec_tag = tag;
1585 ost->
enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1586 ost->
enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1601 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1602 ost->
enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1607 if (ost->
enc && av_get_exact_bits_per_sample(ost->
enc->id) == 24)
1608 av_dict_set(&ost->
swr_opts,
"output_sample_bits",
"24", 0);
1613 if (source_index >= 0) {
1620 ost->
muxing_queue = av_fifo_alloc(8 *
sizeof(AVPacket));
1630 const char *p = str;
1637 av_log(NULL, AV_LOG_FATAL,
"Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1647 AVIOContext *pb = NULL;
1648 AVIOContext *dyn_buf = NULL;
1649 int ret =
avio_open(&pb, filename, AVIO_FLAG_READ);
1650 uint8_t buf[1024], *str;
1653 av_log(NULL, AV_LOG_ERROR,
"Error opening file %s.\n", filename);
1657 ret = avio_open_dyn_buf(&dyn_buf);
1662 while ((ret = avio_read(pb, buf,
sizeof(buf))) > 0)
1663 avio_write(dyn_buf, buf, ret);
1664 avio_w8(dyn_buf, 0);
1667 ret = avio_close_dyn_buf(dyn_buf, &str);
1676 AVStream *st = ost->
st;
1679 av_log(NULL, AV_LOG_ERROR,
"Both -filter and -filter_script set for "
1687 return av_strdup(ost->
filters);
1689 return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
1697 av_log(NULL, AV_LOG_ERROR,
1698 "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1699 "Filtering and streamcopy cannot be used together.\n",
1700 ost->
filters ?
"Filtergraph" :
"Filtergraph script",
1711 AVCodecContext *video_enc;
1712 char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
1719 if (frame_rate && av_parse_video_rate(&ost->
frame_rate, frame_rate) < 0) {
1720 av_log(NULL, AV_LOG_FATAL,
"Invalid framerate value: %s\n", frame_rate);
1725 if (max_frame_rate && av_parse_video_rate(&ost->
max_frame_rate, max_frame_rate) < 0) {
1726 av_log(NULL, AV_LOG_FATAL,
"Invalid maximum framerate value: %s\n", max_frame_rate);
1730 if (frame_rate && max_frame_rate) {
1731 av_log(NULL, AV_LOG_ERROR,
"Only one of -fpsmax and -r can be set for a stream.\n");
1735 if ((frame_rate || max_frame_rate) &&
1737 av_log(NULL, AV_LOG_ERROR,
"Using -vsync 0 and -r/-fpsmax can produce invalid output files\n");
1740 if (frame_aspect_ratio) {
1742 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1743 q.num <= 0 || q.den <= 0) {
1744 av_log(NULL, AV_LOG_FATAL,
"Invalid aspect ratio: %s\n", frame_aspect_ratio);
1754 const char *p = NULL;
1755 char *frame_size = NULL;
1756 char *frame_pix_fmt = NULL;
1757 char *intra_matrix = NULL, *inter_matrix = NULL;
1758 char *chroma_intra_matrix = NULL;
1763 if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1764 av_log(NULL, AV_LOG_FATAL,
"Invalid frame size: %s.\n", frame_size);
1770 if (frame_pix_fmt && *frame_pix_fmt ==
'+') {
1772 if (!*++frame_pix_fmt)
1773 frame_pix_fmt = NULL;
1775 if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1776 av_log(NULL, AV_LOG_FATAL,
"Unknown pixel format requested: %s.\n", frame_pix_fmt);
1779 st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1782 video_enc->gop_size = 0;
1785 if (!(video_enc->intra_matrix = av_mallocz(
sizeof(*video_enc->intra_matrix) * 64))) {
1786 av_log(NULL, AV_LOG_FATAL,
"Could not allocate memory for intra matrix.\n");
1792 if (chroma_intra_matrix) {
1793 uint16_t *p = av_mallocz(
sizeof(*video_enc->chroma_intra_matrix) * 64);
1795 av_log(NULL, AV_LOG_FATAL,
"Could not allocate memory for intra matrix.\n");
1798 video_enc->chroma_intra_matrix = p;
1803 if (!(video_enc->inter_matrix = av_mallocz(
sizeof(*video_enc->inter_matrix) * 64))) {
1804 av_log(NULL, AV_LOG_FATAL,
"Could not allocate memory for inter matrix.\n");
1811 for (i = 0; p; i++) {
1813 int e = sscanf(p,
"%d,%d,%d", &start, &end, &q);
1815 av_log(NULL, AV_LOG_FATAL,
"error parsing rc_override\n");
1818 video_enc->rc_override =
1819 av_realloc_array(video_enc->rc_override,
1820 i + 1,
sizeof(RcOverride));
1821 if (!video_enc->rc_override) {
1822 av_log(NULL, AV_LOG_FATAL,
"Could not (re)allocate memory for rc_override.\n");
1825 video_enc->rc_override[i].start_frame = start;
1826 video_enc->rc_override[i].end_frame = end;
1828 video_enc->rc_override[i].qscale = q;
1829 video_enc->rc_override[i].quality_factor = 1.0;
1832 video_enc->rc_override[i].qscale = 0;
1833 video_enc->rc_override[i].quality_factor = -q/100.0;
1838 video_enc->rc_override_count = i;
1841 video_enc->flags|= AV_CODEC_FLAG_PSNR;
1847 video_enc->flags |= AV_CODEC_FLAG_PASS1;
1848 av_dict_set(&ost->
encoder_opts,
"flags",
"+pass1", AV_DICT_APPEND);
1851 video_enc->flags |= AV_CODEC_FLAG_PASS2;
1852 av_dict_set(&ost->
encoder_opts,
"flags",
"+pass2", AV_DICT_APPEND);
1862 char logfilename[1024];
1865 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
1869 if (!strcmp(ost->
enc->name,
"libx264")) {
1870 av_dict_set(&ost->
encoder_opts,
"stats", logfilename, AV_DICT_DONT_OVERWRITE);
1872 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1876 av_log(NULL, AV_LOG_FATAL,
"Error reading log file '%s' for pass-2 encoding\n",
1880 video_enc->stats_in = logbuffer;
1882 if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1883 f = av_fopen_utf8(logfilename,
"wb");
1885 av_log(NULL, AV_LOG_FATAL,
1886 "Cannot write log file '%s' for pass-1 encoding: %s\n",
1887 logfilename, strerror(errno));
1923 AVCodecContext *audio_enc;
1929 audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1935 char *sample_fmt = NULL;
1941 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1942 av_log(NULL, AV_LOG_FATAL,
"Invalid sample format '%s'\n", sample_fmt);
1965 av_log(NULL, AV_LOG_FATAL,
"Cannot determine input stream for channel mapping %d.%d\n",
1997 av_log(NULL, AV_LOG_FATAL,
"Data stream encoding not supported yet (only streamcopy)\n");
2010 av_log(NULL, AV_LOG_FATAL,
"Unknown stream encoding not supported yet (only streamcopy)\n");
2029 AVCodecContext *subtitle_enc;
2035 subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2040 char *frame_size = NULL;
2043 if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
2044 av_log(NULL, AV_LOG_FATAL,
"Invalid frame size: %s.\n", frame_size);
2060 av_strlcpy(idx_str, arg,
sizeof(idx_str));
2061 p = strchr(idx_str,
':');
2063 av_log(NULL, AV_LOG_FATAL,
2064 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2077 AVFormatContext *is = ifile->
ctx;
2078 AVFormatContext *os = ofile->
ctx;
2082 tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters,
sizeof(*os->chapters));
2084 return AVERROR(ENOMEM);
2087 for (i = 0; i < is->nb_chapters; i++) {
2088 AVChapter *in_ch = is->chapters[i], *out_ch;
2090 int64_t ts_off = av_rescale_q(start_time - ifile->
ts_offset,
2091 AV_TIME_BASE_Q, in_ch->time_base);
2093 av_rescale_q(ofile->
recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2096 if (in_ch->end < ts_off)
2098 if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2101 out_ch = av_mallocz(
sizeof(AVChapter));
2103 return AVERROR(ENOMEM);
2105 out_ch->id = in_ch->id;
2106 out_ch->time_base = in_ch->time_base;
2107 out_ch->start = FFMAX(0, in_ch->start - ts_off);
2108 out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2111 av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2113 os->chapters[os->nb_chapters++] = out_ch;
2119 AVFormatContext *oc)
2123 switch (ofilter->
type) {
2127 av_log(NULL, AV_LOG_FATAL,
"Only video and audio filters are supported "
2139 av_log(NULL, AV_LOG_ERROR,
"Streamcopy requested for output stream %d:%d, "
2140 "which is fed from a complex filtergraph. Filtering and streamcopy "
2146 const char *opt = ost->
filters ?
"-vf/-af/-filter" :
"-filter_script";
2147 av_log(NULL, AV_LOG_ERROR,
2148 "%s '%s' was specified through the %s option "
2149 "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2150 "%s and -filter_complex cannot be used together for the same stream.\n",
2151 ost->
filters ?
"Filtergraph" :
"Filtergraph script",
2157 avfilter_inout_free(&ofilter->
out_tmp);
2174 AVFormatContext *oc;
2179 AVDictionary *unused_opts = NULL;
2180 AVDictionaryEntry *e = NULL;
2181 int format_flags = 0;
2185 av_log(NULL, AV_LOG_WARNING,
"-t and -to cannot be used together; using -t.\n");
2191 av_log(NULL, AV_LOG_ERROR,
"-to value smaller than -ss; aborting.\n");
2199 of = av_mallocz(
sizeof(*of));
2211 if (!strcmp(filename,
"-"))
2214 err = avformat_alloc_output_context2(&oc, NULL, o->
format, filename);
2224 oc->interrupt_callback =
int_cb;
2228 const AVOption *o = av_opt_find(oc,
"fflags", NULL, 0, 0);
2229 av_opt_eval_flags(oc, o, e->value, &format_flags);
2232 format_flags |= AVFMT_FLAG_BITEXACT;
2233 oc->flags |= AVFMT_FLAG_BITEXACT;
2245 switch (ofilter->
type) {
2255 char *subtitle_codec_name = NULL;
2259 if (!o->
video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
2260 int best_score = 0, idx = -1;
2261 int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2265 score = ist->
st->codecpar->width * ist->
st->codecpar->height
2266 + 100000000 * !!(ist->
st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2267 + 5000000*!!(ist->
st->disposition & AV_DISPOSITION_DEFAULT);
2270 if((qcr!=MKTAG(
'A',
'P',
'I',
'C')) && (ist->
st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2272 if (ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2273 score > best_score) {
2274 if((qcr==MKTAG(
'A',
'P',
'I',
'C')) && !(ist->
st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2285 if (!o->
audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
2286 int best_score = 0, idx = -1;
2290 score = ist->
st->codecpar->channels + 100000000*!!ist->
st->codec_info_nb_frames
2291 + 5000000*!!(ist->
st->disposition & AV_DISPOSITION_DEFAULT);
2294 if (ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2295 score > best_score) {
2306 if (!o->
subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2308 if (
input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2309 AVCodecDescriptor
const *input_descriptor =
2310 avcodec_descriptor_get(
input_streams[i]->st->codecpar->codec_id);
2311 AVCodecDescriptor
const *output_descriptor = NULL;
2312 AVCodec
const *output_codec =
2313 avcodec_find_encoder(oc->oformat->subtitle_codec);
2314 int input_props = 0, output_props = 0;
2318 output_descriptor = avcodec_descriptor_get(output_codec->id);
2319 if (input_descriptor)
2320 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2321 if (output_descriptor)
2322 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2323 if (subtitle_codec_name ||
2324 input_props & output_props ||
2326 (input_descriptor && output_descriptor &&
2327 (!input_descriptor->props ||
2328 !output_descriptor->props))) {
2336 enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
2340 if (
input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2361 if (out && !strcmp(out->name, map->
linklabel)) {
2369 av_log(NULL, AV_LOG_FATAL,
"Output with label '%s' does not exist "
2370 "in any defined filter graph, or was already used elsewhere.\n", map->
linklabel);
2379 av_log(NULL, AV_LOG_FATAL,
"Stream #%d:%d is disabled and cannot be mapped.\n",
2385 if(o-> audio_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2387 if(o-> video_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2389 if(o-> data_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2393 switch (ist->
st->codecpar->codec_type) {
2397 case AVMEDIA_TYPE_DATA: ost =
new_data_stream (o, oc, src_idx);
break;
2399 case AVMEDIA_TYPE_UNKNOWN:
2406 "Cannot map stream #%d:%d - unsupported type.\n",
2409 av_log(NULL, AV_LOG_FATAL,
2410 "If you want unsupported types ignored instead "
2411 "of failing, please use the -ignore_unknown option\n"
2412 "If you want them copied, please use -copy_unknown\n");
2426 uint8_t *attachment;
2431 av_log(NULL, AV_LOG_FATAL,
"Could not open attachment file %s.\n",
2435 if ((len = avio_size(pb)) <= 0) {
2436 av_log(NULL, AV_LOG_FATAL,
"Could not get size of the attachment %s.\n",
2440 if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2441 !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2442 av_log(NULL, AV_LOG_FATAL,
"Attachment %s too large.\n",
2446 avio_read(pb, attachment, len);
2447 memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2452 ost->
st->codecpar->extradata = attachment;
2453 ost->
st->codecpar->extradata_size = len;
2456 av_dict_set(&ost->
st->metadata,
"filename", (p && *p) ? p + 1 : o->
attachments[i], AV_DICT_DONT_OVERWRITE);
2460 #if FF_API_LAVF_AVCTX
2462 AVDictionaryEntry *e;
2466 && (e = av_dict_get(o->
g->
codec_opts,
"flags", NULL, AV_DICT_IGNORE_SUFFIX))
2468 if (av_opt_set(ost->
st->codec,
"flags", e->value, 0) < 0)
2473 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2475 av_log(NULL, AV_LOG_ERROR,
"Output file #%d does not contain any stream\n",
nb_output_files - 1);
2484 AV_DICT_IGNORE_SUFFIX)))
2485 av_dict_set(&unused_opts, e->key, NULL, 0);
2489 while ((e = av_dict_get(unused_opts,
"", e, AV_DICT_IGNORE_SUFFIX))) {
2490 const AVClass *
class = avcodec_get_class();
2491 const AVOption *option = av_opt_find(&
class, e->key, NULL, 0,
2492 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2493 const AVClass *fclass = avformat_get_class();
2494 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2495 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2496 if (!option || foption)
2500 if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2501 av_log(NULL, AV_LOG_ERROR,
"Codec AVOption %s (%s) specified for "
2502 "output file #%d (%s) is not an encoding option.\n", e->key,
2509 if (!strcmp(e->key,
"gop_timecode"))
2512 av_log(NULL, AV_LOG_WARNING,
"Codec AVOption %s (%s) specified for "
2513 "output file #%d (%s) has not been used for any stream. The most "
2514 "likely reason is either wrong type (e.g. a video option with "
2515 "no video streams) or that it is a private option of some encoder "
2516 "which was not actually used for any stream.\n", e->key,
2519 av_dict_free(&unused_opts);
2529 if (ost->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2530 ost->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2533 av_log(NULL, AV_LOG_ERROR,
2534 "Error initializing a simple filtergraph between streams "
2546 switch (ost->
enc_ctx->codec_type) {
2547 case AVMEDIA_TYPE_VIDEO:
2551 if (ost->
enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2553 }
else if (ost->
enc->pix_fmts) {
2555 while (ost->
enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2563 case AVMEDIA_TYPE_AUDIO:
2564 if (ost->
enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2566 }
else if (ost->
enc->sample_fmts) {
2568 while (ost->
enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2575 if (ost->
enc_ctx->sample_rate) {
2577 }
else if (ost->
enc->supported_samplerates) {
2579 while (ost->
enc->supported_samplerates[count])
2589 }
else if (ost->
enc->channel_layouts) {
2591 while (ost->
enc->channel_layouts[count])
2605 if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2606 if (!av_filename_number_test(oc->url)) {
2613 av_log(NULL, AV_LOG_ERROR,
2614 "No input streams but output needs an input stream\n");
2618 if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2623 if ((err =
avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2624 &oc->interrupt_callback,
2629 }
else if (strcmp(oc->oformat->name,
"image2")==0 && !av_filename_number_test(filename))
2633 av_dict_set_int(&of->
opts,
"preload", o->
mux_preload*AV_TIME_BASE, 0);
2643 av_log(NULL, AV_LOG_FATAL,
"Invalid input file index %d while processing metadata maps\n", in_file_index);
2647 in_file_index >= 0 ?
2662 av_log(NULL, AV_LOG_FATAL,
"Invalid input file index %d in chapter mapping.\n",
2674 AV_DICT_DONT_OVERWRITE);
2676 av_dict_set(&oc->metadata,
"duration", NULL, 0);
2677 av_dict_set(&oc->metadata,
"creation_time", NULL, 0);
2678 av_dict_set(&oc->metadata,
"company_name", NULL, 0);
2679 av_dict_set(&oc->metadata,
"product_name", NULL, 0);
2680 av_dict_set(&oc->metadata,
"product_version", NULL, 0);
2688 av_dict_copy(&
output_streams[i]->st->metadata, ist->
st->metadata, AV_DICT_DONT_OVERWRITE);
2690 av_dict_set(&
output_streams[i]->st->metadata,
"encoder", NULL, 0);
2701 const char *p2 = av_get_token(&p,
":");
2702 const char *to_dealloc = p2;
2709 key = av_get_token(&p2,
"=");
2711 av_freep(&to_dealloc);
2717 if (!strcmp(key,
"program_num"))
2718 progid = strtol(p2, NULL, 0);
2719 av_freep(&to_dealloc);
2723 program = av_new_program(oc, progid);
2727 const char *p2 = av_get_token(&p,
":");
2728 const char *to_dealloc = p2;
2734 key = av_get_token(&p2,
"=");
2736 av_log(NULL, AV_LOG_FATAL,
2737 "No '=' character in program string %s.\n",
2745 if (!strcmp(key,
"title")) {
2746 av_dict_set(&program->metadata,
"title", p2, 0);
2747 }
else if (!strcmp(key,
"program_num")) {
2748 }
else if (!strcmp(key,
"st")) {
2749 int st_num = strtol(p2, NULL, 0);
2750 av_program_add_stream_index(oc, progid, st_num);
2752 av_log(NULL, AV_LOG_FATAL,
"Unknown program key %s.\n", key);
2755 av_freep(&to_dealloc);
2764 const char *stream_spec;
2765 int index = 0, j, ret = 0;
2769 av_log(NULL, AV_LOG_FATAL,
"No '=' character in metadata string %s.\n",
2777 for (j = 0; j < oc->nb_streams; j++) {
2782 double theta = av_strtod(val, &tail);
2788 av_dict_set(&oc->streams[j]->metadata, o->
metadata[i].
u.
str, *val ? val : NULL, 0);
2800 if (index < 0 || index >= oc->nb_chapters) {
2801 av_log(NULL, AV_LOG_FATAL,
"Invalid chapter index %d in metadata specifier.\n", index);
2804 m = &oc->chapters[index]->metadata;
2807 if (index < 0 || index >= oc->nb_programs) {
2808 av_log(NULL, AV_LOG_FATAL,
"Invalid program index %d in metadata specifier.\n", index);
2811 m = &oc->programs[index]->metadata;
2814 av_log(NULL, AV_LOG_FATAL,
"Invalid metadata specifier %s.\n", o->
metadata[i].
specifier);
2817 av_dict_set(m, o->
metadata[i].
u.
str, *val ? val : NULL, 0);
2828 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2829 const char *
const frame_rates[] = {
"25",
"30000/1001",
"24000/1001" };
2831 if (!strncmp(arg,
"pal-", 4)) {
2834 }
else if (!strncmp(arg,
"ntsc-", 5)) {
2837 }
else if (!strncmp(arg,
"film-", 5)) {
2848 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
2850 fr = st->time_base.den * 1000LL / st->time_base.num;
2854 }
else if ((fr == 29970) || (fr == 23976)) {
2859 if (norm != UNKNOWN)
2863 if (norm != UNKNOWN)
2864 av_log(NULL, AV_LOG_INFO,
"Assuming %s for target.\n", norm == PAL ?
"PAL" :
"NTSC");
2867 if (norm == UNKNOWN) {
2868 av_log(NULL, AV_LOG_FATAL,
"Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2869 av_log(NULL, AV_LOG_FATAL,
"Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2870 av_log(NULL, AV_LOG_FATAL,
"or set a framerate with \"-r xxx\".\n");
2874 if (!strcmp(arg,
"vcd")) {
2879 parse_option(o,
"s", norm == PAL ?
"352x288" :
"352x240", options);
2881 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2901 }
else if (!strcmp(arg,
"svcd")) {
2907 parse_option(o,
"s", norm == PAL ?
"480x576" :
"480x480", options);
2910 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2923 }
else if (!strcmp(arg,
"dvd")) {
2929 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
2932 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2945 }
else if (!strncmp(arg,
"dv", 2)) {
2949 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
2950 parse_option(o,
"pix_fmt", !strncmp(arg,
"dv50", 4) ?
"yuv422p" :
2951 norm == PAL ?
"yuv420p" :
"yuv411p", options);
2958 av_log(NULL, AV_LOG_ERROR,
"Unknown target: %s\n", arg);
2959 return AVERROR(EINVAL);
2978 time_t today2 = time(NULL);
2979 struct tm *today = localtime(&today2);
2982 av_log(NULL, AV_LOG_FATAL,
"Unable to get current time: %s\n", strerror(errno));
2986 snprintf(filename,
sizeof(filename),
"vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
3033 char filename[1000], line[1000], tmp_line[1000];
3034 const char *codec_name = NULL;
3040 if (!(f =
get_preset_file(filename,
sizeof(filename), arg, *opt ==
'f', codec_name))) {
3041 if(!strncmp(arg,
"libx264-lossless", strlen(
"libx264-lossless"))){
3042 av_log(NULL, AV_LOG_FATAL,
"Please use -preset <speed> -qp 0\n");
3044 av_log(NULL, AV_LOG_FATAL,
"File for preset '%s' not found\n", arg);
3048 while (fgets(line,
sizeof(line), f)) {
3049 char *key = tmp_line, *value, *endptr;
3051 if (strcspn(line,
"#\n\r") == 0)
3053 av_strlcpy(tmp_line, line,
sizeof(tmp_line));
3054 if (!av_strtok(key,
"=", &value) ||
3055 !av_strtok(value,
"\r\n", &endptr)) {
3056 av_log(NULL, AV_LOG_FATAL,
"%s: Invalid syntax: '%s'\n", filename, line);
3059 av_log(NULL, AV_LOG_DEBUG,
"ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
3066 av_log(NULL, AV_LOG_FATAL,
"%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3067 filename, line, key, value);
3081 char *s = av_asprintf(
"%s:%c", opt + 1, *opt);
3083 return AVERROR(ENOMEM);
3093 if(!strcmp(opt,
"ab")){
3096 }
else if(!strcmp(opt,
"b")){
3097 av_log(NULL, AV_LOG_WARNING,
"Please use -b:a or -b:v, -b is ambiguous\n");
3111 if(!strcmp(opt,
"qscale")){
3112 av_log(NULL, AV_LOG_WARNING,
"Please use -q:a or -q:v, -qscale is ambiguous\n");
3115 s = av_asprintf(
"q%s", opt + 6);
3117 return AVERROR(ENOMEM);
3126 if(!strcmp(opt,
"profile")){
3127 av_log(NULL, AV_LOG_WARNING,
"Please use -profile:a or -profile:v, -profile is ambiguous\n");
3128 av_dict_set(&o->
g->
codec_opts,
"profile:v", arg, 0);
3147 int opt_vsync(
void *optctx,
const char *opt,
const char *arg)
3163 char *tcr = av_asprintf(
"timecode=%s", arg);
3165 return AVERROR(ENOMEM);
3168 ret = av_dict_set(&o->
g->
codec_opts,
"gop_timecode", arg, 0);
3176 char layout_str[32];
3179 int ret, channels, ac_str_size;
3182 layout = av_get_channel_layout(arg);
3184 av_log(NULL, AV_LOG_ERROR,
"Unknown channel layout: %s\n", arg);
3185 return AVERROR(EINVAL);
3187 snprintf(layout_str,
sizeof(layout_str),
"%"PRIu64, layout);
3193 channels = av_get_channel_layout_nb_channels(layout);
3194 snprintf(layout_str,
sizeof(layout_str),
"%d", channels);
3195 stream_str = strchr(opt,
':');
3196 ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3197 ac_str = av_mallocz(ac_str_size);
3199 return AVERROR(ENOMEM);
3200 av_strlcpy(ac_str,
"ac", 3);
3202 av_strlcat(ac_str, stream_str, ac_str_size);
3219 return AVERROR(ENOMEM);
3223 return AVERROR(ENOMEM);
3234 return AVERROR(EINVAL);
3238 return AVERROR(ENOMEM);
3252 int show_advanced = 0, show_avoptions = 0;
3255 if (!strcmp(opt,
"long"))
3257 else if (!strcmp(opt,
"full"))
3258 show_advanced = show_avoptions = 1;
3260 av_log(NULL, AV_LOG_ERROR,
"Unknown help option '%s'.\n", opt);
3266 " -h -- print basic options\n"
3267 " -h long -- print more options\n"
3268 " -h full -- print all options (including all format and codec specific options, very long)\n"
3269 " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
3270 " See man %s for detailed description of the options.\n"
3277 "instead of just one file):",
3305 if (show_avoptions) {
3306 int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
3312 #if CONFIG_SWRESAMPLE
3315 show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
3316 show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
3322 av_log(NULL, AV_LOG_INFO,
"Hyper fast Audio and Video encoder\n");
3323 av_log(NULL, AV_LOG_INFO,
"usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n",
program_name);
3324 av_log(NULL, AV_LOG_INFO,
"\n");
3333 [GROUP_OUTFILE] = {
"output url", NULL,
OPT_OUTPUT },
3334 [GROUP_INFILE] = {
"input url",
"i",
OPT_INPUT },
3351 av_log(NULL, AV_LOG_ERROR,
"Error parsing options for %s file "
3352 "%s.\n", inout, g->
arg);
3357 av_log(NULL, AV_LOG_DEBUG,
"Opening an %s file: %s.\n", inout, g->
arg);
3358 ret = open_file(&o, g->
arg);
3361 av_log(NULL, AV_LOG_ERROR,
"Error opening %s file %s.\n",
3365 av_log(NULL, AV_LOG_DEBUG,
"Successfully opened the file.\n");
3377 memset(&octx, 0,
sizeof(octx));
3381 FF_ARRAY_ELEMS(groups));
3383 av_log(NULL, AV_LOG_FATAL,
"Error splitting the argument list: ");
3390 av_log(NULL, AV_LOG_FATAL,
"Error parsing global options: ");
3400 av_log(NULL, AV_LOG_FATAL,
"Error opening input files: ");
3407 av_log(NULL, AV_LOG_FATAL,
"Error initializing complex filters.\n");
3414 av_log(NULL, AV_LOG_FATAL,
"Error opening output files: ");
3423 av_strerror(ret, error,
sizeof(error));
3424 av_log(NULL, AV_LOG_FATAL,
"%s\n", error);
3429 int opt_progress(
void *optctx,
const char *opt,
const char *arg)
3431 AVIOContext *avio = NULL;
3434 if (!strcmp(arg,
"-"))
3438 av_log(NULL, AV_LOG_ERROR,
"Failed to open progress URL \"%s\": %s\n",
3439 arg, av_err2str(ret));
#define avformat_open_input
#define avformat_close_input
AVDictionary * codec_opts
AVDictionary * format_opts
AVDictionary * resample_opts
SpecifierOpt * metadata_map
SpecifierOpt * frame_pix_fmts
SpecifierOpt * dump_attachment
SpecifierOpt * audio_sample_rate
int nb_audio_channel_maps
SpecifierOpt * max_frames
int metadata_global_manual
SpecifierOpt * frame_sizes
int metadata_streams_manual
SpecifierOpt * audio_channels
SpecifierOpt * frame_rates
int metadata_chapters_manual
const char ** attachments
AudioChannelMap * audio_channel_maps
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
struct OutputStream * ost
uint64_t * channel_layouts
int max_muxing_queue_size
int copy_initial_nonkeyframes
AVRational frame_aspect_ratio
double rotate_override_value
int audio_channels_mapped
size_t muxing_queue_data_threshold
AVDictionary * resample_opts
AVRational max_frame_rate
AVFifoBuffer * muxing_queue
AVCodecParameters * ref_par
const char * attachment_filename
struct InputStream * sync_ist
AVDictionary * encoder_opts
char * filters
filtergraph associated to the -filter option
int64_t forced_kf_ref_pts
char * filters_script
filtergraph script associated to the -filter_script option
size_t muxing_queue_data_size