66#if HAVE_SYS_RESOURCE_H
68#include <sys/resource.h>
77#include "libavformat/avformat.h"
79#include "libavcodec/avcodec.h"
80#include "libavcodec/bsf.h"
82#include "libavfilter/avfilter.h"
84#include "libavutil/avassert.h"
85#include "libavutil/avstring.h"
86#include "libavutil/avutil.h"
87#include "libavutil/bprint.h"
88#include "libavutil/channel_layout.h"
89#include "libavutil/display.h"
90#include "libavutil/intreadwrite.h"
91#include "libavutil/fifo.h"
92#include "libavutil/mathematics.h"
93#include "libavutil/opt.h"
94#include "libavutil/parseutils.h"
95#include "libavutil/pixdesc.h"
96#include "libavutil/pixfmt.h"
153 void *dst = (uint8_t*)o + po->
u.
off;
157 int i, *count = (
int*)(so + 1);
158 for (i = 0; i < *count; i++) {
159 av_freep(&(*so)[i].specifier);
161 av_freep(&(*so)[i].u.str);
173#if FFMPEG_OPT_MAP_CHANNEL
182 memset(o, 0,
sizeof(*o));
200 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
202 av_log(NULL,
AV_LOG_STDERR,
"Hardware acceleration methods:\n");
203 while ((type = av_hwdevice_iterate_types(type)) !=
204 AV_HWDEVICE_TYPE_NONE)
205 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
213 const AVDictionaryEntry *e = NULL;
214 AVDictionary *ret = NULL;
216 while ((e = av_dict_iterate(dict, e))) {
217 char *p = strchr(e->key,
':');
221 av_dict_set(&ret, e->key, e->value, 0);
230 if (!av_strcasecmp(arg,
"cfr")) *vsync_var =
VSYNC_CFR;
231 else if (!av_strcasecmp(arg,
"vfr")) *vsync_var =
VSYNC_VFR;
233 else if (!av_strcasecmp(arg,
"drop")) *vsync_var =
VSYNC_DROP;
234 else if (!is_global && !av_strcasecmp(arg,
"auto")) *vsync_var =
VSYNC_AUTO;
235 else if (!is_global) {
236 av_log(NULL, AV_LOG_FATAL,
"Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
242 av_log(NULL, AV_LOG_WARNING,
"Passing a number to -vsync is deprecated,"
243 " use a string argument as described in the manual.\n");
253 AVFormatContext *is = ifile->
ctx;
254 int64_t new_start_time = INT64_MAX, diff, abs_start_seek;
258 if (is->start_time == AV_NOPTS_VALUE ||
259 !(is->iformat->flags & AVFMT_TS_DISCONT))
262 for (
int j = 0; j < is->nb_streams; j++) {
263 AVStream *st = is->streams[j];
264 if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
266 new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
269 diff = new_start_time - is->start_time;
271 av_log(NULL, AV_LOG_VERBOSE,
"Correcting start time of Input #%d by %"PRId64
" us.\n", i, diff);
276 abs_start_seek = is->start_time + ((ifile->
start_time != AV_NOPTS_VALUE) ? ifile->
start_time : 0);
277 ifile->
ts_offset = abs_start_seek > new_start_time ? -abs_start_seek : -new_start_time;
291 int64_t self_start_time, ref_start_time, self_seek_start, ref_seek_start;
292 int start_times_set = 1;
296 av_log(NULL, AV_LOG_FATAL,
"-isync for input %d references non-existent input %d.\n", i, self->
input_sync_ref);
301 av_log(NULL, AV_LOG_FATAL,
"Use of -isync requires that start_at_zero be set if copyts is set.\n");
307 av_log(NULL, AV_LOG_ERROR,
"-isync for input %d references a resynced input %d. Sync not set.\n", i, self->
input_sync_ref);
311 if (self->
ctx->start_time_realtime != AV_NOPTS_VALUE && ref->
ctx->start_time_realtime != AV_NOPTS_VALUE) {
312 self_start_time = self->
ctx->start_time_realtime;
313 ref_start_time = ref->
ctx->start_time_realtime;
321 if (start_times_set) {
325 adjustment = (self_start_time - ref_start_time) + !
copy_ts*(self_seek_start - ref_seek_start) + ref->
input_ts_offset;
329 av_log(NULL, AV_LOG_INFO,
"Adjusted ts offset for Input #%d by %"PRId64
" us to sync with Input #%d.\n", i, adjustment, self->
input_sync_ref);
331 av_log(NULL, AV_LOG_INFO,
"Unable to identify start times for Inputs #%d and %d both. No sync adjustment made.\n", i, self->
input_sync_ref);
347 static const AVOption opts[] = {
348 {
"abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, (double)INT64_MAX, .unit =
"flags" },
353 static const AVClass
class = {
355 .item_name = av_default_item_name,
357 .version = LIBAVUTIL_VERSION_INT,
359 const AVClass *pclass = &
class;
361 return av_opt_eval_flags(&pclass, &opts[0], arg, &
abort_on_flags);
368 if (user_stats_period <= 0) {
369 av_log(NULL, AV_LOG_ERROR,
"stats_period %s must be positive.\n", arg);
370 return AVERROR(EINVAL);
374 av_log(NULL, AV_LOG_INFO,
"ffmpeg stats and -progress period set to %s.\n", arg);
403int opt_map(
void *optctx,
const char *opt,
const char *arg)
407 int i, negative = 0, file_idx, disabled = 0;
408#if FFMPEG_OPT_MAP_SYNC
418 map = av_strdup(arg);
420 return AVERROR(ENOMEM);
422#if FFMPEG_OPT_MAP_SYNC
424 if ((sync = strchr(map,
','))) {
426 av_log(NULL, AV_LOG_WARNING,
"Specifying a sync stream is deprecated and has no effect\n");
433 const char *c = map + 1;
438 av_log(NULL, AV_LOG_ERROR,
"Invalid output link label: %s.\n", map);
442 if ((allow_unused = strchr(map,
'?')))
444 file_idx = strtol(map, &p, 0);
446 av_log(NULL, AV_LOG_FATAL,
"Invalid input file index: %d.\n", file_idx);
456 *p ==
':' ? p + 1 : p) > 0)
462 *p ==
':' ? p + 1 : p) <= 0)
464 if (
input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) {
478 av_log(NULL, AV_LOG_VERBOSE,
"Stream map '%s' matches no streams; ignoring.\n", arg);
479 }
else if (disabled) {
480 av_log(NULL, AV_LOG_FATAL,
"Stream map '%s' matches disabled streams.\n"
481 "To ignore this, add a trailing '?' to the map.\n", arg);
484 av_log(NULL, AV_LOG_FATAL,
"Stream map '%s' matches no streams.\n"
485 "To ignore this, add a trailing '?' to the map.\n", arg);
494int opt_attach(
void *optctx,
const char *opt,
const char *arg)
502#if FFMPEG_OPT_MAP_CHANNEL
512 av_log(NULL, AV_LOG_WARNING,
513 "The -%s option is deprecated and will be removed. "
514 "It can be replaced by the 'pan' filter, or in some cases by "
515 "combinations of 'channelsplit', 'channelmap', 'amerge' filters.\n", opt);
517 mapchan = av_strdup(arg);
519 return AVERROR(ENOMEM);
535 n = sscanf(arg,
"%d.%d.%d:%d.%d",
539 if (n != 3 && n != 5) {
540 av_log(NULL, AV_LOG_FATAL,
"Syntax error, mapchan usage: "
541 "[file.stream.channel|-1][:syncfile:syncstream]\n");
550 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid input file index: %d\n",
556 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid input file stream index #%d.%d\n",
561 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
562 av_log(NULL, AV_LOG_FATAL,
"mapchan: stream #%d.%d is not an audio stream.\n",
567 if ((allow_unused = strchr(mapchan,
'?')))
572 av_log(NULL, AV_LOG_VERBOSE,
"mapchan: invalid audio channel #%d.%d.%d\n",
575 av_log(NULL, AV_LOG_FATAL,
"mapchan: invalid audio channel #%d.%d.%d\n"
576 "To ignore this, add a trailing '?' to the map_channel.\n",
595int opt_vaapi_device(
void *optctx,
const char *opt,
const char *arg)
597 const char *prefix =
"vaapi:";
600 tmp = av_asprintf(
"%s%s", prefix, arg);
602 return AVERROR(ENOMEM);
610int opt_qsv_device(
void *optctx,
const char *opt,
const char *arg)
612 const char *prefix =
"qsv=__qsv_device:hw_any,child_device=";
614 char *tmp = av_asprintf(
"%s%s", prefix, arg);
617 return AVERROR(ENOMEM);
628 if (!strcmp(arg,
"list")) {
629 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
630 av_log(NULL,
AV_LOG_STDERR,
"Supported hardware device types:\n");
631 while ((type = av_hwdevice_iterate_types(type)) !=
632 AV_HWDEVICE_TYPE_NONE)
633 av_log(NULL,
AV_LOG_STDERR,
"%s\n", av_hwdevice_get_type_name(type));
644 av_log(NULL, AV_LOG_ERROR,
"Only one filter device can be used.\n");
645 return AVERROR(EINVAL);
649 av_log(NULL, AV_LOG_ERROR,
"Invalid filter device %s.\n", arg);
650 return AVERROR(EINVAL);
660 struct tm time = *gmtime((time_t*)&recording_timestamp);
661 if (!strftime(buf,
sizeof(buf),
"creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
665 av_log(NULL, AV_LOG_WARNING,
"%s is deprecated, set the 'creation_time' metadata "
666 "tag instead.\n", opt);
671 enum AVMediaType type,
int encoder)
673 const AVCodecDescriptor *desc;
674 const char *codec_string = encoder ?
"encoder" :
"decoder";
675 const AVCodec *codec;
678 avcodec_find_encoder_by_name(name) :
679 avcodec_find_decoder_by_name(name);
681 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
682 codec = encoder ? avcodec_find_encoder(desc->id) :
683 avcodec_find_decoder(desc->id);
685 av_log(logctx, AV_LOG_VERBOSE,
"Matched %s '%s' for codec '%s'.\n",
686 codec_string, codec->name, desc->name);
690 av_log(logctx, AV_LOG_FATAL,
"Unknown %s '%s'\n", codec_string, name);
694 av_log(logctx, AV_LOG_FATAL,
"Invalid %s type '%s'\n", codec_string, name);
702 const char *proto_name = avio_find_protocol_name(filename);
705 av_log(NULL, AV_LOG_FATAL,
"Error, both -y and -n supplied. Exiting.\n");
710 if (proto_name && !strcmp(proto_name,
"file") && avio_check(filename, 0) == 0) {
712 av_log(NULL, AV_LOG_FATAL,
"File '%s' already exists. Overwrite? [y/N] ", filename);
714 signal(SIGINT, SIG_DFL);
716 av_log(NULL, AV_LOG_FATAL,
"Not overwriting - exiting\n");
722 av_log(NULL, AV_LOG_FATAL,
"File '%s' already exists. Exiting.\n", filename);
728 if (proto_name && !strcmp(proto_name,
"file")) {
731 if (file->
ctx->iformat->flags & AVFMT_NOFILE)
733 if (!strcmp(filename, file->
ctx->url)) {
734 av_log(NULL, AV_LOG_FATAL,
"Output %s same as Input #%d - exiting\n", filename, i);
735 av_log(NULL, AV_LOG_WARNING,
"FFmpeg cannot edit existing files in-place.\n");
745 AVIOContext *pb = NULL;
746 int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
751 av_log(NULL, AV_LOG_ERROR,
"Error opening file %s.\n", filename);
755 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
756 ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
759 av_bprint_finalize(&bprint, NULL);
762 ret = av_bprint_finalize(&bprint, &str);
776 av_strlcpy(idx_str, arg,
sizeof(idx_str));
777 p = strchr(idx_str,
':');
779 av_log(NULL, AV_LOG_FATAL,
780 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
803int opt_target(
void *optctx,
const char *opt,
const char *arg)
807 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
808 static const char *
const frame_rates[] = {
"25",
"30000/1001",
"24000/1001" };
810 if (!strncmp(arg,
"pal-", 4)) {
813 }
else if (!strncmp(arg,
"ntsc-", 5)) {
816 }
else if (!strncmp(arg,
"film-", 5)) {
827 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
829 fr = st->time_base.den * 1000LL / st->time_base.num;
833 }
else if ((fr == 29970) || (fr == 23976)) {
843 av_log(NULL, AV_LOG_INFO,
"Assuming %s for target.\n", norm == PAL ?
"PAL" :
"NTSC");
846 if (norm == UNKNOWN) {
847 av_log(NULL, AV_LOG_FATAL,
"Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
848 av_log(NULL, AV_LOG_FATAL,
"Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
849 av_log(NULL, AV_LOG_FATAL,
"or set a framerate with \"-r xxx\".\n");
853 if (!strcmp(arg,
"vcd")) {
858 parse_option(o,
"s", norm == PAL ?
"352x288" :
"352x240", options);
880 }
else if (!strcmp(arg,
"svcd")) {
886 parse_option(o,
"s", norm == PAL ?
"480x576" :
"480x480", options);
902 }
else if (!strcmp(arg,
"dvd")) {
908 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
924 }
else if (!strncmp(arg,
"dv", 2)) {
928 parse_option(o,
"s", norm == PAL ?
"720x576" :
"720x480", options);
929 parse_option(o,
"pix_fmt", !strncmp(arg,
"dv50", 4) ?
"yuv422p" :
930 norm == PAL ?
"yuv420p" :
"yuv411p", options);
937 av_log(NULL, AV_LOG_ERROR,
"Unknown target: %s\n", arg);
938 return AVERROR(EINVAL);
954int opt_vstats(
void *optctx,
const char *opt,
const char *arg)
957 time_t today2 = time(NULL);
958 struct tm *today = localtime(&today2);
961 av_log(NULL, AV_LOG_FATAL,
"Unable to get current time: %s\n", strerror(errno));
965 snprintf(filename,
sizeof(filename),
"vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
1012 char filename[1000], line[1000], tmp_line[1000];
1013 const char *codec_name = NULL;
1019 if (!(f =
get_preset_file(filename,
sizeof(filename), arg, *opt ==
'f', codec_name))) {
1020 if(!strncmp(arg,
"libx264-lossless", strlen(
"libx264-lossless"))){
1021 av_log(NULL, AV_LOG_FATAL,
"Please use -preset <speed> -qp 0\n");
1023 av_log(NULL, AV_LOG_FATAL,
"File for preset '%s' not found\n", arg);
1027 while (fgets(line,
sizeof(line), f)) {
1028 char *key = tmp_line, *value, *endptr;
1030 if (strcspn(line,
"#\n\r") == 0)
1032 av_strlcpy(tmp_line, line,
sizeof(tmp_line));
1033 if (!av_strtok(key,
"=", &value) ||
1034 !av_strtok(value,
"\r\n", &endptr)) {
1035 av_log(NULL, AV_LOG_FATAL,
"%s: Invalid syntax: '%s'\n", filename, line);
1038 av_log(NULL, AV_LOG_DEBUG,
"ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
1045 av_log(NULL, AV_LOG_FATAL,
"%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
1046 filename, line, key, value);
1060 char *s = av_asprintf(
"%s:%c", opt + 1, *opt);
1062 return AVERROR(ENOMEM);
1072 if(!strcmp(opt,
"ab")){
1075 }
else if(!strcmp(opt,
"b")){
1076 av_log(NULL, AV_LOG_WARNING,
"Please use -b:a or -b:v, -b is ambiguous\n");
1090 if(!strcmp(opt,
"qscale")){
1091 av_log(NULL, AV_LOG_WARNING,
"Please use -q:a or -q:v, -qscale is ambiguous\n");
1094 s = av_asprintf(
"q%s", opt + 6);
1096 return AVERROR(ENOMEM);
1105 if(!strcmp(opt,
"profile")){
1106 av_log(NULL, AV_LOG_WARNING,
"Please use -profile:a or -profile:v, -profile is ambiguous\n");
1107 av_dict_set(&o->
g->
codec_opts,
"profile:v", arg, 0);
1126int opt_vsync(
void *optctx,
const char *opt,
const char *arg)
1128 av_log(NULL, AV_LOG_WARNING,
"-vsync is deprecated. Use -fps_mode\n");
1137 char *tcr = av_asprintf(
"timecode=%s", arg);
1139 return AVERROR(ENOMEM);
1142 ret = av_dict_set(&o->
g->
codec_opts,
"gop_timecode", arg, 0);
1160 return AVERROR(ENOMEM);
1170 return AVERROR(EINVAL);
1184 int show_advanced = 0, show_avoptions = 0;
1187 if (!strcmp(opt,
"long"))
1189 else if (!strcmp(opt,
"full"))
1190 show_advanced = show_avoptions = 1;
1192 av_log(NULL, AV_LOG_ERROR,
"Unknown help option '%s'.\n", opt);
1198 " -h -- print basic options\n"
1199 " -h long -- print more options\n"
1200 " -h full -- print all options (including all format and codec specific options, very long)\n"
1201 " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
1202 " See man %s for detailed description of the options.\n"
1209 "instead of just one file):",
1237 if (show_avoptions) {
1238 int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
1244#if CONFIG_SWRESAMPLE
1247 show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
1248 show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
1254 av_log(NULL, AV_LOG_INFO,
"Hyper fast Audio and Video encoder\n");
1255 av_log(NULL, AV_LOG_INFO,
"usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n",
program_name);
1256 av_log(NULL, AV_LOG_INFO,
"\n");
1283 av_log(NULL, AV_LOG_ERROR,
"Error parsing options for %s file "
1284 "%s.\n", inout, g->
arg);
1289 av_log(NULL, AV_LOG_DEBUG,
"Opening an %s file: %s.\n", inout, g->
arg);
1290 ret = open_file(&o, g->
arg);
1293 av_log(NULL, AV_LOG_ERROR,
"Error opening %s file %s.\n",
1297 av_log(NULL, AV_LOG_DEBUG,
"Successfully opened the file.\n");
1308 memset(&octx, 0,
sizeof(octx));
1314 av_log(NULL, AV_LOG_FATAL,
"Error splitting the argument list: ");
1321 av_log(NULL, AV_LOG_FATAL,
"Error parsing global options: ");
1331 av_log(NULL, AV_LOG_FATAL,
"Error opening input files: ");
1338 av_log(NULL, AV_LOG_FATAL,
"Error initializing complex filters.\n");
1345 av_log(NULL, AV_LOG_FATAL,
"Error opening output files: ");
1358 av_log(NULL, AV_LOG_FATAL,
"%s\n", av_err2str(ret));
1365 AVIOContext *avio = NULL;
1368 if (!strcmp(arg,
"-"))
1370 ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &
int_cb, NULL);
1372 av_log(NULL, AV_LOG_ERROR,
"Failed to open progress URL \"%s\": %s\n",
1373 arg, av_err2str(ret));
1384 struct rlimit rl = { lim, lim + 1 };
1385 if (setrlimit(RLIMIT_CPU, &rl))
1386 perror(
"setrlimit");
1388 av_log(NULL, AV_LOG_WARNING,
"-%s not implemented on this OS\n", opt);
AVDictionary * codec_opts
AVDictionary * format_opts
int nb_audio_channel_maps
float shortest_buf_duration
const char ** attachments
AudioChannelMap * audio_channel_maps