42 #include "libavformat/avformat.h"
44 #include "libavcodec/avcodec.h"
46 #include "libavfilter/avfilter.h"
48 #include "libavutil/avassert.h"
49 #include "libavutil/avstring.h"
50 #include "libavutil/avutil.h"
51 #include "libavutil/channel_layout.h"
52 #include "libavutil/intreadwrite.h"
53 #include "libavutil/fifo.h"
54 #include "libavutil/mathematics.h"
55 #include "libavutil/opt.h"
56 #include "libavutil/parseutils.h"
57 #include "libavutil/pixdesc.h"
58 #include "libavutil/pixfmt.h"
60 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
62 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
65 for (i = 0; i < o->nb_ ## name; i++) {\
66 char *spec = o->name[i].specifier;\
67 if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
68 outvar = o->name[i].u.type;\
74 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
77 for (i = 0; i < o->nb_ ## name; i++) {\
78 char *spec = o->name[i].specifier;\
79 if (!strcmp(spec, mediatype))\
80 outvar = o->name[i].u.type;\
85 #if CONFIG_VIDEOTOOLBOX
150 void *dst = (uint8_t*)o + po->
u.
off;
154 int i, *count = (
int*)(so + 1);
155 for (i = 0; i < *count; i++) {
156 av_freep(&(*so)[i].specifier);
158 av_freep(&(*so)[i].u.str);
177 memset(o, 0,
sizeof(*o));
191 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
194 av_log(NULL,
AV_LOG_STDERR,
"Hardware acceleration methods:\n");
195 while ((type = av_hwdevice_iterate_types(type)) !=
196 AV_HWDEVICE_TYPE_NONE)
197 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
207 AVDictionaryEntry *e = NULL;
208 AVDictionary *ret = NULL;
210 while ((e = av_dict_get(dict,
"", e, AV_DICT_IGNORE_SUFFIX))) {
211 char *p = strchr(e->key,
':');
215 av_dict_set(&ret, e->key, e->value, 0);
224 const AVOption opts[] = {
225 {
"abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
229 const AVClass
class = {
231 .item_name = av_default_item_name,
233 .version = LIBAVUTIL_VERSION_INT,
235 const AVClass *pclass = &
class;
237 return av_opt_eval_flags(&pclass, &opts[0], arg, &
abort_on_flags);
240 int opt_sameq(
void *optctx,
const char *opt,
const char *arg)
243 "If you are looking for an option to preserve the quality (which is not "
244 "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
246 return AVERROR(EINVAL);
251 av_log(NULL,
AV_LOG_WARNING,
"This option is deprecated, use -channel.\n");
257 av_log(NULL,
AV_LOG_WARNING,
"This option is deprecated, use -standard.\n");
285 int opt_map(
void *optctx,
const char *opt,
const char *arg)
289 int i, negative = 0, file_idx, disabled = 0;
290 int sync_file_idx = -1, sync_stream_idx = 0;
299 map = av_strdup(arg);
301 return AVERROR(ENOMEM);
304 if ((sync = strchr(map,
','))) {
306 sync_file_idx = strtol(sync + 1, &sync, 0);
308 av_log(NULL,
AV_LOG_FATAL,
"Invalid sync file index: %d.\n", sync_file_idx);
320 av_log(NULL,
AV_LOG_FATAL,
"Sync stream specification in map %s does not "
321 "match any streams.\n", arg);
325 av_log(NULL,
AV_LOG_FATAL,
"Sync stream specification in map %s matches a disabled input "
334 const char *c = map + 1;
339 av_log(NULL,
AV_LOG_ERROR,
"Invalid output link label: %s.\n", map);
343 if ((allow_unused = strchr(map,
'?')))
345 file_idx = strtol(map, &p, 0);
347 av_log(NULL,
AV_LOG_FATAL,
"Invalid input file index: %d.\n", file_idx);
357 *p ==
':' ? p + 1 : p) > 0)
363 *p ==
':' ? p + 1 : p) <= 0)
375 if (sync_file_idx >= 0) {
387 av_log(NULL,
AV_LOG_VERBOSE,
"Stream map '%s' matches no streams; ignoring.\n", arg);
388 }
else if (disabled) {
389 av_log(NULL,
AV_LOG_FATAL,
"Stream map '%s' matches disabled streams.\n"
390 "To ignore this, add a trailing '?' to the map.\n", arg);
393 av_log(NULL,
AV_LOG_FATAL,
"Stream map '%s' matches no streams.\n"
394 "To ignore this, add a trailing '?' to the map.\n", arg);
403 int opt_attach(
void *optctx,
const char *opt,
const char *arg)
419 mapchan = av_strdup(arg);
421 return AVERROR(ENOMEM);
437 n = sscanf(arg,
"%d.%d.%d:%d.%d",
441 if (n != 3 && n != 5) {
442 av_log(NULL,
AV_LOG_FATAL,
"Syntax error, mapchan usage: "
443 "[file.stream.channel|-1][:syncfile:syncstream]\n");
452 av_log(NULL,
AV_LOG_FATAL,
"mapchan: invalid input file index: %d\n",
458 av_log(NULL,
AV_LOG_FATAL,
"mapchan: invalid input file stream index #%d.%d\n",
463 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
464 av_log(NULL,
AV_LOG_FATAL,
"mapchan: stream #%d.%d is not an audio stream.\n",
469 if ((allow_unused = strchr(mapchan,
'?')))
474 av_log(NULL,
AV_LOG_VERBOSE,
"mapchan: invalid audio channel #%d.%d.%d\n",
477 av_log(NULL,
AV_LOG_FATAL,
"mapchan: invalid audio channel #%d.%d.%d\n"
478 "To ignore this, add a trailing '?' to the map_channel.\n",
496 int opt_vaapi_device(
void *optctx,
const char *opt,
const char *arg)
499 const char *prefix =
"vaapi:";
502 tmp = av_asprintf(
"%s%s", prefix, arg);
504 return AVERROR(ENOMEM);
511 return AVERROR(ENOMEM);
518 if (!strcmp(arg,
"list")) {
519 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
520 av_log(NULL,
AV_LOG_STDERR,
"Supported hardware device types:\n");
521 while ((type = av_hwdevice_iterate_types(type)) !=
522 AV_HWDEVICE_TYPE_NONE)
523 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
534 av_log(NULL,
AV_LOG_ERROR,
"Only one filter device can be used.\n");
535 return AVERROR(EINVAL);
539 av_log(NULL,
AV_LOG_ERROR,
"Invalid filter device %s.\n", arg);
540 return AVERROR(EINVAL);
560 if (*(++arg) && *arg !=
':') {
561 av_log(NULL,
AV_LOG_FATAL,
"Invalid metadata specifier %s.\n", arg);
564 *stream_spec = *arg ==
':' ? arg + 1 :
"";
569 *index = strtol(++arg, NULL, 0);
572 av_log(NULL,
AV_LOG_FATAL,
"Invalid metadata type %c.\n", *arg);
581 AVDictionary **meta_in = NULL;
582 AVDictionary **meta_out = NULL;
584 char type_in, type_out;
585 const char *istream_spec = NULL, *ostream_spec = NULL;
586 int idx_in = 0, idx_out = 0;
592 if (type_out ==
'g' || !*outspec)
594 if (type_out ==
's' || !*outspec)
596 if (type_out ==
'c' || !*outspec)
601 if (type_in ==
'g' || type_out ==
'g')
603 if (type_in ==
's' || type_out ==
's')
605 if (type_in ==
'c' || type_out ==
'c')
612 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
613 if ((index) < 0 || (index) >= (nb_elems)) {\
614 av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
619 #define SET_DICT(type, meta, context, index)\
622 meta = &context->metadata;\
625 METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
626 meta = &context->chapters[index]->metadata;\
629 METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
630 meta = &context->programs[index]->metadata;\
634 default: av_assert0(0);\
637 SET_DICT(type_in, meta_in, ic, idx_in);
638 SET_DICT(type_out, meta_out, oc, idx_out);
641 if (type_in ==
's') {
642 for (i = 0; i < ic->nb_streams; i++) {
644 meta_in = &ic->streams[i]->metadata;
650 av_log(NULL,
AV_LOG_FATAL,
"Stream specifier %s does not match any streams.\n", istream_spec);
655 if (type_out ==
's') {
656 for (i = 0; i < oc->nb_streams; i++) {
658 meta_out = &oc->streams[i]->metadata;
659 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
664 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
674 struct tm
time = *gmtime((time_t*)&recording_timestamp);
675 if (!strftime(buf,
sizeof(buf),
"creation_time=%Y-%m-%dT%H:%M:%S%z", &
time))
679 av_log(NULL,
AV_LOG_WARNING,
"%s is deprecated, set the 'creation_time' metadata "
680 "tag instead.\n", opt);
686 const AVCodecDescriptor *desc;
687 const char *codec_string = encoder ?
"encoder" :
"decoder";
691 avcodec_find_encoder_by_name(name) :
692 avcodec_find_decoder_by_name(name);
694 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
695 codec = encoder ? avcodec_find_encoder(desc->id) :
696 avcodec_find_decoder(desc->id);
699 codec_string, codec->name, desc->name);
703 av_log(NULL,
AV_LOG_FATAL,
"Unknown %s '%s'\n", codec_string, name);
706 if (codec->type != type) {
707 av_log(NULL,
AV_LOG_FATAL,
"Invalid %s type '%s'\n", codec_string, name);
715 char *codec_name = NULL;
720 st->codecpar->codec_id = codec->id;
723 return avcodec_find_decoder(st->codecpar->codec_id);
732 for (i = 0; i < ic->nb_streams; i++) {
733 AVStream *st = ic->streams[i];
734 AVCodecParameters *par = st->codecpar;
736 char *framerate = NULL, *hwaccel_device = NULL;
737 const char *hwaccel = NULL;
738 char *hwaccel_output_format = NULL;
739 char *codec_tag = NULL;
741 char *discard_str = NULL;
742 const AVClass *cc = avcodec_get_class();
743 const AVOption *discard_opt = av_opt_find(&cc,
"skip_frame", NULL, 0, 0);
754 st->discard = AVDISCARD_ALL;
767 uint32_t tag = strtol(codec_tag, &next, 0);
769 tag = AV_RL32(codec_tag);
770 st->codecpar->codec_tag = tag;
782 if ((o->
video_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
783 (o->
audio_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
785 (o->
data_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
788 if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->
user_set_discard) < 0) {
789 av_log(NULL,
AV_LOG_ERROR,
"Error parsing discard %s.\n",
796 ist->
dec_ctx = avcodec_alloc_context3(ist->
dec);
798 av_log(NULL,
AV_LOG_ERROR,
"Error allocating the decoder context.\n");
802 ret = avcodec_parameters_to_context(ist->
dec_ctx, par);
804 av_log(NULL,
AV_LOG_ERROR,
"Error initializing the decoder context.\n");
809 ist->
dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
811 switch (par->codec_type) {
812 case AVMEDIA_TYPE_VIDEO:
814 ist->
dec = avcodec_find_decoder(par->codec_id);
816 if (st->codec->lowres) {
817 ist->
dec_ctx->lowres = st->codec->lowres;
818 ist->
dec_ctx->width = st->codec->width;
819 ist->
dec_ctx->height = st->codec->height;
820 ist->
dec_ctx->coded_width = st->codec->coded_width;
821 ist->
dec_ctx->coded_height = st->codec->coded_height;
826 ist->
dec_ctx->framerate = st->avg_frame_rate;
829 if (framerate && av_parse_video_rate(&ist->
framerate,
831 av_log(NULL,
AV_LOG_ERROR,
"Error parsing framerate %s.\n",
842 if (!strcmp(hwaccel,
"nvdec"))
845 if (!strcmp(hwaccel,
"none"))
847 else if (!strcmp(hwaccel,
"auto"))
850 enum AVHWDeviceType type;
853 if (!strcmp(
hwaccels[i].name, hwaccel)) {
860 type = av_hwdevice_find_type_by_name(hwaccel);
861 if (type != AV_HWDEVICE_TYPE_NONE) {
868 av_log(NULL,
AV_LOG_FATAL,
"Unrecognized hwaccel: %s.\n",
871 type = AV_HWDEVICE_TYPE_NONE;
872 while ((type = av_hwdevice_iterate_types(type)) !=
873 AV_HWDEVICE_TYPE_NONE)
875 av_hwdevice_get_type_name(type));
885 if (hwaccel_device) {
892 hwaccel_output_format, ic, st);
893 if (hwaccel_output_format) {
896 av_log(NULL,
AV_LOG_FATAL,
"Unrecognised hwaccel output "
897 "format: %s", hwaccel_output_format);
906 case AVMEDIA_TYPE_AUDIO:
911 case AVMEDIA_TYPE_DATA:
912 case AVMEDIA_TYPE_SUBTITLE: {
913 char *canvas_size = NULL;
915 ist->
dec = avcodec_find_decoder(par->codec_id);
919 av_parse_video_size(&ist->
dec_ctx->width, &ist->
dec_ctx->height, canvas_size) < 0) {
920 av_log(NULL,
AV_LOG_FATAL,
"Invalid canvas size: %s.\n", canvas_size);
925 case AVMEDIA_TYPE_ATTACHMENT:
926 case AVMEDIA_TYPE_UNKNOWN:
932 ret = avcodec_parameters_from_context(par, ist->
dec_ctx);
934 av_log(NULL,
AV_LOG_ERROR,
"Error initializing the decoder context.\n");
942 const char *proto_name = avio_find_protocol_name(filename);
945 fprintf(stderr,
"Error, both -y and -n supplied. Exiting.\n");
950 if (proto_name && !strcmp(proto_name,
"file") && avio_check(filename, 0) == 0) {
952 fprintf(stderr,
"File '%s' already exists. Overwrite ? [y/N] ", filename);
955 signal(SIGINT, SIG_DFL);
957 av_log(NULL,
AV_LOG_FATAL,
"Not overwriting - exiting\n");
963 av_log(NULL,
AV_LOG_FATAL,
"File '%s' already exists. Exiting.\n", filename);
969 if (proto_name && !strcmp(proto_name,
"file")) {
972 if (file->
ctx->iformat->flags & AVFMT_NOFILE)
974 if (!strcmp(filename, file->
ctx->url)) {
975 av_log(NULL,
AV_LOG_FATAL,
"Output %s same as Input #%d - exiting\n", filename, i);
976 av_log(NULL,
AV_LOG_WARNING,
"FFmpeg cannot edit existing files in-place.\n");
986 AVIOContext *out = NULL;
987 AVDictionaryEntry *e;
989 if (!st->codecpar->extradata_size) {
990 av_log(NULL,
AV_LOG_WARNING,
"No extradata to dump in stream #%d:%d.\n",
994 if (!*filename && (e = av_dict_get(st->metadata,
"filename", NULL, 0)))
997 av_log(NULL,
AV_LOG_FATAL,
"No filename specified and no 'filename' tag"
1004 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &
int_cb, NULL)) < 0) {
1005 av_log(NULL,
AV_LOG_FATAL,
"Could not open file %s for writing.\n",
1010 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
1018 AVFormatContext *ic;
1019 AVInputFormat *file_iformat = NULL;
1022 AVDictionary *unused_opts = NULL;
1023 AVDictionaryEntry *e = NULL;
1024 char * video_codec_name = NULL;
1025 char * audio_codec_name = NULL;
1026 char *subtitle_codec_name = NULL;
1027 char * data_codec_name = NULL;
1028 int scan_all_pmts_set = 0;
1032 av_log(NULL,
AV_LOG_WARNING,
"-t and -to cannot be used together; using -t.\n");
1038 av_log(NULL,
AV_LOG_ERROR,
"-to value smaller than -ss; aborting.\n");
1046 if (!(file_iformat = av_find_input_format(o->
format))) {
1052 if (!strcmp(filename,
"-"))
1056 strcmp(filename,
"/dev/stdin");
1059 ic = avformat_alloc_context();
1071 if (file_iformat && file_iformat->priv_class &&
1072 av_opt_find(&file_iformat->priv_class,
"channels", NULL, 0,
1073 AV_OPT_SEARCH_FAKE_OBJ)) {
1080 if (file_iformat && file_iformat->priv_class &&
1081 av_opt_find(&file_iformat->priv_class,
"framerate", NULL, 0,
1082 AV_OPT_SEARCH_FAKE_OBJ)) {
1098 if (video_codec_name)
1100 if (audio_codec_name)
1102 if (subtitle_codec_name)
1103 ic->subtitle_codec =
find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1104 if (data_codec_name)
1107 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1108 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1109 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1110 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1112 ic->flags |= AVFMT_FLAG_NONBLOCK;
1114 ic->flags |= AVFMT_FLAG_BITEXACT;
1115 ic->interrupt_callback =
int_cb;
1117 if (!av_dict_get(o->
g->
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1118 av_dict_set(&o->
g->
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
1119 scan_all_pmts_set = 1;
1122 err = avformat_open_input(&ic, filename, file_iformat, &o->
g->
format_opts);
1125 if (err == AVERROR_PROTOCOL_NOT_FOUND)
1126 av_log(NULL,
AV_LOG_ERROR,
"Did you mean file:%s?\n", filename);
1129 if (scan_all_pmts_set)
1130 av_dict_set(&o->
g->
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1135 for (i = 0; i < ic->nb_streams; i++)
1140 int orig_nb_streams = ic->nb_streams;
1144 ret = avformat_find_stream_info(ic, opts);
1146 for (i = 0; i < orig_nb_streams; i++)
1147 av_dict_free(&opts[i]);
1151 av_log(NULL,
AV_LOG_FATAL,
"%s: could not find codec parameters\n", filename);
1152 if (ic->nb_streams == 0) {
1153 avformat_close_input(&ic);
1160 av_log(NULL,
AV_LOG_WARNING,
"Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1166 av_log(NULL,
AV_LOG_ERROR,
"-sseof value must be negative; aborting\n");
1169 if (ic->duration > 0) {
1172 av_log(NULL,
AV_LOG_WARNING,
"-sseof value seeks to before start of file %s; ignored\n", filename);
1176 av_log(NULL,
AV_LOG_WARNING,
"Cannot use -sseof, duration of %s not known\n", filename);
1181 timestamp += ic->start_time;
1185 int64_t seek_timestamp = timestamp;
1187 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1188 int dts_heuristic = 0;
1189 for (i=0; i<ic->nb_streams; i++) {
1190 const AVCodecParameters *par = ic->streams[i]->codecpar;
1191 if (par->video_delay) {
1196 if (dts_heuristic) {
1197 seek_timestamp -= 3*AV_TIME_BASE / 23;
1200 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1202 av_log(NULL,
AV_LOG_WARNING,
"%s: could not seek to position %0.3f\n",
1203 filename, (
double)timestamp / AV_TIME_BASE);
1214 f = av_mallocz(
sizeof(*f));
1239 while ((e = av_dict_get(
input_streams[i]->decoder_opts,
"", e,
1240 AV_DICT_IGNORE_SUFFIX)))
1241 av_dict_set(&unused_opts, e->key, NULL, 0);
1245 while ((e = av_dict_get(unused_opts,
"", e, AV_DICT_IGNORE_SUFFIX))) {
1246 const AVClass *
class = avcodec_get_class();
1247 const AVOption *option = av_opt_find(&
class, e->key, NULL, 0,
1248 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1249 const AVClass *fclass = avformat_get_class();
1250 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1251 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1252 if (!option || foption)
1256 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1257 av_log(NULL,
AV_LOG_ERROR,
"Codec AVOption %s (%s) specified for "
1258 "input file #%d (%s) is not a decoding option.\n", e->key,
1264 av_log(NULL,
AV_LOG_WARNING,
"Codec AVOption %s (%s) specified for "
1265 "input file #%d (%s) has not been used for any stream. The most "
1266 "likely reason is either wrong type (e.g. a video option with "
1267 "no video streams) or that it is a private option of some decoder "
1268 "which was not actually used for any stream.\n", e->key,
1271 av_dict_free(&unused_opts);
1276 for (j = 0; j < ic->nb_streams; j++) {
1277 AVStream *st = ic->streams[j];
1295 if (avio_open_dyn_buf(&line) < 0) {
1296 av_log(NULL,
AV_LOG_FATAL,
"Could not alloc buffer for reading preset.\n");
1300 while ((c = avio_r8(s)) && c !=
'\n')
1303 avio_close_dyn_buf(line, &buf);
1311 char filename[1000];
1312 const char *base[3] = { getenv(
"AVCONV_DATADIR"),
1317 for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1321 snprintf(filename,
sizeof(filename),
"%s%s/%s-%s.avpreset", base[i],
1322 i != 1 ?
"" :
"/.avconv", codec_name, preset_name);
1323 ret = avio_open2(s, filename, AVIO_FLAG_READ, &
int_cb, NULL);
1326 snprintf(filename,
sizeof(filename),
"%s%s/%s.avpreset", base[i],
1327 i != 1 ?
"" :
"/.avconv", preset_name);
1328 ret = avio_open2(s, filename, AVIO_FLAG_READ, &
int_cb, NULL);
1336 enum AVMediaType type = ost->
st->codecpar->codec_type;
1337 char *codec_name = NULL;
1339 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1342 ost->
st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1343 NULL, ost->
st->codecpar->codec_type);
1344 ost->
enc = avcodec_find_encoder(ost->
st->codecpar->codec_id);
1346 av_log(NULL,
AV_LOG_FATAL,
"Automatic encoder selection failed for "
1347 "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1348 "probably disabled. Please choose an encoder manually.\n",
1350 avcodec_get_name(ost->
st->codecpar->codec_id));
1351 return AVERROR_ENCODER_NOT_FOUND;
1353 }
else if (!strcmp(codec_name,
"copy"))
1357 ost->
st->codecpar->codec_id = ost->
enc->id;
1372 AVStream *st = avformat_new_stream(oc, NULL);
1373 int idx = oc->nb_streams - 1, ret = 0;
1374 const char *bsfs = NULL, *time_base = NULL;
1375 char *next, *codec_tag = NULL;
1380 av_log(NULL,
AV_LOG_FATAL,
"Could not alloc stream.\n");
1388 if (!(ost = av_mallocz(
sizeof(*ost))))
1396 st->codecpar->codec_type = type;
1400 av_log(NULL,
AV_LOG_FATAL,
"Error selecting an encoder for stream "
1405 ost->
enc_ctx = avcodec_alloc_context3(ost->
enc);
1407 av_log(NULL,
AV_LOG_ERROR,
"Error allocating the encoding context.\n");
1410 ost->
enc_ctx->codec_type = type;
1412 ost->
ref_par = avcodec_parameters_alloc();
1414 av_log(NULL,
AV_LOG_ERROR,
"Error allocating the encoding parameters.\n");
1419 AVIOContext *s = NULL;
1420 char *buf = NULL, *arg = NULL, *preset = NULL;
1428 if (!buf[0] || buf[0] ==
'#') {
1432 if (!(arg = strchr(buf,
'='))) {
1433 av_log(NULL,
AV_LOG_FATAL,
"Invalid line found in the preset file.\n");
1437 av_dict_set(&ost->
encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1439 }
while (!s->eof_reached);
1444 "Preset %s specified for stream %d:%d, but could not be opened.\n",
1454 ost->
enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1459 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1460 q.num <= 0 || q.den <= 0) {
1461 av_log(NULL,
AV_LOG_FATAL,
"Invalid time base: %s\n", time_base);
1470 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1472 av_log(NULL,
AV_LOG_FATAL,
"Invalid time base: %s\n", time_base);
1482 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1483 av_log(NULL,
AV_LOG_WARNING,
"Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1492 while (bsfs && *bsfs) {
1493 const AVBitStreamFilter *filter;
1494 char *bsf, *bsf_options_str, *bsf_name;
1496 bsf = av_get_token(&bsfs,
",");
1499 bsf_name = av_strtok(bsf,
"=", &bsf_options_str);
1503 filter = av_bsf_get_by_name(bsf_name);
1505 av_log(NULL,
AV_LOG_FATAL,
"Unknown bitstream filter %s\n", bsf_name);
1517 av_log(NULL,
AV_LOG_ERROR,
"Error allocating a bitstream filter context\n");
1523 if (bsf_options_str && filter->priv_class) {
1525 const char * shorthand[2] = {NULL};
1528 shorthand[0] = opt->name;
1532 av_log(NULL,
AV_LOG_ERROR,
"Error parsing options for bitstream filter %s\n", bsf_name);
1544 uint32_t tag = strtol(codec_tag, &next, 0);
1546 tag = AV_RL32(codec_tag);
1547 ost->
st->codecpar->codec_tag =
1548 ost->
enc_ctx->codec_tag = tag;
1553 ost->
enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1554 ost->
enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1564 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1565 ost->
enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1570 if (ost->
enc && av_get_exact_bits_per_sample(ost->
enc->id) == 24)
1571 av_dict_set(&ost->
swr_opts,
"output_sample_bits",
"24", 0);
1576 if (source_index >= 0) {
1583 ost->
muxing_queue = av_fifo_alloc(8 *
sizeof(AVPacket));
1593 const char *p = str;
1600 av_log(NULL,
AV_LOG_FATAL,
"Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1610 AVIOContext *pb = NULL;
1611 AVIOContext *dyn_buf = NULL;
1612 int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1613 uint8_t buf[1024], *str;
1616 av_log(NULL,
AV_LOG_ERROR,
"Error opening file %s.\n", filename);
1620 ret = avio_open_dyn_buf(&dyn_buf);
1625 while ((ret = avio_read(pb, buf,
sizeof(buf))) > 0)
1626 avio_write(dyn_buf, buf, ret);
1627 avio_w8(dyn_buf, 0);
1630 ret = avio_close_dyn_buf(dyn_buf, &str);
1639 AVStream *st = ost->
st;
1642 av_log(NULL,
AV_LOG_ERROR,
"Both -filter and -filter_script set for "
1650 return av_strdup(ost->
filters);
1652 return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
1661 "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1662 "Filtering and streamcopy cannot be used together.\n",
1663 ost->
filters ?
"Filtergraph" :
"Filtergraph script",
1674 AVCodecContext *video_enc;
1675 char *frame_rate = NULL, *frame_aspect_ratio = NULL;
1682 if (frame_rate && av_parse_video_rate(&ost->
frame_rate, frame_rate) < 0) {
1683 av_log(NULL,
AV_LOG_FATAL,
"Invalid framerate value: %s\n", frame_rate);
1687 av_log(NULL,
AV_LOG_ERROR,
"Using -vsync 0 and -r can produce invalid output files\n");
1690 if (frame_aspect_ratio) {
1692 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1693 q.num <= 0 || q.den <= 0) {
1694 av_log(NULL,
AV_LOG_FATAL,
"Invalid aspect ratio: %s\n", frame_aspect_ratio);
1703 av_log(NULL,
AV_LOG_ERROR,
"Only '-vf %s' read, ignoring remaining -vf options: Use ',' to separate filters\n", ost->
filters);
1706 const char *p = NULL;
1707 char *frame_size = NULL;
1708 char *frame_pix_fmt = NULL;
1709 char *intra_matrix = NULL, *inter_matrix = NULL;
1710 char *chroma_intra_matrix = NULL;
1715 if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1716 av_log(NULL,
AV_LOG_FATAL,
"Invalid frame size: %s.\n", frame_size);
1722 if (frame_pix_fmt && *frame_pix_fmt ==
'+') {
1724 if (!*++frame_pix_fmt)
1725 frame_pix_fmt = NULL;
1727 if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1728 av_log(NULL,
AV_LOG_FATAL,
"Unknown pixel format requested: %s.\n", frame_pix_fmt);
1731 st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1734 video_enc->gop_size = 0;
1737 if (!(video_enc->intra_matrix = av_mallocz(
sizeof(*video_enc->intra_matrix) * 64))) {
1738 av_log(NULL,
AV_LOG_FATAL,
"Could not allocate memory for intra matrix.\n");
1744 if (chroma_intra_matrix) {
1745 uint16_t *p = av_mallocz(
sizeof(*video_enc->chroma_intra_matrix) * 64);
1747 av_log(NULL,
AV_LOG_FATAL,
"Could not allocate memory for intra matrix.\n");
1750 video_enc->chroma_intra_matrix = p;
1755 if (!(video_enc->inter_matrix = av_mallocz(
sizeof(*video_enc->inter_matrix) * 64))) {
1756 av_log(NULL,
AV_LOG_FATAL,
"Could not allocate memory for inter matrix.\n");
1763 for (i = 0; p; i++) {
1765 int e = sscanf(p,
"%d,%d,%d", &start, &end, &q);
1767 av_log(NULL,
AV_LOG_FATAL,
"error parsing rc_override\n");
1770 video_enc->rc_override =
1771 av_realloc_array(video_enc->rc_override,
1772 i + 1,
sizeof(RcOverride));
1773 if (!video_enc->rc_override) {
1774 av_log(NULL,
AV_LOG_FATAL,
"Could not (re)allocate memory for rc_override.\n");
1777 video_enc->rc_override[i].start_frame = start;
1778 video_enc->rc_override[i].end_frame = end;
1780 video_enc->rc_override[i].qscale = q;
1781 video_enc->rc_override[i].quality_factor = 1.0;
1784 video_enc->rc_override[i].qscale = 0;
1785 video_enc->rc_override[i].quality_factor = -q/100.0;
1790 video_enc->rc_override_count = i;
1793 video_enc->flags|= AV_CODEC_FLAG_PSNR;
1799 video_enc->flags |= AV_CODEC_FLAG_PASS1;
1800 av_dict_set(&ost->
encoder_opts,
"flags",
"+pass1", AV_DICT_APPEND);
1803 video_enc->flags |= AV_CODEC_FLAG_PASS2;
1804 av_dict_set(&ost->
encoder_opts,
"flags",
"+pass2", AV_DICT_APPEND);
1814 char logfilename[1024];
1817 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
1821 if (!strcmp(ost->
enc->name,
"libx264")) {
1822 av_dict_set(&ost->
encoder_opts,
"stats", logfilename, AV_DICT_DONT_OVERWRITE);
1824 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1828 av_log(NULL,
AV_LOG_FATAL,
"Error reading log file '%s' for pass-2 encoding\n",
1832 video_enc->stats_in = logbuffer;
1834 if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1835 f = av_fopen_utf8(logfilename,
"wb");
1838 "Cannot write log file '%s' for pass-1 encoding: %s\n",
1839 logfilename, strerror(errno));
1875 AVCodecContext *audio_enc;
1881 audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1886 av_log(NULL,
AV_LOG_ERROR,
"Only '-af %s' read, ignoring remaining -af options: Use ',' to separate filters\n", ost->
filters);
1889 char *sample_fmt = NULL;
1895 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1896 av_log(NULL,
AV_LOG_FATAL,
"Invalid sample format '%s'\n", sample_fmt);
1919 av_log(NULL,
AV_LOG_FATAL,
"Cannot determine input stream for channel mapping %d.%d\n",
1951 av_log(NULL,
AV_LOG_FATAL,
"Data stream encoding not supported yet (only streamcopy)\n");
1964 av_log(NULL,
AV_LOG_FATAL,
"Unknown stream encoding not supported yet (only streamcopy)\n");
1983 AVCodecContext *subtitle_enc;
1989 subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
1994 char *frame_size = NULL;
1997 if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
1998 av_log(NULL,
AV_LOG_FATAL,
"Invalid frame size: %s.\n", frame_size);
2014 av_strlcpy(idx_str, arg,
sizeof(idx_str));
2015 p = strchr(idx_str,
':');
2018 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2031 AVFormatContext *is = ifile->
ctx;
2032 AVFormatContext *os = ofile->
ctx;
2036 tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters,
sizeof(*os->chapters));
2038 return AVERROR(ENOMEM);
2041 for (i = 0; i < is->nb_chapters; i++) {
2042 AVChapter *in_ch = is->chapters[i], *out_ch;
2044 int64_t ts_off = av_rescale_q(start_time - ifile->
ts_offset,
2045 AV_TIME_BASE_Q, in_ch->time_base);
2047 av_rescale_q(ofile->
recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2050 if (in_ch->end < ts_off)
2052 if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2055 out_ch = av_mallocz(
sizeof(AVChapter));
2057 return AVERROR(ENOMEM);
2059 out_ch->id = in_ch->id;
2060 out_ch->time_base = in_ch->time_base;
2061 out_ch->start = FFMAX(0, in_ch->start - ts_off);
2062 out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2065 av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2067 os->chapters[os->nb_chapters++] = out_ch;
2073 AVFormatContext *oc)
2077 switch (ofilter->
type) {
2081 av_log(NULL,
AV_LOG_FATAL,
"Only video and audio filters are supported "
2093 av_log(NULL,
AV_LOG_ERROR,
"Streamcopy requested for output stream %d:%d, "
2094 "which is fed from a complex filtergraph. Filtering and streamcopy "
2100 const char *opt = ost->
filters ?
"-vf/-af/-filter" :
"-filter_script";
2102 "%s '%s' was specified through the %s option "
2103 "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2104 "%s and -filter_complex cannot be used together for the same stream.\n",
2105 ost->
filters ?
"Filtergraph" :
"Filtergraph script",
2111 avfilter_inout_free(&ofilter->
out_tmp);
2128 AVFormatContext *oc;
2133 AVDictionary *unused_opts = NULL;
2134 AVDictionaryEntry *e = NULL;
2135 int format_flags = 0;
2139 av_log(NULL,
AV_LOG_WARNING,
"-t and -to cannot be used together; using -t.\n");
2145 av_log(NULL,
AV_LOG_ERROR,
"-to value smaller than -ss; aborting.\n");
2153 of = av_mallocz(
sizeof(*of));
2165 if (!strcmp(filename,
"-"))
2168 err = avformat_alloc_output_context2(&oc, NULL, o->
format, filename);
2178 oc->interrupt_callback =
int_cb;
2182 const AVOption *o = av_opt_find(oc,
"fflags", NULL, 0, 0);
2183 av_opt_eval_flags(oc, o, e->value, &format_flags);
2186 format_flags |= AVFMT_FLAG_BITEXACT;
2187 oc->flags |= AVFMT_FLAG_BITEXACT;
2199 switch (ofilter->
type) {
2209 char *subtitle_codec_name = NULL;
2213 if (!o->
video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
2214 int area = 0, idx = -1;
2215 int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2219 new_area = ist->
st->codecpar->width * ist->
st->codecpar->height + 100000000*!!ist->
st->codec_info_nb_frames
2220 + 5000000*!!(ist->
st->disposition & AV_DISPOSITION_DEFAULT);
2223 if((qcr!=MKTAG(
'A',
'P',
'I',
'C')) && (ist->
st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2225 if (ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2227 if((qcr==MKTAG(
'A',
'P',
'I',
'C')) && !(ist->
st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2238 if (!o->
audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
2239 int best_score = 0, idx = -1;
2243 score = ist->
st->codecpar->channels + 100000000*!!ist->
st->codec_info_nb_frames
2244 + 5000000*!!(ist->
st->disposition & AV_DISPOSITION_DEFAULT);
2247 if (ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2248 score > best_score) {
2259 if (!o->
subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2261 if (
input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2262 AVCodecDescriptor
const *input_descriptor =
2263 avcodec_descriptor_get(
input_streams[i]->st->codecpar->codec_id);
2264 AVCodecDescriptor
const *output_descriptor = NULL;
2265 AVCodec
const *output_codec =
2266 avcodec_find_encoder(oc->oformat->subtitle_codec);
2267 int input_props = 0, output_props = 0;
2271 output_descriptor = avcodec_descriptor_get(output_codec->id);
2272 if (input_descriptor)
2273 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2274 if (output_descriptor)
2275 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2276 if (subtitle_codec_name ||
2277 input_props & output_props ||
2279 (input_descriptor && output_descriptor &&
2280 (!input_descriptor->props ||
2281 !output_descriptor->props))) {
2289 enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
2293 if (
input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2314 if (out && !strcmp(out->name, map->
linklabel)) {
2322 av_log(NULL,
AV_LOG_FATAL,
"Output with label '%s' does not exist "
2323 "in any defined filter graph, or was already used elsewhere.\n", map->
linklabel);
2332 av_log(NULL,
AV_LOG_FATAL,
"Stream #%d:%d is disabled and cannot be mapped.\n",
2338 if(o-> audio_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2340 if(o-> video_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2342 if(o-> data_disable && ist->
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2346 switch (ist->
st->codecpar->codec_type) {
2350 case AVMEDIA_TYPE_DATA: ost =
new_data_stream (o, oc, src_idx);
break;
2352 case AVMEDIA_TYPE_UNKNOWN:
2359 "Cannot map stream #%d:%d - unsupported type.\n",
2363 "If you want unsupported types ignored instead "
2364 "of failing, please use the -ignore_unknown option\n"
2365 "If you want them copied, please use -copy_unknown\n");
2379 uint8_t *attachment;
2383 if ((err = avio_open2(&pb, o->
attachments[i], AVIO_FLAG_READ, &
int_cb, NULL)) < 0) {
2384 av_log(NULL,
AV_LOG_FATAL,
"Could not open attachment file %s.\n",
2388 if ((len = avio_size(pb)) <= 0) {
2389 av_log(NULL,
AV_LOG_FATAL,
"Could not get size of the attachment %s.\n",
2393 if (!(attachment = av_malloc(len))) {
2394 av_log(NULL,
AV_LOG_FATAL,
"Attachment %s too large to fit into memory.\n",
2398 avio_read(pb, attachment, len);
2403 ost->
st->codecpar->extradata = attachment;
2404 ost->
st->codecpar->extradata_size = len;
2407 av_dict_set(&ost->
st->metadata,
"filename", (p && *p) ? p + 1 : o->
attachments[i], AV_DICT_DONT_OVERWRITE);
2411 #if FF_API_LAVF_AVCTX
2413 AVDictionaryEntry *e;
2417 && (e = av_dict_get(o->
g->
codec_opts,
"flags", NULL, AV_DICT_IGNORE_SUFFIX))
2419 if (av_opt_set(ost->
st->codec,
"flags", e->value, 0) < 0)
2424 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2435 AV_DICT_IGNORE_SUFFIX)))
2436 av_dict_set(&unused_opts, e->key, NULL, 0);
2440 while ((e = av_dict_get(unused_opts,
"", e, AV_DICT_IGNORE_SUFFIX))) {
2441 const AVClass *
class = avcodec_get_class();
2442 const AVOption *option = av_opt_find(&
class, e->key, NULL, 0,
2443 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2444 const AVClass *fclass = avformat_get_class();
2445 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2446 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2447 if (!option || foption)
2451 if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2452 av_log(NULL,
AV_LOG_ERROR,
"Codec AVOption %s (%s) specified for "
2453 "output file #%d (%s) is not an encoding option.\n", e->key,
2460 if (!strcmp(e->key,
"gop_timecode"))
2463 av_log(NULL,
AV_LOG_WARNING,
"Codec AVOption %s (%s) specified for "
2464 "output file #%d (%s) has not been used for any stream. The most "
2465 "likely reason is either wrong type (e.g. a video option with "
2466 "no video streams) or that it is a private option of some encoder "
2467 "which was not actually used for any stream.\n", e->key,
2470 av_dict_free(&unused_opts);
2480 if (ost->
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2481 ost->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2485 "Error initializing a simple filtergraph between streams "
2497 switch (ost->
enc_ctx->codec_type) {
2498 case AVMEDIA_TYPE_VIDEO:
2502 if (ost->
enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2504 }
else if (ost->
enc->pix_fmts) {
2506 while (ost->
enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2514 case AVMEDIA_TYPE_AUDIO:
2515 if (ost->
enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2517 }
else if (ost->
enc->sample_fmts) {
2519 while (ost->
enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2526 if (ost->
enc_ctx->sample_rate) {
2528 }
else if (ost->
enc->supported_samplerates) {
2530 while (ost->
enc->supported_samplerates[count])
2540 }
else if (ost->
enc->channel_layouts) {
2542 while (ost->
enc->channel_layouts[count])
2556 if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2557 if (!av_filename_number_test(oc->url)) {
2565 "No input streams but output needs an input stream\n");
2569 if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2574 if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2575 &oc->interrupt_callback,
2580 }
else if (strcmp(oc->oformat->name,
"image2")==0 && !av_filename_number_test(filename))
2584 av_dict_set_int(&of->
opts,
"preload", o->
mux_preload*AV_TIME_BASE, 0);
2594 av_log(NULL,
AV_LOG_FATAL,
"Invalid input file index %d while processing metadata maps\n", in_file_index);
2598 in_file_index >= 0 ?
2613 av_log(NULL,
AV_LOG_FATAL,
"Invalid input file index %d in chapter mapping.\n",
2625 AV_DICT_DONT_OVERWRITE);
2627 av_dict_set(&oc->metadata,
"duration", NULL, 0);
2628 av_dict_set(&oc->metadata,
"creation_time", NULL, 0);
2636 av_dict_copy(&
output_streams[i]->st->metadata, ist->
st->metadata, AV_DICT_DONT_OVERWRITE);
2638 av_dict_set(&
output_streams[i]->st->metadata,
"encoder", NULL, 0);
2649 const char *p2 = av_get_token(&p,
":");
2650 const char *to_dealloc = p2;
2657 key = av_get_token(&p2,
"=");
2659 av_freep(&to_dealloc);
2665 if (!strcmp(key,
"program_num"))
2666 progid = strtol(p2, NULL, 0);
2667 av_freep(&to_dealloc);
2671 program = av_new_program(oc, progid);
2675 const char *p2 = av_get_token(&p,
":");
2676 const char *to_dealloc = p2;
2682 key = av_get_token(&p2,
"=");
2685 "No '=' character in program string %s.\n",
2693 if (!strcmp(key,
"title")) {
2694 av_dict_set(&program->metadata,
"title", p2, 0);
2695 }
else if (!strcmp(key,
"program_num")) {
2696 }
else if (!strcmp(key,
"st")) {
2697 int st_num = strtol(p2, NULL, 0);
2698 av_program_add_stream_index(oc, progid, st_num);
2700 av_log(NULL,
AV_LOG_FATAL,
"Unknown program key %s.\n", key);
2703 av_freep(&to_dealloc);
2712 const char *stream_spec;
2713 int index = 0, j, ret = 0;
2717 av_log(NULL,
AV_LOG_FATAL,
"No '=' character in metadata string %s.\n",
2725 for (j = 0; j < oc->nb_streams; j++) {
2730 double theta = av_strtod(val, &tail);
2736 av_dict_set(&oc->streams[j]->metadata, o->
metadata[i].
u.
str, *val ? val : NULL, 0);
2748 if (index < 0 || index >= oc->nb_chapters) {
2749 av_log(NULL,
AV_LOG_FATAL,
"Invalid chapter index %d in metadata specifier.\n", index);
2752 m = &oc->chapters[index]->metadata;
2755 if (index < 0 || index >= oc->nb_programs) {
2756 av_log(NULL,
AV_LOG_FATAL,
"Invalid program index %d in metadata specifier.\n", index);
2759 m = &oc->programs[index]->metadata;
2765 av_dict_set(m, o->
metadata[i].
u.
str, *val ? val : NULL, 0);
2776 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2777 const char *
const frame_rates[] = {
"25",
"30000/1001",
"24000/1001" };
2779 if (!strncmp(arg,
"pal-", 4)) {
2782 }
else if (!strncmp(arg,
"ntsc-", 5)) {
2785 }
else if (!strncmp(arg,
"film-", 5)) {
2796 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
2798 fr = st->time_base.den * 1000LL / st->time_base.num;
2802 }
else if ((fr == 29970) || (fr == 23976)) {
2807 if (norm != UNKNOWN)
2811 if (norm != UNKNOWN)
2812 av_log(NULL,
AV_LOG_INFO,
"Assuming %s for target.\n", norm == PAL ?
"PAL" :
"NTSC");
2815 if (norm == UNKNOWN) {
2816 av_log(NULL,
AV_LOG_FATAL,
"Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2817 av_log(NULL,
AV_LOG_FATAL,
"Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2818 av_log(NULL,
AV_LOG_FATAL,
"or set a framerate with \"-r xxx\".\n");
2822 if (!strcmp(arg,
"vcd")) {
2827 parse_option(o,
"s", norm == PAL ?
"352x288" :
"352x240", options);
2829 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2849 }
else if (!strcmp(arg,
"svcd")) {
2855 parse_option(o,
"s", norm == PAL ?
"480x576" :
"480x480", options);
2858 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2871 }
else if (!strcmp(arg,
"dvd")) {
2877 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
2880 opt_default(NULL,
"g", norm == PAL ?
"15" :
"18");
2893 }
else if (!strncmp(arg,
"dv", 2)) {
2897 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
2898 parse_option(o,
"pix_fmt", !strncmp(arg,
"dv50", 4) ?
"yuv422p" :
2899 norm == PAL ?
"yuv420p" :
"yuv411p", options);
2906 av_log(NULL,
AV_LOG_ERROR,
"Unknown target: %s\n", arg);
2907 return AVERROR(EINVAL);
2926 time_t today2 =
time(NULL);
2927 struct tm *today = localtime(&today2);
2930 av_log(NULL,
AV_LOG_FATAL,
"Unable to get current time: %s\n", strerror(errno));
2934 snprintf(filename,
sizeof(filename),
"vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
2981 char filename[1000], line[1000], tmp_line[1000];
2982 const char *codec_name = NULL;
2988 if (!(f =
get_preset_file(filename,
sizeof(filename), arg, *opt ==
'f', codec_name))) {
2989 if(!strncmp(arg,
"libx264-lossless", strlen(
"libx264-lossless"))){
2990 av_log(NULL,
AV_LOG_FATAL,
"Please use -preset <speed> -qp 0\n");
2992 av_log(NULL,
AV_LOG_FATAL,
"File for preset '%s' not found\n", arg);
2996 while (fgets(line,
sizeof(line), f)) {
2997 char *key = tmp_line, *
value, *endptr;
2999 if (strcspn(line,
"#\n\r") == 0)
3001 av_strlcpy(tmp_line, line,
sizeof(tmp_line));
3002 if (!av_strtok(key,
"=", &
value) ||
3003 !av_strtok(
value,
"\r\n", &endptr)) {
3004 av_log(NULL,
AV_LOG_FATAL,
"%s: Invalid syntax: '%s'\n", filename, line);
3007 av_log(NULL,
AV_LOG_DEBUG,
"ffpreset[%s]: set '%s' = '%s'\n", filename, key,
value);
3014 av_log(NULL,
AV_LOG_FATAL,
"%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3015 filename, line, key,
value);
3029 char *s = av_asprintf(
"%s:%c", opt + 1, *opt);
3031 return AVERROR(ENOMEM);
3041 if(!strcmp(opt,
"ab")){
3044 }
else if(!strcmp(opt,
"b")){
3045 av_log(NULL,
AV_LOG_WARNING,
"Please use -b:a or -b:v, -b is ambiguous\n");
3059 if(!strcmp(opt,
"qscale")){
3060 av_log(NULL,
AV_LOG_WARNING,
"Please use -q:a or -q:v, -qscale is ambiguous\n");
3063 s = av_asprintf(
"q%s", opt + 6);
3065 return AVERROR(ENOMEM);
3074 if(!strcmp(opt,
"profile")){
3075 av_log(NULL,
AV_LOG_WARNING,
"Please use -profile:a or -profile:v, -profile is ambiguous\n");
3076 av_dict_set(&o->
g->
codec_opts,
"profile:v", arg, 0);
3095 int opt_vsync(
void *optctx,
const char *opt,
const char *arg)
3111 char *tcr = av_asprintf(
"timecode=%s", arg);
3113 return AVERROR(ENOMEM);
3116 ret = av_dict_set(&o->
g->
codec_opts,
"gop_timecode", arg, 0);
3124 char layout_str[32];
3127 int ret, channels, ac_str_size;
3130 layout = av_get_channel_layout(arg);
3132 av_log(NULL,
AV_LOG_ERROR,
"Unknown channel layout: %s\n", arg);
3133 return AVERROR(EINVAL);
3135 snprintf(layout_str,
sizeof(layout_str),
"%"PRIu64, layout);
3141 channels = av_get_channel_layout_nb_channels(layout);
3142 snprintf(layout_str,
sizeof(layout_str),
"%d", channels);
3143 stream_str = strchr(opt,
':');
3144 ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3145 ac_str = av_mallocz(ac_str_size);
3147 return AVERROR(ENOMEM);
3148 av_strlcpy(ac_str,
"ac", 3);
3150 av_strlcat(ac_str, stream_str, ac_str_size);
3167 return AVERROR(ENOMEM);
3171 return AVERROR(ENOMEM);
3182 return AVERROR(EINVAL);
3186 return AVERROR(ENOMEM);
3200 int show_advanced = 0, show_avoptions = 0;
3203 if (!strcmp(opt,
"long"))
3205 else if (!strcmp(opt,
"full"))
3206 show_advanced = show_avoptions = 1;
3208 av_log(NULL,
AV_LOG_ERROR,
"Unknown help option '%s'.\n", opt);
3214 " -h -- print basic options\n"
3215 " -h long -- print more options\n"
3216 " -h full -- print all options (including all format and codec specific options, very long)\n"
3217 " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf\n"
3218 " See man %s for detailed description of the options.\n"
3225 "instead of just one file:",
3253 if (show_avoptions) {
3254 int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
3260 #if CONFIG_SWRESAMPLE
3263 show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
3264 show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
3270 av_log(NULL,
AV_LOG_INFO,
"Hyper fast Audio and Video encoder\n");
3271 av_log(NULL,
AV_LOG_INFO,
"usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n",
program_name);
3281 [GROUP_OUTFILE] = {
"output url", NULL,
OPT_OUTPUT },
3282 [GROUP_INFILE] = {
"input url",
"i",
OPT_INPUT },
3299 av_log(NULL,
AV_LOG_ERROR,
"Error parsing options for %s file "
3300 "%s.\n", inout, g->
arg);
3304 av_log(NULL,
AV_LOG_DEBUG,
"Opening an %s file: %s.\n", inout, g->
arg);
3305 ret = open_file(&o, g->
arg);
3308 av_log(NULL,
AV_LOG_ERROR,
"Error opening %s file %s.\n",
3312 av_log(NULL,
AV_LOG_DEBUG,
"Successfully opened the file.\n");
3324 memset(&octx, 0,
sizeof(octx));
3328 FF_ARRAY_ELEMS(groups));
3330 av_log(NULL,
AV_LOG_FATAL,
"Error splitting the argument list: ");
3337 av_log(NULL,
AV_LOG_FATAL,
"Error parsing global options: ");
3347 av_log(NULL,
AV_LOG_FATAL,
"Error opening input files: ");
3354 av_log(NULL,
AV_LOG_FATAL,
"Error initializing complex filters.\n");
3361 av_log(NULL,
AV_LOG_FATAL,
"Error opening output files: ");
3370 av_strerror(ret, error,
sizeof(error));
3376 int opt_progress(
void *optctx,
const char *opt,
const char *arg)
3378 AVIOContext *avio = NULL;
3381 if (!strcmp(arg,
"-"))
3383 ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &
int_cb, NULL);
3385 av_log(NULL,
AV_LOG_ERROR,
"Failed to open progress URL \"%s\": %s\n",
3386 arg, av_err2str(ret));