1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362 |
- /*
- * ffmpeg option parsing
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- #include "config.h"
- #include <float.h>
- #include <stdint.h>
- #if HAVE_SYS_RESOURCE_H
- #include <sys/time.h>
- #include <sys/resource.h>
- #endif
- #include "ffmpeg.h"
- #include "cmdutils.h"
- #include "opt_common.h"
- #include "sync_queue.h"
- #include "libavformat/avformat.h"
- #include "libavcodec/avcodec.h"
- #include "libavcodec/bsf.h"
- #include "libavfilter/avfilter.h"
- #include "libavutil/avassert.h"
- #include "libavutil/avstring.h"
- #include "libavutil/avutil.h"
- #include "libavutil/bprint.h"
- #include "libavutil/channel_layout.h"
- #include "libavutil/display.h"
- #include "libavutil/intreadwrite.h"
- #include "libavutil/fifo.h"
- #include "libavutil/mathematics.h"
- #include "libavutil/opt.h"
- #include "libavutil/parseutils.h"
- #include "libavutil/pixdesc.h"
- #include "libavutil/pixfmt.h"
- const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
- const char *const opt_name_frame_rates[] = {"r", NULL};
- static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
- static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
- static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
- static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
- static const char *const opt_name_autorotate[] = {"autorotate", NULL};
- const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL};
- const char *const opt_name_top_field_first[] = {"top", NULL};
- static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
- static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
- static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
- static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
- static const char *const opt_name_discard[] = {"discard", NULL};
- static const char *const opt_name_display_rotations[] = {"display_rotation", NULL};
- static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
- static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
- HWDevice *filter_hw_device;
- char *vstats_filename;
- char *sdp_filename;
- float audio_drift_threshold = 0.1;
- float dts_delta_threshold = 10;
- float dts_error_threshold = 3600*30;
- enum VideoSyncMethod video_sync_method = VSYNC_AUTO;
- float frame_drop_threshold = 0;
- int do_benchmark = 0;
- int do_benchmark_all = 0;
- int do_hex_dump = 0;
- int do_pkt_dump = 0;
- int copy_ts = 0;
- int start_at_zero = 0;
- int copy_tb = -1;
- int debug_ts = 0;
- int exit_on_error = 0;
- int abort_on_flags = 0;
- int print_stats = -1;
- int qp_hist = 0;
- int stdin_interaction = 1;
- float max_error_rate = 2.0/3;
- char *filter_nbthreads;
- int filter_complex_nbthreads = 0;
- int vstats_version = 2;
- int auto_conversion_filters = 1;
- int64_t stats_period = 500000;
- static int file_overwrite = 0;
- static int no_file_overwrite = 0;
- #if FFMPEG_OPT_PSNR
- int do_psnr = 0;
- #endif
- int input_stream_potentially_available = 0;
- int ignore_unknown_streams = 0;
- int copy_unknown_streams = 0;
- static int recast_media = 0;
- static void uninit_options(OptionsContext *o)
- {
- const OptionDef *po = options;
- int i;
- /* all OPT_SPEC and OPT_STRING can be freed in generic way */
- while (po->name) {
- void *dst = (uint8_t*)o + po->u.off;
- if (po->flags & OPT_SPEC) {
- SpecifierOpt **so = dst;
- int i, *count = (int*)(so + 1);
- for (i = 0; i < *count; i++) {
- av_freep(&(*so)[i].specifier);
- if (po->flags & OPT_STRING)
- av_freep(&(*so)[i].u.str);
- }
- av_freep(so);
- *count = 0;
- } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
- av_freep(dst);
- po++;
- }
- for (i = 0; i < o->nb_stream_maps; i++)
- av_freep(&o->stream_maps[i].linklabel);
- av_freep(&o->stream_maps);
- #if FFMPEG_OPT_MAP_CHANNEL
- av_freep(&o->audio_channel_maps);
- #endif
- av_freep(&o->streamid_map);
- av_freep(&o->attachments);
- }
- static void init_options(OptionsContext *o)
- {
- memset(o, 0, sizeof(*o));
- o->stop_time = INT64_MAX;
- o->mux_max_delay = 0.7;
- o->start_time = AV_NOPTS_VALUE;
- o->start_time_eof = AV_NOPTS_VALUE;
- o->recording_time = INT64_MAX;
- o->limit_filesize = INT64_MAX;
- o->chapters_input_file = INT_MAX;
- o->accurate_seek = 1;
- o->thread_queue_size = -1;
- o->input_sync_ref = -1;
- o->find_stream_info = 1;
- o->shortest_buf_duration = 10.f;
- }
- static int show_hwaccels(void *optctx, const char *opt, const char *arg)
- {
- enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
- printf("Hardware acceleration methods:\n");
- while ((type = av_hwdevice_iterate_types(type)) !=
- AV_HWDEVICE_TYPE_NONE)
- printf("%s\n", av_hwdevice_get_type_name(type));
- printf("\n");
- return 0;
- }
- /* return a copy of the input with the stream specifiers removed from the keys */
- AVDictionary *strip_specifiers(AVDictionary *dict)
- {
- const AVDictionaryEntry *e = NULL;
- AVDictionary *ret = NULL;
- while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
- char *p = strchr(e->key, ':');
- if (p)
- *p = 0;
- av_dict_set(&ret, e->key, e->value, 0);
- if (p)
- *p = ':';
- }
- return ret;
- }
- int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
- {
- if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
- else if (!av_strcasecmp(arg, "vfr")) *vsync_var = VSYNC_VFR;
- else if (!av_strcasecmp(arg, "passthrough")) *vsync_var = VSYNC_PASSTHROUGH;
- else if (!av_strcasecmp(arg, "drop")) *vsync_var = VSYNC_DROP;
- else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO;
- else if (!is_global) {
- av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
- exit_program(1);
- }
- if (is_global && *vsync_var == VSYNC_AUTO) {
- video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
- av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
- " use a string argument as described in the manual.\n");
- }
- return 0;
- }
- static int apply_sync_offsets(void)
- {
- for (int i = 0; i < nb_input_files; i++) {
- InputFile *ref, *self = input_files[i];
- int64_t adjustment;
- int64_t self_start_time, ref_start_time, self_seek_start, ref_seek_start;
- int start_times_set = 1;
- if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue;
- if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) {
- av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref);
- exit_program(1);
- }
- if (copy_ts && !start_at_zero) {
- av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n");
- exit_program(1);
- }
- ref = input_files[self->input_sync_ref];
- if (ref->input_sync_ref != -1 && ref->input_sync_ref != self->input_sync_ref) {
- av_log(NULL, AV_LOG_ERROR, "-isync for input %d references a resynced input %d. Sync not set.\n", i, self->input_sync_ref);
- continue;
- }
- if (self->ctx->start_time_realtime != AV_NOPTS_VALUE && ref->ctx->start_time_realtime != AV_NOPTS_VALUE) {
- self_start_time = self->ctx->start_time_realtime;
- ref_start_time = ref->ctx->start_time_realtime;
- } else if (self->ctx->start_time != AV_NOPTS_VALUE && ref->ctx->start_time != AV_NOPTS_VALUE) {
- self_start_time = self->ctx->start_time;
- ref_start_time = ref->ctx->start_time;
- } else {
- start_times_set = 0;
- }
- if (start_times_set) {
- self_seek_start = self->start_time == AV_NOPTS_VALUE ? 0 : self->start_time;
- ref_seek_start = ref->start_time == AV_NOPTS_VALUE ? 0 : ref->start_time;
- adjustment = (self_start_time - ref_start_time) + !copy_ts*(self_seek_start - ref_seek_start) + ref->input_ts_offset;
- self->ts_offset += adjustment;
- 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);
- } else {
- 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);
- }
- }
- return 0;
- }
- static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
- {
- av_free(filter_nbthreads);
- filter_nbthreads = av_strdup(arg);
- return 0;
- }
- static int opt_abort_on(void *optctx, const char *opt, const char *arg)
- {
- static const AVOption opts[] = {
- { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
- { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
- { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
- { NULL },
- };
- static const AVClass class = {
- .class_name = "",
- .item_name = av_default_item_name,
- .option = opts,
- .version = LIBAVUTIL_VERSION_INT,
- };
- const AVClass *pclass = &class;
- return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
- }
- static int opt_stats_period(void *optctx, const char *opt, const char *arg)
- {
- int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
- if (user_stats_period <= 0) {
- av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
- return AVERROR(EINVAL);
- }
- stats_period = user_stats_period;
- av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
- return 0;
- }
- static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "codec:a", arg, options);
- }
- static int opt_video_codec(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "codec:v", arg, options);
- }
- static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "codec:s", arg, options);
- }
- static int opt_data_codec(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "codec:d", arg, options);
- }
- static int opt_map(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- StreamMap *m = NULL;
- int i, negative = 0, file_idx, disabled = 0;
- #if FFMPEG_OPT_MAP_SYNC
- char *sync;
- #endif
- char *map, *p;
- char *allow_unused;
- if (*arg == '-') {
- negative = 1;
- arg++;
- }
- map = av_strdup(arg);
- if (!map)
- return AVERROR(ENOMEM);
- #if FFMPEG_OPT_MAP_SYNC
- /* parse sync stream first, just pick first matching stream */
- if (sync = strchr(map, ',')) {
- *sync = 0;
- av_log(NULL, AV_LOG_WARNING, "Specifying a sync stream is deprecated and has no effect\n");
- }
- #endif
- if (map[0] == '[') {
- /* this mapping refers to lavfi output */
- const char *c = map + 1;
- GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
- m = &o->stream_maps[o->nb_stream_maps - 1];
- m->linklabel = av_get_token(&c, "]");
- if (!m->linklabel) {
- av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
- exit_program(1);
- }
- } else {
- if (allow_unused = strchr(map, '?'))
- *allow_unused = 0;
- file_idx = strtol(map, &p, 0);
- if (file_idx >= nb_input_files || file_idx < 0) {
- av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
- exit_program(1);
- }
- if (negative)
- /* disable some already defined maps */
- for (i = 0; i < o->nb_stream_maps; i++) {
- m = &o->stream_maps[i];
- if (file_idx == m->file_index &&
- check_stream_specifier(input_files[m->file_index]->ctx,
- input_files[m->file_index]->ctx->streams[m->stream_index],
- *p == ':' ? p + 1 : p) > 0)
- m->disabled = 1;
- }
- else
- for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
- if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
- *p == ':' ? p + 1 : p) <= 0)
- continue;
- if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
- disabled = 1;
- continue;
- }
- GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
- m = &o->stream_maps[o->nb_stream_maps - 1];
- m->file_index = file_idx;
- m->stream_index = i;
- }
- }
- if (!m) {
- if (allow_unused) {
- av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
- } else if (disabled) {
- av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
- "To ignore this, add a trailing '?' to the map.\n", arg);
- exit_program(1);
- } else {
- av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
- "To ignore this, add a trailing '?' to the map.\n", arg);
- exit_program(1);
- }
- }
- av_freep(&map);
- return 0;
- }
- static int opt_attach(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- GROW_ARRAY(o->attachments, o->nb_attachments);
- o->attachments[o->nb_attachments - 1] = arg;
- return 0;
- }
- #if FFMPEG_OPT_MAP_CHANNEL
- static int opt_map_channel(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- int n;
- AVStream *st;
- AudioChannelMap *m;
- char *allow_unused;
- char *mapchan;
- av_log(NULL, AV_LOG_WARNING,
- "The -%s option is deprecated and will be removed. "
- "It can be replaced by the 'pan' filter, or in some cases by "
- "combinations of 'channelsplit', 'channelmap', 'amerge' filters.\n", opt);
- mapchan = av_strdup(arg);
- if (!mapchan)
- return AVERROR(ENOMEM);
- GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
- m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
- /* muted channel syntax */
- n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
- if ((n == 1 || n == 3) && m->channel_idx == -1) {
- m->file_idx = m->stream_idx = -1;
- if (n == 1)
- m->ofile_idx = m->ostream_idx = -1;
- av_free(mapchan);
- return 0;
- }
- /* normal syntax */
- n = sscanf(arg, "%d.%d.%d:%d.%d",
- &m->file_idx, &m->stream_idx, &m->channel_idx,
- &m->ofile_idx, &m->ostream_idx);
- if (n != 3 && n != 5) {
- av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
- "[file.stream.channel|-1][:syncfile:syncstream]\n");
- exit_program(1);
- }
- if (n != 5) // only file.stream.channel specified
- m->ofile_idx = m->ostream_idx = -1;
- /* check input */
- if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
- av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
- m->file_idx);
- exit_program(1);
- }
- if (m->stream_idx < 0 ||
- m->stream_idx >= input_files[m->file_idx]->nb_streams) {
- av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
- m->file_idx, m->stream_idx);
- exit_program(1);
- }
- st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
- if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
- av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
- m->file_idx, m->stream_idx);
- exit_program(1);
- }
- /* allow trailing ? to map_channel */
- if (allow_unused = strchr(mapchan, '?'))
- *allow_unused = 0;
- if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
- input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
- if (allow_unused) {
- av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
- m->file_idx, m->stream_idx, m->channel_idx);
- } else {
- av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
- "To ignore this, add a trailing '?' to the map_channel.\n",
- m->file_idx, m->stream_idx, m->channel_idx);
- exit_program(1);
- }
- }
- av_free(mapchan);
- return 0;
- }
- #endif
- static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
- {
- av_free(sdp_filename);
- sdp_filename = av_strdup(arg);
- return 0;
- }
- #if CONFIG_VAAPI
- static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
- {
- const char *prefix = "vaapi:";
- char *tmp;
- int err;
- tmp = av_asprintf("%s%s", prefix, arg);
- if (!tmp)
- return AVERROR(ENOMEM);
- err = hw_device_init_from_string(tmp, NULL);
- av_free(tmp);
- return err;
- }
- #endif
- #if CONFIG_QSV
- static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
- {
- const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
- int err;
- char *tmp = av_asprintf("%s%s", prefix, arg);
- if (!tmp)
- return AVERROR(ENOMEM);
- err = hw_device_init_from_string(tmp, NULL);
- av_free(tmp);
- return err;
- }
- #endif
- static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
- {
- if (!strcmp(arg, "list")) {
- enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
- printf("Supported hardware device types:\n");
- while ((type = av_hwdevice_iterate_types(type)) !=
- AV_HWDEVICE_TYPE_NONE)
- printf("%s\n", av_hwdevice_get_type_name(type));
- printf("\n");
- exit_program(0);
- } else {
- return hw_device_init_from_string(arg, NULL);
- }
- }
- static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
- {
- if (filter_hw_device) {
- av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
- return AVERROR(EINVAL);
- }
- filter_hw_device = hw_device_get_by_name(arg);
- if (!filter_hw_device) {
- av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
- return AVERROR(EINVAL);
- }
- return 0;
- }
- static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- char buf[128];
- int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
- struct tm time = *gmtime((time_t*)&recording_timestamp);
- if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
- return -1;
- parse_option(o, "metadata", buf, options);
- av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
- "tag instead.\n", opt);
- return 0;
- }
- static void add_display_matrix_to_stream(OptionsContext *o,
- AVFormatContext *ctx, AVStream *st)
- {
- double rotation = DBL_MAX;
- int hflip = -1, vflip = -1;
- int hflip_set = 0, vflip_set = 0, rotation_set = 0;
- int32_t *buf;
- MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
- MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
- MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
- rotation_set = rotation != DBL_MAX;
- hflip_set = hflip != -1;
- vflip_set = vflip != -1;
- if (!rotation_set && !hflip_set && !vflip_set)
- return;
- buf = (int32_t *)av_stream_new_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
- if (!buf) {
- av_log(NULL, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
- exit_program(1);
- }
- av_display_rotation_set(buf,
- rotation_set ? -(rotation) : -0.0f);
- av_display_matrix_flip(buf,
- hflip_set ? hflip : 0,
- vflip_set ? vflip : 0);
- }
- const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
- {
- const AVCodecDescriptor *desc;
- const char *codec_string = encoder ? "encoder" : "decoder";
- const AVCodec *codec;
- codec = encoder ?
- avcodec_find_encoder_by_name(name) :
- avcodec_find_decoder_by_name(name);
- if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
- codec = encoder ? avcodec_find_encoder(desc->id) :
- avcodec_find_decoder(desc->id);
- if (codec)
- av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
- codec_string, codec->name, desc->name);
- }
- if (!codec) {
- av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
- exit_program(1);
- }
- if (codec->type != type && !recast_media) {
- av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
- exit_program(1);
- }
- return codec;
- }
- static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st,
- enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
- {
- char *codec_name = NULL;
- MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
- if (codec_name) {
- const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
- st->codecpar->codec_id = codec->id;
- if (recast_media && st->codecpar->codec_type != codec->type)
- st->codecpar->codec_type = codec->type;
- return codec;
- } else {
- if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
- hwaccel_id == HWACCEL_GENERIC &&
- hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
- const AVCodec *c;
- void *i = NULL;
- while ((c = av_codec_iterate(&i))) {
- const AVCodecHWConfig *config;
- if (c->id != st->codecpar->codec_id ||
- !av_codec_is_decoder(c))
- continue;
- for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
- if (config->device_type == hwaccel_device_type) {
- av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
- c->name, av_hwdevice_get_type_name(hwaccel_device_type));
- return c;
- }
- }
- }
- }
- return avcodec_find_decoder(st->codecpar->codec_id);
- }
- }
- static int guess_input_channel_layout(InputStream *ist)
- {
- AVCodecContext *dec = ist->dec_ctx;
- if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
- char layout_name[256];
- if (dec->ch_layout.nb_channels > ist->guess_layout_max)
- return 0;
- av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels);
- if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
- return 0;
- av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
- av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
- "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
- }
- return 1;
- }
- /* Add all the streams from the given input file to the global
- * list of input streams. */
- static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
- {
- int i, ret;
- for (i = 0; i < ic->nb_streams; i++) {
- AVStream *st = ic->streams[i];
- AVCodecParameters *par = st->codecpar;
- InputStream *ist;
- char *framerate = NULL, *hwaccel_device = NULL;
- const char *hwaccel = NULL;
- char *hwaccel_output_format = NULL;
- char *codec_tag = NULL;
- char *next;
- char *discard_str = NULL;
- const AVClass *cc = avcodec_get_class();
- const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
- 0, AV_OPT_SEARCH_FAKE_OBJ);
- ist = ALLOC_ARRAY_ELEM(input_streams, nb_input_streams);
- ist->st = st;
- ist->file_index = nb_input_files;
- ist->discard = 1;
- st->discard = AVDISCARD_ALL;
- ist->nb_samples = 0;
- ist->first_dts = AV_NOPTS_VALUE;
- ist->min_pts = INT64_MAX;
- ist->max_pts = INT64_MIN;
- ist->ts_scale = 1.0;
- MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
- ist->autorotate = 1;
- MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
- MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
- if (codec_tag) {
- uint32_t tag = strtol(codec_tag, &next, 0);
- if (*next)
- tag = AV_RL32(codec_tag);
- st->codecpar->codec_tag = tag;
- }
- if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
- add_display_matrix_to_stream(o, ic, st);
- MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
- MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
- hwaccel_output_format, ic, st);
- if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
- av_log(NULL, AV_LOG_WARNING,
- "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
- "with old commandlines. This behaviour is DEPRECATED and will be removed "
- "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
- ist->hwaccel_output_format = AV_PIX_FMT_CUDA;
- } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
- av_log(NULL, AV_LOG_WARNING,
- "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
- "with old commandlines. This behaviour is DEPRECATED and will be removed "
- "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
- ist->hwaccel_output_format = AV_PIX_FMT_QSV;
- } else if (hwaccel_output_format) {
- ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
- if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
- av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
- "format: %s", hwaccel_output_format);
- }
- } else {
- ist->hwaccel_output_format = AV_PIX_FMT_NONE;
- }
- if (hwaccel) {
- // The NVDEC hwaccels use a CUDA device, so remap the name here.
- if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
- hwaccel = "cuda";
- if (!strcmp(hwaccel, "none"))
- ist->hwaccel_id = HWACCEL_NONE;
- else if (!strcmp(hwaccel, "auto"))
- ist->hwaccel_id = HWACCEL_AUTO;
- else {
- enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel);
- if (type != AV_HWDEVICE_TYPE_NONE) {
- ist->hwaccel_id = HWACCEL_GENERIC;
- ist->hwaccel_device_type = type;
- }
- if (!ist->hwaccel_id) {
- av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
- hwaccel);
- av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
- type = AV_HWDEVICE_TYPE_NONE;
- while ((type = av_hwdevice_iterate_types(type)) !=
- AV_HWDEVICE_TYPE_NONE)
- av_log(NULL, AV_LOG_FATAL, "%s ",
- av_hwdevice_get_type_name(type));
- av_log(NULL, AV_LOG_FATAL, "\n");
- exit_program(1);
- }
- }
- }
- MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
- if (hwaccel_device) {
- ist->hwaccel_device = av_strdup(hwaccel_device);
- if (!ist->hwaccel_device)
- report_and_exit(AVERROR(ENOMEM));
- }
- ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
- }
- ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
- ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
- ist->reinit_filters = -1;
- MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
- MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
- ist->user_set_discard = AVDISCARD_NONE;
- if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
- (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
- (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
- (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
- ist->user_set_discard = AVDISCARD_ALL;
- if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
- discard_str);
- exit_program(1);
- }
- ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
- ist->prev_pkt_pts = AV_NOPTS_VALUE;
- ist->dec_ctx = avcodec_alloc_context3(ist->dec);
- if (!ist->dec_ctx)
- report_and_exit(AVERROR(ENOMEM));
- ret = avcodec_parameters_to_context(ist->dec_ctx, par);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
- exit_program(1);
- }
- ist->decoded_frame = av_frame_alloc();
- if (!ist->decoded_frame)
- report_and_exit(AVERROR(ENOMEM));
- ist->pkt = av_packet_alloc();
- if (!ist->pkt)
- report_and_exit(AVERROR(ENOMEM));
- if (o->bitexact)
- ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
- switch (par->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- // avformat_find_stream_info() doesn't set this for us anymore.
- ist->dec_ctx->framerate = st->avg_frame_rate;
- MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
- if (framerate && av_parse_video_rate(&ist->framerate,
- framerate) < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
- framerate);
- exit_program(1);
- }
- ist->top_field_first = -1;
- MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
- ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
- break;
- case AVMEDIA_TYPE_AUDIO:
- ist->guess_layout_max = INT_MAX;
- MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
- guess_input_channel_layout(ist);
- break;
- case AVMEDIA_TYPE_DATA:
- case AVMEDIA_TYPE_SUBTITLE: {
- char *canvas_size = NULL;
- MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
- MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
- if (canvas_size &&
- av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
- exit_program(1);
- }
- break;
- }
- case AVMEDIA_TYPE_ATTACHMENT:
- case AVMEDIA_TYPE_UNKNOWN:
- break;
- default:
- abort();
- }
- ist->par = avcodec_parameters_alloc();
- if (!ist->par)
- report_and_exit(AVERROR(ENOMEM));
- ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
- exit_program(1);
- }
- }
- }
- void assert_file_overwrite(const char *filename)
- {
- const char *proto_name = avio_find_protocol_name(filename);
- if (file_overwrite && no_file_overwrite) {
- fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
- exit_program(1);
- }
- if (!file_overwrite) {
- if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
- if (stdin_interaction && !no_file_overwrite) {
- fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
- fflush(stderr);
- term_exit();
- signal(SIGINT, SIG_DFL);
- if (!read_yesno()) {
- av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
- exit_program(1);
- }
- term_init();
- }
- else {
- av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
- exit_program(1);
- }
- }
- }
- if (proto_name && !strcmp(proto_name, "file")) {
- for (int i = 0; i < nb_input_files; i++) {
- InputFile *file = input_files[i];
- if (file->ctx->iformat->flags & AVFMT_NOFILE)
- continue;
- if (!strcmp(filename, file->ctx->url)) {
- av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
- av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
- exit_program(1);
- }
- }
- }
- }
- static void dump_attachment(AVStream *st, const char *filename)
- {
- int ret;
- AVIOContext *out = NULL;
- const AVDictionaryEntry *e;
- if (!st->codecpar->extradata_size) {
- av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
- nb_input_files - 1, st->index);
- return;
- }
- if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
- filename = e->value;
- if (!*filename) {
- av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
- "in stream #%d:%d.\n", nb_input_files - 1, st->index);
- exit_program(1);
- }
- assert_file_overwrite(filename);
- if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
- filename);
- exit_program(1);
- }
- avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
- avio_flush(out);
- avio_close(out);
- }
- static int open_input_file(OptionsContext *o, const char *filename)
- {
- InputFile *f;
- AVFormatContext *ic;
- const AVInputFormat *file_iformat = NULL;
- int err, i, ret;
- int64_t timestamp;
- AVDictionary *unused_opts = NULL;
- const AVDictionaryEntry *e = NULL;
- char * video_codec_name = NULL;
- char * audio_codec_name = NULL;
- char *subtitle_codec_name = NULL;
- char * data_codec_name = NULL;
- int scan_all_pmts_set = 0;
- if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
- o->stop_time = INT64_MAX;
- av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
- }
- if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
- int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
- if (o->stop_time <= start_time) {
- av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
- exit_program(1);
- } else {
- o->recording_time = o->stop_time - start_time;
- }
- }
- if (o->format) {
- if (!(file_iformat = av_find_input_format(o->format))) {
- av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
- exit_program(1);
- }
- }
- if (!strcmp(filename, "-"))
- filename = "pipe:";
- stdin_interaction &= strncmp(filename, "pipe:", 5) &&
- strcmp(filename, "/dev/stdin");
- /* get default parameters from command line */
- ic = avformat_alloc_context();
- if (!ic)
- report_and_exit(AVERROR(ENOMEM));
- if (o->nb_audio_sample_rate) {
- av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
- }
- if (o->nb_audio_channels) {
- const AVClass *priv_class;
- if (file_iformat && (priv_class = file_iformat->priv_class) &&
- av_opt_find(&priv_class, "ch_layout", NULL, 0,
- AV_OPT_SEARCH_FAKE_OBJ)) {
- char buf[32];
- snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
- av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
- }
- }
- if (o->nb_audio_ch_layouts) {
- const AVClass *priv_class;
- if (file_iformat && (priv_class = file_iformat->priv_class) &&
- av_opt_find(&priv_class, "ch_layout", NULL, 0,
- AV_OPT_SEARCH_FAKE_OBJ)) {
- av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
- }
- }
- if (o->nb_frame_rates) {
- const AVClass *priv_class;
- /* set the format-level framerate option;
- * this is important for video grabbers, e.g. x11 */
- if (file_iformat && (priv_class = file_iformat->priv_class) &&
- av_opt_find(&priv_class, "framerate", NULL, 0,
- AV_OPT_SEARCH_FAKE_OBJ)) {
- av_dict_set(&o->g->format_opts, "framerate",
- o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
- }
- }
- if (o->nb_frame_sizes) {
- av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
- }
- if (o->nb_frame_pix_fmts)
- av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
- MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
- MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
- MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
- MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
- if (video_codec_name)
- ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
- if (audio_codec_name)
- ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
- if (subtitle_codec_name)
- ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
- if (data_codec_name)
- ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
- ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
- ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
- ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
- ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
- ic->flags |= AVFMT_FLAG_NONBLOCK;
- if (o->bitexact)
- ic->flags |= AVFMT_FLAG_BITEXACT;
- ic->interrupt_callback = int_cb;
- if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
- av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
- scan_all_pmts_set = 1;
- }
- /* open the input file with generic avformat function */
- err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
- if (err < 0) {
- print_error(filename, err);
- if (err == AVERROR_PROTOCOL_NOT_FOUND)
- av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
- exit_program(1);
- }
- if (scan_all_pmts_set)
- av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
- remove_avoptions(&o->g->format_opts, o->g->codec_opts);
- assert_avoptions(o->g->format_opts);
- /* apply forced codec ids */
- for (i = 0; i < ic->nb_streams; i++)
- choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE);
- if (o->find_stream_info) {
- AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
- int orig_nb_streams = ic->nb_streams;
- /* If not enough info to get the stream parameters, we decode the
- first frames to get it. (used in mpeg case for example) */
- ret = avformat_find_stream_info(ic, opts);
- for (i = 0; i < orig_nb_streams; i++)
- av_dict_free(&opts[i]);
- av_freep(&opts);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
- if (ic->nb_streams == 0) {
- avformat_close_input(&ic);
- exit_program(1);
- }
- }
- }
- if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) {
- av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
- o->start_time_eof = AV_NOPTS_VALUE;
- }
- if (o->start_time_eof != AV_NOPTS_VALUE) {
- if (o->start_time_eof >= 0) {
- av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
- exit_program(1);
- }
- if (ic->duration > 0) {
- o->start_time = o->start_time_eof + ic->duration;
- if (o->start_time < 0) {
- av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
- o->start_time = AV_NOPTS_VALUE;
- }
- } else
- av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
- }
- timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
- /* add the stream start time */
- if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
- timestamp += ic->start_time;
- /* if seeking requested, we execute it */
- if (o->start_time != AV_NOPTS_VALUE) {
- int64_t seek_timestamp = timestamp;
- if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
- int dts_heuristic = 0;
- for (i=0; i<ic->nb_streams; i++) {
- const AVCodecParameters *par = ic->streams[i]->codecpar;
- if (par->video_delay) {
- dts_heuristic = 1;
- break;
- }
- }
- if (dts_heuristic) {
- seek_timestamp -= 3*AV_TIME_BASE / 23;
- }
- }
- ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
- if (ret < 0) {
- av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
- filename, (double)timestamp / AV_TIME_BASE);
- }
- }
- /* update the current parameters so that they match the one of the input stream */
- add_input_streams(o, ic);
- /* dump the file content */
- av_dump_format(ic, nb_input_files, filename, 0);
- f = ALLOC_ARRAY_ELEM(input_files, nb_input_files);
- f->ctx = ic;
- f->index = nb_input_files - 1;
- f->ist_index = nb_input_streams - ic->nb_streams;
- f->start_time = o->start_time;
- f->recording_time = o->recording_time;
- f->input_sync_ref = o->input_sync_ref;
- f->input_ts_offset = o->input_ts_offset;
- f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
- f->nb_streams = ic->nb_streams;
- f->rate_emu = o->rate_emu;
- f->accurate_seek = o->accurate_seek;
- f->loop = o->loop;
- f->duration = 0;
- f->time_base = (AVRational){ 1, 1 };
- f->readrate = o->readrate ? o->readrate : 0.0;
- if (f->readrate < 0.0f) {
- av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate);
- exit_program(1);
- }
- if (f->readrate && f->rate_emu) {
- av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate);
- f->rate_emu = 0;
- }
- f->thread_queue_size = o->thread_queue_size;
- /* check if all codec options have been used */
- unused_opts = strip_specifiers(o->g->codec_opts);
- for (i = f->ist_index; i < nb_input_streams; i++) {
- e = NULL;
- while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
- AV_DICT_IGNORE_SUFFIX)))
- av_dict_set(&unused_opts, e->key, NULL, 0);
- }
- e = NULL;
- while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
- const AVClass *class = avcodec_get_class();
- const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
- AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
- const AVClass *fclass = avformat_get_class();
- const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
- AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
- if (!option || foption)
- continue;
- if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
- av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
- "input file #%d (%s) is not a decoding option.\n", e->key,
- option->help ? option->help : "", f->index,
- filename);
- exit_program(1);
- }
- av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
- "input file #%d (%s) has not been used for any stream. The most "
- "likely reason is either wrong type (e.g. a video option with "
- "no video streams) or that it is a private option of some decoder "
- "which was not actually used for any stream.\n", e->key,
- option->help ? option->help : "", f->index, filename);
- }
- av_dict_free(&unused_opts);
- for (i = 0; i < o->nb_dump_attachment; i++) {
- int j;
- for (j = 0; j < ic->nb_streams; j++) {
- AVStream *st = ic->streams[j];
- if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
- dump_attachment(st, o->dump_attachment[i].u.str);
- }
- }
- input_stream_potentially_available = 1;
- return 0;
- }
- /* read file contents into a string */
- char *read_file(const char *filename)
- {
- AVIOContext *pb = NULL;
- int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
- AVBPrint bprint;
- char *str;
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
- return NULL;
- }
- av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
- ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
- avio_closep(&pb);
- if (ret < 0) {
- av_bprint_finalize(&bprint, NULL);
- return NULL;
- }
- ret = av_bprint_finalize(&bprint, &str);
- if (ret < 0)
- return NULL;
- return str;
- }
- /* arg format is "output-stream-index:streamid-value". */
- static int opt_streamid(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- int idx;
- char *p;
- char idx_str[16];
- av_strlcpy(idx_str, arg, sizeof(idx_str));
- p = strchr(idx_str, ':');
- if (!p) {
- av_log(NULL, AV_LOG_FATAL,
- "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
- arg, opt);
- exit_program(1);
- }
- *p++ = '\0';
- idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
- o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
- o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
- return 0;
- }
- static int init_complex_filters(void)
- {
- int i, ret = 0;
- for (i = 0; i < nb_filtergraphs; i++) {
- ret = init_complex_filtergraph(filtergraphs[i]);
- if (ret < 0)
- return ret;
- }
- return 0;
- }
- static int opt_target(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
- static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
- if (!strncmp(arg, "pal-", 4)) {
- norm = PAL;
- arg += 4;
- } else if (!strncmp(arg, "ntsc-", 5)) {
- norm = NTSC;
- arg += 5;
- } else if (!strncmp(arg, "film-", 5)) {
- norm = FILM;
- arg += 5;
- } else {
- /* Try to determine PAL/NTSC by peeking in the input files */
- if (nb_input_files) {
- int i, j;
- for (j = 0; j < nb_input_files; j++) {
- for (i = 0; i < input_files[j]->nb_streams; i++) {
- AVStream *st = input_files[j]->ctx->streams[i];
- int64_t fr;
- if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
- continue;
- fr = st->time_base.den * 1000LL / st->time_base.num;
- if (fr == 25000) {
- norm = PAL;
- break;
- } else if ((fr == 29970) || (fr == 23976)) {
- norm = NTSC;
- break;
- }
- }
- if (norm != UNKNOWN)
- break;
- }
- }
- if (norm != UNKNOWN)
- av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
- }
- if (norm == UNKNOWN) {
- av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
- av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
- av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
- exit_program(1);
- }
- if (!strcmp(arg, "vcd")) {
- opt_video_codec(o, "c:v", "mpeg1video");
- opt_audio_codec(o, "c:a", "mp2");
- parse_option(o, "f", "vcd", options);
- parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
- parse_option(o, "r", frame_rates[norm], options);
- opt_default(NULL, "g", norm == PAL ? "15" : "18");
- opt_default(NULL, "b:v", "1150000");
- opt_default(NULL, "maxrate:v", "1150000");
- opt_default(NULL, "minrate:v", "1150000");
- opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
- opt_default(NULL, "b:a", "224000");
- parse_option(o, "ar", "44100", options);
- parse_option(o, "ac", "2", options);
- opt_default(NULL, "packetsize", "2324");
- opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
- /* We have to offset the PTS, so that it is consistent with the SCR.
- SCR starts at 36000, but the first two packs contain only padding
- and the first pack from the other stream, respectively, may also have
- been written before.
- So the real data starts at SCR 36000+3*1200. */
- o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
- } else if (!strcmp(arg, "svcd")) {
- opt_video_codec(o, "c:v", "mpeg2video");
- opt_audio_codec(o, "c:a", "mp2");
- parse_option(o, "f", "svcd", options);
- parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
- parse_option(o, "r", frame_rates[norm], options);
- parse_option(o, "pix_fmt", "yuv420p", options);
- opt_default(NULL, "g", norm == PAL ? "15" : "18");
- opt_default(NULL, "b:v", "2040000");
- opt_default(NULL, "maxrate:v", "2516000");
- opt_default(NULL, "minrate:v", "0"); // 1145000;
- opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
- opt_default(NULL, "scan_offset", "1");
- opt_default(NULL, "b:a", "224000");
- parse_option(o, "ar", "44100", options);
- opt_default(NULL, "packetsize", "2324");
- } else if (!strcmp(arg, "dvd")) {
- opt_video_codec(o, "c:v", "mpeg2video");
- opt_audio_codec(o, "c:a", "ac3");
- parse_option(o, "f", "dvd", options);
- parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
- parse_option(o, "r", frame_rates[norm], options);
- parse_option(o, "pix_fmt", "yuv420p", options);
- opt_default(NULL, "g", norm == PAL ? "15" : "18");
- opt_default(NULL, "b:v", "6000000");
- opt_default(NULL, "maxrate:v", "9000000");
- opt_default(NULL, "minrate:v", "0"); // 1500000;
- opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
- opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
- opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
- opt_default(NULL, "b:a", "448000");
- parse_option(o, "ar", "48000", options);
- } else if (!strncmp(arg, "dv", 2)) {
- parse_option(o, "f", "dv", options);
- parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
- parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
- norm == PAL ? "yuv420p" : "yuv411p", options);
- parse_option(o, "r", frame_rates[norm], options);
- parse_option(o, "ar", "48000", options);
- parse_option(o, "ac", "2", options);
- } else {
- av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
- return AVERROR(EINVAL);
- }
- av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
- av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
- return 0;
- }
- static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
- {
- av_free (vstats_filename);
- vstats_filename = av_strdup (arg);
- return 0;
- }
- static int opt_vstats(void *optctx, const char *opt, const char *arg)
- {
- char filename[40];
- time_t today2 = time(NULL);
- struct tm *today = localtime(&today2);
- if (!today) { // maybe tomorrow
- av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
- exit_program(1);
- }
- snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
- today->tm_sec);
- return opt_vstats_file(NULL, opt, filename);
- }
- static int opt_video_frames(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "frames:v", arg, options);
- }
- static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "frames:a", arg, options);
- }
- static int opt_data_frames(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "frames:d", arg, options);
- }
- static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
- {
- int ret;
- AVDictionary *cbak = codec_opts;
- AVDictionary *fbak = format_opts;
- codec_opts = NULL;
- format_opts = NULL;
- ret = opt_default(NULL, opt, arg);
- av_dict_copy(&o->g->codec_opts , codec_opts, 0);
- av_dict_copy(&o->g->format_opts, format_opts, 0);
- av_dict_free(&codec_opts);
- av_dict_free(&format_opts);
- codec_opts = cbak;
- format_opts = fbak;
- return ret;
- }
- static int opt_preset(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- FILE *f=NULL;
- char filename[1000], line[1000], tmp_line[1000];
- const char *codec_name = NULL;
- tmp_line[0] = *opt;
- tmp_line[1] = 0;
- MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
- if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
- if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
- av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
- }else
- av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
- exit_program(1);
- }
- while (fgets(line, sizeof(line), f)) {
- char *key = tmp_line, *value, *endptr;
- if (strcspn(line, "#\n\r") == 0)
- continue;
- av_strlcpy(tmp_line, line, sizeof(tmp_line));
- if (!av_strtok(key, "=", &value) ||
- !av_strtok(value, "\r\n", &endptr)) {
- av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
- exit_program(1);
- }
- av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
- if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
- else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
- else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
- else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
- else if (opt_default_new(o, key, value) < 0) {
- av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
- filename, line, key, value);
- exit_program(1);
- }
- }
- fclose(f);
- return 0;
- }
- static int opt_old2new(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- int ret;
- char *s = av_asprintf("%s:%c", opt + 1, *opt);
- if (!s)
- return AVERROR(ENOMEM);
- ret = parse_option(o, s, arg, options);
- av_free(s);
- return ret;
- }
- static int opt_bitrate(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- if(!strcmp(opt, "ab")){
- av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
- return 0;
- } else if(!strcmp(opt, "b")){
- av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
- av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
- return 0;
- }
- av_dict_set(&o->g->codec_opts, opt, arg, 0);
- return 0;
- }
- static int opt_qscale(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- char *s;
- int ret;
- if(!strcmp(opt, "qscale")){
- av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
- return parse_option(o, "q:v", arg, options);
- }
- s = av_asprintf("q%s", opt + 6);
- if (!s)
- return AVERROR(ENOMEM);
- ret = parse_option(o, s, arg, options);
- av_free(s);
- return ret;
- }
- static int opt_profile(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- if(!strcmp(opt, "profile")){
- av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
- av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
- return 0;
- }
- av_dict_set(&o->g->codec_opts, opt, arg, 0);
- return 0;
- }
- static int opt_video_filters(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "filter:v", arg, options);
- }
- static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "filter:a", arg, options);
- }
- static int opt_vsync(void *optctx, const char *opt, const char *arg)
- {
- av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n");
- parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1);
- return 0;
- }
- static int opt_timecode(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- int ret;
- char *tcr = av_asprintf("timecode=%s", arg);
- if (!tcr)
- return AVERROR(ENOMEM);
- ret = parse_option(o, "metadata:g", tcr, options);
- if (ret >= 0)
- ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
- av_free(tcr);
- return ret;
- }
- static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
- {
- OptionsContext *o = optctx;
- return parse_option(o, "q:a", arg, options);
- }
- static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
- {
- FilterGraph *fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
- fg->index = nb_filtergraphs - 1;
- fg->graph_desc = av_strdup(arg);
- if (!fg->graph_desc)
- return AVERROR(ENOMEM);
- input_stream_potentially_available = 1;
- return 0;
- }
- static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
- {
- FilterGraph *fg;
- char *graph_desc = read_file(arg);
- if (!graph_desc)
- return AVERROR(EINVAL);
- fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
- fg->index = nb_filtergraphs - 1;
- fg->graph_desc = graph_desc;
- input_stream_potentially_available = 1;
- return 0;
- }
- void show_help_default(const char *opt, const char *arg)
- {
- /* per-file options have at least one of those set */
- const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
- int show_advanced = 0, show_avoptions = 0;
- if (opt && *opt) {
- if (!strcmp(opt, "long"))
- show_advanced = 1;
- else if (!strcmp(opt, "full"))
- show_advanced = show_avoptions = 1;
- else
- av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
- }
- show_usage();
- printf("Getting help:\n"
- " -h -- print basic options\n"
- " -h long -- print more options\n"
- " -h full -- print all options (including all format and codec specific options, very long)\n"
- " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
- " See man %s for detailed description of the options.\n"
- "\n", program_name);
- show_help_options(options, "Print help / information / capabilities:",
- OPT_EXIT, 0, 0);
- show_help_options(options, "Global options (affect whole program "
- "instead of just one file):",
- 0, per_file | OPT_EXIT | OPT_EXPERT, 0);
- if (show_advanced)
- show_help_options(options, "Advanced global options:", OPT_EXPERT,
- per_file | OPT_EXIT, 0);
- show_help_options(options, "Per-file main options:", 0,
- OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE |
- OPT_EXIT, per_file);
- if (show_advanced)
- show_help_options(options, "Advanced per-file options:",
- OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
- show_help_options(options, "Video options:",
- OPT_VIDEO, OPT_EXPERT | OPT_AUDIO, 0);
- if (show_advanced)
- show_help_options(options, "Advanced Video options:",
- OPT_EXPERT | OPT_VIDEO, OPT_AUDIO, 0);
- show_help_options(options, "Audio options:",
- OPT_AUDIO, OPT_EXPERT | OPT_VIDEO, 0);
- if (show_advanced)
- show_help_options(options, "Advanced Audio options:",
- OPT_EXPERT | OPT_AUDIO, OPT_VIDEO, 0);
- show_help_options(options, "Subtitle options:",
- OPT_SUBTITLE, 0, 0);
- printf("\n");
- if (show_avoptions) {
- int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
- show_help_children(avcodec_get_class(), flags);
- show_help_children(avformat_get_class(), flags);
- #if CONFIG_SWSCALE
- show_help_children(sws_get_class(), flags);
- #endif
- #if CONFIG_SWRESAMPLE
- show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
- #endif
- show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
- show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
- }
- }
- void show_usage(void)
- {
- av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
- av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
- av_log(NULL, AV_LOG_INFO, "\n");
- }
- enum OptGroup {
- GROUP_OUTFILE,
- GROUP_INFILE,
- };
- static const OptionGroupDef groups[] = {
- [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
- [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
- };
- static int open_files(OptionGroupList *l, const char *inout,
- int (*open_file)(OptionsContext*, const char*))
- {
- int i, ret;
- for (i = 0; i < l->nb_groups; i++) {
- OptionGroup *g = &l->groups[i];
- OptionsContext o;
- init_options(&o);
- o.g = g;
- ret = parse_optgroup(&o, g);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
- "%s.\n", inout, g->arg);
- uninit_options(&o);
- return ret;
- }
- av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
- ret = open_file(&o, g->arg);
- uninit_options(&o);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
- inout, g->arg);
- return ret;
- }
- av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
- }
- return 0;
- }
- int ffmpeg_parse_options(int argc, char **argv)
- {
- OptionParseContext octx;
- int ret;
- memset(&octx, 0, sizeof(octx));
- /* split the commandline into an internal representation */
- ret = split_commandline(&octx, argc, argv, options, groups,
- FF_ARRAY_ELEMS(groups));
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
- goto fail;
- }
- /* apply global options */
- ret = parse_optgroup(NULL, &octx.global_opts);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
- goto fail;
- }
- /* configure terminal and setup signal handlers */
- term_init();
- /* open input files */
- ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
- goto fail;
- }
- apply_sync_offsets();
- /* create the complex filtergraphs */
- ret = init_complex_filters();
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
- goto fail;
- }
- /* open output files */
- ret = open_files(&octx.groups[GROUP_OUTFILE], "output", of_open);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
- goto fail;
- }
- check_filter_outputs();
- fail:
- uninit_parse_context(&octx);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
- }
- return ret;
- }
- static int opt_progress(void *optctx, const char *opt, const char *arg)
- {
- AVIOContext *avio = NULL;
- int ret;
- if (!strcmp(arg, "-"))
- arg = "pipe:";
- ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
- arg, av_err2str(ret));
- return ret;
- }
- progress_avio = avio;
- return 0;
- }
- int opt_timelimit(void *optctx, const char *opt, const char *arg)
- {
- #if HAVE_SETRLIMIT
- int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
- struct rlimit rl = { lim, lim + 1 };
- if (setrlimit(RLIMIT_CPU, &rl))
- perror("setrlimit");
- #else
- av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
- #endif
- return 0;
- }
- #define OFFSET(x) offsetof(OptionsContext, x)
- const OptionDef options[] = {
- /* main options */
- CMDUTILS_COMMON_OPTIONS
- { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
- "force format", "fmt" },
- { "y", OPT_BOOL, { &file_overwrite },
- "overwrite output files" },
- { "n", OPT_BOOL, { &no_file_overwrite },
- "never overwrite output files" },
- { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
- "Ignore unknown stream types" },
- { "copy_unknown", OPT_BOOL | OPT_EXPERT, { ©_unknown_streams },
- "Copy unknown stream types" },
- { "recast_media", OPT_BOOL | OPT_EXPERT, { &recast_media },
- "allow recasting stream type in order to force a decoder of different media type" },
- { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
- "codec name", "codec" },
- { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
- "codec name", "codec" },
- { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(presets) },
- "preset name", "preset" },
- { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
- OPT_OUTPUT, { .func_arg = opt_map },
- "set input stream mapping",
- "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
- #if FFMPEG_OPT_MAP_CHANNEL
- { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
- "map an audio channel from one stream to another (deprecated)", "file.stream.channel[:syncfile.syncstream]" },
- #endif
- { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(metadata_map) },
- "set metadata information of outfile from infile",
- "outfile[,metadata]:infile[,metadata]" },
- { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
- OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
- "set chapters mapping", "input_file_index" },
- { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
- "record or transcode \"duration\" seconds of audio/video",
- "duration" },
- { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
- "record or transcode stop time", "time_stop" },
- { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
- "set the limit file size in bytes", "limit_size" },
- { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
- "set the start time offset", "time_off" },
- { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
- OPT_INPUT, { .off = OFFSET(start_time_eof) },
- "set the start time offset relative to EOF", "time_off" },
- { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
- OPT_INPUT, { .off = OFFSET(seek_timestamp) },
- "enable/disable seeking by timestamp with -ss" },
- { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
- OPT_INPUT, { .off = OFFSET(accurate_seek) },
- "enable/disable accurate seeking with -ss" },
- { "isync", HAS_ARG | OPT_INT | OPT_OFFSET |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_sync_ref) },
- "Indicate the input index for sync reference", "sync ref" },
- { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
- "set the input ts offset", "time_off" },
- { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
- "set the input ts scale", "scale" },
- { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
- "set the recording timestamp ('now' to set the current time)", "time" },
- { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
- "add metadata", "string=string" },
- { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
- "add program with specified streams", "title=string:st=number..." },
- { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
- OPT_OUTPUT, { .func_arg = opt_data_frames },
- "set the number of data frames to output", "number" },
- { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
- "add timings for benchmarking" },
- { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
- "add timings for each task" },
- { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
- "write program-readable progress information", "url" },
- { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
- "enable or disable interaction on standard input" },
- { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
- "set max runtime in seconds in CPU user time", "limit" },
- { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
- "dump each input packet" },
- { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
- "when dumping packets, also dump the payload" },
- { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
- OPT_INPUT, { .off = OFFSET(rate_emu) },
- "read input at native frame rate; equivalent to -readrate 1", "" },
- { "readrate", HAS_ARG | OPT_FLOAT | OPT_OFFSET |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(readrate) },
- "read input at specified rate", "speed" },
- { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
- "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
- "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
- { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
- "set video sync method globally; deprecated, use -fps_mode", "" },
- { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
- "frame drop threshold", "" },
- { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
- "audio drift threshold", "threshold" },
- { "copyts", OPT_BOOL | OPT_EXPERT, { ©_ts },
- "copy timestamps" },
- { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
- "shift input timestamps to start at 0 when using copyts" },
- { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { ©_tb },
- "copy input stream time base when stream copying", "mode" },
- { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
- OPT_OUTPUT, { .off = OFFSET(shortest) },
- "finish encoding within shortest input" },
- { "shortest_buf_duration", HAS_ARG | OPT_FLOAT | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(shortest_buf_duration) },
- "maximum buffering duration (in seconds) for the -shortest option" },
- { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
- OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
- "bitexact mode" },
- { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(apad) },
- "audio pad", "" },
- { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
- "timestamp discontinuity delta threshold", "threshold" },
- { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
- "timestamp error delta threshold", "threshold" },
- { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
- "exit on error", "error" },
- { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
- "abort on the specified condition flags", "flags" },
- { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
- "copy initial non-keyframes" },
- { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
- "copy or discard frames before start time" },
- { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
- "set the number of frames to output", "number" },
- { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
- OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
- "force codec tag/fourcc", "fourcc/tag" },
- { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
- OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
- "use fixed quality scale (VBR)", "q" },
- { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
- OPT_OUTPUT, { .func_arg = opt_qscale },
- "use fixed quality scale (VBR)", "q" },
- { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
- "set profile", "profile" },
- { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
- "set stream filtergraph", "filter_graph" },
- { "filter_threads", HAS_ARG, { .func_arg = opt_filter_threads },
- "number of non-complex filter threads" },
- { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
- "read stream filtergraph description from a file", "filename" },
- { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
- "reinit filtergraph on input parameter changes", "" },
- { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
- "create a complex filtergraph", "graph_description" },
- { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
- "number of threads for -filter_complex" },
- { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
- "create a complex filtergraph", "graph_description" },
- { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
- "read complex filtergraph description from a file", "filename" },
- { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },
- "enable automatic conversion filters globally" },
- { "stats", OPT_BOOL, { &print_stats },
- "print progress report during encoding", },
- { "stats_period", HAS_ARG | OPT_EXPERT, { .func_arg = opt_stats_period },
- "set the period at which ffmpeg updates stats and -progress output", "time" },
- { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
- OPT_OUTPUT, { .func_arg = opt_attach },
- "add an attachment to the output file", "filename" },
- { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
- "extract an attachment into a file", "filename" },
- { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
- OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
- { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
- "print timestamp debugging info" },
- { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
- "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
- { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
- OPT_INPUT, { .off = OFFSET(discard) },
- "discard", "" },
- { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(disposition) },
- "disposition", "" },
- { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT,
- { .off = OFFSET(thread_queue_size) },
- "set the maximum number of queued packets from the demuxer" },
- { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT | OPT_OFFSET, { .off = OFFSET(find_stream_info) },
- "read and decode the streams to fill missing information with heuristics" },
- { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT,
- { .off = OFFSET(bits_per_raw_sample) },
- "set the number of bits per raw sample", "number" },
- /* video options */
- { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
- "set the number of video frames to output", "number" },
- { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
- "set frame rate (Hz value, fraction or abbreviation)", "rate" },
- { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(max_frame_rates) },
- "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
- { "s", OPT_VIDEO | HAS_ARG | OPT_SUBTITLE | OPT_STRING | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
- "set frame size (WxH or abbreviation)", "size" },
- { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
- "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
- { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
- "set pixel format", "format" },
- { "display_rotation", OPT_VIDEO | HAS_ARG | OPT_DOUBLE | OPT_SPEC |
- OPT_INPUT, { .off = OFFSET(display_rotations) },
- "set pure counter-clockwise rotation in degrees for stream(s)",
- "angle" },
- { "display_hflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_hflips) },
- "set display horizontal flip for stream(s) "
- "(overrides any display rotation if it is not set)"},
- { "display_vflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_vflips) },
- "set display vertical flip for stream(s) "
- "(overrides any display rotation if it is not set)"},
- { "vn", OPT_VIDEO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(video_disable) },
- "disable video" },
- { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
- "rate control override for specific intervals", "override" },
- { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
- OPT_OUTPUT, { .func_arg = opt_video_codec },
- "force video codec ('copy' to copy stream)", "codec" },
- { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
- "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
- { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
- "select the pass number (1 to 3)", "n" },
- { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
- "select two pass log file name prefix", "prefix" },
- #if FFMPEG_OPT_PSNR
- { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
- "calculate PSNR of compressed frames (deprecated, use -flags +psnr)" },
- #endif
- { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
- "dump video coding statistics to file" },
- { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
- "dump video coding statistics to file", "file" },
- { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
- "Version of the vstats format to use."},
- { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
- "set video filters", "filter_graph" },
- { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
- "specify intra matrix coeffs", "matrix" },
- { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
- "specify inter matrix coeffs", "matrix" },
- { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
- "specify intra matrix coeffs", "matrix" },
- { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
- "top=1/bottom=0/auto=-1 field first", "" },
- { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
- OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
- "force video tag/fourcc", "fourcc/tag" },
- { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
- "show QP histogram" },
- { "fps_mode", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT |
- OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(fps_mode) },
- "set framerate mode for matching video streams; overrides vsync" },
- { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
- OPT_OUTPUT, { .off = OFFSET(force_fps) },
- "force the selected framerate, disable the best supported framerate selection" },
- { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
- OPT_OUTPUT, { .func_arg = opt_streamid },
- "set the value of an outfile streamid", "streamIndex:value" },
- { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
- OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
- "force key frames at specified timestamps", "timestamps" },
- { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
- "audio bitrate (please use -b:a)", "bitrate" },
- { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
- "video bitrate (please use -b:v)", "bitrate" },
- { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
- OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
- "use HW accelerated decoding", "hwaccel name" },
- { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
- OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
- "select a device for HW acceleration", "devicename" },
- { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
- OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
- "select output format used with HW accelerated decoding", "format" },
- { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
- "show available HW acceleration methods" },
- { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
- OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
- "automatically insert correct rotate filters" },
- { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC |
- OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) },
- "automatically insert a scale filter at the end of the filter graph" },
- /* audio options */
- { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
- "set the number of audio frames to output", "number" },
- { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
- "set audio quality (codec-specific)", "quality", },
- { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
- "set audio sampling rate (in Hz)", "rate" },
- { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
- OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
- "set number of audio channels", "channels" },
- { "an", OPT_AUDIO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(audio_disable) },
- "disable audio" },
- { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
- OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
- "force audio codec ('copy' to copy stream)", "codec" },
- { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
- OPT_OUTPUT, { .func_arg = opt_old2new },
- "force audio tag/fourcc", "fourcc/tag" },
- { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
- OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(sample_fmts) },
- "set sample format", "format" },
- { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
- OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
- "set channel layout", "layout" },
- { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
- OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
- "set channel layout", "layout" },
- { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
- "set audio filters", "filter_graph" },
- { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
- "set the maximum number of channels to try to guess the channel layout" },
- /* subtitle options */
- { "sn", OPT_SUBTITLE | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(subtitle_disable) },
- "disable subtitle" },
- { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
- "force subtitle codec ('copy' to copy stream)", "codec" },
- { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
- , "force subtitle tag/fourcc", "fourcc/tag" },
- { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
- "fix subtitles duration" },
- { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
- "set canvas size (WxH or abbreviation)", "size" },
- /* muxer options */
- { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
- "set the maximum demux-decode delay", "seconds" },
- { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
- "set the initial demux-decode delay", "seconds" },
- { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
- "specify a file in which to print sdp information", "file" },
- { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
- "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
- { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
- "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
- "two special values are defined - "
- "0 = use frame rate (video) or sample rate (audio),"
- "-1 = match source time base", "ratio" },
- { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
- "A comma-separated list of bitstream filters", "bitstream_filters" },
- { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
- "deprecated", "audio bitstream_filters" },
- { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
- "deprecated", "video bitstream_filters" },
- { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
- "set the audio options to the indicated preset", "preset" },
- { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
- "set the video options to the indicated preset", "preset" },
- { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
- "set the subtitle options to the indicated preset", "preset" },
- { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
- "set options from indicated preset file", "filename" },
- { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
- "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
- { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) },
- "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
- /* data codec support */
- { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
- "force data codec ('copy' to copy stream)", "codec" },
- { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
- "disable data" },
- #if CONFIG_VAAPI
- { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
- "set VAAPI hardware device (DRM path or X11 display name)", "device" },
- #endif
- #if CONFIG_QSV
- { "qsv_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_qsv_device },
- "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
- #endif
- { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
- "initialise hardware device", "args" },
- { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
- "set hardware device used when filtering", "device" },
- { NULL, },
- };
|