@@ -7,3 +7,4 @@
/source/build-AudioDecode-Desktop_Qt_5_13_0_MSVC2017_32bit-Release
/source/OtherDemo/mydemo/build-TestAvFilter-Desktop_Qt_5_13_0_MSVC2017_32bit-Debug
source/OtherDemo/mydemo/FilterDemo/TestAvFilter.pro.user
+/source/build-FFMPEG_Qt-Desktop_Qt_5_13_2_MSVC2017_32bit-Debug
@@ -0,0 +1,45 @@
+TEMPLATE = app
+CONFIG += console c++11
+CONFIG -= app_bundle
+CONFIG -= qt
+
+UI_DIR = obj/Gui
+MOC_DIR = obj/Moc
+OBJECTS_DIR = obj/Obj
+#将输出文件直接放到源码目录下的bin目录下,将dll都放在了次目录中,用以解决运行后找不到dll的问
+#DESTDIR=$$PWD/bin/
+contains(QT_ARCH, i386) {
+ message("32-bit")
+ DESTDIR = $${PWD}/bin/bin32
+} else {
+ message("64-bit")
+ DESTDIR = $${PWD}/bin/bin64
+}
+include($$PWD/lib/lib.pri)
+INCLUDEPATH += $$PWD/src
+win32{
+ INCLUDEPATH += $$PWD/src/compat/atomics/win32
+HEADERS += \
+ src/cmdutils.h \
+ src/config.h \
+ src/ffmpeg.h
+SOURCES += \
+ src/cmdutils.c \
+ src/ffmpeg.c \
+ src/ffmpeg_filter.c \
+ src/ffmpeg_hw.c \
+ src/ffmpeg_opt.c
+LIBS += Shell32.lib
@@ -0,0 +1,337 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE QtCreatorProject>
+<!-- Written by QtCreator 4.10.1, 2020-06-12T17:12:11. -->
+<qtcreator>
+ <data>
+ <variable>EnvironmentId</variable>
+ <value type="QByteArray">{60719a71-fdb8-4fb3-939c-cdb5596b2c1d}</value>
+ </data>
+ <variable>ProjectExplorer.Project.ActiveTarget</variable>
+ <value type="int">0</value>
+ <variable>ProjectExplorer.Project.EditorSettings</variable>
+ <valuemap type="QVariantMap">
+ <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
+ <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
+ <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
+ <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
+ <value type="QString" key="language">Cpp</value>
+ <valuemap type="QVariantMap" key="value">
+ <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
+ </valuemap>
+ <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
+ <value type="QString" key="language">QmlJS</value>
+ <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
+ <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
+ <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
+ <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
+ <value type="int" key="EditorConfiguration.IndentSize">4</value>
+ <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
+ <value type="int" key="EditorConfiguration.MarginColumn">80</value>
+ <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
+ <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
+ <value type="int" key="EditorConfiguration.PaddingMode">1</value>
+ <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
+ <value type="bool" key="EditorConfiguration.ShowMargin">false</value>
+ <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
+ <value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
+ <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
+ <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
+ <value type="int" key="EditorConfiguration.TabSize">8</value>
+ <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
+ <value type="int" key="EditorConfiguration.Utf8BomBehavior">0</value>
+ <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
+ <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
+ <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
+ <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
+ <variable>ProjectExplorer.Project.PluginSettings</variable>
+ <valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
+ <value type="QString">-fno-delayed-template-parsing</value>
+ </valuelist>
+ <value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
+ <variable>ProjectExplorer.Project.Target.0</variable>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.13.2 MSVC2017 32bit</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.13.2 MSVC2017 32bit</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5132.win32_msvc2017_kit</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
+ <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/MyProjects/VideoDevelop/FFMPEG_DEMO/source/build-FFMPEG_Qt-Desktop_Qt_5_13_2_MSVC2017_32bit-Debug</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
+ <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
+ <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
+ <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.BuildTargets"/>
+ <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
+ <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
+ <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
+ <value type="bool" key="Qt4ProjectManager.MakeStep.OverrideMakeflags">false</value>
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
+ <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
+ <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
+ <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
+ <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
+ <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
+ <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
+ <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/MyProjects/VideoDevelop/FFMPEG_DEMO/source/build-FFMPEG_Qt-Desktop_Qt_5_13_2_MSVC2017_32bit-Release</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">true</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
+ <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/MyProjects/VideoDevelop/FFMPEG_DEMO/source/build-FFMPEG_Qt-Desktop_Qt_5_13_2_MSVC2017_32bit-Profile</value>
+ <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">true</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Profile</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
+ <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
+ <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
+ <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy Configuration</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
+ <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
+ <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
+ <value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
+ <valuelist type="QVariantList" key="Analyzer.Perf.Events">
+ <value type="QString">cpu-cycles</value>
+ <valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
+ <value type="int" key="Analyzer.Perf.Frequency">250</value>
+ <value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
+ <value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
+ <value type="int" key="Analyzer.Perf.StackSize">4096</value>
+ <value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
+ <value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
+ <value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
+ <value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
+ <value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
+ <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
+ <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
+ <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
+ <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
+ <value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
+ <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
+ <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
+ <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
+ <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
+ <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
+ <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
+ <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
+ <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
+ <value type="int">1</value>
+ <value type="int">2</value>
+ <value type="int">3</value>
+ <value type="int">4</value>
+ <value type="int">5</value>
+ <value type="int">6</value>
+ <value type="int">7</value>
+ <value type="int">8</value>
+ <value type="int">9</value>
+ <value type="int">10</value>
+ <value type="int">11</value>
+ <value type="int">12</value>
+ <value type="int">13</value>
+ <value type="int">14</value>
+ <value type="int" key="PE.EnvironmentAspect.Base">2</value>
+ <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
+ <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
+ <value type="QString" key="RunConfiguration.Arguments"></value>
+ <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
+ <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
+ <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
+ <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
+ <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
+ <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+ <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
+ <value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
+ <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
+ <variable>ProjectExplorer.Project.TargetCount</variable>
+ <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+ <value type="int">22</value>
+ <variable>Version</variable>
+</qtcreator>
@@ -0,0 +1,12 @@
+# Qt下编译ffmpeg.exe
+这是Qt的工程,建议使用Qt Creator 打开
+Qt下编译ffmpeg.exe,可以用于追踪命令行的调用流程。
+Qt5.6.2(vs2013/mingw) + ffmpeg4.2.3
+1.程序可以在windows/linux下直接编译使用。
+2.windows下的库为官网直接下载的。
+3.linux下已经编译好的库为centos7.4(64位)(gcc 版本 4.8.5)下编译的,如需32位的库请自行编译。
@@ -0,0 +1,2351 @@
+/*
+ * Various utilities for command line tools
+ * Copyright (c) 2000-2003 Fabrice Bellard
+ *
+ * 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 <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <math.h>
+/* Include only the enabled headers since some compilers (namely, Sun
+ Studio) will not omit unused inline functions and create undefined
+ references to libraries that are not being built. */
+#include "config.h"
+#include "compat/va_copy.h"
+#include "libavformat/avformat.h"
+#include "libavfilter/avfilter.h"
+#include "libavdevice/avdevice.h"
+#include "libavresample/avresample.h"
+#include "libswscale/swscale.h"
+#include "libswresample/swresample.h"
+#include "libpostproc/postprocess.h"
+#include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/display.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/libm.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/eval.h"
+#include "libavutil/dict.h"
+#include "libavutil/opt.h"
+#include "libavutil/cpu.h"
+#include "libavutil/ffversion.h"
+#include "libavutil/version.h"
+#include "cmdutils.h"
+#if CONFIG_NETWORK
+#include "libavformat/network.h"
+#endif
+#if HAVE_SYS_RESOURCE_H
+#include <sys/time.h>
+#include <sys/resource.h>
+#ifdef _WIN32
+#include <windows.h>
+static int init_report(const char *env);
+AVDictionary *sws_dict;
+AVDictionary *swr_opts;
+AVDictionary *format_opts, *codec_opts, *resample_opts;
+static FILE *report_file;
+static int report_file_level = AV_LOG_DEBUG;
+int hide_banner = 0;
+enum show_muxdemuxers {
+ SHOW_DEFAULT,
+ SHOW_DEMUXERS,
+ SHOW_MUXERS,
+};
+void init_opts(void)
+{
+ av_dict_set(&sws_dict, "flags", "bicubic", 0);
+void uninit_opts(void)
+ av_dict_free(&swr_opts);
+ av_dict_free(&sws_dict);
+ av_dict_free(&format_opts);
+ av_dict_free(&codec_opts);
+ av_dict_free(&resample_opts);
+void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
+ vfprintf(stdout, fmt, vl);
+static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
+ va_list vl2;
+ char line[1024];
+ static int print_prefix = 1;
+ va_copy(vl2, vl);
+ av_log_default_callback(ptr, level, fmt, vl);
+ av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
+ va_end(vl2);
+ if (report_file_level >= level) {
+ fputs(line, report_file);
+ fflush(report_file);
+ }
+void init_dynload(void)
+ /* Calling SetDllDirectory with the empty string (but not NULL) removes the
+ * current working directory from the DLL search path as a security pre-caution. */
+ SetDllDirectory("");
+static void (*program_exit)(int ret);
+void register_exit(void (*cb)(int ret))
+ program_exit = cb;
+void exit_program(int ret)
+ if (program_exit)
+ program_exit(ret);
+ exit(ret);
+double parse_number_or_die(const char *context, const char *numstr, int type,
+ double min, double max)
+ char *tail;
+ const char *error;
+ double d = av_strtod(numstr, &tail);
+ if (*tail)
+ error = "Expected number for %s but found: %s\n";
+ else if (d < min || d > max)
+ error = "The value for %s was %s which is not within %f - %f\n";
+ else if (type == OPT_INT64 && (int64_t)d != d)
+ error = "Expected int64 for %s but found %s\n";
+ else if (type == OPT_INT && (int)d != d)
+ error = "Expected int for %s but found %s\n";
+ else
+ return d;
+ av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
+ exit_program(1);
+ return 0;
+int64_t parse_time_or_die(const char *context, const char *timestr,
+ int is_duration)
+ int64_t us;
+ if (av_parse_time(&us, timestr, is_duration) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
+ is_duration ? "duration" : "date", context, timestr);
+ return us;
+void show_help_options(const OptionDef *options, const char *msg, int req_flags,
+ int rej_flags, int alt_flags)
+ const OptionDef *po;
+ int first;
+ first = 1;
+ for (po = options; po->name; po++) {
+ char buf[64];
+ if (((po->flags & req_flags) != req_flags) ||
+ (alt_flags && !(po->flags & alt_flags)) ||
+ (po->flags & rej_flags))
+ continue;
+ if (first) {
+ printf("%s\n", msg);
+ first = 0;
+ av_strlcpy(buf, po->name, sizeof(buf));
+ if (po->argname) {
+ av_strlcat(buf, " ", sizeof(buf));
+ av_strlcat(buf, po->argname, sizeof(buf));
+ printf("-%-17s %s\n", buf, po->help);
+ printf("\n");
+void show_help_children(const AVClass *class, int flags)
+ const AVClass *child = NULL;
+ if (class->option) {
+ av_opt_show2(&class, NULL, flags, 0);
+ while (child = av_opt_child_class_next(class, child))
+ show_help_children(child, flags);
+static const OptionDef *find_option(const OptionDef *po, const char *name)
+ const char *p = strchr(name, ':');
+ int len = p ? p - name : strlen(name);
+ while (po->name) {
+ if (!strncmp(name, po->name, len) && strlen(po->name) == len)
+ break;
+ po++;
+ return po;
+/* _WIN32 means using the windows libc - cygwin doesn't define that
+ * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
+ * it doesn't provide the actual command line via GetCommandLineW(). */
+#if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
+#include <shellapi.h>
+/* Will be leaked on exit */
+static char** win32_argv_utf8 = NULL;
+static int win32_argc = 0;
+/**
+ * Prepare command line arguments for executable.
+ * For Windows - perform wide-char to UTF-8 conversion.
+ * Input arguments should be main() function arguments.
+ * @param argc_ptr Arguments number (including executable)
+ * @param argv_ptr Arguments list.
+static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+ char *argstr_flat;
+ wchar_t **argv_w;
+ int i, buffsize = 0, offset = 0;
+ if (win32_argv_utf8) {
+ *argc_ptr = win32_argc;
+ *argv_ptr = win32_argv_utf8;
+ return;
+ win32_argc = 0;
+ argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
+ if (win32_argc <= 0 || !argv_w)
+ /* determine the UTF-8 buffer size (including NULL-termination symbols) */
+ for (i = 0; i < win32_argc; i++)
+ buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+ NULL, 0, NULL, NULL);
+ win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
+ argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
+ if (!win32_argv_utf8) {
+ LocalFree(argv_w);
+ for (i = 0; i < win32_argc; i++) {
+ win32_argv_utf8[i] = &argstr_flat[offset];
+ offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+ &argstr_flat[offset],
+ buffsize - offset, NULL, NULL);
+ win32_argv_utf8[i] = NULL;
+#else
+static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+ /* nothing to do */
+#endif /* HAVE_COMMANDLINETOARGVW */
+static int write_option(void *optctx, const OptionDef *po, const char *opt,
+ const char *arg)
+ /* new-style options contain an offset into optctx, old-style address of
+ * a global var*/
+ void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
+ (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
+ int *dstcount;
+ if (po->flags & OPT_SPEC) {
+ SpecifierOpt **so = dst;
+ char *p = strchr(opt, ':');
+ char *str;
+ dstcount = (int *)(so + 1);
+ *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
+ str = av_strdup(p ? p + 1 : "");
+ if (!str)
+ return AVERROR(ENOMEM);
+ (*so)[*dstcount - 1].specifier = str;
+ dst = &(*so)[*dstcount - 1].u;
+ if (po->flags & OPT_STRING) {
+ str = av_strdup(arg);
+ av_freep(dst);
+ *(char **)dst = str;
+ } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
+ *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ } else if (po->flags & OPT_INT64) {
+ *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
+ } else if (po->flags & OPT_TIME) {
+ *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
+ } else if (po->flags & OPT_FLOAT) {
+ *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
+ } else if (po->flags & OPT_DOUBLE) {
+ *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
+ } else if (po->u.func_arg) {
+ int ret = po->u.func_arg(optctx, opt, arg);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Failed to set value '%s' for option '%s': %s\n",
+ arg, opt, av_err2str(ret));
+ return ret;
+ if (po->flags & OPT_EXIT)
+ exit_program(0);
+int parse_option(void *optctx, const char *opt, const char *arg,
+ const OptionDef *options)
+ int ret;
+ po = find_option(options, opt);
+ if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
+ /* handle 'no' bool option */
+ po = find_option(options, opt + 2);
+ if ((po->name && (po->flags & OPT_BOOL)))
+ arg = "0";
+ } else if (po->flags & OPT_BOOL)
+ arg = "1";
+ if (!po->name)
+ po = find_option(options, "default");
+ if (!po->name) {
+ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
+ return AVERROR(EINVAL);
+ if (po->flags & HAS_ARG && !arg) {
+ av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
+ ret = write_option(optctx, po, opt, arg);
+ if (ret < 0)
+ return !!(po->flags & HAS_ARG);
+void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ void (*parse_arg_function)(void *, const char*))
+ const char *opt;
+ int optindex, handleoptions = 1, ret;
+ /* perform system-dependent conversions for arguments list */
+ prepare_app_arguments(&argc, &argv);
+ /* parse options */
+ optindex = 1;
+ while (optindex < argc) {
+ opt = argv[optindex++];
+ if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
+ if (opt[1] == '-' && opt[2] == '\0') {
+ handleoptions = 0;
+ opt++;
+ if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
+ optindex += ret;
+ } else {
+ if (parse_arg_function)
+ parse_arg_function(optctx, opt);
+int parse_optgroup(void *optctx, OptionGroup *g)
+ int i, ret;
+ av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
+ g->group_def->name, g->arg);
+ for (i = 0; i < g->nb_opts; i++) {
+ Option *o = &g->opts[i];
+ if (g->group_def->flags &&
+ !(g->group_def->flags & o->opt->flags)) {
+ av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
+ "%s %s -- you are trying to apply an input option to an "
+ "output file or vice versa. Move this option before the "
+ "file it belongs to.\n", o->key, o->opt->help,
+ av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
+ o->key, o->opt->help, o->val);
+ ret = write_option(optctx, o->opt, o->key, o->val);
+ av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
+int locate_option(int argc, char **argv, const OptionDef *options,
+ const char *optname)
+ int i;
+ for (i = 1; i < argc; i++) {
+ const char *cur_opt = argv[i];
+ if (*cur_opt++ != '-')
+ po = find_option(options, cur_opt);
+ if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
+ po = find_option(options, cur_opt + 2);
+ if ((!po->name && !strcmp(cur_opt, optname)) ||
+ (po->name && !strcmp(optname, po->name)))
+ return i;
+ if (!po->name || po->flags & HAS_ARG)
+ i++;
+static void dump_argument(const char *a)
+ const unsigned char *p;
+ for (p = a; *p; p++)
+ if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
+ *p == '_' || (*p >= 'a' && *p <= 'z')))
+ if (!*p) {
+ fputs(a, report_file);
+ fputc('"', report_file);
+ for (p = a; *p; p++) {
+ if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
+ fprintf(report_file, "\\%c", *p);
+ else if (*p < ' ' || *p > '~')
+ fprintf(report_file, "\\x%02x", *p);
+ fputc(*p, report_file);
+static void check_options(const OptionDef *po)
+ if (po->flags & OPT_PERFILE)
+ av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT));
+void parse_loglevel(int argc, char **argv, const OptionDef *options)
+ int idx = locate_option(argc, argv, options, "loglevel");
+ const char *env;
+ check_options(options);
+ if (!idx)
+ idx = locate_option(argc, argv, options, "v");
+ if (idx && argv[idx + 1])
+ opt_loglevel(NULL, "loglevel", argv[idx + 1]);
+ idx = locate_option(argc, argv, options, "report");
+ if ((env = getenv("FFREPORT")) || idx) {
+ init_report(env);
+ if (report_file) {
+ fprintf(report_file, "Command line:\n");
+ for (i = 0; i < argc; i++) {
+ dump_argument(argv[i]);
+ fputc(i < argc - 1 ? ' ' : '\n', report_file);
+ idx = locate_option(argc, argv, options, "hide_banner");
+ if (idx)
+ hide_banner = 1;
+static const AVOption *opt_find(void *obj, const char *name, const char *unit,
+ int opt_flags, int search_flags)
+ const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
+ if(o && !o->flags)
+ return NULL;
+ return o;
+#define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
+int opt_default(void *optctx, const char *opt, const char *arg)
+ const AVOption *o;
+ int consumed = 0;
+ char opt_stripped[128];
+ const char *p;
+ const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
+#if CONFIG_AVRESAMPLE
+ const AVClass *rc = avresample_get_class();
+#if CONFIG_SWSCALE
+ const AVClass *sc = sws_get_class();
+#if CONFIG_SWRESAMPLE
+ const AVClass *swr_class = swr_get_class();
+ if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
+ av_log_set_level(AV_LOG_DEBUG);
+ if (!(p = strchr(opt, ':')))
+ p = opt + strlen(opt);
+ av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
+ if ((o = opt_find(&cc, opt_stripped, NULL, 0,
+ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
+ ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
+ (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
+ av_dict_set(&codec_opts, opt, arg, FLAGS);
+ consumed = 1;
+ if ((o = opt_find(&fc, opt, NULL, 0,
+ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
+ av_dict_set(&format_opts, opt, arg, FLAGS);
+ if (consumed)
+ av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
+ if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
+ struct SwsContext *sws = sws_alloc_context();
+ int ret = av_opt_set(sws, opt, arg, 0);
+ sws_freeContext(sws);
+ if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
+ !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
+ !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
+ av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
+ av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
+ av_dict_set(&sws_dict, opt, arg, FLAGS);
+ if (!consumed && !strcmp(opt, "sws_flags")) {
+ av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
+ if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
+ struct SwrContext *swr = swr_alloc();
+ int ret = av_opt_set(swr, opt, arg, 0);
+ swr_free(&swr);
+ av_dict_set(&swr_opts, opt, arg, FLAGS);
+ if ((o=opt_find(&rc, opt, NULL, 0,
+ av_dict_set(&resample_opts, opt, arg, FLAGS);
+ return AVERROR_OPTION_NOT_FOUND;
+/*
+ * Check whether given option is a group separator.
+ * @return index of the group definition that matched or -1 if none
+static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
+ const char *opt)
+ for (i = 0; i < nb_groups; i++) {
+ const OptionGroupDef *p = &groups[i];
+ if (p->sep && !strcmp(p->sep, opt))
+ return -1;
+ * Finish parsing an option group.
+ * @param group_idx which group definition should this group belong to
+ * @param arg argument of the group delimiting option
+static void finish_group(OptionParseContext *octx, int group_idx,
+ OptionGroupList *l = &octx->groups[group_idx];
+ OptionGroup *g;
+ GROW_ARRAY(l->groups, l->nb_groups);
+ g = &l->groups[l->nb_groups - 1];
+ *g = octx->cur_group;
+ g->arg = arg;
+ g->group_def = l->group_def;
+ g->sws_dict = sws_dict;
+ g->swr_opts = swr_opts;
+ g->codec_opts = codec_opts;
+ g->format_opts = format_opts;
+ g->resample_opts = resample_opts;
+ codec_opts = NULL;
+ format_opts = NULL;
+ resample_opts = NULL;
+ sws_dict = NULL;
+ swr_opts = NULL;
+ init_opts();
+ memset(&octx->cur_group, 0, sizeof(octx->cur_group));
+ * Add an option instance to currently parsed group.
+static void add_opt(OptionParseContext *octx, const OptionDef *opt,
+ const char *key, const char *val)
+ int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
+ OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
+ GROW_ARRAY(g->opts, g->nb_opts);
+ g->opts[g->nb_opts - 1].opt = opt;
+ g->opts[g->nb_opts - 1].key = key;
+ g->opts[g->nb_opts - 1].val = val;
+static void init_parse_context(OptionParseContext *octx,
+ const OptionGroupDef *groups, int nb_groups)
+ static const OptionGroupDef global_group = { "global" };
+ memset(octx, 0, sizeof(*octx));
+ octx->nb_groups = nb_groups;
+ octx->groups = av_mallocz_array(octx->nb_groups, sizeof(*octx->groups));
+ if (!octx->groups)
+ for (i = 0; i < octx->nb_groups; i++)
+ octx->groups[i].group_def = &groups[i];
+ octx->global_opts.group_def = &global_group;
+ octx->global_opts.arg = "";
+void uninit_parse_context(OptionParseContext *octx)
+ int i, j;
+ for (i = 0; i < octx->nb_groups; i++) {
+ OptionGroupList *l = &octx->groups[i];
+ for (j = 0; j < l->nb_groups; j++) {
+ av_freep(&l->groups[j].opts);
+ av_dict_free(&l->groups[j].codec_opts);
+ av_dict_free(&l->groups[j].format_opts);
+ av_dict_free(&l->groups[j].resample_opts);
+ av_dict_free(&l->groups[j].sws_dict);
+ av_dict_free(&l->groups[j].swr_opts);
+ av_freep(&l->groups);
+ av_freep(&octx->groups);
+ av_freep(&octx->cur_group.opts);
+ av_freep(&octx->global_opts.opts);
+ uninit_opts();
+int split_commandline(OptionParseContext *octx, int argc, char *argv[],
+ const OptionDef *options,
+ int optindex = 1;
+ int dashdash = -2;
+ init_parse_context(octx, groups, nb_groups);
+ av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
+ const char *opt = argv[optindex++], *arg;
+ av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
+ if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
+ dashdash = optindex;
+ /* unnamed group separators, e.g. output filename */
+ if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
+ finish_group(octx, 0, opt);
+ av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
+#define GET_ARG(arg) \
+do { \
+ arg = argv[optindex++]; \
+ if (!arg) { \
+ av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
+ return AVERROR(EINVAL); \
+ } \
+} while (0)
+ /* named group separators, e.g. -i */
+ if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
+ GET_ARG(arg);
+ finish_group(octx, ret, arg);
+ av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
+ groups[ret].name, arg);
+ /* normal options */
+ if (po->name) {
+ if (po->flags & OPT_EXIT) {
+ /* optional argument, e.g. -h */
+ arg = argv[optindex++];
+ } else if (po->flags & HAS_ARG) {
+ add_opt(octx, po, opt, arg);
+ av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
+ "argument '%s'.\n", po->name, po->help, arg);
+ /* AVOptions */
+ if (argv[optindex]) {
+ ret = opt_default(NULL, opt, argv[optindex]);
+ if (ret >= 0) {
+ av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
+ "argument '%s'.\n", opt, argv[optindex]);
+ optindex++;
+ } else if (ret != AVERROR_OPTION_NOT_FOUND) {
+ av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
+ "with argument '%s'.\n", opt, argv[optindex]);
+ /* boolean -nofoo options */
+ if (opt[0] == 'n' && opt[1] == 'o' &&
+ (po = find_option(options, opt + 2)) &&
+ po->name && po->flags & OPT_BOOL) {
+ add_opt(octx, po, opt, "0");
+ "argument 0.\n", po->name, po->help);
+ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
+ if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts)
+ av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
+ "commandline.\n");
+ av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
+int opt_cpuflags(void *optctx, const char *opt, const char *arg)
+ unsigned flags = av_get_cpu_flags();
+ if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
+ av_force_cpu_flags(flags);
+int opt_loglevel(void *optctx, const char *opt, const char *arg)
+ const struct { const char *name; int level; } log_levels[] = {
+ { "quiet" , AV_LOG_QUIET },
+ { "panic" , AV_LOG_PANIC },
+ { "fatal" , AV_LOG_FATAL },
+ { "error" , AV_LOG_ERROR },
+ { "warning", AV_LOG_WARNING },
+ { "info" , AV_LOG_INFO },
+ { "verbose", AV_LOG_VERBOSE },
+ { "debug" , AV_LOG_DEBUG },
+ { "trace" , AV_LOG_TRACE },
+ };
+ const char *token;
+ int flags = av_log_get_flags();
+ int level = av_log_get_level();
+ int cmd, i = 0;
+ av_assert0(arg);
+ while (*arg) {
+ token = arg;
+ if (*token == '+' || *token == '-') {
+ cmd = *token++;
+ cmd = 0;
+ if (!i && !cmd) {
+ flags = 0; /* missing relative prefix, build absolute value */
+ if (!strncmp(token, "repeat", 6)) {
+ if (cmd == '-') {
+ flags |= AV_LOG_SKIP_REPEATED;
+ flags &= ~AV_LOG_SKIP_REPEATED;
+ arg = token + 6;
+ } else if (!strncmp(token, "level", 5)) {
+ flags &= ~AV_LOG_PRINT_LEVEL;
+ flags |= AV_LOG_PRINT_LEVEL;
+ arg = token + 5;
+ if (!*arg) {
+ goto end;
+ } else if (*arg == '+') {
+ arg++;
+ } else if (!i) {
+ flags = av_log_get_flags(); /* level value without prefix, reset flags */
+ for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
+ if (!strcmp(log_levels[i].name, arg)) {
+ level = log_levels[i].level;
+ level = strtol(arg, &tail, 10);
+ if (*tail) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
+ "Possible levels are numbers or:\n", arg);
+ for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
+ av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
+end:
+ av_log_set_flags(flags);
+ av_log_set_level(level);
+static void expand_filename_template(AVBPrint *bp, const char *template,
+ struct tm *tm)
+ int c;
+ while ((c = *(template++))) {
+ if (c == '%') {
+ if (!(c = *(template++)))
+ switch (c) {
+ case 'p':
+ av_bprintf(bp, "%s", program_name);
+ case 't':
+ av_bprintf(bp, "%04d%02d%02d-%02d%02d%02d",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ case '%':
+ av_bprint_chars(bp, c, 1);
+static int init_report(const char *env)
+ char *filename_template = NULL;
+ char *key, *val;
+ int ret, count = 0;
+ time_t now;
+ struct tm *tm;
+ AVBPrint filename;
+ if (report_file) /* already opened */
+ time(&now);
+ tm = localtime(&now);
+ while (env && *env) {
+ if ((ret = av_opt_get_key_value(&env, "=", ":", 0, &key, &val)) < 0) {
+ if (count)
+ "Failed to parse FFREPORT environment variable: %s\n",
+ av_err2str(ret));
+ if (*env)
+ env++;
+ count++;
+ if (!strcmp(key, "file")) {
+ av_free(filename_template);
+ filename_template = val;
+ val = NULL;
+ } else if (!strcmp(key, "level")) {
+ report_file_level = strtol(val, &tail, 10);
+ av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
+ av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key);
+ av_free(val);
+ av_free(key);
+ av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ expand_filename_template(&filename,
+ av_x_if_null(filename_template, "%p-%t.log"), tm);
+ if (!av_bprint_is_complete(&filename)) {
+ av_log(NULL, AV_LOG_ERROR, "Out of memory building report file name\n");
+ report_file = fopen(filename.str, "w");
+ if (!report_file) {
+ int ret = AVERROR(errno);
+ av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
+ filename.str, strerror(errno));
+ av_log_set_callback(log_callback_report);
+ av_log(NULL, AV_LOG_INFO,
+ "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
+ "Report written to \"%s\"\n",
+ program_name,
+ tm->tm_hour, tm->tm_min, tm->tm_sec,
+ filename.str);
+ av_bprint_finalize(&filename, NULL);
+int opt_report(const char *opt)
+ return init_report(NULL);
+int opt_max_alloc(void *optctx, const char *opt, const char *arg)
+ size_t max;
+ max = strtol(arg, &tail, 10);
+ av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
+ av_max_alloc(max);
+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");
+ av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
+void print_error(const char *filename, int err)
+ char errbuf[128];
+ const char *errbuf_ptr = errbuf;
+ if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
+ errbuf_ptr = strerror(AVUNERROR(err));
+ av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
+static int warned_cfg = 0;
+#define INDENT 1
+#define SHOW_VERSION 2
+#define SHOW_CONFIG 4
+#define SHOW_COPYRIGHT 8
+#define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
+ if (CONFIG_##LIBNAME) { \
+ const char *indent = flags & INDENT? " " : ""; \
+ if (flags & SHOW_VERSION) { \
+ unsigned int version = libname##_version(); \
+ av_log(NULL, level, \
+ "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
+ indent, #libname, \
+ LIB##LIBNAME##_VERSION_MAJOR, \
+ LIB##LIBNAME##_VERSION_MINOR, \
+ LIB##LIBNAME##_VERSION_MICRO, \
+ AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
+ AV_VERSION_MICRO(version)); \
+ if (flags & SHOW_CONFIG) { \
+ const char *cfg = libname##_configuration(); \
+ if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
+ if (!warned_cfg) { \
+ "%sWARNING: library configuration mismatch\n", \
+ indent); \
+ warned_cfg = 1; \
+ av_log(NULL, level, "%s%-11s configuration: %s\n", \
+ indent, #libname, cfg); \
+static void print_all_libs_info(int flags, int level)
+ PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
+ PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
+ PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
+ PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
+ PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
+ PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
+ PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
+ PRINT_LIB_INFO(swresample, SWRESAMPLE, flags, level);
+ PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
+static void print_program_info(int flags, int level)
+ const char *indent = flags & INDENT? " " : "";
+ av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
+ if (flags & SHOW_COPYRIGHT)
+ av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
+ program_birth_year, CONFIG_THIS_YEAR);
+ av_log(NULL, level, "\n");
+ av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
+ av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
+static void print_buildconf(int flags, int level)
+ const char *indent = flags & INDENT ? " " : "";
+ char str[] = { FFMPEG_CONFIGURATION };
+ char *conflist, *remove_tilde, *splitconf;
+ // Change all the ' --' strings to '~--' so that
+ // they can be identified as tokens.
+ while ((conflist = strstr(str, " --")) != NULL) {
+ strncpy(conflist, "~--", 3);
+ // Compensate for the weirdness this would cause
+ // when passing 'pkg-config --static'.
+ while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
+ strncpy(remove_tilde, "pkg-config ", 11);
+ splitconf = strtok(str, "~");
+ av_log(NULL, level, "\n%sconfiguration:\n", indent);
+ while (splitconf != NULL) {
+ av_log(NULL, level, "%s%s%s\n", indent, indent, splitconf);
+ splitconf = strtok(NULL, "~");
+void show_banner(int argc, char **argv, const OptionDef *options)
+ int idx = locate_option(argc, argv, options, "version");
+ if (hide_banner || idx)
+ print_program_info (INDENT|SHOW_COPYRIGHT, AV_LOG_INFO);
+ print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO);
+ print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO);
+int show_version(void *optctx, const char *opt, const char *arg)
+ av_log_set_callback(log_callback_help);
+ print_program_info (SHOW_COPYRIGHT, AV_LOG_INFO);
+ print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
+int show_buildconf(void *optctx, const char *opt, const char *arg)
+ print_buildconf (INDENT|0, AV_LOG_INFO);
+int show_license(void *optctx, const char *opt, const char *arg)
+#if CONFIG_NONFREE
+ printf(
+ "This version of %s has nonfree parts compiled in.\n"
+ "Therefore it is not legally redistributable.\n",
+ program_name );
+#elif CONFIG_GPLV3
+ "%s is free software; you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation; either version 3 of the License, or\n"
+ "(at your option) any later version.\n"
+ "\n"
+ "%s is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n"
+ "You should have received a copy of the GNU General Public License\n"
+ "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
+ program_name, program_name, program_name );
+#elif CONFIG_GPL
+ "the Free Software Foundation; either version 2 of the License, or\n"
+ "along with %s; if not, write to the Free Software\n"
+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
+#elif CONFIG_LGPLV3
+ "it under the terms of the GNU Lesser General Public License as published by\n"
+ "GNU Lesser General Public License for more details.\n"
+ "You should have received a copy of the GNU Lesser General Public License\n"
+ "%s is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU Lesser General Public\n"
+ "License as published by the Free Software Foundation; either\n"
+ "version 2.1 of the License, or (at your option) any later version.\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+ "Lesser General Public License for more details.\n"
+ "You should have received a copy of the GNU Lesser General Public\n"
+ "License along with %s; if not, write to the Free Software\n"
+static int is_device(const AVClass *avclass)
+ if (!avclass)
+ return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
+static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers)
+ void *ifmt_opaque = NULL;
+ const AVInputFormat *ifmt = NULL;
+ void *ofmt_opaque = NULL;
+ const AVOutputFormat *ofmt = NULL;
+ const char *last_name;
+ int is_dev;
+ printf("%s\n"
+ " D. = Demuxing supported\n"
+ " .E = Muxing supported\n"
+ " --\n", device_only ? "Devices:" : "File formats:");
+ last_name = "000";
+ for (;;) {
+ int decode = 0;
+ int encode = 0;
+ const char *name = NULL;
+ const char *long_name = NULL;
+ if (muxdemuxers !=SHOW_DEMUXERS) {
+ ofmt_opaque = NULL;
+ while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
+ is_dev = is_device(ofmt->priv_class);
+ if (!is_dev && device_only)
+ if ((!name || strcmp(ofmt->name, name) < 0) &&
+ strcmp(ofmt->name, last_name) > 0) {
+ name = ofmt->name;
+ long_name = ofmt->long_name;
+ encode = 1;
+ if (muxdemuxers != SHOW_MUXERS) {
+ ifmt_opaque = NULL;
+ while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
+ is_dev = is_device(ifmt->priv_class);
+ if ((!name || strcmp(ifmt->name, name) < 0) &&
+ strcmp(ifmt->name, last_name) > 0) {
+ name = ifmt->name;
+ long_name = ifmt->long_name;
+ encode = 0;
+ if (name && strcmp(ifmt->name, name) == 0)
+ decode = 1;
+ if (!name)
+ last_name = name;
+ printf(" %s%s %-15s %s\n",
+ decode ? "D" : " ",
+ encode ? "E" : " ",
+ name,
+ long_name ? long_name:" ");
+int show_formats(void *optctx, const char *opt, const char *arg)
+ return show_formats_devices(optctx, opt, arg, 0, SHOW_DEFAULT);
+int show_muxers(void *optctx, const char *opt, const char *arg)
+ return show_formats_devices(optctx, opt, arg, 0, SHOW_MUXERS);
+int show_demuxers(void *optctx, const char *opt, const char *arg)
+ return show_formats_devices(optctx, opt, arg, 0, SHOW_DEMUXERS);
+int show_devices(void *optctx, const char *opt, const char *arg)
+ return show_formats_devices(optctx, opt, arg, 1, SHOW_DEFAULT);
+#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
+ if (codec->field) { \
+ const type *p = codec->field; \
+ \
+ printf(" Supported " list_name ":"); \
+ while (*p != term) { \
+ get_name(*p); \
+ printf(" %s", name); \
+ p++; \
+ printf("\n"); \
+static void print_codec(const AVCodec *c)
+ int encoder = av_codec_is_encoder(c);
+ printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
+ c->long_name ? c->long_name : "");
+ printf(" General capabilities: ");
+ if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
+ printf("horizband ");
+ if (c->capabilities & AV_CODEC_CAP_DR1)
+ printf("dr1 ");
+ if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
+ printf("trunc ");
+ if (c->capabilities & AV_CODEC_CAP_DELAY)
+ printf("delay ");
+ if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
+ printf("small ");
+ if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
+ printf("subframes ");
+ if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
+ printf("exp ");
+ if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
+ printf("chconf ");
+ if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
+ printf("paramchange ");
+ if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
+ printf("variable ");
+ if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
+ AV_CODEC_CAP_SLICE_THREADS |
+ AV_CODEC_CAP_AUTO_THREADS))
+ printf("threads ");
+ if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
+ printf("avoidprobe ");
+ if (c->capabilities & AV_CODEC_CAP_INTRA_ONLY)
+ printf("intraonly ");
+ if (c->capabilities & AV_CODEC_CAP_LOSSLESS)
+ printf("lossless ");
+ if (c->capabilities & AV_CODEC_CAP_HARDWARE)
+ printf("hardware ");
+ if (c->capabilities & AV_CODEC_CAP_HYBRID)
+ printf("hybrid ");
+ if (!c->capabilities)
+ printf("none");
+ if (c->type == AVMEDIA_TYPE_VIDEO ||
+ c->type == AVMEDIA_TYPE_AUDIO) {
+ printf(" Threading capabilities: ");
+ switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
+ AV_CODEC_CAP_AUTO_THREADS)) {
+ case AV_CODEC_CAP_FRAME_THREADS |
+ AV_CODEC_CAP_SLICE_THREADS: printf("frame and slice"); break;
+ case AV_CODEC_CAP_FRAME_THREADS: printf("frame"); break;
+ case AV_CODEC_CAP_SLICE_THREADS: printf("slice"); break;
+ case AV_CODEC_CAP_AUTO_THREADS : printf("auto"); break;
+ default: printf("none"); break;
+ if (avcodec_get_hw_config(c, 0)) {
+ printf(" Supported hardware devices: ");
+ for (int i = 0;; i++) {
+ const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
+ if (!config)
+ printf("%s ", av_hwdevice_get_type_name(config->device_type));
+ if (c->supported_framerates) {
+ const AVRational *fps = c->supported_framerates;
+ printf(" Supported framerates:");
+ while (fps->num) {
+ printf(" %d/%d", fps->num, fps->den);
+ fps++;
+ PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
+ AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
+ PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
+ GET_SAMPLE_RATE_NAME);
+ PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
+ AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
+ PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
+ 0, GET_CH_LAYOUT_DESC);
+ if (c->priv_class) {
+ show_help_children(c->priv_class,
+ AV_OPT_FLAG_ENCODING_PARAM |
+ AV_OPT_FLAG_DECODING_PARAM);
+static char get_media_type_char(enum AVMediaType type)
+ switch (type) {
+ case AVMEDIA_TYPE_VIDEO: return 'V';
+ case AVMEDIA_TYPE_AUDIO: return 'A';
+ case AVMEDIA_TYPE_DATA: return 'D';
+ case AVMEDIA_TYPE_SUBTITLE: return 'S';
+ case AVMEDIA_TYPE_ATTACHMENT:return 'T';
+ default: return '?';
+static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
+ int encoder)
+ while ((prev = av_codec_next(prev))) {
+ if (prev->id == id &&
+ (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
+ return prev;
+static int compare_codec_desc(const void *a, const void *b)
+ const AVCodecDescriptor * const *da = a;
+ const AVCodecDescriptor * const *db = b;
+ return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
+ strcmp((*da)->name, (*db)->name);
+static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
+ const AVCodecDescriptor *desc = NULL;
+ const AVCodecDescriptor **codecs;
+ unsigned nb_codecs = 0, i = 0;
+ while ((desc = avcodec_descriptor_next(desc)))
+ nb_codecs++;
+ if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) {
+ av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
+ desc = NULL;
+ codecs[i++] = desc;
+ av_assert0(i == nb_codecs);
+ qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
+ *rcodecs = codecs;
+ return nb_codecs;
+static void print_codecs_for_id(enum AVCodecID id, int encoder)
+ const AVCodec *codec = NULL;
+ printf(" (%s: ", encoder ? "encoders" : "decoders");
+ while ((codec = next_codec_for_id(id, codec, encoder)))
+ printf("%s ", codec->name);
+ printf(")");
+int show_codecs(void *optctx, const char *opt, const char *arg)
+ unsigned i, nb_codecs = get_codecs_sorted(&codecs);
+ printf("Codecs:\n"
+ " D..... = Decoding supported\n"
+ " .E.... = Encoding supported\n"
+ " ..V... = Video codec\n"
+ " ..A... = Audio codec\n"
+ " ..S... = Subtitle codec\n"
+ " ...I.. = Intra frame-only codec\n"
+ " ....L. = Lossy compression\n"
+ " .....S = Lossless compression\n"
+ " -------\n");
+ for (i = 0; i < nb_codecs; i++) {
+ const AVCodecDescriptor *desc = codecs[i];
+ if (strstr(desc->name, "_deprecated"))
+ printf(" ");
+ printf(avcodec_find_decoder(desc->id) ? "D" : ".");
+ printf(avcodec_find_encoder(desc->id) ? "E" : ".");
+ printf("%c", get_media_type_char(desc->type));
+ printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
+ printf((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
+ printf((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
+ printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
+ /* print decoders/encoders when there's more than one or their
+ * names are different from codec name */
+ while ((codec = next_codec_for_id(desc->id, codec, 0))) {
+ if (strcmp(codec->name, desc->name)) {
+ print_codecs_for_id(desc->id, 0);
+ codec = NULL;
+ while ((codec = next_codec_for_id(desc->id, codec, 1))) {
+ print_codecs_for_id(desc->id, 1);
+ av_free(codecs);
+static void print_codecs(int encoder)
+ printf("%s:\n"
+ " V..... = Video\n"
+ " A..... = Audio\n"
+ " S..... = Subtitle\n"
+ " .F.... = Frame-level multithreading\n"
+ " ..S... = Slice-level multithreading\n"
+ " ...X.. = Codec is experimental\n"
+ " ....B. = Supports draw_horiz_band\n"
+ " .....D = Supports direct rendering method 1\n"
+ " ------\n",
+ encoder ? "Encoders" : "Decoders");
+ while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
+ printf(" %c", get_media_type_char(desc->type));
+ printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : ".");
+ printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : ".");
+ printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
+ printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
+ printf((codec->capabilities & AV_CODEC_CAP_DR1) ? "D" : ".");
+ printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
+ if (strcmp(codec->name, desc->name))
+ printf(" (codec %s)", desc->name);
+int show_decoders(void *optctx, const char *opt, const char *arg)
+ print_codecs(0);
+int show_encoders(void *optctx, const char *opt, const char *arg)
+ print_codecs(1);
+int show_bsfs(void *optctx, const char *opt, const char *arg)
+ const AVBitStreamFilter *bsf = NULL;
+ void *opaque = NULL;
+ printf("Bitstream filters:\n");
+ while ((bsf = av_bsf_iterate(&opaque)))
+ printf("%s\n", bsf->name);
+int show_protocols(void *optctx, const char *opt, const char *arg)
+ const char *name;
+ printf("Supported file protocols:\n"
+ "Input:\n");
+ while ((name = avio_enum_protocols(&opaque, 0)))
+ printf(" %s\n", name);
+ printf("Output:\n");
+ while ((name = avio_enum_protocols(&opaque, 1)))
+int show_filters(void *optctx, const char *opt, const char *arg)
+#if CONFIG_AVFILTER
+ const AVFilter *filter = NULL;
+ char descr[64], *descr_cur;
+ const AVFilterPad *pad;
+ printf("Filters:\n"
+ " T.. = Timeline support\n"
+ " .S. = Slice threading\n"
+ " ..C = Command support\n"
+ " A = Audio input/output\n"
+ " V = Video input/output\n"
+ " N = Dynamic number and/or type of input/output\n"
+ " | = Source or sink filter\n");
+ while ((filter = av_filter_iterate(&opaque))) {
+ descr_cur = descr;
+ for (i = 0; i < 2; i++) {
+ if (i) {
+ *(descr_cur++) = '-';
+ *(descr_cur++) = '>';
+ pad = i ? filter->outputs : filter->inputs;
+ for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
+ if (descr_cur >= descr + sizeof(descr) - 4)
+ *(descr_cur++) = get_media_type_char(avfilter_pad_get_type(pad, j));
+ if (!j)
+ *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
+ ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 'N' : '|';
+ *descr_cur = 0;
+ printf(" %c%c%c %-17s %-10s %s\n",
+ filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 'T' : '.',
+ filter->flags & AVFILTER_FLAG_SLICE_THREADS ? 'S' : '.',
+ filter->process_command ? 'C' : '.',
+ filter->name, descr, filter->description);
+ printf("No filters available: libavfilter disabled\n");
+int show_colors(void *optctx, const char *opt, const char *arg)
+ const uint8_t *rgb;
+ printf("%-32s #RRGGBB\n", "name");
+ for (i = 0; name = av_get_known_color_name(i, &rgb); i++)
+ printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
+int show_pix_fmts(void *optctx, const char *opt, const char *arg)
+ const AVPixFmtDescriptor *pix_desc = NULL;
+ printf("Pixel formats:\n"
+ "I.... = Supported Input format for conversion\n"
+ ".O... = Supported Output format for conversion\n"
+ "..H.. = Hardware accelerated format\n"
+ "...P. = Paletted format\n"
+ "....B = Bitstream format\n"
+ "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
+ "-----\n");
+#if !CONFIG_SWSCALE
+# define sws_isSupportedInput(x) 0
+# define sws_isSupportedOutput(x) 0
+ while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
+ enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
+ printf("%c%c%c%c%c %-16s %d %2d\n",
+ sws_isSupportedInput (pix_fmt) ? 'I' : '.',
+ sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
+ pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? 'H' : '.',
+ pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? 'P' : '.',
+ pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 'B' : '.',
+ pix_desc->name,
+ pix_desc->nb_components,
+ av_get_bits_per_pixel(pix_desc));
+int show_layouts(void *optctx, const char *opt, const char *arg)
+ int i = 0;
+ uint64_t layout, j;
+ const char *name, *descr;
+ printf("Individual channels:\n"
+ "NAME DESCRIPTION\n");
+ for (i = 0; i < 63; i++) {
+ name = av_get_channel_name((uint64_t)1 << i);
+ descr = av_get_channel_description((uint64_t)1 << i);
+ printf("%-14s %s\n", name, descr);
+ printf("\nStandard channel layouts:\n"
+ "NAME DECOMPOSITION\n");
+ for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
+ if (name) {
+ printf("%-14s ", name);
+ for (j = 1; j; j <<= 1)
+ if ((layout & j))
+ printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j));
+int show_sample_fmts(void *optctx, const char *opt, const char *arg)
+ char fmt_str[128];
+ for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
+ printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
+static void show_help_codec(const char *name, int encoder)
+ const AVCodecDescriptor *desc;
+ const AVCodec *codec;
+ if (!name) {
+ av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
+ codec = encoder ? avcodec_find_encoder_by_name(name) :
+ avcodec_find_decoder_by_name(name);
+ if (codec)
+ print_codec(codec);
+ else if ((desc = avcodec_descriptor_get_by_name(name))) {
+ int printed = 0;
+ printed = 1;
+ if (!printed) {
+ av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, "
+ "but no %s for it are available. FFmpeg might need to be "
+ "recompiled with additional external libraries.\n",
+ name, encoder ? "encoders" : "decoders");
+ av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n",
+ name);
+static void show_help_demuxer(const char *name)
+ const AVInputFormat *fmt = av_find_input_format(name);
+ if (!fmt) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
+ printf("Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
+ if (fmt->extensions)
+ printf(" Common extensions: %s.\n", fmt->extensions);
+ if (fmt->priv_class)
+ show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
+static void show_help_muxer(const char *name)
+ const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
+ printf("Muxer %s [%s]:\n", fmt->name, fmt->long_name);
+ if (fmt->mime_type)
+ printf(" Mime type: %s.\n", fmt->mime_type);
+ if (fmt->video_codec != AV_CODEC_ID_NONE &&
+ (desc = avcodec_descriptor_get(fmt->video_codec))) {
+ printf(" Default video codec: %s.\n", desc->name);
+ if (fmt->audio_codec != AV_CODEC_ID_NONE &&
+ (desc = avcodec_descriptor_get(fmt->audio_codec))) {
+ printf(" Default audio codec: %s.\n", desc->name);
+ if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
+ (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
+ printf(" Default subtitle codec: %s.\n", desc->name);
+ show_help_children(fmt->priv_class, AV_OPT_FLAG_ENCODING_PARAM);
+static void show_help_filter(const char *name)
+ const AVFilter *f = avfilter_get_by_name(name);
+ int i, count;
+ av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
+ } else if (!f) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown filter '%s'.\n", name);
+ printf("Filter %s\n", f->name);
+ if (f->description)
+ printf(" %s\n", f->description);
+ if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
+ printf(" slice threading supported\n");
+ printf(" Inputs:\n");
+ count = avfilter_pad_count(f->inputs);
+ for (i = 0; i < count; i++) {
+ printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
+ media_type_string(avfilter_pad_get_type(f->inputs, i)));
+ if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
+ printf(" dynamic (depending on the options)\n");
+ else if (!count)
+ printf(" none (source filter)\n");
+ printf(" Outputs:\n");
+ count = avfilter_pad_count(f->outputs);
+ printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
+ media_type_string(avfilter_pad_get_type(f->outputs, i)));
+ if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
+ printf(" none (sink filter)\n");
+ if (f->priv_class)
+ show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
+ AV_OPT_FLAG_AUDIO_PARAM);
+ if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
+ printf("This filter has support for timeline through the 'enable' option.\n");
+ av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
+ "can not to satisfy request\n");
+static void show_help_bsf(const char *name)
+ const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
+ av_log(NULL, AV_LOG_ERROR, "No bitstream filter name specified.\n");
+ } else if (!bsf) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown bit stream filter '%s'.\n", name);
+ printf("Bit stream filter %s\n", bsf->name);
+ PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
+ AV_CODEC_ID_NONE, GET_CODEC_NAME);
+ if (bsf->priv_class)
+ show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
+int show_help(void *optctx, const char *opt, const char *arg)
+ char *topic, *par;
+ topic = av_strdup(arg ? arg : "");
+ if (!topic)
+ par = strchr(topic, '=');
+ if (par)
+ *par++ = 0;
+ if (!*topic) {
+ show_help_default(topic, par);
+ } else if (!strcmp(topic, "decoder")) {
+ show_help_codec(par, 0);
+ } else if (!strcmp(topic, "encoder")) {
+ show_help_codec(par, 1);
+ } else if (!strcmp(topic, "demuxer")) {
+ show_help_demuxer(par);
+ } else if (!strcmp(topic, "muxer")) {
+ show_help_muxer(par);
+ } else if (!strcmp(topic, "filter")) {
+ show_help_filter(par);
+ } else if (!strcmp(topic, "bsf")) {
+ show_help_bsf(par);
+ av_freep(&topic);
+int read_yesno(void)
+ int c = getchar();
+ int yesno = (av_toupper(c) == 'Y');
+ while (c != '\n' && c != EOF)
+ c = getchar();
+ return yesno;
+FILE *get_preset_file(char *filename, size_t filename_size,
+ const char *preset_name, int is_path,
+ const char *codec_name)
+ FILE *f = NULL;
+ const char *base[3] = { getenv("FFMPEG_DATADIR"),
+ getenv("HOME"),
+ FFMPEG_DATADIR, };
+ if (is_path) {
+ av_strlcpy(filename, preset_name, filename_size);
+ f = fopen(filename, "r");
+ char datadir[MAX_PATH], *ls;
+ base[2] = NULL;
+ if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
+ {
+ for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+ if (*ls == '\\') *ls = '/';
+ if (ls = strrchr(datadir, '/'))
+ *ls = 0;
+ strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
+ base[2] = datadir;
+ for (i = 0; i < 3 && !f; i++) {
+ if (!base[i])
+ snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
+ i != 1 ? "" : "/.ffmpeg", preset_name);
+ if (!f && codec_name) {
+ snprintf(filename, filename_size,
+ "%s%s/%s-%s.ffpreset",
+ base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
+ preset_name);
+ return f;
+int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
+ int ret = avformat_match_stream_specifier(s, st, spec);
+ av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
+AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
+ AVFormatContext *s, AVStream *st, AVCodec *codec)
+ AVDictionary *ret = NULL;
+ AVDictionaryEntry *t = NULL;
+ int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
+ : AV_OPT_FLAG_DECODING_PARAM;
+ char prefix = 0;
+ const AVClass *cc = avcodec_get_class();
+ if (!codec)
+ codec = s->oformat ? avcodec_find_encoder(codec_id)
+ : avcodec_find_decoder(codec_id);
+ switch (st->codecpar->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ prefix = 'v';
+ flags |= AV_OPT_FLAG_VIDEO_PARAM;
+ case AVMEDIA_TYPE_AUDIO:
+ prefix = 'a';
+ flags |= AV_OPT_FLAG_AUDIO_PARAM;
+ case AVMEDIA_TYPE_SUBTITLE:
+ prefix = 's';
+ flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
+ while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
+ char *p = strchr(t->key, ':');
+ /* check stream specification in opt name */
+ if (p)
+ switch (check_stream_specifier(s, st, p + 1)) {
+ case 1: *p = 0; break;
+ case 0: continue;
+ default: exit_program(1);
+ if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
+ !codec ||
+ (codec->priv_class &&
+ av_opt_find(&codec->priv_class, t->key, NULL, flags,
+ AV_OPT_SEARCH_FAKE_OBJ)))
+ av_dict_set(&ret, t->key, t->value, 0);
+ else if (t->key[0] == prefix &&
+ av_opt_find(&cc, t->key + 1, NULL, flags,
+ AV_OPT_SEARCH_FAKE_OBJ))
+ av_dict_set(&ret, t->key + 1, t->value, 0);
+ *p = ':';
+AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
+ AVDictionary *codec_opts)
+ AVDictionary **opts;
+ if (!s->nb_streams)
+ opts = av_mallocz_array(s->nb_streams, sizeof(*opts));
+ if (!opts) {
+ "Could not alloc memory for stream options.\n");
+ for (i = 0; i < s->nb_streams; i++)
+ opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
+ s, s->streams[i], NULL);
+ return opts;
+void *grow_array(void *array, int elem_size, int *size, int new_size)
+ if (new_size >= INT_MAX / elem_size) {
+ av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
+ if (*size < new_size) {
+ uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
+ if (!tmp) {
+ av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
+ memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
+ *size = new_size;
+ return tmp;
+ return array;
+double get_rotation(AVStream *st)
+ uint8_t* displaymatrix = av_stream_get_side_data(st,
+ AV_PKT_DATA_DISPLAYMATRIX, NULL);
+ double theta = 0;
+ if (displaymatrix)
+ theta = -av_display_rotation_get((int32_t*) displaymatrix);
+ theta -= 360*floor(theta/360 + 0.9/360);
+ if (fabs(theta - 90*round(theta/90)) > 2)
+ av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
+ "If you want to help, upload a sample "
+ "of this file to ftp://upload.ffmpeg.org/incoming/ "
+ "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
+ return theta;
+#if CONFIG_AVDEVICE
+static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
+ int ret, i;
+ AVDeviceInfoList *device_list = NULL;
+ if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
+ printf("Auto-detected sources for %s:\n", fmt->name);
+ if (!fmt->get_device_list) {
+ ret = AVERROR(ENOSYS);
+ printf("Cannot list sources. Not implemented.\n");
+ goto fail;
+ if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
+ printf("Cannot list sources.\n");
+ for (i = 0; i < device_list->nb_devices; i++) {
+ printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
+ device_list->devices[i]->device_name, device_list->devices[i]->device_description);
+ fail:
+ avdevice_free_list_devices(&device_list);
+static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
+ if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
+ printf("Auto-detected sinks for %s:\n", fmt->name);
+ printf("Cannot list sinks. Not implemented.\n");
+ if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
+ printf("Cannot list sinks.\n");
+static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
+ if (arg) {
+ char *opts_str = NULL;
+ av_assert0(dev && opts);
+ *dev = av_strdup(arg);
+ if (!*dev)
+ if ((opts_str = strchr(*dev, ','))) {
+ *(opts_str++) = '\0';
+ if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, "=", ":", 0)) < 0)) {
+ av_freep(dev);
+ } else
+ printf("\nDevice name is not provided.\n"
+ "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
+int show_sources(void *optctx, const char *opt, const char *arg)
+ AVInputFormat *fmt = NULL;
+ char *dev = NULL;
+ AVDictionary *opts = NULL;
+ int ret = 0;
+ int error_level = av_log_get_level();
+ av_log_set_level(AV_LOG_ERROR);
+ if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
+ do {
+ fmt = av_input_audio_device_next(fmt);
+ if (fmt) {
+ if (!strcmp(fmt->name, "lavfi"))
+ continue; //it's pointless to probe lavfi
+ if (dev && !av_match_name(dev, fmt->name))
+ print_device_sources(fmt, opts);
+ } while (fmt);
+ fmt = av_input_video_device_next(fmt);
+ av_dict_free(&opts);
+ av_free(dev);
+ av_log_set_level(error_level);
+int show_sinks(void *optctx, const char *opt, const char *arg)
+ AVOutputFormat *fmt = NULL;
+ fmt = av_output_audio_device_next(fmt);
+ print_device_sinks(fmt, opts);
+ fmt = av_output_video_device_next(fmt);
@@ -0,0 +1,667 @@
+ * copyright (c) 2003 Fabrice Bellard
+#ifndef FFTOOLS_CMDUTILS_H
+#define FFTOOLS_CMDUTILS_H
+#include "libavcodec/avcodec.h"
+#undef main /* We don't want SDL to override our main() */
+#ifndef _TM_DEFINED
+#define _TM_DEFINED /* 避免重复定义 tm */
+struct tm
+ int tm_sec; /* 秒 - 取值区间为[0,59] */
+ int tm_min; /* 分 - 取值区间为[0,59] */
+ int tm_hour; /* 时 - 取值区间为[0,23] */
+ int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
+ int tm_mon; /* 月份(从一月开始,0代表一月)- 取值区间为[0,11] */
+ int tm_year; /* 年份,其值等于实际年份减去1900 */
+ int tm_wday; /* 星期–取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
+ int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
+ int tm_isdst; /*夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/
+ * program name, defined by the program for show_version().
+extern const char program_name[];
+ * program birth year, defined by the program for show_banner()
+extern const int program_birth_year;
+extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
+extern AVFormatContext *avformat_opts;
+extern AVDictionary *sws_dict;
+extern AVDictionary *swr_opts;
+extern AVDictionary *format_opts, *codec_opts, *resample_opts;
+extern int hide_banner;
+ * Register a program-specific cleanup routine.
+void register_exit(void (*cb)(int ret));
+ * Wraps exit with a program-specific cleanup routine.
+void exit_program(int ret) av_noreturn;
+ * Initialize dynamic library loading
+void init_dynload(void);
+ * Initialize the cmdutils option system, in particular
+ * allocate the *_opts contexts.
+void init_opts(void);
+ * Uninitialize the cmdutils option system, in particular
+ * free the *_opts contexts and their contents.
+void uninit_opts(void);
+ * Trivial log callback.
+ * Only suitable for opt_help and similar since it lacks prefix handling.
+void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
+ * Override the cpuflags.
+int opt_cpuflags(void *optctx, const char *opt, const char *arg);
+ * Fallback for options that are not explicitly handled, these will be
+ * parsed through AVOptions.
+int opt_default(void *optctx, const char *opt, const char *arg);
+ * Set the libav* libraries log level.
+int opt_loglevel(void *optctx, const char *opt, const char *arg);
+int opt_report(const char *opt);
+int opt_max_alloc(void *optctx, const char *opt, const char *arg);
+int opt_codec_debug(void *optctx, const char *opt, const char *arg);
+ * Limit the execution time.
+int opt_timelimit(void *optctx, const char *opt, const char *arg);
+ * Parse a string and return its corresponding value as a double.
+ * Exit from the application if the string cannot be correctly
+ * parsed or the corresponding value is invalid.
+ * @param context the context of the value to be set (e.g. the
+ * corresponding command line option name)
+ * @param numstr the string to be parsed
+ * @param type the type (OPT_INT64 or OPT_FLOAT) as which the
+ * string should be parsed
+ * @param min the minimum valid accepted value
+ * @param max the maximum valid accepted value
+ double min, double max);
+ * Parse a string specifying a time and return its corresponding
+ * value as a number of microseconds. Exit from the application if
+ * the string cannot be correctly parsed.
+ * @param timestr the string to be parsed
+ * @param is_duration a flag which tells how to interpret timestr, if
+ * not zero timestr is interpreted as a duration, otherwise as a
+ * date
+ * @see av_parse_time()
+ int is_duration);
+typedef struct SpecifierOpt {
+ char *specifier; /**< stream/chapter/program/... specifier */
+ union {
+ uint8_t *str;
+ int64_t i64;
+ uint64_t ui64;
+ float f;
+ double dbl;
+ } u;
+} SpecifierOpt;
+typedef struct OptionDef {
+ int flags;
+#define HAS_ARG 0x0001
+#define OPT_BOOL 0x0002
+#define OPT_EXPERT 0x0004
+#define OPT_STRING 0x0008
+#define OPT_VIDEO 0x0010
+#define OPT_AUDIO 0x0020
+#define OPT_INT 0x0080
+#define OPT_FLOAT 0x0100
+#define OPT_SUBTITLE 0x0200
+#define OPT_INT64 0x0400
+#define OPT_EXIT 0x0800
+#define OPT_DATA 0x1000
+#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only).
+ implied by OPT_OFFSET or OPT_SPEC */
+#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */
+#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt.
+ Implies OPT_OFFSET. Next element after the offset is
+ an int containing element count in the array. */
+#define OPT_TIME 0x10000
+#define OPT_DOUBLE 0x20000
+#define OPT_INPUT 0x40000
+#define OPT_OUTPUT 0x80000
+ void *dst_ptr;
+ int (*func_arg)(void *, const char *, const char *);
+ size_t off;
+ const char *help;
+ const char *argname;
+} OptionDef;
+ * Print help for all options matching specified flags.
+ * @param options a list of options
+ * @param msg title of this group. Only printed if at least one option matches.
+ * @param req_flags print only options which have all those flags set.
+ * @param rej_flags don't print options which have any of those flags set.
+ * @param alt_flags print only options that have at least one of those flags set
+ int rej_flags, int alt_flags);
+#define CMDUTILS_COMMON_OPTIONS_AVDEVICE \
+ { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \
+ "list sources of the input device", "device" }, \
+ { "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks }, \
+ "list sinks of the output device", "device" }, \
+#define CMDUTILS_COMMON_OPTIONS_AVDEVICE
+#define CMDUTILS_COMMON_OPTIONS \
+ { "L", OPT_EXIT, { .func_arg = show_license }, "show license" }, \
+ { "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
+ { "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
+ { "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
+ { "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
+ { "version", OPT_EXIT, { .func_arg = show_version }, "show version" }, \
+ { "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" }, \
+ { "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" }, \
+ { "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" }, \
+ { "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" }, \
+ { "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" }, \
+ { "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" }, \
+ { "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" }, \
+ { "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" }, \
+ { "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" }, \
+ { "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" }, \
+ { "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" }, \
+ { "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" }, \
+ { "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" }, \
+ { "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" }, \
+ { "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \
+ { "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
+ { "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
+ { "report", 0, { (void*)opt_report }, "generate a report" }, \
+ { "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
+ { "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \
+ { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \
+ CMDUTILS_COMMON_OPTIONS_AVDEVICE \
+ * Show help for all options with given flags in class and all its
+ * children.
+void show_help_children(const AVClass *class, int flags);
+ * Per-fftool specific help handler. Implemented in each
+ * fftool, called by show_help().
+void show_help_default(const char *opt, const char *arg);
+ * Generic -h handler common to all fftools.
+int show_help(void *optctx, const char *opt, const char *arg);
+ * Parse the command line arguments.
+ * @param optctx an opaque options context
+ * @param argc number of command line arguments
+ * @param argv values of command line arguments
+ * @param options Array with the definitions required to interpret every
+ * option of the form: -option_name [argument]
+ * @param parse_arg_function Name of the function called to process every
+ * argument without a leading option name flag. NULL if such arguments do
+ * not have to be processed.
+ void (* parse_arg_function)(void *optctx, const char*));
+ * Parse one given option.
+ * @return on success 1 if arg was consumed, 0 otherwise; negative number on error
+ const OptionDef *options);
+ * An option extracted from the commandline.
+ * Cannot use AVDictionary because of options like -map which can be
+ * used multiple times.
+typedef struct Option {
+ const OptionDef *opt;
+ const char *key;
+ const char *val;
+} Option;
+typedef struct OptionGroupDef {
+ /**< group name */
+ /**
+ * Option to be used as group separator. Can be NULL for groups which
+ * are terminated by a non-option argument (e.g. ffmpeg output files)
+ const char *sep;
+ * Option flags that must be set on each option that is
+ * applied to this group
+} OptionGroupDef;
+typedef struct OptionGroup {
+ const OptionGroupDef *group_def;
+ const char *arg;
+ Option *opts;
+ int nb_opts;
+ AVDictionary *codec_opts;
+ AVDictionary *format_opts;
+ AVDictionary *resample_opts;
+ AVDictionary *sws_dict;
+ AVDictionary *swr_opts;
+} OptionGroup;
+ * A list of option groups that all have the same group type
+ * (e.g. input files or output files)
+typedef struct OptionGroupList {
+ OptionGroup *groups;
+ int nb_groups;
+} OptionGroupList;
+typedef struct OptionParseContext {
+ OptionGroup global_opts;
+ OptionGroupList *groups;
+ /* parsing state */
+ OptionGroup cur_group;
+} OptionParseContext;
+ * Parse an options group and write results into optctx.
+ * @param optctx an app-specific options context. NULL for global options group
+int parse_optgroup(void *optctx, OptionGroup *g);
+ * Split the commandline into an intermediate form convenient for further
+ * processing.
+ * The commandline is assumed to be composed of options which either belong to a
+ * group (those with OPT_SPEC, OPT_OFFSET or OPT_PERFILE) or are global
+ * (everything else).
+ * A group (defined by an OptionGroupDef struct) is a sequence of options
+ * terminated by either a group separator option (e.g. -i) or a parameter that
+ * is not an option (doesn't start with -). A group without a separator option
+ * must always be first in the supplied groups list.
+ * All options within the same group are stored in one OptionGroup struct in an
+ * OptionGroupList, all groups with the same group definition are stored in one
+ * OptionGroupList in OptionParseContext.groups. The order of group lists is the
+ * same as the order of group definitions.
+ const OptionGroupDef *groups, int nb_groups);
+ * Free all allocated memory in an OptionParseContext.
+void uninit_parse_context(OptionParseContext *octx);
+ * Find the '-loglevel' option in the command line args and apply it.
+void parse_loglevel(int argc, char **argv, const OptionDef *options);
+ * Return index of option opt in argv or 0 if not found.
+ const char *optname);
+ * Check if the given stream matches a stream specifier.
+ * @param s Corresponding format context.
+ * @param st Stream from s to be checked.
+ * @param spec A stream specifier of the [v|a|s|d]:[\<stream index\>] form.
+ * @return 1 if the stream matches, 0 if it doesn't, <0 on error
+int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
+ * Filter out options for given codec.
+ * Create a new options dictionary containing only the options from
+ * opts which apply to the codec with ID codec_id.
+ * @param opts dictionary to place options in
+ * @param codec_id ID of the codec that should be filtered for
+ * @param st A stream from s for which the options should be filtered.
+ * @param codec The particular codec for which the options should be filtered.
+ * If null, the default one is looked up according to the codec id.
+ * @return a pointer to the created dictionary
+ AVFormatContext *s, AVStream *st, AVCodec *codec);
+ * Setup AVCodecContext options for avformat_find_stream_info().
+ * Create an array of dictionaries, one dictionary for each stream
+ * contained in s.
+ * Each dictionary will contain the options from codec_opts which can
+ * be applied to the corresponding stream codec context.
+ * @return pointer to the created array of dictionaries, NULL if it
+ * cannot be created
+ AVDictionary *codec_opts);
+ * Print an error message to stderr, indicating filename and a human
+ * readable description of the error code err.
+ * If strerror_r() is not available the use of this function in a
+ * multithreaded application may be unsafe.
+ * @see av_strerror()
+void print_error(const char *filename, int err);
+ * Print the program banner to stderr. The banner contents depend on the
+ * current version of the repository and of the libav* libraries used by
+ * the program.
+void show_banner(int argc, char **argv, const OptionDef *options);
+ * Print the version of the program to stdout. The version message
+ * depends on the current versions of the repository and of the libav*
+ * libraries.
+ * This option processing function does not utilize the arguments.
+int show_version(void *optctx, const char *opt, const char *arg);
+ * Print the build configuration of the program to stdout. The contents
+ * depend on the definition of FFMPEG_CONFIGURATION.
+int show_buildconf(void *optctx, const char *opt, const char *arg);
+ * Print the license of the program to stdout. The license depends on
+ * the license of the libraries compiled into the program.
+int show_license(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the formats supported by the
+ * program (including devices).
+int show_formats(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the muxers supported by the
+int show_muxers(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the demuxer supported by the
+int show_demuxers(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the devices supported by the
+ * program.
+int show_devices(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing autodetected sinks of the output device.
+ * Device name with options may be passed as an argument to limit results.
+int show_sinks(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing autodetected sources of the input device.
+int show_sources(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the codecs supported by the
+int show_codecs(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the decoders supported by the
+int show_decoders(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the encoders supported by the
+int show_encoders(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the filters supported by the
+int show_filters(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the bit stream filters supported by the
+int show_bsfs(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the protocols supported by the
+int show_protocols(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the pixel formats supported by the
+int show_pix_fmts(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the standard channel layouts supported by
+int show_layouts(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the sample formats supported by the
+int show_sample_fmts(void *optctx, const char *opt, const char *arg);
+ * Print a listing containing all the color names and values recognized
+ * by the program.
+int show_colors(void *optctx, const char *opt, const char *arg);
+ * Return a positive value if a line read from standard input
+ * starts with [yY], otherwise return 0.
+int read_yesno(void);
+ * Get a file corresponding to a preset file.
+ * If is_path is non-zero, look for the file in the path preset_name.
+ * Otherwise search for a file named arg.ffpreset in the directories
+ * $FFMPEG_DATADIR (if set), $HOME/.ffmpeg, and in the datadir defined
+ * at configuration time or in a "ffpresets" folder along the executable
+ * on win32, in that order. If no such file is found and
+ * codec_name is defined, then search for a file named
+ * codec_name-preset_name.avpreset in the above-mentioned directories.
+ * @param filename buffer where the name of the found filename is written
+ * @param filename_size size in bytes of the filename buffer
+ * @param preset_name name of the preset to search
+ * @param is_path tell if preset_name is a filename path
+ * @param codec_name name of the codec for which to look for the
+ * preset, may be NULL
+ const char *preset_name, int is_path, const char *codec_name);
+ * Realloc array to hold new_size elements of elem_size.
+ * Calls exit() on failure.
+ * @param array array to reallocate
+ * @param elem_size size in bytes of each element
+ * @param size new element count will be written here
+ * @param new_size number of elements to place in reallocated array
+ * @return reallocated array
+void *grow_array(void *array, int elem_size, int *size, int new_size);
+#define media_type_string av_get_media_type_string
+#define GROW_ARRAY(array, nb_elems)\
+ array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
+#define GET_PIX_FMT_NAME(pix_fmt)\
+ const char *name = av_get_pix_fmt_name(pix_fmt);
+#define GET_CODEC_NAME(id)\
+ const char *name = avcodec_descriptor_get(id)->name;
+#define GET_SAMPLE_FMT_NAME(sample_fmt)\
+ const char *name = av_get_sample_fmt_name(sample_fmt)
+#define GET_SAMPLE_RATE_NAME(rate)\
+ char name[16];\
+ snprintf(name, sizeof(name), "%d", rate);
+#define GET_CH_LAYOUT_NAME(ch_layout)\
+ snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
+#define GET_CH_LAYOUT_DESC(ch_layout)\
+ char name[128];\
+ av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
+double get_rotation(AVStream *st);
+#endif /* FFTOOLS_CMDUTILS_H */
@@ -0,0 +1,176 @@
+ * based on vlc_atomic.h from VLC
+ * Copyright (C) 2010 Rémi Denis-Courmont
+#ifndef COMPAT_ATOMICS_DUMMY_STDATOMIC_H
+#define COMPAT_ATOMICS_DUMMY_STDATOMIC_H
+#define ATOMIC_FLAG_INIT 0
+#define ATOMIC_VAR_INIT(value) (value)
+#define atomic_init(obj, value) \
+ *(obj) = (value); \
+} while(0)
+#define kill_dependency(y) ((void)0)
+#define atomic_thread_fence(order) \
+ ((void)0)
+#define atomic_signal_fence(order) \
+#define atomic_is_lock_free(obj) 0
+typedef intptr_t atomic_flag;
+typedef intptr_t atomic_bool;
+typedef intptr_t atomic_char;
+typedef intptr_t atomic_schar;
+typedef intptr_t atomic_uchar;
+typedef intptr_t atomic_short;
+typedef intptr_t atomic_ushort;
+typedef intptr_t atomic_int;
+typedef intptr_t atomic_uint;
+typedef intptr_t atomic_long;
+typedef intptr_t atomic_ulong;
+typedef intptr_t atomic_llong;
+typedef intptr_t atomic_ullong;
+typedef intptr_t atomic_wchar_t;
+typedef intptr_t atomic_int_least8_t;
+typedef intptr_t atomic_uint_least8_t;
+typedef intptr_t atomic_int_least16_t;
+typedef intptr_t atomic_uint_least16_t;
+typedef intptr_t atomic_int_least32_t;
+typedef intptr_t atomic_uint_least32_t;
+typedef intptr_t atomic_int_least64_t;
+typedef intptr_t atomic_uint_least64_t;
+typedef intptr_t atomic_int_fast8_t;
+typedef intptr_t atomic_uint_fast8_t;
+typedef intptr_t atomic_int_fast16_t;
+typedef intptr_t atomic_uint_fast16_t;
+typedef intptr_t atomic_int_fast32_t;
+typedef intptr_t atomic_uint_fast32_t;
+typedef intptr_t atomic_int_fast64_t;
+typedef intptr_t atomic_uint_fast64_t;
+typedef intptr_t atomic_intptr_t;
+typedef intptr_t atomic_uintptr_t;
+typedef intptr_t atomic_size_t;
+typedef intptr_t atomic_ptrdiff_t;
+typedef intptr_t atomic_intmax_t;
+typedef intptr_t atomic_uintmax_t;
+#define atomic_store(object, desired) \
+ *(object) = (desired); \
+#define atomic_store_explicit(object, desired, order) \
+ atomic_store(object, desired)
+#define atomic_load(object) \
+ (*(object))
+#define atomic_load_explicit(object, order) \
+ atomic_load(object)
+static inline intptr_t atomic_exchange(intptr_t *object, intptr_t desired)
+ intptr_t ret = *object;
+ *object = desired;
+#define atomic_exchange_explicit(object, desired, order) \
+ atomic_exchange(object, desired)
+static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *expected,
+ intptr_t desired)
+ if (*object == *expected) {
+ ret = 1;
+ *expected = *object;
+ ret = 0;
+#define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
+ atomic_compare_exchange_strong(object, expected, desired)
+#define atomic_compare_exchange_weak(object, expected, desired) \
+#define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
+ atomic_compare_exchange_weak(object, expected, desired)
+#define FETCH_MODIFY(opname, op) \
+static inline intptr_t atomic_fetch_ ## opname(intptr_t *object, intptr_t operand) \
+{ \
+ intptr_t ret; \
+ ret = *object; \
+ *object = *object op operand; \
+ return ret; \
+FETCH_MODIFY(add, +)
+FETCH_MODIFY(sub, -)
+FETCH_MODIFY(or, |)
+FETCH_MODIFY(xor, ^)
+FETCH_MODIFY(and, &)
+#undef FETCH_MODIFY
+#define atomic_fetch_add_explicit(object, operand, order) \
+ atomic_fetch_add(object, operand)
+#define atomic_fetch_sub_explicit(object, operand, order) \
+ atomic_fetch_sub(object, operand)
+#define atomic_fetch_or_explicit(object, operand, order) \
+ atomic_fetch_or(object, operand)
+#define atomic_fetch_xor_explicit(object, operand, order) \
+ atomic_fetch_xor(object, operand)
+#define atomic_fetch_and_explicit(object, operand, order) \
+ atomic_fetch_and(object, operand)
+#define atomic_flag_test_and_set(object) \
+ atomic_exchange(object, 1)
+#define atomic_flag_test_and_set_explicit(object, order) \
+ atomic_flag_test_and_set(object)
+#define atomic_flag_clear(object) \
+ atomic_store(object, 0)
+#define atomic_flag_clear_explicit(object, order) \
+ atomic_flag_clear(object)
+#endif /* COMPAT_ATOMICS_DUMMY_STDATOMIC_H */
@@ -0,0 +1,173 @@
+#ifndef COMPAT_ATOMICS_GCC_STDATOMIC_H
+#define COMPAT_ATOMICS_GCC_STDATOMIC_H
+#include <stddef.h>
+ __sync_synchronize()
+typedef _Bool atomic_flag;
+typedef _Bool atomic_bool;
+typedef char atomic_char;
+typedef signed char atomic_schar;
+typedef unsigned char atomic_uchar;
+typedef short atomic_short;
+typedef unsigned short atomic_ushort;
+typedef int atomic_int;
+typedef unsigned int atomic_uint;
+typedef long atomic_long;
+typedef unsigned long atomic_ulong;
+typedef long long atomic_llong;
+typedef unsigned long long atomic_ullong;
+typedef wchar_t atomic_wchar_t;
+typedef int_least8_t atomic_int_least8_t;
+typedef uint_least8_t atomic_uint_least8_t;
+typedef int_least16_t atomic_int_least16_t;
+typedef uint_least16_t atomic_uint_least16_t;
+typedef int_least32_t atomic_int_least32_t;
+typedef uint_least32_t atomic_uint_least32_t;
+typedef int_least64_t atomic_int_least64_t;
+typedef uint_least64_t atomic_uint_least64_t;
+typedef int_fast8_t atomic_int_fast8_t;
+typedef uint_fast8_t atomic_uint_fast8_t;
+typedef int_fast16_t atomic_int_fast16_t;
+typedef uint_fast16_t atomic_uint_fast16_t;
+typedef int_fast32_t atomic_int_fast32_t;
+typedef uint_fast32_t atomic_uint_fast32_t;
+typedef int_fast64_t atomic_int_fast64_t;
+typedef uint_fast64_t atomic_uint_fast64_t;
+typedef uintptr_t atomic_uintptr_t;
+typedef size_t atomic_size_t;
+typedef ptrdiff_t atomic_ptrdiff_t;
+typedef intmax_t atomic_intmax_t;
+typedef uintmax_t atomic_uintmax_t;
+ __sync_synchronize(); \
+ (__sync_synchronize(), *(object))
+#define atomic_exchange(object, desired) \
+({ \
+ __typeof__(object) _obj = (object); \
+ __typeof__(*object) _old; \
+ do \
+ _old = atomic_load(_obj); \
+ while (!__sync_bool_compare_and_swap(_obj, _old, (desired))); \
+ _old; \
+})
+#define atomic_compare_exchange_strong(object, expected, desired) \
+ __typeof__(object) _exp = (expected); \
+ __typeof__(*object) _old = *_exp; \
+ *_exp = __sync_val_compare_and_swap((object), _old, (desired)); \
+ *_exp == _old; \
+#define atomic_fetch_add(object, operand) \
+ __sync_fetch_and_add(object, operand)
+#define atomic_fetch_sub(object, operand) \
+ __sync_fetch_and_sub(object, operand)
+#define atomic_fetch_or(object, operand) \
+ __sync_fetch_and_or(object, operand)
+#define atomic_fetch_xor(object, operand) \
+ __sync_fetch_and_xor(object, operand)
+#define atomic_fetch_and(object, operand) \
+ __sync_fetch_and_and(object, operand)
+#endif /* COMPAT_ATOMICS_GCC_STDATOMIC_H */
@@ -0,0 +1,39 @@
+#include <pthread.h>
+#include "stdatomic.h"
+static pthread_mutex_t atomic_lock = PTHREAD_MUTEX_INITIALIZER;
+void avpriv_atomic_lock(void)
+ pthread_mutex_lock(&atomic_lock);
+void avpriv_atomic_unlock(void)
+ pthread_mutex_unlock(&atomic_lock);
@@ -0,0 +1,197 @@
+#ifndef COMPAT_ATOMICS_PTHREAD_STDATOMIC_H
+#define COMPAT_ATOMICS_PTHREAD_STDATOMIC_H
+void avpriv_atomic_lock(void);
+void avpriv_atomic_unlock(void);
+static inline void atomic_thread_fence(int order)
+ avpriv_atomic_lock();
+ avpriv_atomic_unlock();
+static inline void atomic_store(intptr_t *object, intptr_t desired)
+static inline intptr_t atomic_load(intptr_t *object)
+ intptr_t ret;
+ ret = *object;
+ avpriv_atomic_lock(); \
+ avpriv_atomic_unlock(); \
+#endif /* COMPAT_ATOMICS_PTHREAD_STDATOMIC_H */
@@ -0,0 +1,186 @@
+#ifndef COMPAT_ATOMICS_SUNCC_STDATOMIC_H
+#define COMPAT_ATOMICS_SUNCC_STDATOMIC_H
+#include <atomic.h>
+#include <mbarrier.h>
+ __machine_rw_barrier();
+ return *object;
+ atomic_swap_ptr(object, desired)
+ intptr_t old = *expected;
+ *expected = (intptr_t)atomic_cas_ptr(object, (void *)old, (void *)desired);
+ return *expected == old;
+static inline intptr_t atomic_fetch_add(intptr_t *object, intptr_t operand)
+ return atomic_add_ptr_nv(object, operand) - operand;
+ atomic_fetch_add(object, -(operand))
+static inline intptr_t atomic_fetch_or(intptr_t *object, intptr_t operand)
+ intptr_t old;
+ old = atomic_load(object);
+ } while (!atomic_compare_exchange_strong(object, old, old | operand));
+ return old;
+static inline intptr_t atomic_fetch_xor(intptr_t *object, intptr_t operand)
+ } while (!atomic_compare_exchange_strong(object, old, old ^ operand));
+static inline intptr_t atomic_fetch_and(intptr_t *object, intptr_t operand)
+ } while (!atomic_compare_exchange_strong(object, old, old & operand));
+#endif /* COMPAT_ATOMICS_SUNCC_STDATOMIC_H */
@@ -0,0 +1,181 @@
+#ifndef COMPAT_ATOMICS_WIN32_STDATOMIC_H
+#define COMPAT_ATOMICS_WIN32_STDATOMIC_H
+#define WIN32_LEAN_AND_MEAN
+ MemoryBarrier();
+ MemoryBarrier(); \
+ (MemoryBarrier(), *(object))
+ InterlockedExchangePointer(object, desired);
+ *expected = (intptr_t)InterlockedCompareExchangePointer(
+ (PVOID *)object, (PVOID)desired, (PVOID)old);
+#ifdef _WIN64
+ InterlockedExchangeAdd64(object, operand)
+ InterlockedExchangeAdd64(object, -(operand))
+ InterlockedOr64(object, operand)
+ InterlockedXor64(object, operand)
+ InterlockedAnd64(object, operand)
+ InterlockedExchangeAdd(object, operand)
+ InterlockedExchangeAdd(object, -(operand))
+ InterlockedOr(object, operand)
+ InterlockedXor(object, operand)
+ InterlockedAnd(object, operand)
+#endif /* _WIN64 */
+#endif /* COMPAT_ATOMICS_WIN32_STDATOMIC_H */
@@ -0,0 +1,34 @@
+ * MSVC Compatible va_copy macro
+ * Copyright (c) 2012 Derek Buitenhuis
+#ifndef COMPAT_VA_COPY_H
+#define COMPAT_VA_COPY_H
+#include <stdarg.h>
+#if !defined(va_copy) && defined(_MSC_VER)
+#define va_copy(dst, src) ((dst) = (src))
+#if !defined(va_copy) && defined(__GNUC__) && __GNUC__ < 3
+#define va_copy(dst, src) __va_copy(dst, src)
+#endif /* COMPAT_VA_COPY_H */
@@ -0,0 +1,2514 @@
+/* Automatically generated by configure - do not modify! */
+#ifndef FFMPEG_CONFIG_H
+#define FFMPEG_CONFIG_H
+#define FFMPEG_CONFIGURATION ""
+#define FFMPEG_LICENSE "LGPL version 2.1 or later"
+#define CONFIG_THIS_YEAR 2020
+#define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
+#define AVCONV_DATADIR "/usr/local/share/ffmpeg"
+#define CC_IDENT "gcc 6.3.0 (MinGW.org GCC-6.3.0-1)"
+#define av_restrict restrict
+#define EXTERN_PREFIX "_"
+#define EXTERN_ASM _
+#define BUILDSUF ""
+#define SLIBSUF ".dll"
+#define HAVE_MMX2 HAVE_MMXEXT
+#define SWS_MAX_FILTER_SIZE 256
+#define ARCH_AARCH64 0
+#define ARCH_ALPHA 0
+#define ARCH_ARM 0
+#define ARCH_AVR32 0
+#define ARCH_AVR32_AP 0
+#define ARCH_AVR32_UC 0
+#define ARCH_BFIN 0
+#define ARCH_IA64 0
+#define ARCH_M68K 0
+#define ARCH_MIPS 0
+#define ARCH_MIPS64 0
+#define ARCH_PARISC 0
+#define ARCH_PPC 0
+#define ARCH_PPC64 0
+#define ARCH_S390 0
+#define ARCH_SH4 0
+#define ARCH_SPARC 0
+#define ARCH_SPARC64 0
+#define ARCH_TILEGX 0
+#define ARCH_TILEPRO 0
+#define ARCH_TOMI 0
+#define ARCH_X86 1
+#define ARCH_X86_32 1
+#define ARCH_X86_64 0
+#define HAVE_ARMV5TE 0
+#define HAVE_ARMV6 0
+#define HAVE_ARMV6T2 0
+#define HAVE_ARMV8 0
+#define HAVE_NEON 0
+#define HAVE_VFP 0
+#define HAVE_VFPV3 0
+#define HAVE_SETEND 0
+#define HAVE_ALTIVEC 0
+#define HAVE_DCBZL 0
+#define HAVE_LDBRX 0
+#define HAVE_POWER8 0
+#define HAVE_PPC4XX 0
+#define HAVE_VSX 0
+#define HAVE_AESNI 1
+#define HAVE_AMD3DNOW 1
+#define HAVE_AMD3DNOWEXT 1
+#define HAVE_AVX 1
+#define HAVE_AVX2 1
+#define HAVE_AVX512 1
+#define HAVE_FMA3 1
+#define HAVE_FMA4 1
+#define HAVE_MMX 1
+#define HAVE_MMXEXT 1
+#define HAVE_SSE 1
+#define HAVE_SSE2 1
+#define HAVE_SSE3 1
+#define HAVE_SSE4 1
+#define HAVE_SSE42 1
+#define HAVE_SSSE3 1
+#define HAVE_XOP 1
+#define HAVE_CPUNOP 1
+#define HAVE_I686 1
+#define HAVE_MIPSFPU 0
+#define HAVE_MIPS32R2 0
+#define HAVE_MIPS32R5 0
+#define HAVE_MIPS64R2 0
+#define HAVE_MIPS32R6 0
+#define HAVE_MIPS64R6 0
+#define HAVE_MIPSDSP 0
+#define HAVE_MIPSDSPR2 0
+#define HAVE_MSA 0
+#define HAVE_MSA2 0
+#define HAVE_LOONGSON2 0
+#define HAVE_LOONGSON3 0
+#define HAVE_MMI 0
+#define HAVE_ARMV5TE_EXTERNAL 0
+#define HAVE_ARMV6_EXTERNAL 0
+#define HAVE_ARMV6T2_EXTERNAL 0
+#define HAVE_ARMV8_EXTERNAL 0
+#define HAVE_NEON_EXTERNAL 0
+#define HAVE_VFP_EXTERNAL 0
+#define HAVE_VFPV3_EXTERNAL 0
+#define HAVE_SETEND_EXTERNAL 0
+#define HAVE_ALTIVEC_EXTERNAL 0
+#define HAVE_DCBZL_EXTERNAL 0
+#define HAVE_LDBRX_EXTERNAL 0
+#define HAVE_POWER8_EXTERNAL 0
+#define HAVE_PPC4XX_EXTERNAL 0
+#define HAVE_VSX_EXTERNAL 0
+#define HAVE_AESNI_EXTERNAL 1
+#define HAVE_AMD3DNOW_EXTERNAL 1
+#define HAVE_AMD3DNOWEXT_EXTERNAL 1
+#define HAVE_AVX_EXTERNAL 1
+#define HAVE_AVX2_EXTERNAL 1
+#define HAVE_AVX512_EXTERNAL 0
+#define HAVE_FMA3_EXTERNAL 1
+#define HAVE_FMA4_EXTERNAL 1
+#define HAVE_MMX_EXTERNAL 1
+#define HAVE_MMXEXT_EXTERNAL 1
+#define HAVE_SSE_EXTERNAL 1
+#define HAVE_SSE2_EXTERNAL 1
+#define HAVE_SSE3_EXTERNAL 1
+#define HAVE_SSE4_EXTERNAL 1
+#define HAVE_SSE42_EXTERNAL 1
+#define HAVE_SSSE3_EXTERNAL 1
+#define HAVE_XOP_EXTERNAL 1
+#define HAVE_CPUNOP_EXTERNAL 0
+#define HAVE_I686_EXTERNAL 0
+#define HAVE_MIPSFPU_EXTERNAL 0
+#define HAVE_MIPS32R2_EXTERNAL 0
+#define HAVE_MIPS32R5_EXTERNAL 0
+#define HAVE_MIPS64R2_EXTERNAL 0
+#define HAVE_MIPS32R6_EXTERNAL 0
+#define HAVE_MIPS64R6_EXTERNAL 0
+#define HAVE_MIPSDSP_EXTERNAL 0
+#define HAVE_MIPSDSPR2_EXTERNAL 0
+#define HAVE_MSA_EXTERNAL 0
+#define HAVE_MSA2_EXTERNAL 0
+#define HAVE_LOONGSON2_EXTERNAL 0
+#define HAVE_LOONGSON3_EXTERNAL 0
+#define HAVE_MMI_EXTERNAL 0
+#define HAVE_ARMV5TE_INLINE 0
+#define HAVE_ARMV6_INLINE 0
+#define HAVE_ARMV6T2_INLINE 0
+#define HAVE_ARMV8_INLINE 0
+#define HAVE_NEON_INLINE 0
+#define HAVE_VFP_INLINE 0
+#define HAVE_VFPV3_INLINE 0
+#define HAVE_SETEND_INLINE 0
+#define HAVE_ALTIVEC_INLINE 0
+#define HAVE_DCBZL_INLINE 0
+#define HAVE_LDBRX_INLINE 0
+#define HAVE_POWER8_INLINE 0
+#define HAVE_PPC4XX_INLINE 0
+#define HAVE_VSX_INLINE 0
+#define HAVE_AESNI_INLINE 1
+#define HAVE_AMD3DNOW_INLINE 1
+#define HAVE_AMD3DNOWEXT_INLINE 1
+#define HAVE_AVX_INLINE 1
+#define HAVE_AVX2_INLINE 1
+#define HAVE_AVX512_INLINE 1
+#define HAVE_FMA3_INLINE 1
+#define HAVE_FMA4_INLINE 1
+#define HAVE_MMX_INLINE 0
+#define HAVE_MMXEXT_INLINE 1
+#define HAVE_SSE_INLINE 1
+#define HAVE_SSE2_INLINE 1
+#define HAVE_SSE3_INLINE 1
+#define HAVE_SSE4_INLINE 1
+#define HAVE_SSE42_INLINE 1
+#define HAVE_SSSE3_INLINE 1
+#define HAVE_XOP_INLINE 1
+#define HAVE_CPUNOP_INLINE 0
+#define HAVE_I686_INLINE 0
+#define HAVE_MIPSFPU_INLINE 0
+#define HAVE_MIPS32R2_INLINE 0
+#define HAVE_MIPS32R5_INLINE 0
+#define HAVE_MIPS64R2_INLINE 0
+#define HAVE_MIPS32R6_INLINE 0
+#define HAVE_MIPS64R6_INLINE 0
+#define HAVE_MIPSDSP_INLINE 0
+#define HAVE_MIPSDSPR2_INLINE 0
+#define HAVE_MSA_INLINE 0
+#define HAVE_MSA2_INLINE 0
+#define HAVE_LOONGSON2_INLINE 0
+#define HAVE_LOONGSON3_INLINE 0
+#define HAVE_MMI_INLINE 0
+#define HAVE_ALIGNED_STACK 1
+#define HAVE_FAST_64BIT 0
+#define HAVE_FAST_CLZ 1
+#define HAVE_FAST_CMOV 0
+#define HAVE_LOCAL_ALIGNED 1
+#define HAVE_SIMD_ALIGN_16 1
+#define HAVE_SIMD_ALIGN_32 1
+#define HAVE_SIMD_ALIGN_64 1
+#define HAVE_ATOMIC_CAS_PTR 0
+#define HAVE_MACHINE_RW_BARRIER 0
+#define HAVE_MEMORYBARRIER 1
+#define HAVE_MM_EMPTY 0
+#define HAVE_RDTSC 0
+#define HAVE_SEM_TIMEDWAIT 0
+#define HAVE_SYNC_VAL_COMPARE_AND_SWAP 1
+#define HAVE_CABS 1
+#define HAVE_CEXP 1
+#define HAVE_INLINE_ASM 0
+#define HAVE_SYMVER 1
+#define HAVE_X86ASM 1
+#define HAVE_BIGENDIAN 0
+#define HAVE_FAST_UNALIGNED 1
+#define HAVE_ARPA_INET_H 0
+#define HAVE_ASM_TYPES_H 0
+#define HAVE_CDIO_PARANOIA_H 0
+#define HAVE_CDIO_PARANOIA_PARANOIA_H 0
+#define HAVE_CUDA_H 0
+#define HAVE_DISPATCH_DISPATCH_H 0
+#define HAVE_DEV_BKTR_IOCTL_BT848_H 0
+#define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
+#define HAVE_DEV_IC_BT8XX_H 0
+#define HAVE_DEV_VIDEO_BKTR_IOCTL_BT848_H 0
+#define HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H 0
+#define HAVE_DIRECT_H 1
+#define HAVE_DIRENT_H 1
+#define HAVE_DXGIDEBUG_H 0
+#define HAVE_DXVA_H 0
+#define HAVE_ES2_GL_H 0
+#define HAVE_GSM_H 0
+#define HAVE_IO_H 1
+#define HAVE_LINUX_PERF_EVENT_H 0
+#define HAVE_MACHINE_IOCTL_BT848_H 0
+#define HAVE_MACHINE_IOCTL_METEOR_H 0
+#define HAVE_MALLOC_H 1
+#define HAVE_OPENCV2_CORE_CORE_C_H 0
+#define HAVE_OPENGL_GL3_H 0
+#define HAVE_POLL_H 0
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_SYS_RESOURCE_H 0
+#define HAVE_SYS_SELECT_H 0
+#define HAVE_SYS_SOUNDCARD_H 0
+#define HAVE_SYS_TIME_H 1
+#define HAVE_SYS_UN_H 0
+#define HAVE_SYS_VIDEOIO_H 0
+#define HAVE_TERMIOS_H 0
+#define HAVE_UDPLITE_H 0
+#define HAVE_UNISTD_H 0
+#define HAVE_VALGRIND_VALGRIND_H 0
+#define HAVE_WINDOWS_H 1
+#define HAVE_WINSOCK2_H 1
+#define HAVE_INTRINSICS_NEON 0
+#define HAVE_ATANF 1
+#define HAVE_ATAN2F 1
+#define HAVE_CBRT 1
+#define HAVE_CBRTF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COSF 1
+#define HAVE_ERF 1
+#define HAVE_EXP2 1
+#define HAVE_EXP2F 1
+#define HAVE_EXPF 1
+#define HAVE_HYPOT 1
+#define HAVE_ISFINITE 1
+#define HAVE_ISINF 1
+#define HAVE_ISNAN 1
+#define HAVE_LDEXPF 1
+#define HAVE_LLRINT 1
+#define HAVE_LLRINTF 1
+#define HAVE_LOG2 1
+#define HAVE_LOG2F 1
+#define HAVE_LOG10F 1
+#define HAVE_LRINT 1
+#define HAVE_LRINTF 1
+#define HAVE_POWF 1
+#define HAVE_RINT 1
+#define HAVE_ROUND 1
+#define HAVE_ROUNDF 1
+#define HAVE_SINF 1
+#define HAVE_TRUNC 1
+#define HAVE_TRUNCF 1
+#define HAVE_DOS_PATHS 1
+#define HAVE_LIBC_MSVCRT 0
+#define HAVE_MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS 0
+#define HAVE_SECTION_DATA_REL_RO 0
+#define HAVE_THREADS 0
+#define HAVE_UWP 0
+#define HAVE_WINRT 0
+#define HAVE_ACCESS 1
+#define HAVE_ALIGNED_MALLOC 1
+#define HAVE_ARC4RANDOM 0
+#define HAVE_CLOCK_GETTIME 0
+#define HAVE_CLOSESOCKET 1
+#define HAVE_COMMANDLINETOARGVW 1
+#define HAVE_FCNTL 0
+#define HAVE_GETADDRINFO 1
+#define HAVE_GETHRTIME 0
+#define HAVE_GETOPT 1
+#define HAVE_GETPROCESSAFFINITYMASK 1
+#define HAVE_GETPROCESSMEMORYINFO 1
+#define HAVE_GETPROCESSTIMES 1
+#define HAVE_GETRUSAGE 0
+#define HAVE_GETSYSTEMTIMEASFILETIME 1
+#define HAVE_GETTIMEOFDAY 1
+#define HAVE_GLOB 1
+#define HAVE_GLXGETPROCADDRESS 0
+#define HAVE_GMTIME_R 0
+#define HAVE_INET_ATON 0
+#define HAVE_ISATTY 1
+#define HAVE_KBHIT 1
+#define HAVE_LOCALTIME_R 0
+#define HAVE_LSTAT 0
+#define HAVE_LZO1X_999_COMPRESS 0
+#define HAVE_MACH_ABSOLUTE_TIME 0
+#define HAVE_MAPVIEWOFFILE 1
+#define HAVE_MEMALIGN 0
+#define HAVE_MKSTEMP 1
+#define HAVE_MMAP 0
+#define HAVE_MPROTECT 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_PEEKNAMEDPIPE 1
+#define HAVE_POSIX_MEMALIGN 0
+#define HAVE_PTHREAD_CANCEL 0
+#define HAVE_SCHED_GETAFFINITY 0
+#define HAVE_SECITEMIMPORT 0
+#define HAVE_SETCONSOLETEXTATTRIBUTE 1
+#define HAVE_SETCONSOLECTRLHANDLER 1
+#define HAVE_SETMODE 1
+#define HAVE_SETRLIMIT 0
+#define HAVE_SLEEP 1
+#define HAVE_STRERROR_R 1
+#define HAVE_SYSCONF 0
+#define HAVE_SYSCTL 0
+#define HAVE_USLEEP 1
+#define HAVE_UTGETOSTYPEFROMSTRING 0
+#define HAVE_VIRTUALALLOC 1
+#define HAVE_WGLGETPROCADDRESS 0
+#define HAVE_BCRYPT 0
+#define HAVE_VAAPI_DRM 0
+#define HAVE_VAAPI_X11 0
+#define HAVE_VDPAU_X11 0
+#define HAVE_PTHREADS 0
+#define HAVE_OS2THREADS 0
+#define HAVE_W32THREADS 0
+#define HAVE_AS_ARCH_DIRECTIVE 0
+#define HAVE_AS_DN_DIRECTIVE 0
+#define HAVE_AS_FPU_DIRECTIVE 0
+#define HAVE_AS_FUNC 0
+#define HAVE_AS_OBJECT_ARCH 0
+#define HAVE_ASM_MOD_Q 0
+#define HAVE_BLOCKS_EXTENSION 0
+#define HAVE_EBP_AVAILABLE 1
+#define HAVE_EBX_AVAILABLE 1
+#define HAVE_GNU_AS 0
+#define HAVE_GNU_WINDRES 0
+#define HAVE_IBM_ASM 0
+#define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
+#define HAVE_INLINE_ASM_LABELS 1
+#define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
+#define HAVE_PRAGMA_DEPRECATED 1
+#define HAVE_RSYNC_CONTIMEOUT 1
+#define HAVE_SYMVER_ASM_LABEL 1
+#define HAVE_SYMVER_GNU_ASM 0
+#define HAVE_VFP_ARGS 0
+#define HAVE_XFORM_ASM 0
+#define HAVE_XMM_CLOBBERS 0
+#define HAVE_KCMVIDEOCODECTYPE_HEVC 0
+#define HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE 0
+#define HAVE_SOCKLEN_T 1
+#define HAVE_STRUCT_ADDRINFO 1
+#define HAVE_STRUCT_GROUP_SOURCE_REQ 0
+#define HAVE_STRUCT_IP_MREQ_SOURCE 1
+#define HAVE_STRUCT_IPV6_MREQ 1
+#define HAVE_STRUCT_MSGHDR_MSG_FLAGS 0
+#define HAVE_STRUCT_POLLFD 1
+#define HAVE_STRUCT_RUSAGE_RU_MAXRSS 0
+#define HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE 0
+#define HAVE_STRUCT_SOCKADDR_IN6 1
+#define HAVE_STRUCT_SOCKADDR_SA_LEN 0
+#define HAVE_STRUCT_SOCKADDR_STORAGE 1
+#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 0
+#define HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE 0
+#define HAVE_MAKEINFO 1
+#define HAVE_MAKEINFO_HTML 0
+#define HAVE_OPENCL_D3D11 0
+#define HAVE_OPENCL_DRM_ARM 0
+#define HAVE_OPENCL_DRM_BEIGNET 0
+#define HAVE_OPENCL_DXVA2 0
+#define HAVE_OPENCL_VAAPI_BEIGNET 0
+#define HAVE_OPENCL_VAAPI_INTEL_MEDIA 0
+#define HAVE_PERL 1
+#define HAVE_POD2MAN 1
+#define HAVE_TEXI2HTML 0
+#define CONFIG_DOC 1
+#define CONFIG_HTMLPAGES 0
+#define CONFIG_MANPAGES 1
+#define CONFIG_PODPAGES 1
+#define CONFIG_TXTPAGES 1
+#define CONFIG_AVIO_DIR_CMD_EXAMPLE 1
+#define CONFIG_AVIO_READING_EXAMPLE 1
+#define CONFIG_DECODE_AUDIO_EXAMPLE 1
+#define CONFIG_DECODE_VIDEO_EXAMPLE 1
+#define CONFIG_DEMUXING_DECODING_EXAMPLE 1
+#define CONFIG_ENCODE_AUDIO_EXAMPLE 1
+#define CONFIG_ENCODE_VIDEO_EXAMPLE 1
+#define CONFIG_EXTRACT_MVS_EXAMPLE 1
+#define CONFIG_FILTER_AUDIO_EXAMPLE 1
+#define CONFIG_FILTERING_AUDIO_EXAMPLE 1
+#define CONFIG_FILTERING_VIDEO_EXAMPLE 1
+#define CONFIG_HTTP_MULTICLIENT_EXAMPLE 0
+#define CONFIG_HW_DECODE_EXAMPLE 1
+#define CONFIG_METADATA_EXAMPLE 1
+#define CONFIG_MUXING_EXAMPLE 1
+#define CONFIG_QSVDEC_EXAMPLE 0
+#define CONFIG_REMUXING_EXAMPLE 1
+#define CONFIG_RESAMPLING_AUDIO_EXAMPLE 1
+#define CONFIG_SCALING_VIDEO_EXAMPLE 1
+#define CONFIG_TRANSCODE_AAC_EXAMPLE 1
+#define CONFIG_TRANSCODING_EXAMPLE 1
+#define CONFIG_VAAPI_ENCODE_EXAMPLE 0
+#define CONFIG_VAAPI_TRANSCODE_EXAMPLE 0
+#define CONFIG_AVISYNTH 0
+#define CONFIG_FREI0R 0
+#define CONFIG_LIBCDIO 0
+#define CONFIG_LIBDAVS2 0
+#define CONFIG_LIBRUBBERBAND 0
+#define CONFIG_LIBVIDSTAB 0
+#define CONFIG_LIBX264 0
+#define CONFIG_LIBX265 0
+#define CONFIG_LIBXAVS 0
+#define CONFIG_LIBXAVS2 0
+#define CONFIG_LIBXVID 0
+#define CONFIG_DECKLINK 0
+#define CONFIG_LIBFDK_AAC 0
+#define CONFIG_OPENSSL 0
+#define CONFIG_LIBTLS 0
+#define CONFIG_GMP 0
+#define CONFIG_LIBARIBB24 0
+#define CONFIG_LIBLENSFUN 0
+#define CONFIG_LIBOPENCORE_AMRNB 0
+#define CONFIG_LIBOPENCORE_AMRWB 0
+#define CONFIG_LIBVMAF 0
+#define CONFIG_LIBVO_AMRWBENC 0
+#define CONFIG_MBEDTLS 0
+#define CONFIG_RKMPP 0
+#define CONFIG_LIBSMBCLIENT 0
+#define CONFIG_CHROMAPRINT 0
+#define CONFIG_GCRYPT 0
+#define CONFIG_GNUTLS 0
+#define CONFIG_JNI 0
+#define CONFIG_LADSPA 0
+#define CONFIG_LIBAOM 0
+#define CONFIG_LIBASS 0
+#define CONFIG_LIBBLURAY 0
+#define CONFIG_LIBBS2B 0
+#define CONFIG_LIBCACA 0
+#define CONFIG_LIBCELT 0
+#define CONFIG_LIBCODEC2 0
+#define CONFIG_LIBDAV1D 0
+#define CONFIG_LIBDC1394 0
+#define CONFIG_LIBDRM 0
+#define CONFIG_LIBFLITE 0
+#define CONFIG_LIBFONTCONFIG 0
+#define CONFIG_LIBFREETYPE 0
+#define CONFIG_LIBFRIBIDI 0
+#define CONFIG_LIBGME 0
+#define CONFIG_LIBGSM 0
+#define CONFIG_LIBIEC61883 0
+#define CONFIG_LIBILBC 0
+#define CONFIG_LIBJACK 0
+#define CONFIG_LIBKLVANC 0
+#define CONFIG_LIBKVAZAAR 0
+#define CONFIG_LIBMODPLUG 0
+#define CONFIG_LIBMP3LAME 0
+#define CONFIG_LIBMYSOFA 0
+#define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
+#define CONFIG_LIBOPENJPEG 0
+#define CONFIG_LIBOPENMPT 0
+#define CONFIG_LIBOPUS 0
+#define CONFIG_LIBPULSE 0
+#define CONFIG_LIBRSVG 0
+#define CONFIG_LIBRTMP 0
+#define CONFIG_LIBSHINE 0
+#define CONFIG_LIBSNAPPY 0
+#define CONFIG_LIBSOXR 0
+#define CONFIG_LIBSPEEX 0
+#define CONFIG_LIBSRT 0
+#define CONFIG_LIBSSH 0
+#define CONFIG_LIBTENSORFLOW 0
+#define CONFIG_LIBTESSERACT 0
+#define CONFIG_LIBTHEORA 0
+#define CONFIG_LIBTWOLAME 0
+#define CONFIG_LIBV4L2 0
+#define CONFIG_LIBVORBIS 0
+#define CONFIG_LIBVPX 0
+#define CONFIG_LIBWAVPACK 0
+#define CONFIG_LIBWEBP 0
+#define CONFIG_LIBXML2 0
+#define CONFIG_LIBZIMG 0
+#define CONFIG_LIBZMQ 0
+#define CONFIG_LIBZVBI 0
+#define CONFIG_LV2 0
+#define CONFIG_MEDIACODEC 0
+#define CONFIG_OPENAL 0
+#define CONFIG_OPENGL 0
+#define CONFIG_POCKETSPHINX 0
+#define CONFIG_VAPOURSYNTH 0
+#define CONFIG_ALSA 0
+#define CONFIG_APPKIT 0
+#define CONFIG_AVFOUNDATION 0
+#define CONFIG_BZLIB 0
+#define CONFIG_COREIMAGE 0
+#define CONFIG_ICONV 1
+#define CONFIG_LIBXCB 0
+#define CONFIG_LIBXCB_SHM 0
+#define CONFIG_LIBXCB_SHAPE 0
+#define CONFIG_LIBXCB_XFIXES 0
+#define CONFIG_LZMA 0
+#define CONFIG_SCHANNEL 0
+#define CONFIG_SDL2 0
+#define CONFIG_SECURETRANSPORT 0
+#define CONFIG_SNDIO 0
+#define CONFIG_XLIB 0
+#define CONFIG_ZLIB 0
+#define CONFIG_CUDA_NVCC 0
+#define CONFIG_CUDA_SDK 0
+#define CONFIG_LIBNPP 0
+#define CONFIG_LIBMFX 0
+#define CONFIG_MMAL 0
+#define CONFIG_OMX 0
+#define CONFIG_OPENCL 0
+#define CONFIG_AMF 0
+#define CONFIG_AUDIOTOOLBOX 0
+#define CONFIG_CRYSTALHD 0
+#define CONFIG_CUDA 0
+#define CONFIG_CUDA_LLVM 0
+#define CONFIG_CUVID 0
+#define CONFIG_D3D11VA 0
+#define CONFIG_DXVA2 0
+#define CONFIG_FFNVCODEC 0
+#define CONFIG_NVDEC 0
+#define CONFIG_NVENC 0
+#define CONFIG_VAAPI 0
+#define CONFIG_VDPAU 0
+#define CONFIG_VIDEOTOOLBOX 0
+#define CONFIG_V4L2_M2M 0
+#define CONFIG_XVMC 0
+#define CONFIG_FTRAPV 0
+#define CONFIG_GRAY 0
+#define CONFIG_HARDCODED_TABLES 0
+#define CONFIG_OMX_RPI 0
+#define CONFIG_RUNTIME_CPUDETECT 1
+#define CONFIG_SAFE_BITSTREAM_READER 1
+#define CONFIG_SHARED 0
+#define CONFIG_SMALL 0
+#define CONFIG_STATIC 1
+#define CONFIG_SWSCALE_ALPHA 1
+#define CONFIG_GPL 0
+#define CONFIG_NONFREE 0
+#define CONFIG_VERSION3 0
+#define CONFIG_AVDEVICE 1
+#define CONFIG_AVFILTER 1
+#define CONFIG_SWSCALE 1
+#define CONFIG_POSTPROC 0
+#define CONFIG_AVFORMAT 1
+#define CONFIG_AVCODEC 1
+#define CONFIG_SWRESAMPLE 1
+#define CONFIG_AVRESAMPLE 0
+#define CONFIG_AVUTIL 1
+#define CONFIG_FFPLAY 0
+#define CONFIG_FFPROBE 1
+#define CONFIG_FFMPEG 1
+#define CONFIG_DCT 1
+#define CONFIG_DWT 1
+#define CONFIG_ERROR_RESILIENCE 1
+#define CONFIG_FAAN 1
+#define CONFIG_FAST_UNALIGNED 1
+#define CONFIG_FFT 1
+#define CONFIG_LSP 1
+#define CONFIG_LZO 1
+#define CONFIG_MDCT 1
+#define CONFIG_PIXELUTILS 1
+#define CONFIG_NETWORK 1
+#define CONFIG_RDFT 1
+#define CONFIG_AUTODETECT 0
+#define CONFIG_FONTCONFIG 0
+#define CONFIG_LINUX_PERF 0
+#define CONFIG_MEMORY_POISONING 0
+#define CONFIG_NEON_CLOBBER_TEST 0
+#define CONFIG_OSSFUZZ 0
+#define CONFIG_PIC 0
+#define CONFIG_THUMB 0
+#define CONFIG_VALGRIND_BACKTRACE 0
+#define CONFIG_XMM_CLOBBER_TEST 0
+#define CONFIG_BSFS 1
+#define CONFIG_DECODERS 1
+#define CONFIG_ENCODERS 1
+#define CONFIG_HWACCELS 0
+#define CONFIG_PARSERS 1
+#define CONFIG_INDEVS 1
+#define CONFIG_OUTDEVS 0
+#define CONFIG_FILTERS 1
+#define CONFIG_DEMUXERS 1
+#define CONFIG_MUXERS 1
+#define CONFIG_PROTOCOLS 1
+#define CONFIG_AANDCTTABLES 1
+#define CONFIG_AC3DSP 1
+#define CONFIG_ADTS_HEADER 1
+#define CONFIG_AUDIO_FRAME_QUEUE 1
+#define CONFIG_AUDIODSP 1
+#define CONFIG_BLOCKDSP 1
+#define CONFIG_BSWAPDSP 1
+#define CONFIG_CABAC 1
+#define CONFIG_CBS 1
+#define CONFIG_CBS_AV1 1
+#define CONFIG_CBS_H264 1
+#define CONFIG_CBS_H265 1
+#define CONFIG_CBS_JPEG 0
+#define CONFIG_CBS_MPEG2 1
+#define CONFIG_CBS_VP9 1
+#define CONFIG_DIRAC_PARSE 1
+#define CONFIG_DNN 1
+#define CONFIG_DVPROFILE 1
+#define CONFIG_EXIF 1
+#define CONFIG_FAANDCT 1
+#define CONFIG_FAANIDCT 1
+#define CONFIG_FDCTDSP 1
+#define CONFIG_FLACDSP 1
+#define CONFIG_FMTCONVERT 1
+#define CONFIG_FRAME_THREAD_ENCODER 0
+#define CONFIG_G722DSP 1
+#define CONFIG_GOLOMB 1
+#define CONFIG_GPLV3 0
+#define CONFIG_H263DSP 1
+#define CONFIG_H264CHROMA 1
+#define CONFIG_H264DSP 1
+#define CONFIG_H264PARSE 1
+#define CONFIG_H264PRED 1
+#define CONFIG_H264QPEL 1
+#define CONFIG_HEVCPARSE 1
+#define CONFIG_HPELDSP 1
+#define CONFIG_HUFFMAN 1
+#define CONFIG_HUFFYUVDSP 1
+#define CONFIG_HUFFYUVENCDSP 1
+#define CONFIG_IDCTDSP 1
+#define CONFIG_IIRFILTER 1
+#define CONFIG_MDCT15 1
+#define CONFIG_INTRAX8 1
+#define CONFIG_ISO_MEDIA 1
+#define CONFIG_IVIDSP 1
+#define CONFIG_JPEGTABLES 1
+#define CONFIG_LGPLV3 0
+#define CONFIG_LIBX262 0
+#define CONFIG_LLAUDDSP 1
+#define CONFIG_LLVIDDSP 1
+#define CONFIG_LLVIDENCDSP 1
+#define CONFIG_LPC 1
+#define CONFIG_LZF 1
+#define CONFIG_ME_CMP 1
+#define CONFIG_MPEG_ER 1
+#define CONFIG_MPEGAUDIO 1
+#define CONFIG_MPEGAUDIODSP 1
+#define CONFIG_MPEGAUDIOHEADER 1
+#define CONFIG_MPEGVIDEO 1
+#define CONFIG_MPEGVIDEOENC 1
+#define CONFIG_MSS34DSP 1
+#define CONFIG_PIXBLOCKDSP 1
+#define CONFIG_QPELDSP 1
+#define CONFIG_QSV 0
+#define CONFIG_QSVDEC 0
+#define CONFIG_QSVENC 0
+#define CONFIG_QSVVPP 0
+#define CONFIG_RANGECODER 1
+#define CONFIG_RIFFDEC 1
+#define CONFIG_RIFFENC 1
+#define CONFIG_RTPDEC 1
+#define CONFIG_RTPENC_CHAIN 1
+#define CONFIG_RV34DSP 1
+#define CONFIG_SCENE_SAD 1
+#define CONFIG_SINEWIN 1
+#define CONFIG_SNAPPY 1
+#define CONFIG_SRTP 1
+#define CONFIG_STARTCODE 1
+#define CONFIG_TEXTUREDSP 1
+#define CONFIG_TEXTUREDSPENC 0
+#define CONFIG_TPELDSP 1
+#define CONFIG_VAAPI_1 0
+#define CONFIG_VAAPI_ENCODE 0
+#define CONFIG_VC1DSP 1
+#define CONFIG_VIDEODSP 1
+#define CONFIG_VP3DSP 1
+#define CONFIG_VP56DSP 1
+#define CONFIG_VP8DSP 1
+#define CONFIG_WMA_FREQS 1
+#define CONFIG_WMV2DSP 1
+#define CONFIG_AAC_ADTSTOASC_BSF 1
+#define CONFIG_AV1_FRAME_SPLIT_BSF 1
+#define CONFIG_AV1_METADATA_BSF 1
+#define CONFIG_CHOMP_BSF 1
+#define CONFIG_DUMP_EXTRADATA_BSF 1
+#define CONFIG_DCA_CORE_BSF 1
+#define CONFIG_EAC3_CORE_BSF 1
+#define CONFIG_EXTRACT_EXTRADATA_BSF 1
+#define CONFIG_FILTER_UNITS_BSF 1
+#define CONFIG_H264_METADATA_BSF 1
+#define CONFIG_H264_MP4TOANNEXB_BSF 1
+#define CONFIG_H264_REDUNDANT_PPS_BSF 1
+#define CONFIG_HAPQA_EXTRACT_BSF 1
+#define CONFIG_HEVC_METADATA_BSF 1
+#define CONFIG_HEVC_MP4TOANNEXB_BSF 1
+#define CONFIG_IMX_DUMP_HEADER_BSF 1
+#define CONFIG_MJPEG2JPEG_BSF 1
+#define CONFIG_MJPEGA_DUMP_HEADER_BSF 1
+#define CONFIG_MP3_HEADER_DECOMPRESS_BSF 1
+#define CONFIG_MPEG2_METADATA_BSF 1
+#define CONFIG_MPEG4_UNPACK_BFRAMES_BSF 1
+#define CONFIG_MOV2TEXTSUB_BSF 1
+#define CONFIG_NOISE_BSF 1
+#define CONFIG_NULL_BSF 1
+#define CONFIG_PRORES_METADATA_BSF 1
+#define CONFIG_REMOVE_EXTRADATA_BSF 1
+#define CONFIG_TEXT2MOVSUB_BSF 1
+#define CONFIG_TRACE_HEADERS_BSF 1
+#define CONFIG_TRUEHD_CORE_BSF 1
+#define CONFIG_VP9_METADATA_BSF 1
+#define CONFIG_VP9_RAW_REORDER_BSF 1
+#define CONFIG_VP9_SUPERFRAME_BSF 1
+#define CONFIG_VP9_SUPERFRAME_SPLIT_BSF 1
+#define CONFIG_AASC_DECODER 1
+#define CONFIG_AIC_DECODER 1
+#define CONFIG_ALIAS_PIX_DECODER 1
+#define CONFIG_AGM_DECODER 1
+#define CONFIG_AMV_DECODER 1
+#define CONFIG_ANM_DECODER 1
+#define CONFIG_ANSI_DECODER 1
+#define CONFIG_APNG_DECODER 0
+#define CONFIG_ARBC_DECODER 1
+#define CONFIG_ASV1_DECODER 1
+#define CONFIG_ASV2_DECODER 1
+#define CONFIG_AURA_DECODER 1
+#define CONFIG_AURA2_DECODER 1
+#define CONFIG_AVRP_DECODER 1
+#define CONFIG_AVRN_DECODER 1
+#define CONFIG_AVS_DECODER 1
+#define CONFIG_AVUI_DECODER 1
+#define CONFIG_AYUV_DECODER 1
+#define CONFIG_BETHSOFTVID_DECODER 1
+#define CONFIG_BFI_DECODER 1
+#define CONFIG_BINK_DECODER 1
+#define CONFIG_BITPACKED_DECODER 1
+#define CONFIG_BMP_DECODER 1
+#define CONFIG_BMV_VIDEO_DECODER 1
+#define CONFIG_BRENDER_PIX_DECODER 1
+#define CONFIG_C93_DECODER 1
+#define CONFIG_CAVS_DECODER 1
+#define CONFIG_CDGRAPHICS_DECODER 1
+#define CONFIG_CDXL_DECODER 1
+#define CONFIG_CFHD_DECODER 1
+#define CONFIG_CINEPAK_DECODER 1
+#define CONFIG_CLEARVIDEO_DECODER 1
+#define CONFIG_CLJR_DECODER 1
+#define CONFIG_CLLC_DECODER 1
+#define CONFIG_COMFORTNOISE_DECODER 1
+#define CONFIG_CPIA_DECODER 1
+#define CONFIG_CSCD_DECODER 1
+#define CONFIG_CYUV_DECODER 1
+#define CONFIG_DDS_DECODER 1
+#define CONFIG_DFA_DECODER 1
+#define CONFIG_DIRAC_DECODER 1
+#define CONFIG_DNXHD_DECODER 1
+#define CONFIG_DPX_DECODER 1
+#define CONFIG_DSICINVIDEO_DECODER 1
+#define CONFIG_DVAUDIO_DECODER 1
+#define CONFIG_DVVIDEO_DECODER 1
+#define CONFIG_DXA_DECODER 0
+#define CONFIG_DXTORY_DECODER 1
+#define CONFIG_DXV_DECODER 1
+#define CONFIG_EACMV_DECODER 1
+#define CONFIG_EAMAD_DECODER 1
+#define CONFIG_EATGQ_DECODER 1
+#define CONFIG_EATGV_DECODER 1
+#define CONFIG_EATQI_DECODER 1
+#define CONFIG_EIGHTBPS_DECODER 1
+#define CONFIG_EIGHTSVX_EXP_DECODER 1
+#define CONFIG_EIGHTSVX_FIB_DECODER 1
+#define CONFIG_ESCAPE124_DECODER 1
+#define CONFIG_ESCAPE130_DECODER 1
+#define CONFIG_EXR_DECODER 0
+#define CONFIG_FFV1_DECODER 1
+#define CONFIG_FFVHUFF_DECODER 1
+#define CONFIG_FIC_DECODER 1
+#define CONFIG_FITS_DECODER 1
+#define CONFIG_FLASHSV_DECODER 0
+#define CONFIG_FLASHSV2_DECODER 0
+#define CONFIG_FLIC_DECODER 1
+#define CONFIG_FLV_DECODER 1
+#define CONFIG_FMVC_DECODER 1
+#define CONFIG_FOURXM_DECODER 1
+#define CONFIG_FRAPS_DECODER 1
+#define CONFIG_FRWU_DECODER 1
+#define CONFIG_G2M_DECODER 0
+#define CONFIG_GDV_DECODER 1
+#define CONFIG_GIF_DECODER 1
+#define CONFIG_H261_DECODER 1
+#define CONFIG_H263_DECODER 1
+#define CONFIG_H263I_DECODER 1
+#define CONFIG_H263P_DECODER 1
+#define CONFIG_H263_V4L2M2M_DECODER 0
+#define CONFIG_H264_DECODER 1
+#define CONFIG_H264_CRYSTALHD_DECODER 0
+#define CONFIG_H264_V4L2M2M_DECODER 0
+#define CONFIG_H264_MEDIACODEC_DECODER 0
+#define CONFIG_H264_MMAL_DECODER 0
+#define CONFIG_H264_QSV_DECODER 0
+#define CONFIG_H264_RKMPP_DECODER 0
+#define CONFIG_HAP_DECODER 1
+#define CONFIG_HEVC_DECODER 1
+#define CONFIG_HEVC_QSV_DECODER 0
+#define CONFIG_HEVC_RKMPP_DECODER 0
+#define CONFIG_HEVC_V4L2M2M_DECODER 0
+#define CONFIG_HNM4_VIDEO_DECODER 1
+#define CONFIG_HQ_HQA_DECODER 1
+#define CONFIG_HQX_DECODER 1
+#define CONFIG_HUFFYUV_DECODER 1
+#define CONFIG_HYMT_DECODER 1
+#define CONFIG_IDCIN_DECODER 1
+#define CONFIG_IFF_ILBM_DECODER 1
+#define CONFIG_IMM4_DECODER 1
+#define CONFIG_INDEO2_DECODER 1
+#define CONFIG_INDEO3_DECODER 1
+#define CONFIG_INDEO4_DECODER 1
+#define CONFIG_INDEO5_DECODER 1
+#define CONFIG_INTERPLAY_VIDEO_DECODER 1
+#define CONFIG_JPEG2000_DECODER 1
+#define CONFIG_JPEGLS_DECODER 1
+#define CONFIG_JV_DECODER 1
+#define CONFIG_KGV1_DECODER 1
+#define CONFIG_KMVC_DECODER 1
+#define CONFIG_LAGARITH_DECODER 1
+#define CONFIG_LOCO_DECODER 1
+#define CONFIG_LSCR_DECODER 0
+#define CONFIG_M101_DECODER 1
+#define CONFIG_MAGICYUV_DECODER 1
+#define CONFIG_MDEC_DECODER 1
+#define CONFIG_MIMIC_DECODER 1
+#define CONFIG_MJPEG_DECODER 1
+#define CONFIG_MJPEGB_DECODER 1
+#define CONFIG_MMVIDEO_DECODER 1
+#define CONFIG_MOTIONPIXELS_DECODER 1
+#define CONFIG_MPEG1VIDEO_DECODER 1
+#define CONFIG_MPEG2VIDEO_DECODER 1
+#define CONFIG_MPEG4_DECODER 1
+#define CONFIG_MPEG4_CRYSTALHD_DECODER 0
+#define CONFIG_MPEG4_V4L2M2M_DECODER 0
+#define CONFIG_MPEG4_MMAL_DECODER 0
+#define CONFIG_MPEGVIDEO_DECODER 1
+#define CONFIG_MPEG1_V4L2M2M_DECODER 0
+#define CONFIG_MPEG2_MMAL_DECODER 0
+#define CONFIG_MPEG2_CRYSTALHD_DECODER 0
+#define CONFIG_MPEG2_V4L2M2M_DECODER 0
+#define CONFIG_MPEG2_QSV_DECODER 0
+#define CONFIG_MPEG2_MEDIACODEC_DECODER 0
+#define CONFIG_MSA1_DECODER 1
+#define CONFIG_MSCC_DECODER 0
+#define CONFIG_MSMPEG4V1_DECODER 1
+#define CONFIG_MSMPEG4V2_DECODER 1
+#define CONFIG_MSMPEG4V3_DECODER 1
+#define CONFIG_MSMPEG4_CRYSTALHD_DECODER 0
+#define CONFIG_MSRLE_DECODER 1
+#define CONFIG_MSS1_DECODER 1
+#define CONFIG_MSS2_DECODER 1
+#define CONFIG_MSVIDEO1_DECODER 1
+#define CONFIG_MSZH_DECODER 1
+#define CONFIG_MTS2_DECODER 1
+#define CONFIG_MVC1_DECODER 1
+#define CONFIG_MVC2_DECODER 1
+#define CONFIG_MWSC_DECODER 0
+#define CONFIG_MXPEG_DECODER 1
+#define CONFIG_NUV_DECODER 1
+#define CONFIG_PAF_VIDEO_DECODER 1
+#define CONFIG_PAM_DECODER 1
+#define CONFIG_PBM_DECODER 1
+#define CONFIG_PCX_DECODER 1
+#define CONFIG_PGM_DECODER 1
+#define CONFIG_PGMYUV_DECODER 1
+#define CONFIG_PICTOR_DECODER 1
+#define CONFIG_PIXLET_DECODER 1
+#define CONFIG_PNG_DECODER 0
+#define CONFIG_PPM_DECODER 1
+#define CONFIG_PRORES_DECODER 1
+#define CONFIG_PROSUMER_DECODER 1
+#define CONFIG_PSD_DECODER 1
+#define CONFIG_PTX_DECODER 1
+#define CONFIG_QDRAW_DECODER 1
+#define CONFIG_QPEG_DECODER 1
+#define CONFIG_QTRLE_DECODER 1
+#define CONFIG_R10K_DECODER 1
+#define CONFIG_R210_DECODER 1
+#define CONFIG_RASC_DECODER 0
+#define CONFIG_RAWVIDEO_DECODER 1
+#define CONFIG_RL2_DECODER 1
+#define CONFIG_ROQ_DECODER 1
+#define CONFIG_RPZA_DECODER 1
+#define CONFIG_RSCC_DECODER 0
+#define CONFIG_RV10_DECODER 1
+#define CONFIG_RV20_DECODER 1
+#define CONFIG_RV30_DECODER 1
+#define CONFIG_RV40_DECODER 1
+#define CONFIG_S302M_DECODER 1
+#define CONFIG_SANM_DECODER 1
+#define CONFIG_SCPR_DECODER 1
+#define CONFIG_SCREENPRESSO_DECODER 0
+#define CONFIG_SDX2_DPCM_DECODER 1
+#define CONFIG_SGI_DECODER 1
+#define CONFIG_SGIRLE_DECODER 1
+#define CONFIG_SHEERVIDEO_DECODER 1
+#define CONFIG_SMACKER_DECODER 1
+#define CONFIG_SMC_DECODER 1
+#define CONFIG_SMVJPEG_DECODER 1
+#define CONFIG_SNOW_DECODER 1
+#define CONFIG_SP5X_DECODER 1
+#define CONFIG_SPEEDHQ_DECODER 1
+#define CONFIG_SRGC_DECODER 0
+#define CONFIG_SUNRAST_DECODER 1
+#define CONFIG_SVQ1_DECODER 1
+#define CONFIG_SVQ3_DECODER 1
+#define CONFIG_TARGA_DECODER 1
+#define CONFIG_TARGA_Y216_DECODER 1
+#define CONFIG_TDSC_DECODER 0
+#define CONFIG_THEORA_DECODER 1
+#define CONFIG_THP_DECODER 1
+#define CONFIG_TIERTEXSEQVIDEO_DECODER 1
+#define CONFIG_TIFF_DECODER 1
+#define CONFIG_TMV_DECODER 1
+#define CONFIG_TRUEMOTION1_DECODER 1
+#define CONFIG_TRUEMOTION2_DECODER 1
+#define CONFIG_TRUEMOTION2RT_DECODER 1
+#define CONFIG_TSCC_DECODER 0
+#define CONFIG_TSCC2_DECODER 1
+#define CONFIG_TXD_DECODER 1
+#define CONFIG_ULTI_DECODER 1
+#define CONFIG_UTVIDEO_DECODER 1
+#define CONFIG_V210_DECODER 1
+#define CONFIG_V210X_DECODER 1
+#define CONFIG_V308_DECODER 1
+#define CONFIG_V408_DECODER 1
+#define CONFIG_V410_DECODER 1
+#define CONFIG_VB_DECODER 1
+#define CONFIG_VBLE_DECODER 1
+#define CONFIG_VC1_DECODER 1
+#define CONFIG_VC1_CRYSTALHD_DECODER 0
+#define CONFIG_VC1IMAGE_DECODER 1
+#define CONFIG_VC1_MMAL_DECODER 0
+#define CONFIG_VC1_QSV_DECODER 0
+#define CONFIG_VC1_V4L2M2M_DECODER 0
+#define CONFIG_VCR1_DECODER 1
+#define CONFIG_VMDVIDEO_DECODER 1
+#define CONFIG_VMNC_DECODER 1
+#define CONFIG_VP3_DECODER 1
+#define CONFIG_VP4_DECODER 1
+#define CONFIG_VP5_DECODER 1
+#define CONFIG_VP6_DECODER 1
+#define CONFIG_VP6A_DECODER 1
+#define CONFIG_VP6F_DECODER 1
+#define CONFIG_VP7_DECODER 1
+#define CONFIG_VP8_DECODER 1
+#define CONFIG_VP8_RKMPP_DECODER 0
+#define CONFIG_VP8_V4L2M2M_DECODER 0
+#define CONFIG_VP9_DECODER 1
+#define CONFIG_VP9_RKMPP_DECODER 0
+#define CONFIG_VP9_V4L2M2M_DECODER 0
+#define CONFIG_VQA_DECODER 1
+#define CONFIG_WEBP_DECODER 1
+#define CONFIG_WCMV_DECODER 0
+#define CONFIG_WRAPPED_AVFRAME_DECODER 1
+#define CONFIG_WMV1_DECODER 1
+#define CONFIG_WMV2_DECODER 1
+#define CONFIG_WMV3_DECODER 1
+#define CONFIG_WMV3_CRYSTALHD_DECODER 0
+#define CONFIG_WMV3IMAGE_DECODER 1
+#define CONFIG_WNV1_DECODER 1
+#define CONFIG_XAN_WC3_DECODER 1
+#define CONFIG_XAN_WC4_DECODER 1
+#define CONFIG_XBM_DECODER 1
+#define CONFIG_XFACE_DECODER 1
+#define CONFIG_XL_DECODER 1
+#define CONFIG_XPM_DECODER 1
+#define CONFIG_XWD_DECODER 1
+#define CONFIG_Y41P_DECODER 1
+#define CONFIG_YLC_DECODER 1
+#define CONFIG_YOP_DECODER 1
+#define CONFIG_YUV4_DECODER 1
+#define CONFIG_ZERO12V_DECODER 1
+#define CONFIG_ZEROCODEC_DECODER 0
+#define CONFIG_ZLIB_DECODER 0
+#define CONFIG_ZMBV_DECODER 0
+#define CONFIG_AAC_DECODER 1
+#define CONFIG_AAC_FIXED_DECODER 1
+#define CONFIG_AAC_LATM_DECODER 1
+#define CONFIG_AC3_DECODER 1
+#define CONFIG_AC3_FIXED_DECODER 1
+#define CONFIG_ALAC_DECODER 1
+#define CONFIG_ALS_DECODER 1
+#define CONFIG_AMRNB_DECODER 1
+#define CONFIG_AMRWB_DECODER 1
+#define CONFIG_APE_DECODER 1
+#define CONFIG_APTX_DECODER 1
+#define CONFIG_APTX_HD_DECODER 1
+#define CONFIG_ATRAC1_DECODER 1
+#define CONFIG_ATRAC3_DECODER 1
+#define CONFIG_ATRAC3AL_DECODER 1
+#define CONFIG_ATRAC3P_DECODER 1
+#define CONFIG_ATRAC3PAL_DECODER 1
+#define CONFIG_ATRAC9_DECODER 1
+#define CONFIG_BINKAUDIO_DCT_DECODER 1
+#define CONFIG_BINKAUDIO_RDFT_DECODER 1
+#define CONFIG_BMV_AUDIO_DECODER 1
+#define CONFIG_COOK_DECODER 1
+#define CONFIG_DCA_DECODER 1
+#define CONFIG_DOLBY_E_DECODER 1
+#define CONFIG_DSD_LSBF_DECODER 1
+#define CONFIG_DSD_MSBF_DECODER 1
+#define CONFIG_DSD_LSBF_PLANAR_DECODER 1
+#define CONFIG_DSD_MSBF_PLANAR_DECODER 1
+#define CONFIG_DSICINAUDIO_DECODER 1
+#define CONFIG_DSS_SP_DECODER 1
+#define CONFIG_DST_DECODER 1
+#define CONFIG_EAC3_DECODER 1
+#define CONFIG_EVRC_DECODER 1
+#define CONFIG_FFWAVESYNTH_DECODER 1
+#define CONFIG_FLAC_DECODER 1
+#define CONFIG_G723_1_DECODER 1
+#define CONFIG_G729_DECODER 1
+#define CONFIG_GSM_DECODER 1
+#define CONFIG_GSM_MS_DECODER 1
+#define CONFIG_HCOM_DECODER 1
+#define CONFIG_IAC_DECODER 1
+#define CONFIG_ILBC_DECODER 1
+#define CONFIG_IMC_DECODER 1
+#define CONFIG_INTERPLAY_ACM_DECODER 1
+#define CONFIG_MACE3_DECODER 1
+#define CONFIG_MACE6_DECODER 1
+#define CONFIG_METASOUND_DECODER 1
+#define CONFIG_MLP_DECODER 1
+#define CONFIG_MP1_DECODER 1
+#define CONFIG_MP1FLOAT_DECODER 1
+#define CONFIG_MP2_DECODER 1
+#define CONFIG_MP2FLOAT_DECODER 1
+#define CONFIG_MP3FLOAT_DECODER 1
+#define CONFIG_MP3_DECODER 1
+#define CONFIG_MP3ADUFLOAT_DECODER 1
+#define CONFIG_MP3ADU_DECODER 1
+#define CONFIG_MP3ON4FLOAT_DECODER 1
+#define CONFIG_MP3ON4_DECODER 1
+#define CONFIG_MPC7_DECODER 1
+#define CONFIG_MPC8_DECODER 1
+#define CONFIG_NELLYMOSER_DECODER 1
+#define CONFIG_ON2AVC_DECODER 1
+#define CONFIG_OPUS_DECODER 1
+#define CONFIG_PAF_AUDIO_DECODER 1
+#define CONFIG_QCELP_DECODER 1
+#define CONFIG_QDM2_DECODER 1
+#define CONFIG_QDMC_DECODER 1
+#define CONFIG_RA_144_DECODER 1
+#define CONFIG_RA_288_DECODER 1
+#define CONFIG_RALF_DECODER 1
+#define CONFIG_SBC_DECODER 1
+#define CONFIG_SHORTEN_DECODER 1
+#define CONFIG_SIPR_DECODER 1
+#define CONFIG_SMACKAUD_DECODER 1
+#define CONFIG_SONIC_DECODER 1
+#define CONFIG_TAK_DECODER 1
+#define CONFIG_TRUEHD_DECODER 1
+#define CONFIG_TRUESPEECH_DECODER 1
+#define CONFIG_TTA_DECODER 1
+#define CONFIG_TWINVQ_DECODER 1
+#define CONFIG_VMDAUDIO_DECODER 1
+#define CONFIG_VORBIS_DECODER 1
+#define CONFIG_WAVPACK_DECODER 1
+#define CONFIG_WMALOSSLESS_DECODER 1
+#define CONFIG_WMAPRO_DECODER 1
+#define CONFIG_WMAV1_DECODER 1
+#define CONFIG_WMAV2_DECODER 1
+#define CONFIG_WMAVOICE_DECODER 1
+#define CONFIG_WS_SND1_DECODER 1
+#define CONFIG_XMA1_DECODER 1
+#define CONFIG_XMA2_DECODER 1
+#define CONFIG_PCM_ALAW_DECODER 1
+#define CONFIG_PCM_BLURAY_DECODER 1
+#define CONFIG_PCM_DVD_DECODER 1
+#define CONFIG_PCM_F16LE_DECODER 1
+#define CONFIG_PCM_F24LE_DECODER 1
+#define CONFIG_PCM_F32BE_DECODER 1
+#define CONFIG_PCM_F32LE_DECODER 1
+#define CONFIG_PCM_F64BE_DECODER 1
+#define CONFIG_PCM_F64LE_DECODER 1
+#define CONFIG_PCM_LXF_DECODER 1
+#define CONFIG_PCM_MULAW_DECODER 1
+#define CONFIG_PCM_S8_DECODER 1
+#define CONFIG_PCM_S8_PLANAR_DECODER 1
+#define CONFIG_PCM_S16BE_DECODER 1
+#define CONFIG_PCM_S16BE_PLANAR_DECODER 1
+#define CONFIG_PCM_S16LE_DECODER 1
+#define CONFIG_PCM_S16LE_PLANAR_DECODER 1
+#define CONFIG_PCM_S24BE_DECODER 1
+#define CONFIG_PCM_S24DAUD_DECODER 1
+#define CONFIG_PCM_S24LE_DECODER 1
+#define CONFIG_PCM_S24LE_PLANAR_DECODER 1
+#define CONFIG_PCM_S32BE_DECODER 1
+#define CONFIG_PCM_S32LE_DECODER 1
+#define CONFIG_PCM_S32LE_PLANAR_DECODER 1
+#define CONFIG_PCM_S64BE_DECODER 1
+#define CONFIG_PCM_S64LE_DECODER 1
+#define CONFIG_PCM_U8_DECODER 1
+#define CONFIG_PCM_U16BE_DECODER 1
+#define CONFIG_PCM_U16LE_DECODER 1
+#define CONFIG_PCM_U24BE_DECODER 1
+#define CONFIG_PCM_U24LE_DECODER 1
+#define CONFIG_PCM_U32BE_DECODER 1
+#define CONFIG_PCM_U32LE_DECODER 1
+#define CONFIG_PCM_VIDC_DECODER 1
+#define CONFIG_PCM_ZORK_DECODER 1
+#define CONFIG_GREMLIN_DPCM_DECODER 1
+#define CONFIG_INTERPLAY_DPCM_DECODER 1
+#define CONFIG_ROQ_DPCM_DECODER 1
+#define CONFIG_SOL_DPCM_DECODER 1
+#define CONFIG_XAN_DPCM_DECODER 1
+#define CONFIG_ADPCM_4XM_DECODER 1
+#define CONFIG_ADPCM_ADX_DECODER 1
+#define CONFIG_ADPCM_AFC_DECODER 1
+#define CONFIG_ADPCM_AGM_DECODER 1
+#define CONFIG_ADPCM_AICA_DECODER 1
+#define CONFIG_ADPCM_CT_DECODER 1
+#define CONFIG_ADPCM_DTK_DECODER 1
+#define CONFIG_ADPCM_EA_DECODER 1
+#define CONFIG_ADPCM_EA_MAXIS_XA_DECODER 1
+#define CONFIG_ADPCM_EA_R1_DECODER 1
+#define CONFIG_ADPCM_EA_R2_DECODER 1
+#define CONFIG_ADPCM_EA_R3_DECODER 1
+#define CONFIG_ADPCM_EA_XAS_DECODER 1
+#define CONFIG_ADPCM_G722_DECODER 1
+#define CONFIG_ADPCM_G726_DECODER 1
+#define CONFIG_ADPCM_G726LE_DECODER 1
+#define CONFIG_ADPCM_IMA_AMV_DECODER 1
+#define CONFIG_ADPCM_IMA_APC_DECODER 1
+#define CONFIG_ADPCM_IMA_DAT4_DECODER 1
+#define CONFIG_ADPCM_IMA_DK3_DECODER 1
+#define CONFIG_ADPCM_IMA_DK4_DECODER 1
+#define CONFIG_ADPCM_IMA_EA_EACS_DECODER 1
+#define CONFIG_ADPCM_IMA_EA_SEAD_DECODER 1
+#define CONFIG_ADPCM_IMA_ISS_DECODER 1
+#define CONFIG_ADPCM_IMA_OKI_DECODER 1
+#define CONFIG_ADPCM_IMA_QT_DECODER 1
+#define CONFIG_ADPCM_IMA_RAD_DECODER 1
+#define CONFIG_ADPCM_IMA_SMJPEG_DECODER 1
+#define CONFIG_ADPCM_IMA_WAV_DECODER 1
+#define CONFIG_ADPCM_IMA_WS_DECODER 1
+#define CONFIG_ADPCM_MS_DECODER 1
+#define CONFIG_ADPCM_MTAF_DECODER 1
+#define CONFIG_ADPCM_PSX_DECODER 1
+#define CONFIG_ADPCM_SBPRO_2_DECODER 1
+#define CONFIG_ADPCM_SBPRO_3_DECODER 1
+#define CONFIG_ADPCM_SBPRO_4_DECODER 1
+#define CONFIG_ADPCM_SWF_DECODER 1
+#define CONFIG_ADPCM_THP_DECODER 1
+#define CONFIG_ADPCM_THP_LE_DECODER 1
+#define CONFIG_ADPCM_VIMA_DECODER 1
+#define CONFIG_ADPCM_XA_DECODER 1
+#define CONFIG_ADPCM_YAMAHA_DECODER 1
+#define CONFIG_SSA_DECODER 1
+#define CONFIG_ASS_DECODER 1
+#define CONFIG_CCAPTION_DECODER 1
+#define CONFIG_DVBSUB_DECODER 1
+#define CONFIG_DVDSUB_DECODER 1
+#define CONFIG_JACOSUB_DECODER 1
+#define CONFIG_MICRODVD_DECODER 1
+#define CONFIG_MOVTEXT_DECODER 1
+#define CONFIG_MPL2_DECODER 1
+#define CONFIG_PGSSUB_DECODER 1
+#define CONFIG_PJS_DECODER 1
+#define CONFIG_REALTEXT_DECODER 1
+#define CONFIG_SAMI_DECODER 1
+#define CONFIG_SRT_DECODER 1
+#define CONFIG_STL_DECODER 1
+#define CONFIG_SUBRIP_DECODER 1
+#define CONFIG_SUBVIEWER_DECODER 1
+#define CONFIG_SUBVIEWER1_DECODER 1
+#define CONFIG_TEXT_DECODER 1
+#define CONFIG_VPLAYER_DECODER 1
+#define CONFIG_WEBVTT_DECODER 1
+#define CONFIG_XSUB_DECODER 1
+#define CONFIG_AAC_AT_DECODER 0
+#define CONFIG_AC3_AT_DECODER 0
+#define CONFIG_ADPCM_IMA_QT_AT_DECODER 0
+#define CONFIG_ALAC_AT_DECODER 0
+#define CONFIG_AMR_NB_AT_DECODER 0
+#define CONFIG_EAC3_AT_DECODER 0
+#define CONFIG_GSM_MS_AT_DECODER 0
+#define CONFIG_ILBC_AT_DECODER 0
+#define CONFIG_MP1_AT_DECODER 0
+#define CONFIG_MP2_AT_DECODER 0
+#define CONFIG_MP3_AT_DECODER 0
+#define CONFIG_PCM_ALAW_AT_DECODER 0
+#define CONFIG_PCM_MULAW_AT_DECODER 0
+#define CONFIG_QDMC_AT_DECODER 0
+#define CONFIG_QDM2_AT_DECODER 0
+#define CONFIG_LIBAOM_AV1_DECODER 0
+#define CONFIG_LIBARIBB24_DECODER 0
+#define CONFIG_LIBCELT_DECODER 0
+#define CONFIG_LIBCODEC2_DECODER 0
+#define CONFIG_LIBDAV1D_DECODER 0
+#define CONFIG_LIBDAVS2_DECODER 0
+#define CONFIG_LIBFDK_AAC_DECODER 0
+#define CONFIG_LIBGSM_DECODER 0
+#define CONFIG_LIBGSM_MS_DECODER 0
+#define CONFIG_LIBILBC_DECODER 0
+#define CONFIG_LIBOPENCORE_AMRNB_DECODER 0
+#define CONFIG_LIBOPENCORE_AMRWB_DECODER 0
+#define CONFIG_LIBOPENJPEG_DECODER 0
+#define CONFIG_LIBOPUS_DECODER 0
+#define CONFIG_LIBRSVG_DECODER 0
+#define CONFIG_LIBSPEEX_DECODER 0
+#define CONFIG_LIBVORBIS_DECODER 0
+#define CONFIG_LIBVPX_VP8_DECODER 0
+#define CONFIG_LIBVPX_VP9_DECODER 0
+#define CONFIG_LIBZVBI_TELETEXT_DECODER 0
+#define CONFIG_BINTEXT_DECODER 1
+#define CONFIG_XBIN_DECODER 1
+#define CONFIG_IDF_DECODER 1
+#define CONFIG_LIBOPENH264_DECODER 0
+#define CONFIG_H264_CUVID_DECODER 0
+#define CONFIG_HEVC_CUVID_DECODER 0
+#define CONFIG_HEVC_MEDIACODEC_DECODER 0
+#define CONFIG_MJPEG_CUVID_DECODER 0
+#define CONFIG_MPEG1_CUVID_DECODER 0
+#define CONFIG_MPEG2_CUVID_DECODER 0
+#define CONFIG_MPEG4_CUVID_DECODER 0
+#define CONFIG_MPEG4_MEDIACODEC_DECODER 0
+#define CONFIG_VC1_CUVID_DECODER 0
+#define CONFIG_VP8_CUVID_DECODER 0
+#define CONFIG_VP8_MEDIACODEC_DECODER 0
+#define CONFIG_VP8_QSV_DECODER 0
+#define CONFIG_VP9_CUVID_DECODER 0
+#define CONFIG_VP9_MEDIACODEC_DECODER 0
+#define CONFIG_A64MULTI_ENCODER 1
+#define CONFIG_A64MULTI5_ENCODER 1
+#define CONFIG_ALIAS_PIX_ENCODER 1
+#define CONFIG_AMV_ENCODER 1
+#define CONFIG_APNG_ENCODER 0
+#define CONFIG_ASV1_ENCODER 1
+#define CONFIG_ASV2_ENCODER 1
+#define CONFIG_AVRP_ENCODER 1
+#define CONFIG_AVUI_ENCODER 1
+#define CONFIG_AYUV_ENCODER 1
+#define CONFIG_BMP_ENCODER 1
+#define CONFIG_CINEPAK_ENCODER 1
+#define CONFIG_CLJR_ENCODER 1
+#define CONFIG_COMFORTNOISE_ENCODER 1
+#define CONFIG_DNXHD_ENCODER 1
+#define CONFIG_DPX_ENCODER 1
+#define CONFIG_DVVIDEO_ENCODER 1
+#define CONFIG_FFV1_ENCODER 1
+#define CONFIG_FFVHUFF_ENCODER 1
+#define CONFIG_FITS_ENCODER 1
+#define CONFIG_FLASHSV_ENCODER 0
+#define CONFIG_FLASHSV2_ENCODER 0
+#define CONFIG_FLV_ENCODER 1
+#define CONFIG_GIF_ENCODER 1
+#define CONFIG_H261_ENCODER 1
+#define CONFIG_H263_ENCODER 1
+#define CONFIG_H263P_ENCODER 1
+#define CONFIG_HAP_ENCODER 0
+#define CONFIG_HUFFYUV_ENCODER 1
+#define CONFIG_JPEG2000_ENCODER 1
+#define CONFIG_JPEGLS_ENCODER 1
+#define CONFIG_LJPEG_ENCODER 1
+#define CONFIG_MAGICYUV_ENCODER 1
+#define CONFIG_MJPEG_ENCODER 1
+#define CONFIG_MPEG1VIDEO_ENCODER 1
+#define CONFIG_MPEG2VIDEO_ENCODER 1
+#define CONFIG_MPEG4_ENCODER 1
+#define CONFIG_MSMPEG4V2_ENCODER 1
+#define CONFIG_MSMPEG4V3_ENCODER 1
+#define CONFIG_MSVIDEO1_ENCODER 1
+#define CONFIG_PAM_ENCODER 1
+#define CONFIG_PBM_ENCODER 1
+#define CONFIG_PCX_ENCODER 1
+#define CONFIG_PGM_ENCODER 1
+#define CONFIG_PGMYUV_ENCODER 1
+#define CONFIG_PNG_ENCODER 0
+#define CONFIG_PPM_ENCODER 1
+#define CONFIG_PRORES_ENCODER 1
+#define CONFIG_PRORES_AW_ENCODER 1
+#define CONFIG_PRORES_KS_ENCODER 1
+#define CONFIG_QTRLE_ENCODER 1
+#define CONFIG_R10K_ENCODER 1
+#define CONFIG_R210_ENCODER 1
+#define CONFIG_RAWVIDEO_ENCODER 1
+#define CONFIG_ROQ_ENCODER 1
+#define CONFIG_RV10_ENCODER 1
+#define CONFIG_RV20_ENCODER 1
+#define CONFIG_S302M_ENCODER 1
+#define CONFIG_SGI_ENCODER 1
+#define CONFIG_SNOW_ENCODER 1
+#define CONFIG_SUNRAST_ENCODER 1
+#define CONFIG_SVQ1_ENCODER 1
+#define CONFIG_TARGA_ENCODER 1
+#define CONFIG_TIFF_ENCODER 1
+#define CONFIG_UTVIDEO_ENCODER 1
+#define CONFIG_V210_ENCODER 1
+#define CONFIG_V308_ENCODER 1
+#define CONFIG_V408_ENCODER 1
+#define CONFIG_V410_ENCODER 1
+#define CONFIG_VC2_ENCODER 1
+#define CONFIG_WRAPPED_AVFRAME_ENCODER 1
+#define CONFIG_WMV1_ENCODER 1
+#define CONFIG_WMV2_ENCODER 1
+#define CONFIG_XBM_ENCODER 1
+#define CONFIG_XFACE_ENCODER 1
+#define CONFIG_XWD_ENCODER 1
+#define CONFIG_Y41P_ENCODER 1
+#define CONFIG_YUV4_ENCODER 1
+#define CONFIG_ZLIB_ENCODER 0
+#define CONFIG_ZMBV_ENCODER 0
+#define CONFIG_AAC_ENCODER 1
+#define CONFIG_AC3_ENCODER 1
+#define CONFIG_AC3_FIXED_ENCODER 1
+#define CONFIG_ALAC_ENCODER 1
+#define CONFIG_APTX_ENCODER 1
+#define CONFIG_APTX_HD_ENCODER 1
+#define CONFIG_DCA_ENCODER 1
+#define CONFIG_EAC3_ENCODER 1
+#define CONFIG_FLAC_ENCODER 1
+#define CONFIG_G723_1_ENCODER 1
+#define CONFIG_MLP_ENCODER 1
+#define CONFIG_MP2_ENCODER 1
+#define CONFIG_MP2FIXED_ENCODER 1
+#define CONFIG_NELLYMOSER_ENCODER 1
+#define CONFIG_OPUS_ENCODER 1
+#define CONFIG_RA_144_ENCODER 1
+#define CONFIG_SBC_ENCODER 1
+#define CONFIG_SONIC_ENCODER 1
+#define CONFIG_SONIC_LS_ENCODER 1
+#define CONFIG_TRUEHD_ENCODER 1
+#define CONFIG_TTA_ENCODER 1
+#define CONFIG_VORBIS_ENCODER 1
+#define CONFIG_WAVPACK_ENCODER 1
+#define CONFIG_WMAV1_ENCODER 1
+#define CONFIG_WMAV2_ENCODER 1
+#define CONFIG_PCM_ALAW_ENCODER 1
+#define CONFIG_PCM_DVD_ENCODER 1
+#define CONFIG_PCM_F32BE_ENCODER 1
+#define CONFIG_PCM_F32LE_ENCODER 1
+#define CONFIG_PCM_F64BE_ENCODER 1
+#define CONFIG_PCM_F64LE_ENCODER 1
+#define CONFIG_PCM_MULAW_ENCODER 1
+#define CONFIG_PCM_S8_ENCODER 1
+#define CONFIG_PCM_S8_PLANAR_ENCODER 1
+#define CONFIG_PCM_S16BE_ENCODER 1
+#define CONFIG_PCM_S16BE_PLANAR_ENCODER 1
+#define CONFIG_PCM_S16LE_ENCODER 1
+#define CONFIG_PCM_S16LE_PLANAR_ENCODER 1
+#define CONFIG_PCM_S24BE_ENCODER 1
+#define CONFIG_PCM_S24DAUD_ENCODER 1
+#define CONFIG_PCM_S24LE_ENCODER 1
+#define CONFIG_PCM_S24LE_PLANAR_ENCODER 1
+#define CONFIG_PCM_S32BE_ENCODER 1
+#define CONFIG_PCM_S32LE_ENCODER 1
+#define CONFIG_PCM_S32LE_PLANAR_ENCODER 1
+#define CONFIG_PCM_S64BE_ENCODER 1
+#define CONFIG_PCM_S64LE_ENCODER 1
+#define CONFIG_PCM_U8_ENCODER 1
+#define CONFIG_PCM_U16BE_ENCODER 1
+#define CONFIG_PCM_U16LE_ENCODER 1
+#define CONFIG_PCM_U24BE_ENCODER 1
+#define CONFIG_PCM_U24LE_ENCODER 1
+#define CONFIG_PCM_U32BE_ENCODER 1
+#define CONFIG_PCM_U32LE_ENCODER 1
+#define CONFIG_PCM_VIDC_ENCODER 1
+#define CONFIG_ROQ_DPCM_ENCODER 1
+#define CONFIG_ADPCM_ADX_ENCODER 1
+#define CONFIG_ADPCM_G722_ENCODER 1
+#define CONFIG_ADPCM_G726_ENCODER 1
+#define CONFIG_ADPCM_G726LE_ENCODER 1
+#define CONFIG_ADPCM_IMA_QT_ENCODER 1
+#define CONFIG_ADPCM_IMA_WAV_ENCODER 1
+#define CONFIG_ADPCM_MS_ENCODER 1
+#define CONFIG_ADPCM_SWF_ENCODER 1
+#define CONFIG_ADPCM_YAMAHA_ENCODER 1
+#define CONFIG_SSA_ENCODER 1
+#define CONFIG_ASS_ENCODER 1
+#define CONFIG_DVBSUB_ENCODER 1
+#define CONFIG_DVDSUB_ENCODER 1
+#define CONFIG_MOVTEXT_ENCODER 1
+#define CONFIG_SRT_ENCODER 1
+#define CONFIG_SUBRIP_ENCODER 1
+#define CONFIG_TEXT_ENCODER 1
+#define CONFIG_WEBVTT_ENCODER 1
+#define CONFIG_XSUB_ENCODER 1
+#define CONFIG_AAC_AT_ENCODER 0
+#define CONFIG_ALAC_AT_ENCODER 0
+#define CONFIG_ILBC_AT_ENCODER 0
+#define CONFIG_PCM_ALAW_AT_ENCODER 0
+#define CONFIG_PCM_MULAW_AT_ENCODER 0
+#define CONFIG_LIBAOM_AV1_ENCODER 0
+#define CONFIG_LIBCODEC2_ENCODER 0
+#define CONFIG_LIBFDK_AAC_ENCODER 0
+#define CONFIG_LIBGSM_ENCODER 0
+#define CONFIG_LIBGSM_MS_ENCODER 0
+#define CONFIG_LIBILBC_ENCODER 0
+#define CONFIG_LIBMP3LAME_ENCODER 0
+#define CONFIG_LIBOPENCORE_AMRNB_ENCODER 0
+#define CONFIG_LIBOPENJPEG_ENCODER 0
+#define CONFIG_LIBOPUS_ENCODER 0
+#define CONFIG_LIBSHINE_ENCODER 0
+#define CONFIG_LIBSPEEX_ENCODER 0
+#define CONFIG_LIBTHEORA_ENCODER 0
+#define CONFIG_LIBTWOLAME_ENCODER 0
+#define CONFIG_LIBVO_AMRWBENC_ENCODER 0
+#define CONFIG_LIBVORBIS_ENCODER 0
+#define CONFIG_LIBVPX_VP8_ENCODER 0
+#define CONFIG_LIBVPX_VP9_ENCODER 0
+#define CONFIG_LIBWAVPACK_ENCODER 0
+#define CONFIG_LIBWEBP_ANIM_ENCODER 0
+#define CONFIG_LIBWEBP_ENCODER 0
+#define CONFIG_LIBX262_ENCODER 0
+#define CONFIG_LIBX264_ENCODER 0
+#define CONFIG_LIBX264RGB_ENCODER 0
+#define CONFIG_LIBX265_ENCODER 0
+#define CONFIG_LIBXAVS_ENCODER 0
+#define CONFIG_LIBXAVS2_ENCODER 0
+#define CONFIG_LIBXVID_ENCODER 0
+#define CONFIG_H263_V4L2M2M_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
+#define CONFIG_H264_AMF_ENCODER 0
+#define CONFIG_H264_NVENC_ENCODER 0
+#define CONFIG_H264_OMX_ENCODER 0
+#define CONFIG_H264_QSV_ENCODER 0
+#define CONFIG_H264_V4L2M2M_ENCODER 0
+#define CONFIG_H264_VAAPI_ENCODER 0
+#define CONFIG_H264_VIDEOTOOLBOX_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
+#define CONFIG_NVENC_H264_ENCODER 0
+#define CONFIG_NVENC_HEVC_ENCODER 0
+#define CONFIG_HEVC_AMF_ENCODER 0
+#define CONFIG_HEVC_NVENC_ENCODER 0
+#define CONFIG_HEVC_QSV_ENCODER 0
+#define CONFIG_HEVC_V4L2M2M_ENCODER 0
+#define CONFIG_HEVC_VAAPI_ENCODER 0
+#define CONFIG_HEVC_VIDEOTOOLBOX_ENCODER 0
+#define CONFIG_LIBKVAZAAR_ENCODER 0
+#define CONFIG_MJPEG_QSV_ENCODER 0
+#define CONFIG_MJPEG_VAAPI_ENCODER 0
+#define CONFIG_MPEG2_QSV_ENCODER 0
+#define CONFIG_MPEG2_VAAPI_ENCODER 0
+#define CONFIG_MPEG4_V4L2M2M_ENCODER 0
+#define CONFIG_VP8_V4L2M2M_ENCODER 0
+#define CONFIG_VP8_VAAPI_ENCODER 0
+#define CONFIG_VP9_VAAPI_ENCODER 0
+#define CONFIG_H263_VAAPI_HWACCEL 0
+#define CONFIG_H263_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_H264_D3D11VA_HWACCEL 0
+#define CONFIG_H264_D3D11VA2_HWACCEL 0
+#define CONFIG_H264_DXVA2_HWACCEL 0
+#define CONFIG_H264_NVDEC_HWACCEL 0
+#define CONFIG_H264_VAAPI_HWACCEL 0
+#define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_H264_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_HEVC_D3D11VA_HWACCEL 0
+#define CONFIG_HEVC_D3D11VA2_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
+#define CONFIG_HEVC_NVDEC_HWACCEL 0
+#define CONFIG_HEVC_VAAPI_HWACCEL 0
+#define CONFIG_HEVC_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_MJPEG_NVDEC_HWACCEL 0
+#define CONFIG_MJPEG_VAAPI_HWACCEL 0
+#define CONFIG_MPEG1_NVDEC_HWACCEL 0
+#define CONFIG_MPEG1_VDPAU_HWACCEL 0
+#define CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_MPEG1_XVMC_HWACCEL 0
+#define CONFIG_MPEG2_D3D11VA_HWACCEL 0
+#define CONFIG_MPEG2_D3D11VA2_HWACCEL 0
+#define CONFIG_MPEG2_NVDEC_HWACCEL 0
+#define CONFIG_MPEG2_DXVA2_HWACCEL 0
+#define CONFIG_MPEG2_VAAPI_HWACCEL 0
+#define CONFIG_MPEG2_VDPAU_HWACCEL 0
+#define CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_MPEG2_XVMC_HWACCEL 0
+#define CONFIG_MPEG4_NVDEC_HWACCEL 0
+#define CONFIG_MPEG4_VAAPI_HWACCEL 0
+#define CONFIG_MPEG4_VDPAU_HWACCEL 0
+#define CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL 0
+#define CONFIG_VC1_D3D11VA_HWACCEL 0
+#define CONFIG_VC1_D3D11VA2_HWACCEL 0
+#define CONFIG_VC1_DXVA2_HWACCEL 0
+#define CONFIG_VC1_NVDEC_HWACCEL 0
+#define CONFIG_VC1_VAAPI_HWACCEL 0
+#define CONFIG_VC1_VDPAU_HWACCEL 0
+#define CONFIG_VP8_NVDEC_HWACCEL 0
+#define CONFIG_VP8_VAAPI_HWACCEL 0
+#define CONFIG_VP9_D3D11VA_HWACCEL 0
+#define CONFIG_VP9_D3D11VA2_HWACCEL 0
+#define CONFIG_VP9_DXVA2_HWACCEL 0
+#define CONFIG_VP9_NVDEC_HWACCEL 0
+#define CONFIG_VP9_VAAPI_HWACCEL 0
+#define CONFIG_WMV3_D3D11VA_HWACCEL 0
+#define CONFIG_WMV3_D3D11VA2_HWACCEL 0
+#define CONFIG_WMV3_DXVA2_HWACCEL 0
+#define CONFIG_WMV3_NVDEC_HWACCEL 0
+#define CONFIG_WMV3_VAAPI_HWACCEL 0
+#define CONFIG_WMV3_VDPAU_HWACCEL 0
+#define CONFIG_AAC_PARSER 1
+#define CONFIG_AAC_LATM_PARSER 1
+#define CONFIG_AC3_PARSER 1
+#define CONFIG_ADX_PARSER 1
+#define CONFIG_AV1_PARSER 1
+#define CONFIG_AVS2_PARSER 1
+#define CONFIG_BMP_PARSER 1
+#define CONFIG_CAVSVIDEO_PARSER 1
+#define CONFIG_COOK_PARSER 1
+#define CONFIG_DCA_PARSER 1
+#define CONFIG_DIRAC_PARSER 1
+#define CONFIG_DNXHD_PARSER 1
+#define CONFIG_DPX_PARSER 1
+#define CONFIG_DVAUDIO_PARSER 1
+#define CONFIG_DVBSUB_PARSER 1
+#define CONFIG_DVDSUB_PARSER 1
+#define CONFIG_DVD_NAV_PARSER 1
+#define CONFIG_FLAC_PARSER 1
+#define CONFIG_G723_1_PARSER 1
+#define CONFIG_G729_PARSER 1
+#define CONFIG_GIF_PARSER 1
+#define CONFIG_GSM_PARSER 1
+#define CONFIG_H261_PARSER 1
+#define CONFIG_H263_PARSER 1
+#define CONFIG_H264_PARSER 1
+#define CONFIG_HEVC_PARSER 1
+#define CONFIG_MJPEG_PARSER 1
+#define CONFIG_MLP_PARSER 1
+#define CONFIG_MPEG4VIDEO_PARSER 1
+#define CONFIG_MPEGAUDIO_PARSER 1
+#define CONFIG_MPEGVIDEO_PARSER 1
+#define CONFIG_OPUS_PARSER 1
+#define CONFIG_PNG_PARSER 1
+#define CONFIG_PNM_PARSER 1
+#define CONFIG_RV30_PARSER 1
+#define CONFIG_RV40_PARSER 1
+#define CONFIG_SBC_PARSER 1
+#define CONFIG_SIPR_PARSER 1
+#define CONFIG_TAK_PARSER 1
+#define CONFIG_VC1_PARSER 1
+#define CONFIG_VORBIS_PARSER 1
+#define CONFIG_VP3_PARSER 1
+#define CONFIG_VP8_PARSER 1
+#define CONFIG_VP9_PARSER 1
+#define CONFIG_XMA_PARSER 1
+#define CONFIG_ALSA_INDEV 0
+#define CONFIG_ANDROID_CAMERA_INDEV 0
+#define CONFIG_AVFOUNDATION_INDEV 0
+#define CONFIG_BKTR_INDEV 0
+#define CONFIG_DECKLINK_INDEV 0
+#define CONFIG_DSHOW_INDEV 0
+#define CONFIG_FBDEV_INDEV 0
+#define CONFIG_GDIGRAB_INDEV 1
+#define CONFIG_IEC61883_INDEV 0
+#define CONFIG_JACK_INDEV 0
+#define CONFIG_KMSGRAB_INDEV 0
+#define CONFIG_LAVFI_INDEV 1
+#define CONFIG_OPENAL_INDEV 0
+#define CONFIG_OSS_INDEV 0
+#define CONFIG_PULSE_INDEV 0
+#define CONFIG_SNDIO_INDEV 0
+#define CONFIG_V4L2_INDEV 0
+#define CONFIG_VFWCAP_INDEV 1
+#define CONFIG_XCBGRAB_INDEV 0
+#define CONFIG_LIBCDIO_INDEV 0
+#define CONFIG_LIBDC1394_INDEV 0
+#define CONFIG_ALSA_OUTDEV 0
+#define CONFIG_CACA_OUTDEV 0
+#define CONFIG_DECKLINK_OUTDEV 0
+#define CONFIG_FBDEV_OUTDEV 0
+#define CONFIG_OPENGL_OUTDEV 0
+#define CONFIG_OSS_OUTDEV 0
+#define CONFIG_PULSE_OUTDEV 0
+#define CONFIG_SDL2_OUTDEV 0
+#define CONFIG_SNDIO_OUTDEV 0
+#define CONFIG_V4L2_OUTDEV 0
+#define CONFIG_XV_OUTDEV 0
+#define CONFIG_ABENCH_FILTER 1
+#define CONFIG_ACOMPRESSOR_FILTER 1
+#define CONFIG_ACONTRAST_FILTER 1
+#define CONFIG_ACOPY_FILTER 1
+#define CONFIG_ACUE_FILTER 1
+#define CONFIG_ACROSSFADE_FILTER 1
+#define CONFIG_ACROSSOVER_FILTER 1
+#define CONFIG_ACRUSHER_FILTER 1
+#define CONFIG_ADECLICK_FILTER 1
+#define CONFIG_ADECLIP_FILTER 1
+#define CONFIG_ADELAY_FILTER 1
+#define CONFIG_ADERIVATIVE_FILTER 1
+#define CONFIG_AECHO_FILTER 1
+#define CONFIG_AEMPHASIS_FILTER 1
+#define CONFIG_AEVAL_FILTER 1
+#define CONFIG_AFADE_FILTER 1
+#define CONFIG_AFFTDN_FILTER 1
+#define CONFIG_AFFTFILT_FILTER 1
+#define CONFIG_AFIR_FILTER 1
+#define CONFIG_AFORMAT_FILTER 1
+#define CONFIG_AGATE_FILTER 1
+#define CONFIG_AIIR_FILTER 1
+#define CONFIG_AINTEGRAL_FILTER 1
+#define CONFIG_AINTERLEAVE_FILTER 1
+#define CONFIG_ALIMITER_FILTER 1
+#define CONFIG_ALLPASS_FILTER 1
+#define CONFIG_ALOOP_FILTER 1
+#define CONFIG_AMERGE_FILTER 1
+#define CONFIG_AMETADATA_FILTER 1
+#define CONFIG_AMIX_FILTER 1
+#define CONFIG_AMULTIPLY_FILTER 1
+#define CONFIG_ANEQUALIZER_FILTER 1
+#define CONFIG_ANLMDN_FILTER 1
+#define CONFIG_ANULL_FILTER 1
+#define CONFIG_APAD_FILTER 1
+#define CONFIG_APERMS_FILTER 1
+#define CONFIG_APHASER_FILTER 1
+#define CONFIG_APULSATOR_FILTER 1
+#define CONFIG_AREALTIME_FILTER 1
+#define CONFIG_ARESAMPLE_FILTER 1
+#define CONFIG_AREVERSE_FILTER 1
+#define CONFIG_ASELECT_FILTER 1
+#define CONFIG_ASENDCMD_FILTER 1
+#define CONFIG_ASETNSAMPLES_FILTER 1
+#define CONFIG_ASETPTS_FILTER 1
+#define CONFIG_ASETRATE_FILTER 1
+#define CONFIG_ASETTB_FILTER 1
+#define CONFIG_ASHOWINFO_FILTER 1
+#define CONFIG_ASIDEDATA_FILTER 1
+#define CONFIG_ASOFTCLIP_FILTER 1
+#define CONFIG_ASPLIT_FILTER 1
+#define CONFIG_ASR_FILTER 0
+#define CONFIG_ASTATS_FILTER 1
+#define CONFIG_ASTREAMSELECT_FILTER 1
+#define CONFIG_ATEMPO_FILTER 1
+#define CONFIG_ATRIM_FILTER 1
+#define CONFIG_AZMQ_FILTER 0
+#define CONFIG_BANDPASS_FILTER 1
+#define CONFIG_BANDREJECT_FILTER 1
+#define CONFIG_BASS_FILTER 1
+#define CONFIG_BIQUAD_FILTER 1
+#define CONFIG_BS2B_FILTER 0
+#define CONFIG_CHANNELMAP_FILTER 1
+#define CONFIG_CHANNELSPLIT_FILTER 1
+#define CONFIG_CHORUS_FILTER 1
+#define CONFIG_COMPAND_FILTER 1
+#define CONFIG_COMPENSATIONDELAY_FILTER 1
+#define CONFIG_CROSSFEED_FILTER 1
+#define CONFIG_CRYSTALIZER_FILTER 1
+#define CONFIG_DCSHIFT_FILTER 1
+#define CONFIG_DEESSER_FILTER 1
+#define CONFIG_DRMETER_FILTER 1
+#define CONFIG_DYNAUDNORM_FILTER 1
+#define CONFIG_EARWAX_FILTER 1
+#define CONFIG_EBUR128_FILTER 1
+#define CONFIG_EQUALIZER_FILTER 1
+#define CONFIG_EXTRASTEREO_FILTER 1
+#define CONFIG_FIREQUALIZER_FILTER 1
+#define CONFIG_FLANGER_FILTER 1
+#define CONFIG_HAAS_FILTER 1
+#define CONFIG_HDCD_FILTER 1
+#define CONFIG_HEADPHONE_FILTER 1
+#define CONFIG_HIGHPASS_FILTER 1
+#define CONFIG_HIGHSHELF_FILTER 1
+#define CONFIG_JOIN_FILTER 1
+#define CONFIG_LADSPA_FILTER 0
+#define CONFIG_LOUDNORM_FILTER 1
+#define CONFIG_LOWPASS_FILTER 1
+#define CONFIG_LOWSHELF_FILTER 1
+#define CONFIG_LV2_FILTER 0
+#define CONFIG_MCOMPAND_FILTER 1
+#define CONFIG_PAN_FILTER 1
+#define CONFIG_REPLAYGAIN_FILTER 1
+#define CONFIG_RESAMPLE_FILTER 0
+#define CONFIG_RUBBERBAND_FILTER 0
+#define CONFIG_SIDECHAINCOMPRESS_FILTER 1
+#define CONFIG_SIDECHAINGATE_FILTER 1
+#define CONFIG_SILENCEDETECT_FILTER 1
+#define CONFIG_SILENCEREMOVE_FILTER 1
+#define CONFIG_SOFALIZER_FILTER 0
+#define CONFIG_STEREOTOOLS_FILTER 1
+#define CONFIG_STEREOWIDEN_FILTER 1
+#define CONFIG_SUPEREQUALIZER_FILTER 1
+#define CONFIG_SURROUND_FILTER 1
+#define CONFIG_TREBLE_FILTER 1
+#define CONFIG_TREMOLO_FILTER 1
+#define CONFIG_VIBRATO_FILTER 1
+#define CONFIG_VOLUME_FILTER 1
+#define CONFIG_VOLUMEDETECT_FILTER 1
+#define CONFIG_AEVALSRC_FILTER 1
+#define CONFIG_ANOISESRC_FILTER 1
+#define CONFIG_ANULLSRC_FILTER 1
+#define CONFIG_FLITE_FILTER 0
+#define CONFIG_HILBERT_FILTER 1
+#define CONFIG_SINC_FILTER 1
+#define CONFIG_SINE_FILTER 1
+#define CONFIG_ANULLSINK_FILTER 1
+#define CONFIG_ALPHAEXTRACT_FILTER 1
+#define CONFIG_ALPHAMERGE_FILTER 1
+#define CONFIG_AMPLIFY_FILTER 1
+#define CONFIG_ASS_FILTER 0
+#define CONFIG_ATADENOISE_FILTER 1
+#define CONFIG_AVGBLUR_FILTER 1
+#define CONFIG_AVGBLUR_OPENCL_FILTER 0
+#define CONFIG_BBOX_FILTER 1
+#define CONFIG_BENCH_FILTER 1
+#define CONFIG_BITPLANENOISE_FILTER 1
+#define CONFIG_BLACKDETECT_FILTER 1
+#define CONFIG_BLACKFRAME_FILTER 0
+#define CONFIG_BLEND_FILTER 1
+#define CONFIG_BM3D_FILTER 1
+#define CONFIG_BOXBLUR_FILTER 0
+#define CONFIG_BOXBLUR_OPENCL_FILTER 0
+#define CONFIG_BWDIF_FILTER 1
+#define CONFIG_CHROMAHOLD_FILTER 1
+#define CONFIG_CHROMAKEY_FILTER 1
+#define CONFIG_CHROMASHIFT_FILTER 1
+#define CONFIG_CIESCOPE_FILTER 1
+#define CONFIG_CODECVIEW_FILTER 1
+#define CONFIG_COLORBALANCE_FILTER 1
+#define CONFIG_COLORCHANNELMIXER_FILTER 1
+#define CONFIG_COLORKEY_FILTER 1
+#define CONFIG_COLORKEY_OPENCL_FILTER 0
+#define CONFIG_COLORHOLD_FILTER 1
+#define CONFIG_COLORLEVELS_FILTER 1
+#define CONFIG_COLORMATRIX_FILTER 0
+#define CONFIG_COLORSPACE_FILTER 1
+#define CONFIG_CONVOLUTION_FILTER 1
+#define CONFIG_CONVOLUTION_OPENCL_FILTER 0
+#define CONFIG_CONVOLVE_FILTER 1
+#define CONFIG_COPY_FILTER 1
+#define CONFIG_COREIMAGE_FILTER 0
+#define CONFIG_COVER_RECT_FILTER 0
+#define CONFIG_CROP_FILTER 1
+#define CONFIG_CROPDETECT_FILTER 0
+#define CONFIG_CUE_FILTER 1
+#define CONFIG_CURVES_FILTER 1
+#define CONFIG_DATASCOPE_FILTER 1
+#define CONFIG_DCTDNOIZ_FILTER 1
+#define CONFIG_DEBAND_FILTER 1
+#define CONFIG_DEBLOCK_FILTER 1
+#define CONFIG_DECIMATE_FILTER 1
+#define CONFIG_DECONVOLVE_FILTER 1
+#define CONFIG_DEDOT_FILTER 1
+#define CONFIG_DEFLATE_FILTER 1
+#define CONFIG_DEFLICKER_FILTER 1
+#define CONFIG_DEINTERLACE_QSV_FILTER 0
+#define CONFIG_DEINTERLACE_VAAPI_FILTER 0
+#define CONFIG_DEJUDDER_FILTER 1
+#define CONFIG_DELOGO_FILTER 0
+#define CONFIG_DENOISE_VAAPI_FILTER 0
+#define CONFIG_DERAIN_FILTER 1
+#define CONFIG_DESHAKE_FILTER 1
+#define CONFIG_DESPILL_FILTER 1
+#define CONFIG_DETELECINE_FILTER 1
+#define CONFIG_DILATION_FILTER 1
+#define CONFIG_DILATION_OPENCL_FILTER 0
+#define CONFIG_DISPLACE_FILTER 1
+#define CONFIG_DOUBLEWEAVE_FILTER 1
+#define CONFIG_DRAWBOX_FILTER 1
+#define CONFIG_DRAWGRAPH_FILTER 1
+#define CONFIG_DRAWGRID_FILTER 1
+#define CONFIG_DRAWTEXT_FILTER 0
+#define CONFIG_EDGEDETECT_FILTER 1
+#define CONFIG_ELBG_FILTER 1
+#define CONFIG_ENTROPY_FILTER 1
+#define CONFIG_EQ_FILTER 0
+#define CONFIG_EROSION_FILTER 1
+#define CONFIG_EROSION_OPENCL_FILTER 0
+#define CONFIG_EXTRACTPLANES_FILTER 1
+#define CONFIG_FADE_FILTER 1
+#define CONFIG_FFTDNOIZ_FILTER 1
+#define CONFIG_FFTFILT_FILTER 1
+#define CONFIG_FIELD_FILTER 1
+#define CONFIG_FIELDHINT_FILTER 1
+#define CONFIG_FIELDMATCH_FILTER 1
+#define CONFIG_FIELDORDER_FILTER 1
+#define CONFIG_FILLBORDERS_FILTER 1
+#define CONFIG_FIND_RECT_FILTER 0
+#define CONFIG_FLOODFILL_FILTER 1
+#define CONFIG_FORMAT_FILTER 1
+#define CONFIG_FPS_FILTER 1
+#define CONFIG_FRAMEPACK_FILTER 1
+#define CONFIG_FRAMERATE_FILTER 1
+#define CONFIG_FRAMESTEP_FILTER 1
+#define CONFIG_FREEZEDETECT_FILTER 1
+#define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
+#define CONFIG_GBLUR_FILTER 1
+#define CONFIG_GEQ_FILTER 0
+#define CONFIG_GRADFUN_FILTER 1
+#define CONFIG_GRAPHMONITOR_FILTER 1
+#define CONFIG_GREYEDGE_FILTER 1
+#define CONFIG_HALDCLUT_FILTER 1
+#define CONFIG_HFLIP_FILTER 1
+#define CONFIG_HISTEQ_FILTER 0
+#define CONFIG_HISTOGRAM_FILTER 1
+#define CONFIG_HQDN3D_FILTER 0
+#define CONFIG_HQX_FILTER 1
+#define CONFIG_HSTACK_FILTER 1
+#define CONFIG_HUE_FILTER 1
+#define CONFIG_HWDOWNLOAD_FILTER 1
+#define CONFIG_HWMAP_FILTER 1
+#define CONFIG_HWUPLOAD_FILTER 1
+#define CONFIG_HWUPLOAD_CUDA_FILTER 0
+#define CONFIG_HYSTERESIS_FILTER 1
+#define CONFIG_IDET_FILTER 1
+#define CONFIG_IL_FILTER 1
+#define CONFIG_INFLATE_FILTER 1
+#define CONFIG_INTERLACE_FILTER 0
+#define CONFIG_INTERLEAVE_FILTER 1
+#define CONFIG_KERNDEINT_FILTER 0
+#define CONFIG_LAGFUN_FILTER 1
+#define CONFIG_LENSCORRECTION_FILTER 1
+#define CONFIG_LENSFUN_FILTER 0
+#define CONFIG_LIBVMAF_FILTER 0
+#define CONFIG_LIMITER_FILTER 1
+#define CONFIG_LOOP_FILTER 1
+#define CONFIG_LUMAKEY_FILTER 1
+#define CONFIG_LUT_FILTER 1
+#define CONFIG_LUT1D_FILTER 1
+#define CONFIG_LUT2_FILTER 1
+#define CONFIG_LUT3D_FILTER 1
+#define CONFIG_LUTRGB_FILTER 1
+#define CONFIG_LUTYUV_FILTER 1
+#define CONFIG_MASKEDCLAMP_FILTER 1
+#define CONFIG_MASKEDMERGE_FILTER 1
+#define CONFIG_MASKFUN_FILTER 1
+#define CONFIG_MCDEINT_FILTER 0
+#define CONFIG_MERGEPLANES_FILTER 1
+#define CONFIG_MESTIMATE_FILTER 1
+#define CONFIG_METADATA_FILTER 1
+#define CONFIG_MIDEQUALIZER_FILTER 1
+#define CONFIG_MINTERPOLATE_FILTER 1
+#define CONFIG_MIX_FILTER 1
+#define CONFIG_MPDECIMATE_FILTER 0
+#define CONFIG_NEGATE_FILTER 1
+#define CONFIG_NLMEANS_FILTER 1
+#define CONFIG_NLMEANS_OPENCL_FILTER 0
+#define CONFIG_NNEDI_FILTER 0
+#define CONFIG_NOFORMAT_FILTER 1
+#define CONFIG_NOISE_FILTER 1
+#define CONFIG_NORMALIZE_FILTER 1
+#define CONFIG_NULL_FILTER 1
+#define CONFIG_OCR_FILTER 0
+#define CONFIG_OCV_FILTER 0
+#define CONFIG_OSCILLOSCOPE_FILTER 1
+#define CONFIG_OVERLAY_FILTER 1
+#define CONFIG_OVERLAY_OPENCL_FILTER 0
+#define CONFIG_OVERLAY_QSV_FILTER 0
+#define CONFIG_OWDENOISE_FILTER 0
+#define CONFIG_PAD_FILTER 1
+#define CONFIG_PALETTEGEN_FILTER 1
+#define CONFIG_PALETTEUSE_FILTER 1
+#define CONFIG_PERMS_FILTER 1
+#define CONFIG_PERSPECTIVE_FILTER 0
+#define CONFIG_PHASE_FILTER 0
+#define CONFIG_PIXDESCTEST_FILTER 1
+#define CONFIG_PIXSCOPE_FILTER 1
+#define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
+#define CONFIG_PREMULTIPLY_FILTER 1
+#define CONFIG_PREWITT_FILTER 1
+#define CONFIG_PREWITT_OPENCL_FILTER 0
+#define CONFIG_PROCAMP_VAAPI_FILTER 0
+#define CONFIG_PROGRAM_OPENCL_FILTER 0
+#define CONFIG_PSEUDOCOLOR_FILTER 1
+#define CONFIG_PSNR_FILTER 1
+#define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 1
+#define CONFIG_RANDOM_FILTER 1
+#define CONFIG_READEIA608_FILTER 1
+#define CONFIG_READVITC_FILTER 1
+#define CONFIG_REALTIME_FILTER 1
+#define CONFIG_REMAP_FILTER 1
+#define CONFIG_REMOVEGRAIN_FILTER 1
+#define CONFIG_REMOVELOGO_FILTER 1
+#define CONFIG_REPEATFIELDS_FILTER 0
+#define CONFIG_REVERSE_FILTER 1
+#define CONFIG_RGBASHIFT_FILTER 1
+#define CONFIG_ROBERTS_FILTER 1
+#define CONFIG_ROBERTS_OPENCL_FILTER 0
+#define CONFIG_ROTATE_FILTER 1
+#define CONFIG_SAB_FILTER 0
+#define CONFIG_SCALE_FILTER 1
+#define CONFIG_SCALE_CUDA_FILTER 0
+#define CONFIG_SCALE_NPP_FILTER 0
+#define CONFIG_SCALE_QSV_FILTER 0
+#define CONFIG_SCALE_VAAPI_FILTER 0
+#define CONFIG_SCALE2REF_FILTER 1
+#define CONFIG_SELECT_FILTER 1
+#define CONFIG_SELECTIVECOLOR_FILTER 1
+#define CONFIG_SENDCMD_FILTER 1
+#define CONFIG_SEPARATEFIELDS_FILTER 1
+#define CONFIG_SETDAR_FILTER 1
+#define CONFIG_SETFIELD_FILTER 1
+#define CONFIG_SETPARAMS_FILTER 1
+#define CONFIG_SETPTS_FILTER 1
+#define CONFIG_SETRANGE_FILTER 1
+#define CONFIG_SETSAR_FILTER 1
+#define CONFIG_SETTB_FILTER 1
+#define CONFIG_SHARPNESS_VAAPI_FILTER 0
+#define CONFIG_SHOWINFO_FILTER 1
+#define CONFIG_SHOWPALETTE_FILTER 1
+#define CONFIG_SHUFFLEFRAMES_FILTER 1
+#define CONFIG_SHUFFLEPLANES_FILTER 1
+#define CONFIG_SIDEDATA_FILTER 1
+#define CONFIG_SIGNALSTATS_FILTER 1
+#define CONFIG_SIGNATURE_FILTER 0
+#define CONFIG_SMARTBLUR_FILTER 0
+#define CONFIG_SOBEL_FILTER 1
+#define CONFIG_SOBEL_OPENCL_FILTER 0
+#define CONFIG_SPLIT_FILTER 1
+#define CONFIG_SPP_FILTER 0
+#define CONFIG_SR_FILTER 1
+#define CONFIG_SSIM_FILTER 1
+#define CONFIG_STEREO3D_FILTER 0
+#define CONFIG_STREAMSELECT_FILTER 1
+#define CONFIG_SUBTITLES_FILTER 0
+#define CONFIG_SUPER2XSAI_FILTER 0
+#define CONFIG_SWAPRECT_FILTER 1
+#define CONFIG_SWAPUV_FILTER 1
+#define CONFIG_TBLEND_FILTER 1
+#define CONFIG_TELECINE_FILTER 1
+#define CONFIG_THRESHOLD_FILTER 1
+#define CONFIG_THUMBNAIL_FILTER 1
+#define CONFIG_THUMBNAIL_CUDA_FILTER 0
+#define CONFIG_TILE_FILTER 1
+#define CONFIG_TINTERLACE_FILTER 0
+#define CONFIG_TLUT2_FILTER 1
+#define CONFIG_TMIX_FILTER 1
+#define CONFIG_TONEMAP_FILTER 1
+#define CONFIG_TONEMAP_OPENCL_FILTER 0
+#define CONFIG_TPAD_FILTER 1
+#define CONFIG_TRANSPOSE_FILTER 1
+#define CONFIG_TRANSPOSE_NPP_FILTER 0
+#define CONFIG_TRANSPOSE_OPENCL_FILTER 0
+#define CONFIG_TRANSPOSE_VAAPI_FILTER 0
+#define CONFIG_TRIM_FILTER 1
+#define CONFIG_UNPREMULTIPLY_FILTER 1
+#define CONFIG_UNSHARP_FILTER 1
+#define CONFIG_UNSHARP_OPENCL_FILTER 0
+#define CONFIG_USPP_FILTER 0
+#define CONFIG_VAGUEDENOISER_FILTER 0
+#define CONFIG_VECTORSCOPE_FILTER 1
+#define CONFIG_VFLIP_FILTER 1
+#define CONFIG_VFRDET_FILTER 1
+#define CONFIG_VIBRANCE_FILTER 1
+#define CONFIG_VIDSTABDETECT_FILTER 0
+#define CONFIG_VIDSTABTRANSFORM_FILTER 0
+#define CONFIG_VIGNETTE_FILTER 1
+#define CONFIG_VMAFMOTION_FILTER 1
+#define CONFIG_VPP_QSV_FILTER 0
+#define CONFIG_VSTACK_FILTER 1
+#define CONFIG_W3FDIF_FILTER 1
+#define CONFIG_WAVEFORM_FILTER 1
+#define CONFIG_WEAVE_FILTER 1
+#define CONFIG_XBR_FILTER 1
+#define CONFIG_XMEDIAN_FILTER 1
+#define CONFIG_XSTACK_FILTER 1
+#define CONFIG_YADIF_FILTER 1
+#define CONFIG_YADIF_CUDA_FILTER 0
+#define CONFIG_ZMQ_FILTER 0
+#define CONFIG_ZOOMPAN_FILTER 1
+#define CONFIG_ZSCALE_FILTER 0
+#define CONFIG_ALLRGB_FILTER 1
+#define CONFIG_ALLYUV_FILTER 1
+#define CONFIG_CELLAUTO_FILTER 1
+#define CONFIG_COLOR_FILTER 1
+#define CONFIG_COREIMAGESRC_FILTER 0
+#define CONFIG_FREI0R_SRC_FILTER 0
+#define CONFIG_HALDCLUTSRC_FILTER 1
+#define CONFIG_LIFE_FILTER 1
+#define CONFIG_MANDELBROT_FILTER 1
+#define CONFIG_MPTESTSRC_FILTER 0
+#define CONFIG_NULLSRC_FILTER 1
+#define CONFIG_OPENCLSRC_FILTER 0
+#define CONFIG_PAL75BARS_FILTER 1
+#define CONFIG_PAL100BARS_FILTER 1
+#define CONFIG_RGBTESTSRC_FILTER 1
+#define CONFIG_SMPTEBARS_FILTER 1
+#define CONFIG_SMPTEHDBARS_FILTER 1
+#define CONFIG_TESTSRC_FILTER 1
+#define CONFIG_TESTSRC2_FILTER 1
+#define CONFIG_YUVTESTSRC_FILTER 1
+#define CONFIG_NULLSINK_FILTER 1
+#define CONFIG_ABITSCOPE_FILTER 1
+#define CONFIG_ADRAWGRAPH_FILTER 1
+#define CONFIG_AGRAPHMONITOR_FILTER 1
+#define CONFIG_AHISTOGRAM_FILTER 1
+#define CONFIG_APHASEMETER_FILTER 1
+#define CONFIG_AVECTORSCOPE_FILTER 1
+#define CONFIG_CONCAT_FILTER 1
+#define CONFIG_SHOWCQT_FILTER 1
+#define CONFIG_SHOWFREQS_FILTER 1
+#define CONFIG_SHOWSPATIAL_FILTER 1
+#define CONFIG_SHOWSPECTRUM_FILTER 1
+#define CONFIG_SHOWSPECTRUMPIC_FILTER 1
+#define CONFIG_SHOWVOLUME_FILTER 1
+#define CONFIG_SHOWWAVES_FILTER 1
+#define CONFIG_SHOWWAVESPIC_FILTER 1
+#define CONFIG_SPECTRUMSYNTH_FILTER 1
+#define CONFIG_AMOVIE_FILTER 1
+#define CONFIG_MOVIE_FILTER 1
+#define CONFIG_AFIFO_FILTER 1
+#define CONFIG_FIFO_FILTER 1
+#define CONFIG_AA_DEMUXER 1
+#define CONFIG_AAC_DEMUXER 1
+#define CONFIG_AC3_DEMUXER 1
+#define CONFIG_ACM_DEMUXER 1
+#define CONFIG_ACT_DEMUXER 1
+#define CONFIG_ADF_DEMUXER 1
+#define CONFIG_ADP_DEMUXER 1
+#define CONFIG_ADS_DEMUXER 1
+#define CONFIG_ADX_DEMUXER 1
+#define CONFIG_AEA_DEMUXER 1
+#define CONFIG_AFC_DEMUXER 1
+#define CONFIG_AIFF_DEMUXER 1
+#define CONFIG_AIX_DEMUXER 1
+#define CONFIG_AMR_DEMUXER 1
+#define CONFIG_AMRNB_DEMUXER 1
+#define CONFIG_AMRWB_DEMUXER 1
+#define CONFIG_ANM_DEMUXER 1
+#define CONFIG_APC_DEMUXER 1
+#define CONFIG_APE_DEMUXER 1
+#define CONFIG_APNG_DEMUXER 1
+#define CONFIG_APTX_DEMUXER 1
+#define CONFIG_APTX_HD_DEMUXER 1
+#define CONFIG_AQTITLE_DEMUXER 1
+#define CONFIG_ASF_DEMUXER 1
+#define CONFIG_ASF_O_DEMUXER 1
+#define CONFIG_ASS_DEMUXER 1
+#define CONFIG_AST_DEMUXER 1
+#define CONFIG_AU_DEMUXER 1
+#define CONFIG_AVI_DEMUXER 1
+#define CONFIG_AVISYNTH_DEMUXER 0
+#define CONFIG_AVR_DEMUXER 1
+#define CONFIG_AVS_DEMUXER 1
+#define CONFIG_AVS2_DEMUXER 1
+#define CONFIG_BETHSOFTVID_DEMUXER 1
+#define CONFIG_BFI_DEMUXER 1
+#define CONFIG_BINTEXT_DEMUXER 1
+#define CONFIG_BINK_DEMUXER 1
+#define CONFIG_BIT_DEMUXER 1
+#define CONFIG_BMV_DEMUXER 1
+#define CONFIG_BFSTM_DEMUXER 1
+#define CONFIG_BRSTM_DEMUXER 1
+#define CONFIG_BOA_DEMUXER 1
+#define CONFIG_C93_DEMUXER 1
+#define CONFIG_CAF_DEMUXER 1
+#define CONFIG_CAVSVIDEO_DEMUXER 1
+#define CONFIG_CDG_DEMUXER 1
+#define CONFIG_CDXL_DEMUXER 1
+#define CONFIG_CINE_DEMUXER 1
+#define CONFIG_CODEC2_DEMUXER 1
+#define CONFIG_CODEC2RAW_DEMUXER 1
+#define CONFIG_CONCAT_DEMUXER 1
+#define CONFIG_DASH_DEMUXER 0
+#define CONFIG_DATA_DEMUXER 1
+#define CONFIG_DAUD_DEMUXER 1
+#define CONFIG_DCSTR_DEMUXER 1
+#define CONFIG_DFA_DEMUXER 1
+#define CONFIG_DHAV_DEMUXER 1
+#define CONFIG_DIRAC_DEMUXER 1
+#define CONFIG_DNXHD_DEMUXER 1
+#define CONFIG_DSF_DEMUXER 1
+#define CONFIG_DSICIN_DEMUXER 1
+#define CONFIG_DSS_DEMUXER 1
+#define CONFIG_DTS_DEMUXER 1
+#define CONFIG_DTSHD_DEMUXER 1
+#define CONFIG_DV_DEMUXER 1
+#define CONFIG_DVBSUB_DEMUXER 1
+#define CONFIG_DVBTXT_DEMUXER 1
+#define CONFIG_DXA_DEMUXER 1
+#define CONFIG_EA_DEMUXER 1
+#define CONFIG_EA_CDATA_DEMUXER 1
+#define CONFIG_EAC3_DEMUXER 1
+#define CONFIG_EPAF_DEMUXER 1
+#define CONFIG_FFMETADATA_DEMUXER 1
+#define CONFIG_FILMSTRIP_DEMUXER 1
+#define CONFIG_FITS_DEMUXER 1
+#define CONFIG_FLAC_DEMUXER 1
+#define CONFIG_FLIC_DEMUXER 1
+#define CONFIG_FLV_DEMUXER 1
+#define CONFIG_LIVE_FLV_DEMUXER 1
+#define CONFIG_FOURXM_DEMUXER 1
+#define CONFIG_FRM_DEMUXER 1
+#define CONFIG_FSB_DEMUXER 1
+#define CONFIG_G722_DEMUXER 1
+#define CONFIG_G723_1_DEMUXER 1
+#define CONFIG_G726_DEMUXER 1
+#define CONFIG_G726LE_DEMUXER 1
+#define CONFIG_G729_DEMUXER 1
+#define CONFIG_GDV_DEMUXER 1
+#define CONFIG_GENH_DEMUXER 1
+#define CONFIG_GIF_DEMUXER 1
+#define CONFIG_GSM_DEMUXER 1
+#define CONFIG_GXF_DEMUXER 1
+#define CONFIG_H261_DEMUXER 1
+#define CONFIG_H263_DEMUXER 1
+#define CONFIG_H264_DEMUXER 1
+#define CONFIG_HCOM_DEMUXER 1
+#define CONFIG_HEVC_DEMUXER 1
+#define CONFIG_HLS_DEMUXER 1
+#define CONFIG_HNM_DEMUXER 1
+#define CONFIG_ICO_DEMUXER 1
+#define CONFIG_IDCIN_DEMUXER 1
+#define CONFIG_IDF_DEMUXER 1
+#define CONFIG_IFF_DEMUXER 1
+#define CONFIG_IFV_DEMUXER 1
+#define CONFIG_ILBC_DEMUXER 1
+#define CONFIG_IMAGE2_DEMUXER 1
+#define CONFIG_IMAGE2PIPE_DEMUXER 1
+#define CONFIG_IMAGE2_ALIAS_PIX_DEMUXER 1
+#define CONFIG_IMAGE2_BRENDER_PIX_DEMUXER 1
+#define CONFIG_INGENIENT_DEMUXER 1
+#define CONFIG_IPMOVIE_DEMUXER 1
+#define CONFIG_IRCAM_DEMUXER 1
+#define CONFIG_ISS_DEMUXER 1
+#define CONFIG_IV8_DEMUXER 1
+#define CONFIG_IVF_DEMUXER 1
+#define CONFIG_IVR_DEMUXER 1
+#define CONFIG_JACOSUB_DEMUXER 1
+#define CONFIG_JV_DEMUXER 1
+#define CONFIG_KUX_DEMUXER 1
+#define CONFIG_LMLM4_DEMUXER 1
+#define CONFIG_LOAS_DEMUXER 1
+#define CONFIG_LRC_DEMUXER 1
+#define CONFIG_LVF_DEMUXER 1
+#define CONFIG_LXF_DEMUXER 1
+#define CONFIG_M4V_DEMUXER 1
+#define CONFIG_MATROSKA_DEMUXER 1
+#define CONFIG_MGSTS_DEMUXER 1
+#define CONFIG_MICRODVD_DEMUXER 1
+#define CONFIG_MJPEG_DEMUXER 1
+#define CONFIG_MJPEG_2000_DEMUXER 1
+#define CONFIG_MLP_DEMUXER 1
+#define CONFIG_MLV_DEMUXER 1
+#define CONFIG_MM_DEMUXER 1
+#define CONFIG_MMF_DEMUXER 1
+#define CONFIG_MOV_DEMUXER 1
+#define CONFIG_MP3_DEMUXER 1
+#define CONFIG_MPC_DEMUXER 1
+#define CONFIG_MPC8_DEMUXER 1
+#define CONFIG_MPEGPS_DEMUXER 1
+#define CONFIG_MPEGTS_DEMUXER 1
+#define CONFIG_MPEGTSRAW_DEMUXER 1
+#define CONFIG_MPEGVIDEO_DEMUXER 1
+#define CONFIG_MPJPEG_DEMUXER 1
+#define CONFIG_MPL2_DEMUXER 1
+#define CONFIG_MPSUB_DEMUXER 1
+#define CONFIG_MSF_DEMUXER 1
+#define CONFIG_MSNWC_TCP_DEMUXER 1
+#define CONFIG_MTAF_DEMUXER 1
+#define CONFIG_MTV_DEMUXER 1
+#define CONFIG_MUSX_DEMUXER 1
+#define CONFIG_MV_DEMUXER 1
+#define CONFIG_MVI_DEMUXER 1
+#define CONFIG_MXF_DEMUXER 1
+#define CONFIG_MXG_DEMUXER 1
+#define CONFIG_NC_DEMUXER 1
+#define CONFIG_NISTSPHERE_DEMUXER 1
+#define CONFIG_NSP_DEMUXER 1
+#define CONFIG_NSV_DEMUXER 1
+#define CONFIG_NUT_DEMUXER 1
+#define CONFIG_NUV_DEMUXER 1
+#define CONFIG_OGG_DEMUXER 1
+#define CONFIG_OMA_DEMUXER 1
+#define CONFIG_PAF_DEMUXER 1
+#define CONFIG_PCM_ALAW_DEMUXER 1
+#define CONFIG_PCM_MULAW_DEMUXER 1
+#define CONFIG_PCM_VIDC_DEMUXER 1
+#define CONFIG_PCM_F64BE_DEMUXER 1
+#define CONFIG_PCM_F64LE_DEMUXER 1
+#define CONFIG_PCM_F32BE_DEMUXER 1
+#define CONFIG_PCM_F32LE_DEMUXER 1
+#define CONFIG_PCM_S32BE_DEMUXER 1
+#define CONFIG_PCM_S32LE_DEMUXER 1
+#define CONFIG_PCM_S24BE_DEMUXER 1
+#define CONFIG_PCM_S24LE_DEMUXER 1
+#define CONFIG_PCM_S16BE_DEMUXER 1
+#define CONFIG_PCM_S16LE_DEMUXER 1
+#define CONFIG_PCM_S8_DEMUXER 1
+#define CONFIG_PCM_U32BE_DEMUXER 1
+#define CONFIG_PCM_U32LE_DEMUXER 1
+#define CONFIG_PCM_U24BE_DEMUXER 1
+#define CONFIG_PCM_U24LE_DEMUXER 1
+#define CONFIG_PCM_U16BE_DEMUXER 1
+#define CONFIG_PCM_U16LE_DEMUXER 1
+#define CONFIG_PCM_U8_DEMUXER 1
+#define CONFIG_PJS_DEMUXER 1
+#define CONFIG_PMP_DEMUXER 1
+#define CONFIG_PVA_DEMUXER 1
+#define CONFIG_PVF_DEMUXER 1
+#define CONFIG_QCP_DEMUXER 1
+#define CONFIG_R3D_DEMUXER 1
+#define CONFIG_RAWVIDEO_DEMUXER 1
+#define CONFIG_REALTEXT_DEMUXER 1
+#define CONFIG_REDSPARK_DEMUXER 1
+#define CONFIG_RL2_DEMUXER 1
+#define CONFIG_RM_DEMUXER 1
+#define CONFIG_ROQ_DEMUXER 1
+#define CONFIG_RPL_DEMUXER 1
+#define CONFIG_RSD_DEMUXER 1
+#define CONFIG_RSO_DEMUXER 1
+#define CONFIG_RTP_DEMUXER 1
+#define CONFIG_RTSP_DEMUXER 1
+#define CONFIG_S337M_DEMUXER 1
+#define CONFIG_SAMI_DEMUXER 1
+#define CONFIG_SAP_DEMUXER 1
+#define CONFIG_SBC_DEMUXER 1
+#define CONFIG_SBG_DEMUXER 1
+#define CONFIG_SCC_DEMUXER 1
+#define CONFIG_SDP_DEMUXER 1
+#define CONFIG_SDR2_DEMUXER 1
+#define CONFIG_SDS_DEMUXER 1
+#define CONFIG_SDX_DEMUXER 1
+#define CONFIG_SEGAFILM_DEMUXER 1
+#define CONFIG_SER_DEMUXER 1
+#define CONFIG_SHORTEN_DEMUXER 1
+#define CONFIG_SIFF_DEMUXER 1
+#define CONFIG_SLN_DEMUXER 1
+#define CONFIG_SMACKER_DEMUXER 1
+#define CONFIG_SMJPEG_DEMUXER 1
+#define CONFIG_SMUSH_DEMUXER 1
+#define CONFIG_SOL_DEMUXER 1
+#define CONFIG_SOX_DEMUXER 1
+#define CONFIG_SPDIF_DEMUXER 1
+#define CONFIG_SRT_DEMUXER 1
+#define CONFIG_STR_DEMUXER 1
+#define CONFIG_STL_DEMUXER 1
+#define CONFIG_SUBVIEWER1_DEMUXER 1
+#define CONFIG_SUBVIEWER_DEMUXER 1
+#define CONFIG_SUP_DEMUXER 1
+#define CONFIG_SVAG_DEMUXER 1
+#define CONFIG_SWF_DEMUXER 1
+#define CONFIG_TAK_DEMUXER 1
+#define CONFIG_TEDCAPTIONS_DEMUXER 1
+#define CONFIG_THP_DEMUXER 1
+#define CONFIG_THREEDOSTR_DEMUXER 1
+#define CONFIG_TIERTEXSEQ_DEMUXER 1
+#define CONFIG_TMV_DEMUXER 1
+#define CONFIG_TRUEHD_DEMUXER 1
+#define CONFIG_TTA_DEMUXER 1
+#define CONFIG_TXD_DEMUXER 1
+#define CONFIG_TTY_DEMUXER 1
+#define CONFIG_TY_DEMUXER 1
+#define CONFIG_V210_DEMUXER 1
+#define CONFIG_V210X_DEMUXER 1
+#define CONFIG_VAG_DEMUXER 1
+#define CONFIG_VC1_DEMUXER 1
+#define CONFIG_VC1T_DEMUXER 1
+#define CONFIG_VIVIDAS_DEMUXER 1
+#define CONFIG_VIVO_DEMUXER 1
+#define CONFIG_VMD_DEMUXER 1
+#define CONFIG_VOBSUB_DEMUXER 1
+#define CONFIG_VOC_DEMUXER 1
+#define CONFIG_VPK_DEMUXER 1
+#define CONFIG_VPLAYER_DEMUXER 1
+#define CONFIG_VQF_DEMUXER 1
+#define CONFIG_W64_DEMUXER 1
+#define CONFIG_WAV_DEMUXER 1
+#define CONFIG_WC3_DEMUXER 1
+#define CONFIG_WEBM_DASH_MANIFEST_DEMUXER 1
+#define CONFIG_WEBVTT_DEMUXER 1
+#define CONFIG_WSAUD_DEMUXER 1
+#define CONFIG_WSD_DEMUXER 1
+#define CONFIG_WSVQA_DEMUXER 1
+#define CONFIG_WTV_DEMUXER 1
+#define CONFIG_WVE_DEMUXER 1
+#define CONFIG_WV_DEMUXER 1
+#define CONFIG_XA_DEMUXER 1
+#define CONFIG_XBIN_DEMUXER 1
+#define CONFIG_XMV_DEMUXER 1
+#define CONFIG_XVAG_DEMUXER 1
+#define CONFIG_XWMA_DEMUXER 1
+#define CONFIG_YOP_DEMUXER 1
+#define CONFIG_YUV4MPEGPIPE_DEMUXER 1
+#define CONFIG_IMAGE_BMP_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_DDS_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_DPX_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_EXR_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_GIF_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_J2K_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_JPEG_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PAM_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PBM_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PCX_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PGMYUV_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PGM_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PICTOR_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PNG_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PPM_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_PSD_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_QDRAW_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_SGI_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_SVG_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_SUNRAST_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_TIFF_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_WEBP_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_XPM_PIPE_DEMUXER 1
+#define CONFIG_IMAGE_XWD_PIPE_DEMUXER 1
+#define CONFIG_LIBGME_DEMUXER 0
+#define CONFIG_LIBMODPLUG_DEMUXER 0
+#define CONFIG_LIBOPENMPT_DEMUXER 0
+#define CONFIG_VAPOURSYNTH_DEMUXER 0
+#define CONFIG_A64_MUXER 1
+#define CONFIG_AC3_MUXER 1
+#define CONFIG_ADTS_MUXER 1
+#define CONFIG_ADX_MUXER 1
+#define CONFIG_AIFF_MUXER 1
+#define CONFIG_AMR_MUXER 1
+#define CONFIG_APNG_MUXER 1
+#define CONFIG_APTX_MUXER 1
+#define CONFIG_APTX_HD_MUXER 1
+#define CONFIG_ASF_MUXER 1
+#define CONFIG_ASS_MUXER 1
+#define CONFIG_AST_MUXER 1
+#define CONFIG_ASF_STREAM_MUXER 1
+#define CONFIG_AU_MUXER 1
+#define CONFIG_AVI_MUXER 1
+#define CONFIG_AVM2_MUXER 1
+#define CONFIG_AVS2_MUXER 1
+#define CONFIG_BIT_MUXER 1
+#define CONFIG_CAF_MUXER 1
+#define CONFIG_CAVSVIDEO_MUXER 1
+#define CONFIG_CODEC2_MUXER 1
+#define CONFIG_CODEC2RAW_MUXER 1
+#define CONFIG_CRC_MUXER 1
+#define CONFIG_DASH_MUXER 1
+#define CONFIG_DATA_MUXER 1
+#define CONFIG_DAUD_MUXER 1
+#define CONFIG_DIRAC_MUXER 1
+#define CONFIG_DNXHD_MUXER 1
+#define CONFIG_DTS_MUXER 1
+#define CONFIG_DV_MUXER 1
+#define CONFIG_EAC3_MUXER 1
+#define CONFIG_F4V_MUXER 1
+#define CONFIG_FFMETADATA_MUXER 1
+#define CONFIG_FIFO_MUXER 0
+#define CONFIG_FIFO_TEST_MUXER 1
+#define CONFIG_FILMSTRIP_MUXER 1
+#define CONFIG_FITS_MUXER 1
+#define CONFIG_FLAC_MUXER 1
+#define CONFIG_FLV_MUXER 1
+#define CONFIG_FRAMECRC_MUXER 1
+#define CONFIG_FRAMEHASH_MUXER 1
+#define CONFIG_FRAMEMD5_MUXER 1
+#define CONFIG_G722_MUXER 1
+#define CONFIG_G723_1_MUXER 1
+#define CONFIG_G726_MUXER 1
+#define CONFIG_G726LE_MUXER 1
+#define CONFIG_GIF_MUXER 1
+#define CONFIG_GSM_MUXER 1
+#define CONFIG_GXF_MUXER 1
+#define CONFIG_H261_MUXER 1
+#define CONFIG_H263_MUXER 1
+#define CONFIG_H264_MUXER 1
+#define CONFIG_HASH_MUXER 1
+#define CONFIG_HDS_MUXER 1
+#define CONFIG_HEVC_MUXER 1
+#define CONFIG_HLS_MUXER 1
+#define CONFIG_ICO_MUXER 1
+#define CONFIG_ILBC_MUXER 1
+#define CONFIG_IMAGE2_MUXER 1
+#define CONFIG_IMAGE2PIPE_MUXER 1
+#define CONFIG_IPOD_MUXER 1
+#define CONFIG_IRCAM_MUXER 1
+#define CONFIG_ISMV_MUXER 1
+#define CONFIG_IVF_MUXER 1
+#define CONFIG_JACOSUB_MUXER 1
+#define CONFIG_LATM_MUXER 1
+#define CONFIG_LRC_MUXER 1
+#define CONFIG_M4V_MUXER 1
+#define CONFIG_MD5_MUXER 1
+#define CONFIG_MATROSKA_MUXER 1
+#define CONFIG_MATROSKA_AUDIO_MUXER 1
+#define CONFIG_MICRODVD_MUXER 1
+#define CONFIG_MJPEG_MUXER 1
+#define CONFIG_MLP_MUXER 1
+#define CONFIG_MMF_MUXER 1
+#define CONFIG_MOV_MUXER 1
+#define CONFIG_MP2_MUXER 1
+#define CONFIG_MP3_MUXER 1
+#define CONFIG_MP4_MUXER 1
+#define CONFIG_MPEG1SYSTEM_MUXER 1
+#define CONFIG_MPEG1VCD_MUXER 1
+#define CONFIG_MPEG1VIDEO_MUXER 1
+#define CONFIG_MPEG2DVD_MUXER 1
+#define CONFIG_MPEG2SVCD_MUXER 1
+#define CONFIG_MPEG2VIDEO_MUXER 1
+#define CONFIG_MPEG2VOB_MUXER 1
+#define CONFIG_MPEGTS_MUXER 1
+#define CONFIG_MPJPEG_MUXER 1
+#define CONFIG_MXF_MUXER 1
+#define CONFIG_MXF_D10_MUXER 1
+#define CONFIG_MXF_OPATOM_MUXER 1
+#define CONFIG_NULL_MUXER 1
+#define CONFIG_NUT_MUXER 1
+#define CONFIG_OGA_MUXER 1
+#define CONFIG_OGG_MUXER 1
+#define CONFIG_OGV_MUXER 1
+#define CONFIG_OMA_MUXER 1
+#define CONFIG_OPUS_MUXER 1
+#define CONFIG_PCM_ALAW_MUXER 1
+#define CONFIG_PCM_MULAW_MUXER 1
+#define CONFIG_PCM_VIDC_MUXER 1
+#define CONFIG_PCM_F64BE_MUXER 1
+#define CONFIG_PCM_F64LE_MUXER 1
+#define CONFIG_PCM_F32BE_MUXER 1
+#define CONFIG_PCM_F32LE_MUXER 1
+#define CONFIG_PCM_S32BE_MUXER 1
+#define CONFIG_PCM_S32LE_MUXER 1
+#define CONFIG_PCM_S24BE_MUXER 1
+#define CONFIG_PCM_S24LE_MUXER 1
+#define CONFIG_PCM_S16BE_MUXER 1
+#define CONFIG_PCM_S16LE_MUXER 1
+#define CONFIG_PCM_S8_MUXER 1
+#define CONFIG_PCM_U32BE_MUXER 1
+#define CONFIG_PCM_U32LE_MUXER 1
+#define CONFIG_PCM_U24BE_MUXER 1
+#define CONFIG_PCM_U24LE_MUXER 1
+#define CONFIG_PCM_U16BE_MUXER 1
+#define CONFIG_PCM_U16LE_MUXER 1
+#define CONFIG_PCM_U8_MUXER 1
+#define CONFIG_PSP_MUXER 1
+#define CONFIG_RAWVIDEO_MUXER 1
+#define CONFIG_RM_MUXER 1
+#define CONFIG_ROQ_MUXER 1
+#define CONFIG_RSO_MUXER 1
+#define CONFIG_RTP_MUXER 1
+#define CONFIG_RTP_MPEGTS_MUXER 1
+#define CONFIG_RTSP_MUXER 1
+#define CONFIG_SAP_MUXER 1
+#define CONFIG_SBC_MUXER 1
+#define CONFIG_SCC_MUXER 1
+#define CONFIG_SEGAFILM_MUXER 1
+#define CONFIG_SEGMENT_MUXER 1
+#define CONFIG_STREAM_SEGMENT_MUXER 1
+#define CONFIG_SINGLEJPEG_MUXER 1
+#define CONFIG_SMJPEG_MUXER 1
+#define CONFIG_SMOOTHSTREAMING_MUXER 1
+#define CONFIG_SOX_MUXER 1
+#define CONFIG_SPX_MUXER 1
+#define CONFIG_SPDIF_MUXER 1
+#define CONFIG_SRT_MUXER 1
+#define CONFIG_SUP_MUXER 1
+#define CONFIG_SWF_MUXER 1
+#define CONFIG_TEE_MUXER 1
+#define CONFIG_TG2_MUXER 1
+#define CONFIG_TGP_MUXER 1
+#define CONFIG_MKVTIMESTAMP_V2_MUXER 1
+#define CONFIG_TRUEHD_MUXER 1
+#define CONFIG_TTA_MUXER 1
+#define CONFIG_UNCODEDFRAMECRC_MUXER 1
+#define CONFIG_VC1_MUXER 1
+#define CONFIG_VC1T_MUXER 1
+#define CONFIG_VOC_MUXER 1
+#define CONFIG_W64_MUXER 1
+#define CONFIG_WAV_MUXER 1
+#define CONFIG_WEBM_MUXER 1
+#define CONFIG_WEBM_DASH_MANIFEST_MUXER 1
+#define CONFIG_WEBM_CHUNK_MUXER 1
+#define CONFIG_WEBP_MUXER 1
+#define CONFIG_WEBVTT_MUXER 1
+#define CONFIG_WTV_MUXER 1
+#define CONFIG_WV_MUXER 1
+#define CONFIG_YUV4MPEGPIPE_MUXER 1
+#define CONFIG_CHROMAPRINT_MUXER 0
+#define CONFIG_ASYNC_PROTOCOL 0
+#define CONFIG_BLURAY_PROTOCOL 0
+#define CONFIG_CACHE_PROTOCOL 1
+#define CONFIG_CONCAT_PROTOCOL 1
+#define CONFIG_CRYPTO_PROTOCOL 1
+#define CONFIG_DATA_PROTOCOL 1
+#define CONFIG_FFRTMPCRYPT_PROTOCOL 0
+#define CONFIG_FFRTMPHTTP_PROTOCOL 1
+#define CONFIG_FILE_PROTOCOL 1
+#define CONFIG_FTP_PROTOCOL 1
+#define CONFIG_GOPHER_PROTOCOL 1
+#define CONFIG_HLS_PROTOCOL 1
+#define CONFIG_HTTP_PROTOCOL 1
+#define CONFIG_HTTPPROXY_PROTOCOL 1
+#define CONFIG_HTTPS_PROTOCOL 0
+#define CONFIG_ICECAST_PROTOCOL 1
+#define CONFIG_MMSH_PROTOCOL 1
+#define CONFIG_MMST_PROTOCOL 1
+#define CONFIG_MD5_PROTOCOL 1
+#define CONFIG_PIPE_PROTOCOL 1
+#define CONFIG_PROMPEG_PROTOCOL 1
+#define CONFIG_RTMP_PROTOCOL 1
+#define CONFIG_RTMPE_PROTOCOL 0
+#define CONFIG_RTMPS_PROTOCOL 0
+#define CONFIG_RTMPT_PROTOCOL 1
+#define CONFIG_RTMPTE_PROTOCOL 0
+#define CONFIG_RTMPTS_PROTOCOL 0
+#define CONFIG_RTP_PROTOCOL 1
+#define CONFIG_SCTP_PROTOCOL 0
+#define CONFIG_SRTP_PROTOCOL 1
+#define CONFIG_SUBFILE_PROTOCOL 1
+#define CONFIG_TEE_PROTOCOL 1
+#define CONFIG_TCP_PROTOCOL 1
+#define CONFIG_TLS_PROTOCOL 0
+#define CONFIG_UDP_PROTOCOL 1
+#define CONFIG_UDPLITE_PROTOCOL 1
+#define CONFIG_UNIX_PROTOCOL 0
+#define CONFIG_LIBRTMP_PROTOCOL 0
+#define CONFIG_LIBRTMPE_PROTOCOL 0
+#define CONFIG_LIBRTMPS_PROTOCOL 0
+#define CONFIG_LIBRTMPT_PROTOCOL 0
+#define CONFIG_LIBRTMPTE_PROTOCOL 0
+#define CONFIG_LIBSRT_PROTOCOL 0
+#define CONFIG_LIBSSH_PROTOCOL 0
+#define CONFIG_LIBSMBCLIENT_PROTOCOL 0
+#endif /* FFMPEG_CONFIG_H */
@@ -0,0 +1,4930 @@
+ * @file
+ * multimedia converter based on the FFmpeg libraries
+#include <ctype.h>
+#include <limits.h>
+#include <stdatomic.h>
+#if HAVE_IO_H
+#include <io.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#include "libavutil/channel_layout.h"
+#include "libavutil/samplefmt.h"
+#include "libavutil/fifo.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/timestamp.h"
+#include "libavutil/time.h"
+#include "libavutil/thread.h"
+#include "libavutil/threadmessage.h"
+#include "libavcodec/mathops.h"
+#include "libavformat/os_support.h"
+# include "libavfilter/avfilter.h"
+# include "libavfilter/buffersrc.h"
+# include "libavfilter/buffersink.h"
+#include <sys/types.h>
+#elif HAVE_GETPROCESSTIMES
+#if HAVE_GETPROCESSMEMORYINFO
+#include <psapi.h>
+#if HAVE_SETCONSOLECTRLHANDLER
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#if HAVE_TERMIOS_H
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#elif HAVE_KBHIT
+#include <conio.h>
+#include <time.h>
+#include "ffmpeg.h"
+///自己添加的-begin
+#include "libavresample/version.h"
+unsigned avresample_version(void)
+ return LIBAVRESAMPLE_VERSION_INT;
+const char *avresample_configuration(void)
+ return FFMPEG_CONFIGURATION;
+///自己添加的-end
+const char program_name[] = "ffmpeg";
+const int program_birth_year = 2000;
+static FILE *vstats_file;
+const char *const forced_keyframes_const_names[] = {
+ "n",
+ "n_forced",
+ "prev_forced_n",
+ "prev_forced_t",
+ "t",
+ NULL
+typedef struct BenchmarkTimeStamps {
+ int64_t real_usec;
+ int64_t user_usec;
+ int64_t sys_usec;
+} BenchmarkTimeStamps;
+static void do_video_stats(OutputStream *ost, int frame_size);
+static BenchmarkTimeStamps get_benchmark_time_stamps(void);
+static int64_t getmaxrss(void);
+static int ifilter_has_all_input_formats(FilterGraph *fg);
+static int run_as_daemon = 0;
+static int nb_frames_dup = 0;
+static unsigned dup_warning = 1000;
+static int nb_frames_drop = 0;
+static int64_t decode_error_stat[2];
+static int want_sdp = 1;
+static BenchmarkTimeStamps current_time;
+AVIOContext *progress_avio = NULL;
+static uint8_t *subtitle_out;
+InputStream **input_streams = NULL;
+int nb_input_streams = 0;
+InputFile **input_files = NULL;
+int nb_input_files = 0;
+OutputStream **output_streams = NULL;
+int nb_output_streams = 0;
+OutputFile **output_files = NULL;
+int nb_output_files = 0;
+FilterGraph **filtergraphs;
+int nb_filtergraphs;
+/* init terminal so that we can grab keys */
+static struct termios oldtty;
+static int restore_tty;
+#if HAVE_THREADS
+static void free_input_threads(void);
+/* sub2video hack:
+ Convert subtitles to video with alpha to insert them in filter graphs.
+ This is a temporary solution until libavfilter gets real subtitles support.
+static int sub2video_get_blank_frame(InputStream *ist)
+ AVFrame *frame = ist->sub2video.frame;
+ av_frame_unref(frame);
+ ist->sub2video.frame->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
+ ist->sub2video.frame->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
+ ist->sub2video.frame->format = AV_PIX_FMT_RGB32;
+ if ((ret = av_frame_get_buffer(frame, 32)) < 0)
+ memset(frame->data[0], 0, frame->height * frame->linesize[0]);
+static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h,
+ AVSubtitleRect *r)
+ uint32_t *pal, *dst2;
+ uint8_t *src, *src2;
+ int x, y;
+ if (r->type != SUBTITLE_BITMAP) {
+ av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n");
+ if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) {
+ av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) overflowing %d %d\n",
+ r->x, r->y, r->w, r->h, w, h
+ );
+ dst += r->y * dst_linesize + r->x * 4;
+ src = r->data[0];
+ pal = (uint32_t *)r->data[1];
+ for (y = 0; y < r->h; y++) {
+ dst2 = (uint32_t *)dst;
+ src2 = src;
+ for (x = 0; x < r->w; x++)
+ *(dst2++) = pal[*(src2++)];
+ dst += dst_linesize;
+ src += r->linesize[0];
+static void sub2video_push_ref(InputStream *ist, int64_t pts)
+ av_assert1(frame->data[0]);
+ ist->sub2video.last_pts = frame->pts = pts;
+ for (i = 0; i < ist->nb_filters; i++) {
+ ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, frame,
+ AV_BUFFERSRC_FLAG_KEEP_REF |
+ AV_BUFFERSRC_FLAG_PUSH);
+ if (ret != AVERROR_EOF && ret < 0)
+ av_log(NULL, AV_LOG_WARNING, "Error while add the frame to buffer source(%s).\n",
+void sub2video_update(InputStream *ist, AVSubtitle *sub)
+ int8_t *dst;
+ int dst_linesize;
+ int num_rects, i;
+ int64_t pts, end_pts;
+ if (!frame)
+ if (sub) {
+ pts = av_rescale_q(sub->pts + sub->start_display_time * 1000LL,
+ AV_TIME_BASE_Q, ist->st->time_base);
+ end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000LL,
+ num_rects = sub->num_rects;
+ pts = ist->sub2video.end_pts;
+ end_pts = INT64_MAX;
+ num_rects = 0;
+ if (sub2video_get_blank_frame(ist) < 0) {
+ av_log(ist->dec_ctx, AV_LOG_ERROR,
+ "Impossible to get a blank canvas.\n");
+ dst = frame->data [0];
+ dst_linesize = frame->linesize[0];
+ for (i = 0; i < num_rects; i++)
+ sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]);
+ sub2video_push_ref(ist, pts);
+ ist->sub2video.end_pts = end_pts;
+static void sub2video_heartbeat(InputStream *ist, int64_t pts)
+ InputFile *infile = input_files[ist->file_index];
+ int i, j, nb_reqs;
+ int64_t pts2;
+ /* When a frame is read from a file, examine all sub2video streams in
+ the same file and send the sub2video frame again. Otherwise, decoded
+ video frames could be accumulating in the filter graph while a filter
+ (possibly overlay) is desperately waiting for a subtitle frame. */
+ for (i = 0; i < infile->nb_streams; i++) {
+ InputStream *ist2 = input_streams[infile->ist_index + i];
+ if (!ist2->sub2video.frame)
+ /* subtitles seem to be usually muxed ahead of other streams;
+ if not, subtracting a larger time here is necessary */
+ pts2 = av_rescale_q(pts, ist->st->time_base, ist2->st->time_base) - 1;
+ /* do not send the heartbeat frame if the subtitle is already ahead */
+ if (pts2 <= ist2->sub2video.last_pts)
+ if (pts2 >= ist2->sub2video.end_pts ||
+ (!ist2->sub2video.frame->data[0] && ist2->sub2video.end_pts < INT64_MAX))
+ sub2video_update(ist2, NULL);
+ for (j = 0, nb_reqs = 0; j < ist2->nb_filters; j++)
+ nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->filters[j]->filter);
+ if (nb_reqs)
+ sub2video_push_ref(ist2, pts2);
+static void sub2video_flush(InputStream *ist)
+ if (ist->sub2video.end_pts < INT64_MAX)
+ sub2video_update(ist, NULL);
+ ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL);
+ av_log(NULL, AV_LOG_WARNING, "Flush the frame error.\n");
+/* end of sub2video hack */
+static void term_exit_sigsafe(void)
+ if(restore_tty)
+ tcsetattr (0, TCSANOW, &oldtty);
+void term_exit(void)
+ av_log(NULL, AV_LOG_QUIET, "%s", "");
+ term_exit_sigsafe();
+static volatile int received_sigterm = 0;
+static volatile int received_nb_signals = 0;
+static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
+static volatile int ffmpeg_exited = 0;
+static int main_return_code = 0;
+static void
+sigterm_handler(int sig)
+ received_sigterm = sig;
+ received_nb_signals++;
+ if(received_nb_signals > 3) {
+ ret = write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard exiting\n",
+ strlen("Received > 3 system signals, hard exiting\n"));
+ if (ret < 0) { /* Do nothing */ };
+ exit(123);
+static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
+ av_log(NULL, AV_LOG_DEBUG, "\nReceived windows signal %ld\n", fdwCtrlType);
+ switch (fdwCtrlType)
+ case CTRL_C_EVENT:
+ case CTRL_BREAK_EVENT:
+ sigterm_handler(SIGINT);
+ return TRUE;
+ case CTRL_CLOSE_EVENT:
+ case CTRL_LOGOFF_EVENT:
+ case CTRL_SHUTDOWN_EVENT:
+ sigterm_handler(SIGTERM);
+ /* Basically, with these 3 events, when we return from this method the
+ process is hard terminated, so stall as long as we need to
+ to try and let the main thread(s) clean up and gracefully terminate
+ (we have at most 5 seconds, but should be done far before that). */
+ while (!ffmpeg_exited) {
+ Sleep(0);
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Received unknown windows signal %ld\n", fdwCtrlType);
+ return FALSE;
+void term_init(void)
+ if (!run_as_daemon && stdin_interaction) {
+ struct termios tty;
+ if (tcgetattr (0, &tty) == 0) {
+ oldtty = tty;
+ restore_tty = 1;
+ tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
+ |INLCR|IGNCR|ICRNL|IXON);
+ tty.c_oflag |= OPOST;
+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+ tty.c_cflag &= ~(CSIZE|PARENB);
+ tty.c_cflag |= CS8;
+ tty.c_cc[VMIN] = 1;
+ tty.c_cc[VTIME] = 0;
+ tcsetattr (0, TCSANOW, &tty);
+ signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
+ signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
+ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
+#ifdef SIGXCPU
+ signal(SIGXCPU, sigterm_handler);
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
+/* read a key without blocking */
+static int read_key(void)
+ unsigned char ch;
+ int n = 1;
+ struct timeval tv;
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ n = select(1, &rfds, NULL, NULL, &tv);
+ if (n > 0) {
+ n = read(0, &ch, 1);
+ if (n == 1)
+ return ch;
+ return n;
+# if HAVE_PEEKNAMEDPIPE
+ static int is_pipe;
+ static HANDLE input_handle;
+ DWORD dw, nchars;
+ if(!input_handle){
+ input_handle = GetStdHandle(STD_INPUT_HANDLE);
+ is_pipe = !GetConsoleMode(input_handle, &dw);
+ if (is_pipe) {
+ /* When running under a GUI, you will end here. */
+ if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) {
+ // input pipe may have been closed by the program that ran ffmpeg
+ //Read it
+ if(nchars != 0) {
+ read(0, &ch, 1);
+ }else{
+# endif
+ if(kbhit())
+ return(getch());
+static int decode_interrupt_cb(void *ctx)
+ return received_nb_signals > atomic_load(&transcode_init_done);
+const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
+static void ffmpeg_cleanup(int ret)
+ if (do_benchmark) {
+ int maxrss = getmaxrss() / 1024;
+ av_log(NULL, AV_LOG_INFO, "bench: maxrss=%ikB\n", maxrss);
+ for (i = 0; i < nb_filtergraphs; i++) {
+ FilterGraph *fg = filtergraphs[i];
+ avfilter_graph_free(&fg->graph);
+ for (j = 0; j < fg->nb_inputs; j++) {
+ while (av_fifo_size(fg->inputs[j]->frame_queue)) {
+ AVFrame *frame;
+ av_fifo_generic_read(fg->inputs[j]->frame_queue, &frame,
+ sizeof(frame), NULL);
+ av_frame_free(&frame);
+ av_fifo_freep(&fg->inputs[j]->frame_queue);
+ if (fg->inputs[j]->ist->sub2video.sub_queue) {
+ while (av_fifo_size(fg->inputs[j]->ist->sub2video.sub_queue)) {
+ AVSubtitle sub;
+ av_fifo_generic_read(fg->inputs[j]->ist->sub2video.sub_queue,
+ &sub, sizeof(sub), NULL);
+ avsubtitle_free(&sub);
+ av_fifo_freep(&fg->inputs[j]->ist->sub2video.sub_queue);
+ av_buffer_unref(&fg->inputs[j]->hw_frames_ctx);
+ av_freep(&fg->inputs[j]->name);
+ av_freep(&fg->inputs[j]);
+ av_freep(&fg->inputs);
+ for (j = 0; j < fg->nb_outputs; j++) {
+ av_freep(&fg->outputs[j]->name);
+ av_freep(&fg->outputs[j]->formats);
+ av_freep(&fg->outputs[j]->channel_layouts);
+ av_freep(&fg->outputs[j]->sample_rates);
+ av_freep(&fg->outputs[j]);
+ av_freep(&fg->outputs);
+ av_freep(&fg->graph_desc);
+ av_freep(&filtergraphs[i]);
+ av_freep(&filtergraphs);
+ av_freep(&subtitle_out);
+ /* close files */
+ for (i = 0; i < nb_output_files; i++) {
+ OutputFile *of = output_files[i];
+ AVFormatContext *s;
+ if (!of)
+ s = of->ctx;
+ if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))
+ avio_closep(&s->pb);
+ avformat_free_context(s);
+ av_dict_free(&of->opts);
+ av_freep(&output_files[i]);
+ for (i = 0; i < nb_output_streams; i++) {
+ OutputStream *ost = output_streams[i];
+ if (!ost)
+ for (j = 0; j < ost->nb_bitstream_filters; j++)
+ av_bsf_free(&ost->bsf_ctx[j]);
+ av_freep(&ost->bsf_ctx);
+ av_frame_free(&ost->filtered_frame);
+ av_frame_free(&ost->last_frame);
+ av_dict_free(&ost->encoder_opts);
+ av_freep(&ost->forced_keyframes);
+ av_expr_free(ost->forced_keyframes_pexpr);
+ av_freep(&ost->avfilter);
+ av_freep(&ost->logfile_prefix);
+ av_freep(&ost->audio_channels_map);
+ ost->audio_channels_mapped = 0;
+ av_dict_free(&ost->sws_dict);
+ av_dict_free(&ost->swr_opts);
+ avcodec_free_context(&ost->enc_ctx);
+ avcodec_parameters_free(&ost->ref_par);
+ if (ost->muxing_queue) {
+ while (av_fifo_size(ost->muxing_queue)) {
+ AVPacket pkt;
+ av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+ av_packet_unref(&pkt);
+ av_fifo_freep(&ost->muxing_queue);
+ av_freep(&output_streams[i]);
+ free_input_threads();
+ for (i = 0; i < nb_input_files; i++) {
+ avformat_close_input(&input_files[i]->ctx);
+ av_freep(&input_files[i]);
+ for (i = 0; i < nb_input_streams; i++) {
+ InputStream *ist = input_streams[i];
+ av_frame_free(&ist->decoded_frame);
+ av_frame_free(&ist->filter_frame);
+ av_dict_free(&ist->decoder_opts);
+ avsubtitle_free(&ist->prev_sub.subtitle);
+ av_frame_free(&ist->sub2video.frame);
+ av_freep(&ist->filters);
+ av_freep(&ist->hwaccel_device);
+ av_freep(&ist->dts_buffer);
+ avcodec_free_context(&ist->dec_ctx);
+ av_freep(&input_streams[i]);
+ if (vstats_file) {
+ if (fclose(vstats_file))
+ "Error closing vstats file, loss of information possible: %s\n",
+ av_err2str(AVERROR(errno)));
+ av_freep(&vstats_filename);
+ av_freep(&input_streams);
+ av_freep(&input_files);
+ av_freep(&output_streams);
+ av_freep(&output_files);
+ avformat_network_deinit();
+ if (received_sigterm) {
+ av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
+ (int) received_sigterm);
+ } else if (ret && atomic_load(&transcode_init_done)) {
+ av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
+ term_exit();
+ ffmpeg_exited = 1;
+void remove_avoptions(AVDictionary **a, AVDictionary *b)
+ while ((t = av_dict_get(b, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE);
+void assert_avoptions(AVDictionary *m)
+ AVDictionaryEntry *t;
+ if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
+static void abort_codec_experimental(AVCodec *c, int encoder)
+static void update_benchmark(const char *fmt, ...)
+ if (do_benchmark_all) {
+ BenchmarkTimeStamps t = get_benchmark_time_stamps();
+ va_list va;
+ char buf[1024];
+ va_start(va, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, va);
+ va_end(va);
+ "bench: %8" PRIu64 " user %8" PRIu64 " sys %8" PRIu64 " real %s \n",
+ t.user_usec - current_time.user_usec,
+ t.sys_usec - current_time.sys_usec,
+ t.real_usec - current_time.real_usec, buf);
+ current_time = t;
+static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others)
+ OutputStream *ost2 = output_streams[i];
+ ost2->finished |= ost == ost2 ? this_stream : others;
+static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
+ AVFormatContext *s = of->ctx;
+ AVStream *st = ost->st;
+ /*
+ * Audio encoders may split the packets -- #frames in != #packets out.
+ * But there is no reordering, so we can limit the number of output packets
+ * by simply dropping them here.
+ * Counting encoded video frames needs to be done separately because of
+ * reordering, see do_video_out().
+ * Do not count the packet when unqueued because it has been counted when queued.
+ if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) {
+ if (ost->frame_number >= ost->max_frames) {
+ av_packet_unref(pkt);
+ ost->frame_number++;
+ if (!of->header_written) {
+ AVPacket tmp_pkt = {0};
+ /* the muxer is not initialized yet, buffer the packet */
+ if (!av_fifo_space(ost->muxing_queue)) {
+ int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
+ ost->max_muxing_queue_size);
+ if (new_size <= av_fifo_size(ost->muxing_queue)) {
+ "Too many packets buffered for output stream %d:%d.\n",
+ ost->file_index, ost->st->index);
+ ret = av_fifo_realloc2(ost->muxing_queue, new_size);
+ ret = av_packet_make_refcounted(pkt);
+ av_packet_move_ref(&tmp_pkt, pkt);
+ av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);
+ if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) ||
+ (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
+ pkt->pts = pkt->dts = AV_NOPTS_VALUE;
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+ uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
+ NULL);
+ ost->quality = sd ? AV_RL32(sd) : -1;
+ ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
+ for (i = 0; i<FF_ARRAY_ELEMS(ost->error); i++) {
+ if (sd && i < sd[5])
+ ost->error[i] = AV_RL64(sd + 8 + 8*i);
+ ost->error[i] = -1;
+ if (ost->frame_rate.num && ost->is_cfr) {
+ if (pkt->duration > 0)
+ av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n");
+ pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),
+ ost->mux_timebase);
+ av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);
+ if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
+ if (pkt->dts != AV_NOPTS_VALUE &&
+ pkt->pts != AV_NOPTS_VALUE &&
+ pkt->dts > pkt->pts) {
+ av_log(s, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64" in output stream %d:%d, replacing by guess\n",
+ pkt->dts, pkt->pts,
+ pkt->pts =
+ pkt->dts = pkt->pts + pkt->dts + ost->last_mux_dts + 1
+ - FFMIN3(pkt->pts, pkt->dts, ost->last_mux_dts + 1)
+ - FFMAX3(pkt->pts, pkt->dts, ost->last_mux_dts + 1);
+ if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) &&
+ pkt->dts != AV_NOPTS_VALUE &&
+ !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) &&
+ ost->last_mux_dts != AV_NOPTS_VALUE) {
+ int64_t max = ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);
+ if (pkt->dts < max) {
+ int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
+ av_log(s, loglevel, "Non-monotonous DTS in output stream "
+ "%d:%d; previous: %"PRId64", current: %"PRId64"; ",
+ ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts);
+ if (exit_on_error) {
+ av_log(NULL, AV_LOG_FATAL, "aborting.\n");
+ av_log(s, loglevel, "changing to %"PRId64". This may result "
+ "in incorrect timestamps in the output file.\n",
+ max);
+ if (pkt->pts >= pkt->dts)
+ pkt->pts = FFMAX(pkt->pts, max);
+ pkt->dts = max;
+ ost->last_mux_dts = pkt->dts;
+ ost->data_size += pkt->size;
+ ost->packets_written++;
+ pkt->stream_index = ost->index;
+ if (debug_ts) {
+ av_log(NULL, AV_LOG_INFO, "muxer <- type:%s "
+ "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n",
+ av_get_media_type_string(ost->enc_ctx->codec_type),
+ av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base),
+ av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base),
+ pkt->size
+ ret = av_interleaved_write_frame(s, pkt);
+ print_error("av_interleaved_write_frame()", ret);
+ main_return_code = 1;
+ close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED);
+static void close_output_stream(OutputStream *ost)
+ OutputFile *of = output_files[ost->file_index];
+ ost->finished |= ENCODER_FINISHED;
+ if (of->shortest) {
+ int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, AV_TIME_BASE_Q);
+ of->recording_time = FFMIN(of->recording_time, end);
+ * Send a single packet to the output, applying any bitstream filters
+ * associated with the output stream. This may result in any number
+ * of packets actually being written, depending on what bitstream
+ * filters are applied. The supplied packet is consumed and will be
+ * blank (as if newly-allocated) when this function returns.
+ * If eof is set, instead indicate EOF to all bitstream filters and
+ * therefore flush any delayed packets to the output. A blank packet
+ * must be supplied in this case.
+static void output_packet(OutputFile *of, AVPacket *pkt,
+ OutputStream *ost, int eof)
+ /* apply the output bitstream filters, if any */
+ if (ost->nb_bitstream_filters) {
+ int idx;
+ ret = av_bsf_send_packet(ost->bsf_ctx[0], eof ? NULL : pkt);
+ goto finish;
+ eof = 0;
+ idx = 1;
+ while (idx) {
+ /* get a packet from the previous filter up the chain */
+ ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
+ if (ret == AVERROR(EAGAIN)) {
+ idx--;
+ } else if (ret == AVERROR_EOF) {
+ eof = 1;
+ } else if (ret < 0)
+ /* send it to the next filter down the chain or to the muxer */
+ if (idx < ost->nb_bitstream_filters) {
+ ret = av_bsf_send_packet(ost->bsf_ctx[idx], eof ? NULL : pkt);
+ idx++;
+ } else if (eof)
+ write_packet(of, pkt, ost, 0);
+ } else if (!eof)
+finish:
+ if (ret < 0 && ret != AVERROR_EOF) {
+ av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "
+ "packet for stream #%d:%d.\n", ost->file_index, ost->index);
+ if(exit_on_error)
+static int check_recording_time(OutputStream *ost)
+ if (of->recording_time != INT64_MAX &&
+ av_compare_ts(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, of->recording_time,
+ AV_TIME_BASE_Q) >= 0) {
+ close_output_stream(ost);
+ return 1;
+static void do_audio_out(OutputFile *of, OutputStream *ost,
+ AVFrame *frame)
+ AVCodecContext *enc = ost->enc_ctx;
+ av_init_packet(&pkt);
+ pkt.data = NULL;
+ pkt.size = 0;
+ if (!check_recording_time(ost))
+ if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
+ frame->pts = ost->sync_opts;
+ ost->sync_opts = frame->pts + frame->nb_samples;
+ ost->samples_encoded += frame->nb_samples;
+ ost->frames_encoded++;
+ av_assert0(pkt.size || !pkt.data);
+ update_benchmark(NULL);
+ av_log(NULL, AV_LOG_INFO, "encoder <- type:audio "
+ "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
+ av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base),
+ enc->time_base.num, enc->time_base.den);
+ ret = avcodec_send_frame(enc, frame);
+ goto error;
+ while (1) {
+ ret = avcodec_receive_packet(enc, &pkt);
+ if (ret == AVERROR(EAGAIN))
+ update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
+ av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase);
+ av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
+ "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
+ av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base),
+ av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &enc->time_base));
+ output_packet(of, &pkt, ost, 0);
+error:
+ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
+static void do_subtitle_out(OutputFile *of,
+ OutputStream *ost,
+ AVSubtitle *sub)
+ int subtitle_out_max_size = 1024 * 1024;
+ int subtitle_out_size, nb, i;
+ AVCodecContext *enc;
+ int64_t pts;
+ if (sub->pts == AV_NOPTS_VALUE) {
+ av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
+ if (exit_on_error)
+ enc = ost->enc_ctx;
+ if (!subtitle_out) {
+ subtitle_out = av_malloc(subtitle_out_max_size);
+ av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
+ /* Note: DVB subtitle need one packet to draw them and one other
+ packet to clear them */
+ /* XXX: signal it in the codec context ? */
+ if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
+ nb = 2;
+ nb = 1;
+ /* shift timestamp to honor -ss and make check_recording_time() work with -t */
+ pts = sub->pts;
+ if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE)
+ pts -= output_files[ost->file_index]->start_time;
+ for (i = 0; i < nb; i++) {
+ unsigned save_num_rects = sub->num_rects;
+ ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
+ sub->pts = pts;
+ // start_display_time is required to be 0
+ sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
+ sub->end_display_time -= sub->start_display_time;
+ sub->start_display_time = 0;
+ if (i == 1)
+ sub->num_rects = 0;
+ subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
+ subtitle_out_max_size, sub);
+ sub->num_rects = save_num_rects;
+ if (subtitle_out_size < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
+ pkt.data = subtitle_out;
+ pkt.size = subtitle_out_size;
+ pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase);
+ pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
+ if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
+ /* XXX: the pts correction is handled here. Maybe handling
+ it in the codec would be better */
+ if (i == 0)
+ pkt.pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
+ pkt.pts += av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
+ pkt.dts = pkt.pts;
+static void do_video_out(OutputFile *of,
+ AVFrame *next_picture,
+ double sync_ipts)
+ int ret, format_video_sync;
+ AVCodecParameters *mux_par = ost->st->codecpar;
+ AVRational frame_rate;
+ int nb_frames, nb0_frames, i;
+ double delta, delta0;
+ double duration = 0;
+ int frame_size = 0;
+ InputStream *ist = NULL;
+ AVFilterContext *filter = ost->filter->filter;
+ if (ost->source_index >= 0)
+ ist = input_streams[ost->source_index];
+ frame_rate = av_buffersink_get_frame_rate(filter);
+ if (frame_rate.num > 0 && frame_rate.den > 0)
+ duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
+ if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
+ duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
+ if (!ost->filters_script &&
+ !ost->filters &&
+ (nb_filtergraphs == 0 || !filtergraphs[0]->graph_desc) &&
+ next_picture &&
+ ist &&
+ lrintf(next_picture->pkt_duration * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) {
+ duration = lrintf(next_picture->pkt_duration * av_q2d(ist->st->time_base) / av_q2d(enc->time_base));
+ if (!next_picture) {
+ //end, flushing
+ nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0],
+ ost->last_nb0_frames[1],
+ ost->last_nb0_frames[2]);
+ delta0 = sync_ipts - ost->sync_opts; // delta0 is the "drift" between the input frame (next_picture) and where it would fall in the output.
+ delta = delta0 + duration;
+ /* by default, we output a single frame */
+ nb0_frames = 0; // tracks the number of times the PREVIOUS frame should be duplicated, mostly for variable framerate (VFR)
+ nb_frames = 1;
+ format_video_sync = video_sync_method;
+ if (format_video_sync == VSYNC_AUTO) {
+ if(!strcmp(of->ctx->oformat->name, "avi")) {
+ format_video_sync = VSYNC_VFR;
+ format_video_sync = (of->ctx->oformat->flags & AVFMT_VARIABLE_FPS) ? ((of->ctx->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR;
+ if ( ist
+ && format_video_sync == VSYNC_CFR
+ && input_files[ist->file_index]->ctx->nb_streams == 1
+ && input_files[ist->file_index]->input_ts_offset == 0) {
+ format_video_sync = VSYNC_VSCFR;
+ if (format_video_sync == VSYNC_CFR && copy_ts) {
+ ost->is_cfr = (format_video_sync == VSYNC_CFR || format_video_sync == VSYNC_VSCFR);
+ if (delta0 < 0 &&
+ delta > 0 &&
+ format_video_sync != VSYNC_PASSTHROUGH &&
+ format_video_sync != VSYNC_DROP) {
+ if (delta0 < -0.6) {
+ av_log(NULL, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0);
+ av_log(NULL, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0);
+ sync_ipts = ost->sync_opts;
+ duration += delta0;
+ delta0 = 0;
+ switch (format_video_sync) {
+ case VSYNC_VSCFR:
+ if (ost->frame_number == 0 && delta0 >= 0.5) {
+ av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0));
+ delta = duration;
+ ost->sync_opts = lrint(sync_ipts);
+ case VSYNC_CFR:
+ // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
+ if (frame_drop_threshold && delta < frame_drop_threshold && ost->frame_number) {
+ nb_frames = 0;
+ } else if (delta < -1.1)
+ else if (delta > 1.1) {
+ nb_frames = lrintf(delta);
+ if (delta0 > 1.1)
+ nb0_frames = lrintf(delta0 - 0.6);
+ case VSYNC_VFR:
+ if (delta <= -0.6)
+ else if (delta > 0.6)
+ case VSYNC_DROP:
+ case VSYNC_PASSTHROUGH:
+ av_assert0(0);
+ nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);
+ nb0_frames = FFMIN(nb0_frames, nb_frames);
+ memmove(ost->last_nb0_frames + 1,
+ ost->last_nb0_frames,
+ sizeof(ost->last_nb0_frames[0]) * (FF_ARRAY_ELEMS(ost->last_nb0_frames) - 1));
+ ost->last_nb0_frames[0] = nb0_frames;
+ if (nb0_frames == 0 && ost->last_dropped) {
+ nb_frames_drop++;
+ av_log(NULL, AV_LOG_VERBOSE,
+ "*** dropping frame %d from stream %d at ts %"PRId64"\n",
+ ost->frame_number, ost->st->index, ost->last_frame->pts);
+ if (nb_frames > (nb0_frames && ost->last_dropped) + (nb_frames > nb0_frames)) {
+ if (nb_frames > dts_error_threshold * 30) {
+ av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skipping\n", nb_frames - 1);
+ nb_frames_dup += nb_frames - (nb0_frames && ost->last_dropped) - (nb_frames > nb0_frames);
+ av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1);
+ if (nb_frames_dup > dup_warning) {
+ av_log(NULL, AV_LOG_WARNING, "More than %d frames duplicated\n", dup_warning);
+ dup_warning *= 10;
+ ost->last_dropped = nb_frames == nb0_frames && next_picture;
+ /* duplicates frame if needed */
+ for (i = 0; i < nb_frames; i++) {
+ AVFrame *in_picture;
+ int forced_keyframe = 0;
+ double pts_time;
+ if (i < nb0_frames && ost->last_frame) {
+ in_picture = ost->last_frame;
+ in_picture = next_picture;
+ if (!in_picture)
+ in_picture->pts = ost->sync_opts;
+ if (enc->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&
+ ost->top_field_first >= 0)
+ in_picture->top_field_first = !!ost->top_field_first;
+ if (in_picture->interlaced_frame) {
+ if (enc->codec->id == AV_CODEC_ID_MJPEG)
+ mux_par->field_order = in_picture->top_field_first ? AV_FIELD_TT:AV_FIELD_BB;
+ mux_par->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
+ mux_par->field_order = AV_FIELD_PROGRESSIVE;
+ in_picture->quality = enc->global_quality;
+ in_picture->pict_type = 0;
+ if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&
+ in_picture->pts != AV_NOPTS_VALUE)
+ ost->forced_kf_ref_pts = in_picture->pts;
+ pts_time = in_picture->pts != AV_NOPTS_VALUE ?
+ (in_picture->pts - ost->forced_kf_ref_pts) * av_q2d(enc->time_base) : NAN;
+ if (ost->forced_kf_index < ost->forced_kf_count &&
+ in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
+ ost->forced_kf_index++;
+ forced_keyframe = 1;
+ } else if (ost->forced_keyframes_pexpr) {
+ double res;
+ ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
+ res = av_expr_eval(ost->forced_keyframes_pexpr,
+ ost->forced_keyframes_expr_const_values, NULL);
+ ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
+ ost->forced_keyframes_expr_const_values[FKF_N],
+ ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
+ ost->forced_keyframes_expr_const_values[FKF_T],
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
+ res);
+ if (res) {
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
+ ost->forced_keyframes_expr_const_values[FKF_N];
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
+ ost->forced_keyframes_expr_const_values[FKF_T];
+ ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
+ ost->forced_keyframes_expr_const_values[FKF_N] += 1;
+ } else if ( ost->forced_keyframes
+ && !strncmp(ost->forced_keyframes, "source", 6)
+ && in_picture->key_frame==1) {
+ if (forced_keyframe) {
+ in_picture->pict_type = AV_PICTURE_TYPE_I;
+ av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time);
+ av_log(NULL, AV_LOG_INFO, "encoder <- type:video "
+ av_ts2str(in_picture->pts), av_ts2timestr(in_picture->pts, &enc->time_base),
+ ret = avcodec_send_frame(enc, in_picture);
+ // Make sure Closed Captions will not be duplicated
+ av_frame_remove_side_data(in_picture, AV_FRAME_DATA_A53_CC);
+ update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
+ av_log(NULL, AV_LOG_INFO, "encoder -> type:video "
+ if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & AV_CODEC_CAP_DELAY))
+ pkt.pts = ost->sync_opts;
+ av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->mux_timebase),
+ av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->mux_timebase));
+ frame_size = pkt.size;
+ /* if two pass, output log */
+ if (ost->logfile && enc->stats_out) {
+ fprintf(ost->logfile, "%s", enc->stats_out);
+ ost->sync_opts++;
+ * For video, number of frames in == number of packets out.
+ * But there may be reordering, so we can't throw away frames on encoder
+ * flush, we need to limit them here, before they go into encoder.
+ if (vstats_filename && frame_size)
+ do_video_stats(ost, frame_size);
+ if (!ost->last_frame)
+ ost->last_frame = av_frame_alloc();
+ av_frame_unref(ost->last_frame);
+ if (next_picture && ost->last_frame)
+ av_frame_ref(ost->last_frame, next_picture);
+ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
+static double psnr(double d)
+ return -10.0 * log10(d);
+static void do_video_stats(OutputStream *ost, int frame_size)
+ int frame_number;
+ double ti1, bitrate, avg_bitrate;
+ /* this is executed just the first time do_video_stats is called */
+ if (!vstats_file) {
+ vstats_file = fopen(vstats_filename, "w");
+ perror("fopen");
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ frame_number = ost->st->nb_frames;
+ if (vstats_version <= 1) {
+ fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
+ ost->quality / (float)FF_QP2LAMBDA);
+ fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number,
+ if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
+ fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
+ fprintf(vstats_file,"f_size= %6d ", frame_size);
+ /* compute pts value */
+ ti1 = av_stream_get_end_pts(ost->st) * av_q2d(ost->st->time_base);
+ if (ti1 < 0.01)
+ ti1 = 0.01;
+ bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
+ avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0;
+ fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
+ (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate);
+ fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type));
+static int init_output_stream(OutputStream *ost, char *error, int error_len);
+static void finish_output_stream(OutputStream *ost)
+ ost->finished = ENCODER_FINISHED | MUXER_FINISHED;
+ for (i = 0; i < of->ctx->nb_streams; i++)
+ output_streams[of->ost_index + i]->finished = ENCODER_FINISHED | MUXER_FINISHED;
+ * Get and encode new output from any of the filtergraphs, without causing
+ * activity.
+ * @return 0 for success, <0 for severe errors
+static int reap_filters(int flush)
+ AVFrame *filtered_frame = NULL;
+ /* Reap all buffers present in the buffer sinks */
+ AVFilterContext *filter;
+ if (!ost->filter || !ost->filter->graph->graph)
+ filter = ost->filter->filter;
+ if (!ost->initialized) {
+ char error[1024] = "";
+ ret = init_output_stream(ost, error, sizeof(error));
+ av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n",
+ ost->file_index, ost->index, error);
+ if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) {
+ filtered_frame = ost->filtered_frame;
+ double float_pts = AV_NOPTS_VALUE; // this is identical to filtered_frame.pts but with higher precision
+ ret = av_buffersink_get_frame_flags(filter, filtered_frame,
+ AV_BUFFERSINK_FLAG_NO_REQUEST);
+ if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
+ av_log(NULL, AV_LOG_WARNING,
+ "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
+ } else if (flush && ret == AVERROR_EOF) {
+ if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
+ do_video_out(of, ost, NULL, AV_NOPTS_VALUE);
+ if (ost->finished) {
+ av_frame_unref(filtered_frame);
+ if (filtered_frame->pts != AV_NOPTS_VALUE) {
+ int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
+ AVRational filter_tb = av_buffersink_get_time_base(filter);
+ AVRational tb = enc->time_base;
+ int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
+ tb.den <<= extra_bits;
+ float_pts =
+ av_rescale_q(filtered_frame->pts, filter_tb, tb) -
+ av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
+ float_pts /= 1 << extra_bits;
+ // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers
+ float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
+ filtered_frame->pts =
+ av_rescale_q(filtered_frame->pts, filter_tb, enc->time_base) -
+ av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
+ switch (av_buffersink_get_type(filter)) {
+ if (!ost->frame_aspect_ratio.num)
+ enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
+ av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n",
+ av_ts2str(filtered_frame->pts), av_ts2timestr(filtered_frame->pts, &enc->time_base),
+ float_pts,
+ do_video_out(of, ost, filtered_frame, float_pts);
+ if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
+ enc->channels != filtered_frame->channels) {
+ "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
+ do_audio_out(of, ost, filtered_frame);
+ // TODO support subtitle filters
+static void print_final_stats(int64_t total_size)
+ uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
+ uint64_t subtitle_size = 0;
+ uint64_t data_size = 0;
+ float percent = -1.0;
+ int pass1_used = 1;
+ switch (ost->enc_ctx->codec_type) {
+ case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
+ case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
+ case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->data_size; break;
+ default: other_size += ost->data_size; break;
+ extra_size += ost->enc_ctx->extradata_size;
+ data_size += ost->data_size;
+ if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
+ != AV_CODEC_FLAG_PASS1)
+ pass1_used = 0;
+ if (data_size && total_size>0 && total_size >= data_size)
+ percent = 100.0 * (total_size - data_size) / data_size;
+ av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
+ video_size / 1024.0,
+ audio_size / 1024.0,
+ subtitle_size / 1024.0,
+ other_size / 1024.0,
+ extra_size / 1024.0);
+ if (percent >= 0.0)
+ av_log(NULL, AV_LOG_INFO, "%f%%", percent);
+ av_log(NULL, AV_LOG_INFO, "unknown");
+ av_log(NULL, AV_LOG_INFO, "\n");
+ /* print verbose per-stream stats */
+ InputFile *f = input_files[i];
+ uint64_t total_packets = 0, total_size = 0;
+ av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
+ i, f->ctx->url);
+ for (j = 0; j < f->nb_streams; j++) {
+ InputStream *ist = input_streams[f->ist_index + j];
+ enum AVMediaType type = ist->dec_ctx->codec_type;
+ total_size += ist->data_size;
+ total_packets += ist->nb_packets;
+ av_log(NULL, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
+ i, j, media_type_string(type));
+ av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
+ ist->nb_packets, ist->data_size);
+ if (ist->decoding_needed) {
+ av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
+ ist->frames_decoded);
+ if (type == AVMEDIA_TYPE_AUDIO)
+ av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+ av_log(NULL, AV_LOG_VERBOSE, "; ");
+ av_log(NULL, AV_LOG_VERBOSE, "\n");
+ av_log(NULL, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
+ total_packets, total_size);
+ av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
+ i, of->ctx->url);
+ for (j = 0; j < of->ctx->nb_streams; j++) {
+ OutputStream *ost = output_streams[of->ost_index + j];
+ enum AVMediaType type = ost->enc_ctx->codec_type;
+ total_size += ost->data_size;
+ total_packets += ost->packets_written;
+ av_log(NULL, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ",
+ if (ost->encoding_needed) {
+ av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
+ ost->frames_encoded);
+ av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
+ av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
+ ost->packets_written, ost->data_size);
+ av_log(NULL, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
+ if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
+ av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded ");
+ if (pass1_used) {
+ av_log(NULL, AV_LOG_WARNING, "\n");
+ av_log(NULL, AV_LOG_WARNING, "(check -ss / -t / -frames parameters if used)\n");
+static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
+ AVBPrint buf, buf_script;
+ OutputStream *ost;
+ AVFormatContext *oc;
+ int64_t total_size;
+ int frame_number, vid, i;
+ double bitrate;
+ double speed;
+ int64_t pts = INT64_MIN + 1;
+ static int64_t last_time = -1;
+ static int qp_histogram[52];
+ int hours, mins, secs, us;
+ const char *hours_sign;
+ float t;
+ if (!print_stats && !is_last_report && !progress_avio)
+ if (!is_last_report) {
+ if (last_time == -1) {
+ last_time = cur_time;
+ if ((cur_time - last_time) < 500000)
+ t = (cur_time-timer_start) / 1000000.0;
+ oc = output_files[0]->ctx;
+ total_size = avio_size(oc->pb);
+ if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too
+ total_size = avio_tell(oc->pb);
+ vid = 0;
+ av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ float q = -1;
+ ost = output_streams[i];
+ if (!ost->stream_copy)
+ q = ost->quality / (float) FF_QP2LAMBDA;
+ if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ av_bprintf(&buf, "q=%2.1f ", q);
+ av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
+ ost->file_index, ost->index, q);
+ if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ float fps;
+ frame_number = ost->frame_number;
+ fps = t > 1 ? frame_number / t : 0;
+ av_bprintf(&buf, "frame=%5d fps=%3.*f q=%3.1f ",
+ frame_number, fps < 9.95, fps, q);
+ av_bprintf(&buf_script, "frame=%d\n", frame_number);
+ av_bprintf(&buf_script, "fps=%.2f\n", fps);
+ if (is_last_report)
+ av_bprintf(&buf, "L");
+ if (qp_hist) {
+ int j;
+ int qp = lrintf(q);
+ if (qp >= 0 && qp < FF_ARRAY_ELEMS(qp_histogram))
+ qp_histogram[qp]++;
+ for (j = 0; j < 32; j++)
+ av_bprintf(&buf, "%X", av_log2(qp_histogram[j] + 1));
+ if ((enc->flags & AV_CODEC_FLAG_PSNR) && (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) {
+ double error, error_sum = 0;
+ double scale, scale_sum = 0;
+ double p;
+ char type[3] = { 'Y','U','V' };
+ av_bprintf(&buf, "PSNR=");
+ for (j = 0; j < 3; j++) {
+ if (is_last_report) {
+ error = enc->error[j];
+ scale = enc->width * enc->height * 255.0 * 255.0 * frame_number;
+ error = ost->error[j];
+ scale = enc->width * enc->height * 255.0 * 255.0;
+ if (j)
+ scale /= 4;
+ error_sum += error;
+ scale_sum += scale;
+ p = psnr(error / scale);
+ av_bprintf(&buf, "%c:%2.2f ", type[j], p);
+ av_bprintf(&buf_script, "stream_%d_%d_psnr_%c=%2.2f\n",
+ ost->file_index, ost->index, type[j] | 32, p);
+ p = psnr(error_sum / scale_sum);
+ av_bprintf(&buf, "*:%2.2f ", psnr(error_sum / scale_sum));
+ av_bprintf(&buf_script, "stream_%d_%d_psnr_all=%2.2f\n",
+ ost->file_index, ost->index, p);
+ vid = 1;
+ /* compute min output value */
+ if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
+ pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
+ ost->st->time_base, AV_TIME_BASE_Q));
+ nb_frames_drop += ost->last_dropped;
+ secs = FFABS(pts) / AV_TIME_BASE;
+ us = FFABS(pts) % AV_TIME_BASE;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
+ hours_sign = (pts < 0) ? "-" : "";
+ bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
+ speed = t != 0.0 ? (double)pts / AV_TIME_BASE / t : -1;
+ if (total_size < 0) av_bprintf(&buf, "size=N/A time=");
+ else av_bprintf(&buf, "size=%8.0fkB time=", total_size / 1024.0);
+ if (pts == AV_NOPTS_VALUE) {
+ av_bprintf(&buf, "N/A ");
+ av_bprintf(&buf, "%s%02d:%02d:%02d.%02d ",
+ hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE);
+ if (bitrate < 0) {
+ av_bprintf(&buf, "bitrate=N/A");
+ av_bprintf(&buf_script, "bitrate=N/A\n");
+ av_bprintf(&buf, "bitrate=%6.1fkbits/s", bitrate);
+ av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate);
+ if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n");
+ else av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size);
+ av_bprintf(&buf_script, "out_time_us=N/A\n");
+ av_bprintf(&buf_script, "out_time_ms=N/A\n");
+ av_bprintf(&buf_script, "out_time=N/A\n");
+ av_bprintf(&buf_script, "out_time_us=%"PRId64"\n", pts);
+ av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
+ av_bprintf(&buf_script, "out_time=%s%02d:%02d:%02d.%06d\n",
+ hours_sign, hours, mins, secs, us);
+ if (nb_frames_dup || nb_frames_drop)
+ av_bprintf(&buf, " dup=%d drop=%d", nb_frames_dup, nb_frames_drop);
+ av_bprintf(&buf_script, "dup_frames=%d\n", nb_frames_dup);
+ av_bprintf(&buf_script, "drop_frames=%d\n", nb_frames_drop);
+ if (speed < 0) {
+ av_bprintf(&buf, " speed=N/A");
+ av_bprintf(&buf_script, "speed=N/A\n");
+ av_bprintf(&buf, " speed=%4.3gx", speed);
+ av_bprintf(&buf_script, "speed=%4.3gx\n", speed);
+ if (print_stats || is_last_report) {
+ const char end = is_last_report ? '\n' : '\r';
+ if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
+ fprintf(stderr, "%s %c", buf.str, end);
+ av_log(NULL, AV_LOG_INFO, "%s %c", buf.str, end);
+ fflush(stderr);
+ av_bprint_finalize(&buf, NULL);
+ if (progress_avio) {
+ av_bprintf(&buf_script, "progress=%s\n",
+ is_last_report ? "end" : "continue");
+ avio_write(progress_avio, buf_script.str,
+ FFMIN(buf_script.len, buf_script.size - 1));
+ avio_flush(progress_avio);
+ av_bprint_finalize(&buf_script, NULL);
+ if ((ret = avio_closep(&progress_avio)) < 0)
+ "Error closing progress log, loss of information possible: %s\n", av_err2str(ret));
+ print_final_stats(total_size);
+static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
+ // We never got any input. Set a fake format, which will
+ // come from libavformat.
+ ifilter->format = par->format;
+ ifilter->sample_rate = par->sample_rate;
+ ifilter->channels = par->channels;
+ ifilter->channel_layout = par->channel_layout;
+ ifilter->width = par->width;
+ ifilter->height = par->height;
+ ifilter->sample_aspect_ratio = par->sample_aspect_ratio;
+static void flush_encoders(void)
+ if (!ost->encoding_needed)
+ // Try to enable encoding with no input frames.
+ // Maybe we should just let encoding fail instead.
+ FilterGraph *fg = ost->filter->graph;
+ "Finishing stream %d:%d without any data written to it.\n",
+ if (ost->filter && !fg->graph) {
+ int x;
+ for (x = 0; x < fg->nb_inputs; x++) {
+ InputFilter *ifilter = fg->inputs[x];
+ if (ifilter->format < 0)
+ ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar);
+ if (!ifilter_has_all_input_formats(fg))
+ ret = configure_filtergraph(fg);
+ av_log(NULL, AV_LOG_ERROR, "Error configuring filter graph\n");
+ finish_output_stream(ost);
+ if (enc->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1)
+ if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
+ const char *desc = NULL;
+ int pkt_size;
+ switch (enc->codec_type) {
+ desc = "audio";
+ desc = "video";
+ while ((ret = avcodec_receive_packet(enc, &pkt)) == AVERROR(EAGAIN)) {
+ ret = avcodec_send_frame(enc, NULL);
+ av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
+ desc,
+ update_benchmark("flush_%s %d.%d", desc, ost->file_index, ost->index);
+ if (ret == AVERROR_EOF) {
+ output_packet(of, &pkt, ost, 1);
+ if (ost->finished & MUXER_FINISHED) {
+ pkt_size = pkt.size;
+ if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) {
+ do_video_stats(ost, pkt_size);
+ * Check whether a packet from ist should be written into ost at this time
+static int check_output_constraints(InputStream *ist, OutputStream *ost)
+ int ist_index = input_files[ist->file_index]->ist_index + ist->st->index;
+ if (ost->source_index != ist_index)
+ if (ost->finished)
+ if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time)
+static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
+ InputFile *f = input_files [ist->file_index];
+ int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
+ AVPacket opkt = { 0 };
+ av_init_packet(&opkt);
+ // EOF: flush output bitstream filters.
+ if (!pkt) {
+ output_packet(of, &opkt, ost, 1);
+ if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
+ !ost->copy_initial_nonkeyframes)
+ if (!ost->frame_number && !ost->copy_prior_start) {
+ int64_t comp_start = start_time;
+ if (copy_ts && f->start_time != AV_NOPTS_VALUE)
+ comp_start = FFMAX(start_time, f->start_time + f->ts_offset);
+ if (pkt->pts == AV_NOPTS_VALUE ?
+ ist->pts < comp_start :
+ pkt->pts < av_rescale_q(comp_start, AV_TIME_BASE_Q, ist->st->time_base))
+ ist->pts >= of->recording_time + start_time) {
+ if (f->recording_time != INT64_MAX) {
+ start_time = f->ctx->start_time;
+ if (f->start_time != AV_NOPTS_VALUE && copy_ts)
+ start_time += f->start_time;
+ if (ist->pts >= f->recording_time + start_time) {
+ /* force the input stream PTS */
+ if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (pkt->pts != AV_NOPTS_VALUE)
+ opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time;
+ opkt.pts = AV_NOPTS_VALUE;
+ if (pkt->dts == AV_NOPTS_VALUE)
+ opkt.dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase);
+ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
+ opkt.dts -= ost_tb_start_time;
+ if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && pkt->dts != AV_NOPTS_VALUE) {
+ int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size);
+ if(!duration)
+ duration = ist->dec_ctx->frame_size;
+ opkt.dts = opkt.pts = av_rescale_delta(ist->st->time_base, pkt->dts,
+ (AVRational){1, ist->dec_ctx->sample_rate}, duration, &ist->filter_in_rescale_delta_last,
+ ost->mux_timebase) - ost_tb_start_time;
+ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);
+ opkt.flags = pkt->flags;
+ if (pkt->buf) {
+ opkt.buf = av_buffer_ref(pkt->buf);
+ if (!opkt.buf)
+ opkt.data = pkt->data;
+ opkt.size = pkt->size;
+ av_copy_packet_side_data(&opkt, pkt);
+ output_packet(of, &opkt, ost, 0);
+int guess_input_channel_layout(InputStream *ist)
+ AVCodecContext *dec = ist->dec_ctx;
+ if (!dec->channel_layout) {
+ char layout_name[256];
+ if (dec->channels > ist->guess_layout_max)
+ dec->channel_layout = av_get_default_channel_layout(dec->channels);
+ if (!dec->channel_layout)
+ av_get_channel_layout_string(layout_name, sizeof(layout_name),
+ dec->channels, dec->channel_layout);
+ av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
+ "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
+static void check_decode_result(InputStream *ist, int *got_output, int ret)
+ if (*got_output || ret<0)
+ decode_error_stat[ret<0] ++;
+ if (ret < 0 && exit_on_error)
+ if (*got_output && ist) {
+ if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
+ av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
+ "%s: corrupt decoded frame in stream %d\n", input_files[ist->file_index]->ctx->url, ist->st->index);
+// Filters can be configured only if the formats of all inputs are known.
+static int ifilter_has_all_input_formats(FilterGraph *fg)
+ for (i = 0; i < fg->nb_inputs; i++) {
+ if (fg->inputs[i]->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO ||
+ fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO))
+static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame)
+ FilterGraph *fg = ifilter->graph;
+ int need_reinit, ret, i;
+ /* determine if the parameters for this input changed */
+ need_reinit = ifilter->format != frame->format;
+ switch (ifilter->ist->st->codecpar->codec_type) {
+ need_reinit |= ifilter->sample_rate != frame->sample_rate ||
+ ifilter->channels != frame->channels ||
+ ifilter->channel_layout != frame->channel_layout;
+ need_reinit |= ifilter->width != frame->width ||
+ ifilter->height != frame->height;
+ if (!ifilter->ist->reinit_filters && fg->graph)
+ need_reinit = 0;
+ if (!!ifilter->hw_frames_ctx != !!frame->hw_frames_ctx ||
+ (ifilter->hw_frames_ctx && ifilter->hw_frames_ctx->data != frame->hw_frames_ctx->data))
+ need_reinit = 1;
+ if (need_reinit) {
+ ret = ifilter_parameters_from_frame(ifilter, frame);
+ /* (re)init the graph if possible, otherwise buffer the frame and return */
+ if (need_reinit || !fg->graph) {
+ if (!ifilter_has_all_input_formats(fg)) {
+ AVFrame *tmp = av_frame_clone(frame);
+ if (!tmp)
+ if (!av_fifo_space(ifilter->frame_queue)) {
+ ret = av_fifo_realloc2(ifilter->frame_queue, 2 * av_fifo_size(ifilter->frame_queue));
+ av_frame_free(&tmp);
+ av_fifo_generic_write(ifilter->frame_queue, &tmp, sizeof(tmp), NULL);
+ ret = reap_filters(1);
+ av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
+ av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
+ ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, AV_BUFFERSRC_FLAG_PUSH);
+ if (ret != AVERROR_EOF)
+static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
+ ifilter->eof = 1;
+ if (ifilter->filter) {
+ ret = av_buffersrc_close(ifilter->filter, pts, AV_BUFFERSRC_FLAG_PUSH);
+ // the filtergraph was never configured
+ if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index);
+ return AVERROR_INVALIDDATA;
+// This does not quite work like avcodec_decode_audio4/avcodec_decode_video2.
+// There is the following difference: if you got a frame, you must call
+// it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0
+// (pkt==NULL means get more output, pkt->size==0 is a flush/drain packet)
+static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
+ *got_frame = 0;
+ if (pkt) {
+ ret = avcodec_send_packet(avctx, pkt);
+ // In particular, we don't expect AVERROR(EAGAIN), because we read all
+ // decoded frames with avcodec_receive_frame() until done.
+ if (ret < 0 && ret != AVERROR_EOF)
+ ret = avcodec_receive_frame(avctx, frame);
+ if (ret < 0 && ret != AVERROR(EAGAIN))
+ if (ret >= 0)
+ *got_frame = 1;
+static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
+ AVFrame *f;
+ av_assert1(ist->nb_filters > 0); /* ensure ret is initialized */
+ if (i < ist->nb_filters - 1) {
+ f = ist->filter_frame;
+ ret = av_frame_ref(f, decoded_frame);
+ f = decoded_frame;
+ ret = ifilter_send_frame(ist->filters[i], f);
+ if (ret == AVERROR_EOF)
+ ret = 0; /* ignore */
+ "Failed to inject frame into filter network: %s\n", av_err2str(ret));
+static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
+ int *decode_failed)
+ AVFrame *decoded_frame;
+ AVCodecContext *avctx = ist->dec_ctx;
+ int ret, err = 0;
+ AVRational decoded_frame_tb;
+ if (!ist->decoded_frame && !(ist->decoded_frame = av_frame_alloc()))
+ if (!ist->filter_frame && !(ist->filter_frame = av_frame_alloc()))
+ decoded_frame = ist->decoded_frame;
+ ret = decode(avctx, decoded_frame, got_output, pkt);
+ update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index);
+ *decode_failed = 1;
+ if (ret >= 0 && avctx->sample_rate <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Sample rate %d invalid\n", avctx->sample_rate);
+ ret = AVERROR_INVALIDDATA;
+ check_decode_result(ist, got_output, ret);
+ if (!*got_output || ret < 0)
+ ist->samples_decoded += decoded_frame->nb_samples;
+ ist->frames_decoded++;
+ /* increment next_dts to use for the case where the input stream does not
+ have timestamps or there are multiple frames in the packet */
+ ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
+ avctx->sample_rate;
+ ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
+ if (decoded_frame->pts != AV_NOPTS_VALUE) {
+ decoded_frame_tb = ist->st->time_base;
+ } else if (pkt && pkt->pts != AV_NOPTS_VALUE) {
+ decoded_frame->pts = pkt->pts;
+ }else {
+ decoded_frame->pts = ist->dts;
+ decoded_frame_tb = AV_TIME_BASE_Q;
+ if (decoded_frame->pts != AV_NOPTS_VALUE)
+ decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts,
+ (AVRational){1, avctx->sample_rate}, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last,
+ (AVRational){1, avctx->sample_rate});
+ ist->nb_samples = decoded_frame->nb_samples;
+ err = send_frame_to_filters(ist, decoded_frame);
+ av_frame_unref(ist->filter_frame);
+ av_frame_unref(decoded_frame);
+ return err < 0 ? err : ret;
+static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *duration_pts, int eof,
+ int i, ret = 0, err = 0;
+ int64_t best_effort_timestamp;
+ int64_t dts = AV_NOPTS_VALUE;
+ AVPacket avpkt;
+ // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
+ // reason. This seems like a semi-critical bug. Don't trigger EOF, and
+ // skip the packet.
+ if (!eof && pkt && pkt->size == 0)
+ if (ist->dts != AV_NOPTS_VALUE)
+ dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
+ avpkt = *pkt;
+ avpkt.dts = dts; // ffmpeg.c probably shouldn't do this
+ // The old code used to set dts on the drain packet, which does not work
+ // with the new API anymore.
+ if (eof) {
+ void *new = av_realloc_array(ist->dts_buffer, ist->nb_dts_buffer + 1, sizeof(ist->dts_buffer[0]));
+ if (!new)
+ ist->dts_buffer = new;
+ ist->dts_buffer[ist->nb_dts_buffer++] = dts;
+ ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt ? &avpkt : NULL);
+ update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index);
+ // The following line may be required in some cases where there is no parser
+ // or the parser does not has_b_frames correctly
+ if (ist->st->codecpar->video_delay < ist->dec_ctx->has_b_frames) {
+ if (ist->dec_ctx->codec_id == AV_CODEC_ID_H264) {
+ ist->st->codecpar->video_delay = ist->dec_ctx->has_b_frames;
+ av_log(ist->dec_ctx, AV_LOG_WARNING,
+ "video_delay is larger in decoder than demuxer %d > %d.\n"
+ "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
+ ist->dec_ctx->has_b_frames,
+ ist->st->codecpar->video_delay);
+ if (*got_output && ret >= 0) {
+ if (ist->dec_ctx->width != decoded_frame->width ||
+ ist->dec_ctx->height != decoded_frame->height ||
+ ist->dec_ctx->pix_fmt != decoded_frame->format) {
+ av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n",
+ decoded_frame->width,
+ decoded_frame->height,
+ decoded_frame->format,
+ ist->dec_ctx->width,
+ ist->dec_ctx->height,
+ ist->dec_ctx->pix_fmt);
+ if(ist->top_field_first>=0)
+ decoded_frame->top_field_first = ist->top_field_first;
+ if (ist->hwaccel_retrieve_data && decoded_frame->format == ist->hwaccel_pix_fmt) {
+ err = ist->hwaccel_retrieve_data(ist->dec_ctx, decoded_frame);
+ if (err < 0)
+ ist->hwaccel_retrieved_pix_fmt = decoded_frame->format;
+ best_effort_timestamp= decoded_frame->best_effort_timestamp;
+ *duration_pts = decoded_frame->pkt_duration;
+ if (ist->framerate.num)
+ best_effort_timestamp = ist->cfr_next_pts++;
+ if (eof && best_effort_timestamp == AV_NOPTS_VALUE && ist->nb_dts_buffer > 0) {
+ best_effort_timestamp = ist->dts_buffer[0];
+ for (i = 0; i < ist->nb_dts_buffer - 1; i++)
+ ist->dts_buffer[i] = ist->dts_buffer[i + 1];
+ ist->nb_dts_buffer--;
+ if(best_effort_timestamp != AV_NOPTS_VALUE) {
+ int64_t ts = av_rescale_q(decoded_frame->pts = best_effort_timestamp, ist->st->time_base, AV_TIME_BASE_Q);
+ if (ts != AV_NOPTS_VALUE)
+ ist->next_pts = ist->pts = ts;
+ av_log(NULL, AV_LOG_INFO, "decoder -> ist_index:%d type:video "
+ "frame_pts:%s frame_pts_time:%s best_effort_ts:%"PRId64" best_effort_ts_time:%s keyframe:%d frame_type:%d time_base:%d/%d\n",
+ ist->st->index, av_ts2str(decoded_frame->pts),
+ av_ts2timestr(decoded_frame->pts, &ist->st->time_base),
+ best_effort_timestamp,
+ av_ts2timestr(best_effort_timestamp, &ist->st->time_base),
+ decoded_frame->key_frame, decoded_frame->pict_type,
+ ist->st->time_base.num, ist->st->time_base.den);
+ if (ist->st->sample_aspect_ratio.num)
+ decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
+fail:
+static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
+ AVSubtitle subtitle;
+ int free_sub = 1;
+ int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
+ &subtitle, got_output, pkt);
+ check_decode_result(NULL, got_output, ret);
+ if (ret < 0 || !*got_output) {
+ if (!pkt->size)
+ sub2video_flush(ist);
+ if (ist->fix_sub_duration) {
+ int end = 1;
+ if (ist->prev_sub.got_output) {
+ end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts,
+ 1000, AV_TIME_BASE);
+ if (end < ist->prev_sub.subtitle.end_display_time) {
+ av_log(ist->dec_ctx, AV_LOG_DEBUG,
+ "Subtitle duration reduced from %"PRId32" to %d%s\n",
+ ist->prev_sub.subtitle.end_display_time, end,
+ end <= 0 ? ", dropping it" : "");
+ ist->prev_sub.subtitle.end_display_time = end;
+ FFSWAP(int, *got_output, ist->prev_sub.got_output);
+ FFSWAP(int, ret, ist->prev_sub.ret);
+ FFSWAP(AVSubtitle, subtitle, ist->prev_sub.subtitle);
+ if (end <= 0)
+ goto out;
+ if (!*got_output)
+ if (ist->sub2video.frame) {
+ sub2video_update(ist, &subtitle);
+ } else if (ist->nb_filters) {
+ if (!ist->sub2video.sub_queue)
+ ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));
+ if (!av_fifo_space(ist->sub2video.sub_queue)) {
+ ret = av_fifo_realloc2(ist->sub2video.sub_queue, 2 * av_fifo_size(ist->sub2video.sub_queue));
+ av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL);
+ free_sub = 0;
+ if (!subtitle.num_rects)
+ if (!check_output_constraints(ist, ost) || !ost->encoding_needed
+ || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
+ do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
+out:
+ if (free_sub)
+ avsubtitle_free(&subtitle);
+static int send_filter_eof(InputStream *ist)
+ /* TODO keep pts also in stream time base to avoid converting back */
+ int64_t pts = av_rescale_q_rnd(ist->pts, AV_TIME_BASE_Q, ist->st->time_base,
+ AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
+ ret = ifilter_send_eof(ist->filters[i], pts);
+/* pkt = NULL means EOF (needed to flush decoder buffers) */
+static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
+ int ret = 0, i;
+ int repeating = 0;
+ int eof_reached = 0;
+ if (!ist->saw_first_ts) {
+ ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+ ist->pts = 0;
+ if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
+ ist->dts += av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);
+ ist->pts = ist->dts; //unused but better to set it to a value thats not totally wrong
+ ist->saw_first_ts = 1;
+ if (ist->next_dts == AV_NOPTS_VALUE)
+ ist->next_dts = ist->dts;
+ if (ist->next_pts == AV_NOPTS_VALUE)
+ ist->next_pts = ist->pts;
+ /* EOF handling */
+ av_init_packet(&avpkt);
+ avpkt.data = NULL;
+ avpkt.size = 0;
+ if (pkt && pkt->dts != AV_NOPTS_VALUE) {
+ ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+ if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
+ ist->next_pts = ist->pts = ist->dts;
+ // while we have more to decode or while the decoder did output something on EOF
+ while (ist->decoding_needed) {
+ int64_t duration_dts = 0;
+ int64_t duration_pts = 0;
+ int got_output = 0;
+ int decode_failed = 0;
+ ist->pts = ist->next_pts;
+ ist->dts = ist->next_dts;
+ switch (ist->dec_ctx->codec_type) {
+ ret = decode_audio (ist, repeating ? NULL : &avpkt, &got_output,
+ &decode_failed);
+ ret = decode_video (ist, repeating ? NULL : &avpkt, &got_output, &duration_pts, !pkt,
+ if (!repeating || !pkt || got_output) {
+ if (pkt && pkt->duration) {
+ duration_dts = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
+ } else if(ist->dec_ctx->framerate.num != 0 && ist->dec_ctx->framerate.den != 0) {
+ int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict+1 : ist->dec_ctx->ticks_per_frame;
+ duration_dts = ((int64_t)AV_TIME_BASE *
+ ist->dec_ctx->framerate.den * ticks) /
+ ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame;
+ if(ist->dts != AV_NOPTS_VALUE && duration_dts) {
+ ist->next_dts += duration_dts;
+ }else
+ ist->next_dts = AV_NOPTS_VALUE;
+ if (got_output) {
+ if (duration_pts > 0) {
+ ist->next_pts += av_rescale_q(duration_pts, ist->st->time_base, AV_TIME_BASE_Q);
+ ist->next_pts += duration_dts;
+ if (repeating)
+ ret = transcode_subtitles(ist, &avpkt, &got_output, &decode_failed);
+ if (!pkt && ret >= 0)
+ ret = AVERROR_EOF;
+ eof_reached = 1;
+ if (decode_failed) {
+ av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n",
+ ist->file_index, ist->st->index, av_err2str(ret));
+ av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded "
+ "data for stream #%d:%d\n", ist->file_index, ist->st->index);
+ if (!decode_failed || exit_on_error)
+ if (got_output)
+ ist->got_output = 1;
+ if (!got_output)
+ // During draining, we might get multiple output frames in this loop.
+ // ffmpeg.c does not drain the filter chain on configuration changes,
+ // which means if we send multiple frames at once to the filters, and
+ // one of those frames changes configuration, the buffered frames will
+ // be lost. This can upset certain FATE tests.
+ // Decode only 1 frame per call on EOF to appease these FATE tests.
+ // The ideal solution would be to rewrite decoding to use the new
+ // decoding API in a better way.
+ if (!pkt)
+ repeating = 1;
+ /* after flushing, send an EOF on all the filter inputs attached to the stream */
+ /* except when looping we need to flush but not to send an EOF */
+ if (!pkt && ist->decoding_needed && eof_reached && !no_eof) {
+ int ret = send_filter_eof(ist);
+ av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n");
+ /* handle stream copy */
+ if (!ist->decoding_needed && pkt) {
+ av_assert1(pkt->duration >= 0);
+ if (ist->dec_ctx->sample_rate) {
+ ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) /
+ ist->dec_ctx->sample_rate;
+ ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
+ if (ist->framerate.num) {
+ // TODO: Remove work-around for c99-to-c89 issue 7
+ AVRational time_base_q = AV_TIME_BASE_Q;
+ int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
+ ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
+ } else if (pkt->duration) {
+ } else if(ist->dec_ctx->framerate.num != 0) {
+ int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;
+ ist->next_dts += ((int64_t)AV_TIME_BASE *
+ ist->pts = ist->dts;
+ ist->next_pts = ist->next_dts;
+ if (!check_output_constraints(ist, ost) || ost->encoding_needed)
+ do_streamcopy(ist, ost, pkt);
+ return !eof_reached;
+static void print_sdp(void)
+ char sdp[16384];
+ AVIOContext *sdp_pb;
+ AVFormatContext **avc;
+ if (!output_files[i]->header_written)
+ avc = av_malloc_array(nb_output_files, sizeof(*avc));
+ if (!avc)
+ for (i = 0, j = 0; i < nb_output_files; i++) {
+ if (!strcmp(output_files[i]->ctx->oformat->name, "rtp")) {
+ avc[j] = output_files[i]->ctx;
+ j++;
+ av_sdp_create(avc, j, sdp, sizeof(sdp));
+ if (!sdp_filename) {
+ printf("SDP:\n%s\n", sdp);
+ fflush(stdout);
+ if (avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename);
+ avio_printf(sdp_pb, "SDP:\n%s", sdp);
+ avio_closep(&sdp_pb);
+ av_freep(&sdp_filename);
+ av_freep(&avc);
+static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
+ InputStream *ist = s->opaque;
+ const enum AVPixelFormat *p;
+ for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p);
+ const AVCodecHWConfig *config = NULL;
+ if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
+ if (ist->hwaccel_id == HWACCEL_GENERIC ||
+ ist->hwaccel_id == HWACCEL_AUTO) {
+ for (i = 0;; i++) {
+ config = avcodec_get_hw_config(s->codec, i);
+ if (!(config->methods &
+ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
+ if (config->pix_fmt == *p)
+ if (config) {
+ if (config->device_type != ist->hwaccel_device_type) {
+ // Different hwaccel offered, ignore.
+ ret = hwaccel_decode_init(s);
+ if (ist->hwaccel_id == HWACCEL_GENERIC) {
+ av_log(NULL, AV_LOG_FATAL,
+ "%s hwaccel requested for input stream #%d:%d, "
+ "but cannot be initialized.\n",
+ av_hwdevice_get_type_name(config->device_type),
+ ist->file_index, ist->st->index);
+ return AV_PIX_FMT_NONE;
+ const HWAccel *hwaccel = NULL;
+ for (i = 0; hwaccels[i].name; i++) {
+ if (hwaccels[i].pix_fmt == *p) {
+ hwaccel = &hwaccels[i];
+ if (!hwaccel) {
+ // No hwaccel supporting this pixfmt.
+ if (hwaccel->id != ist->hwaccel_id) {
+ // Does not match requested hwaccel.
+ ret = hwaccel->init(s);
+ "but cannot be initialized.\n", hwaccel->name,
+ if (ist->hw_frames_ctx) {
+ s->hw_frames_ctx = av_buffer_ref(ist->hw_frames_ctx);
+ if (!s->hw_frames_ctx)
+ ist->hwaccel_pix_fmt = *p;
+ return *p;
+static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
+ if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
+ return ist->hwaccel_get_buffer(s, frame, flags);
+ return avcodec_default_get_buffer2(s, frame, flags);
+static int init_input_stream(int ist_index, char *error, int error_len)
+ InputStream *ist = input_streams[ist_index];
+ AVCodec *codec = ist->dec;
+ if (!codec) {
+ snprintf(error, error_len, "Decoder (codec %s) not found for input stream #%d:%d",
+ avcodec_get_name(ist->dec_ctx->codec_id), ist->file_index, ist->st->index);
+ ist->dec_ctx->opaque = ist;
+ ist->dec_ctx->get_format = get_format;
+ ist->dec_ctx->get_buffer2 = get_buffer;
+ ist->dec_ctx->thread_safe_callbacks = 1;
+ av_opt_set_int(ist->dec_ctx, "refcounted_frames", 1, 0);
+ if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE &&
+ (ist->decoding_needed & DECODING_FOR_OST)) {
+ av_dict_set(&ist->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
+ if (ist->decoding_needed & DECODING_FOR_FILTER)
+ av_log(NULL, AV_LOG_WARNING, "Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n");
+ av_dict_set(&ist->decoder_opts, "sub_text_format", "ass", AV_DICT_DONT_OVERWRITE);
+ /* Useful for subtitles retiming by lavf (FIXME), skipping samples in
+ * audio, and video decoders such as cuvid or mediacodec */
+ ist->dec_ctx->pkt_timebase = ist->st->time_base;
+ if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
+ av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
+ /* Attached pics are sparse, therefore we would not want to delay their decoding till EOF. */
+ if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+ av_dict_set(&ist->decoder_opts, "threads", "1", 0);
+ ret = hw_device_setup_for_decode(ist);
+ snprintf(error, error_len, "Device setup failed for "
+ "decoder on input stream #%d:%d : %s",
+ if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
+ if (ret == AVERROR_EXPERIMENTAL)
+ abort_codec_experimental(codec, 0);
+ snprintf(error, error_len,
+ "Error while opening decoder for input stream "
+ "#%d:%d : %s",
+ assert_avoptions(ist->decoder_opts);
+ ist->next_pts = AV_NOPTS_VALUE;
+static InputStream *get_input_stream(OutputStream *ost)
+ return input_streams[ost->source_index];
+static int compare_int64(const void *a, const void *b)
+ return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
+/* open the muxer when all the streams are initialized */
+static int check_init_output_file(OutputFile *of, int file_index)
+ for (i = 0; i < of->ctx->nb_streams; i++) {
+ OutputStream *ost = output_streams[of->ost_index + i];
+ if (!ost->initialized)
+ of->ctx->interrupt_callback = int_cb;
+ ret = avformat_write_header(of->ctx, &of->opts);
+ "Could not write header for output file #%d "
+ "(incorrect codec parameters ?): %s\n",
+ file_index, av_err2str(ret));
+ //assert_avoptions(of->opts);
+ of->header_written = 1;
+ av_dump_format(of->ctx, file_index, of->ctx->url, 1);
+ if (sdp_filename || want_sdp)
+ print_sdp();
+ /* flush the muxing queues */
+ /* try to improve muxing time_base (only possible if nothing has been written yet) */
+ if (!av_fifo_size(ost->muxing_queue))
+ ost->mux_timebase = ost->st->time_base;
+ write_packet(of, &pkt, ost, 1);
+static int init_output_bsfs(OutputStream *ost)
+ AVBSFContext *ctx;
+ if (!ost->nb_bitstream_filters)
+ for (i = 0; i < ost->nb_bitstream_filters; i++) {
+ ctx = ost->bsf_ctx[i];
+ ret = avcodec_parameters_copy(ctx->par_in,
+ i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
+ ctx->time_base_in = i ? ost->bsf_ctx[i - 1]->time_base_out : ost->st->time_base;
+ ret = av_bsf_init(ctx);
+ av_log(NULL, AV_LOG_ERROR, "Error initializing bitstream filter: %s\n",
+ ost->bsf_ctx[i]->filter->name);
+ ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
+ ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
+ ost->st->time_base = ctx->time_base_out;
+static int init_output_stream_streamcopy(OutputStream *ost)
+ InputStream *ist = get_input_stream(ost);
+ AVCodecParameters *par_dst = ost->st->codecpar;
+ AVCodecParameters *par_src = ost->ref_par;
+ AVRational sar;
+ uint32_t codec_tag = par_dst->codec_tag;
+ av_assert0(ist && !ost->filter);
+ ret = avcodec_parameters_to_context(ost->enc_ctx, ist->st->codecpar);
+ ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
+ "Error setting up codec context options.\n");
+ ret = avcodec_parameters_from_context(par_src, ost->enc_ctx);
+ "Error getting reference codec parameters.\n");
+ if (!codec_tag) {
+ unsigned int codec_tag_tmp;
+ if (!of->ctx->oformat->codec_tag ||
+ av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_src->codec_id ||
+ !av_codec_get_tag2(of->ctx->oformat->codec_tag, par_src->codec_id, &codec_tag_tmp))
+ codec_tag = par_src->codec_tag;
+ ret = avcodec_parameters_copy(par_dst, par_src);
+ par_dst->codec_tag = codec_tag;
+ if (!ost->frame_rate.num)
+ ost->frame_rate = ist->framerate;
+ ost->st->avg_frame_rate = ost->frame_rate;
+ ret = avformat_transfer_internal_stream_timing_info(of->ctx->oformat, ost->st, ist->st, copy_tb);
+ // copy timebase while removing common factors
+ if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
+ ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
+ // copy estimated duration as a hint to the muxer
+ if (ost->st->duration <= 0 && ist->st->duration > 0)
+ ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
+ // copy disposition
+ ost->st->disposition = ist->st->disposition;
+ if (ist->st->nb_side_data) {
+ for (i = 0; i < ist->st->nb_side_data; i++) {
+ const AVPacketSideData *sd_src = &ist->st->side_data[i];
+ uint8_t *dst_data;
+ dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size);
+ if (!dst_data)
+ memcpy(dst_data, sd_src->data, sd_src->size);
+ if (ost->rotate_overridden) {
+ uint8_t *sd = av_stream_new_side_data(ost->st, AV_PKT_DATA_DISPLAYMATRIX,
+ sizeof(int32_t) * 9);
+ if (sd)
+ av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value);
+ switch (par_dst->codec_type) {
+ if (audio_volume != 256) {
+ av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
+ if((par_dst->block_align == 1 || par_dst->block_align == 1152 || par_dst->block_align == 576) && par_dst->codec_id == AV_CODEC_ID_MP3)
+ par_dst->block_align= 0;
+ if(par_dst->codec_id == AV_CODEC_ID_AC3)
+ if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
+ sar =
+ av_mul_q(ost->frame_aspect_ratio,
+ (AVRational){ par_dst->height, par_dst->width });
+ av_log(NULL, AV_LOG_WARNING, "Overriding aspect ratio "
+ "with stream copy may produce invalid files\n");
+ else if (ist->st->sample_aspect_ratio.num)
+ sar = ist->st->sample_aspect_ratio;
+ sar = par_src->sample_aspect_ratio;
+ ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
+ ost->st->avg_frame_rate = ist->st->avg_frame_rate;
+ ost->st->r_frame_rate = ist->st->r_frame_rate;
+ ost->mux_timebase = ist->st->time_base;
+static void set_encoder_id(OutputFile *of, OutputStream *ost)
+ AVDictionaryEntry *e;
+ uint8_t *encoder_string;
+ int encoder_string_len;
+ int format_flags = 0;
+ int codec_flags = ost->enc_ctx->flags;
+ if (av_dict_get(ost->st->metadata, "encoder", NULL, 0))
+ e = av_dict_get(of->opts, "fflags", NULL, 0);
+ if (e) {
+ const AVOption *o = av_opt_find(of->ctx, "fflags", NULL, 0, 0);
+ if (!o)
+ av_opt_eval_flags(of->ctx, o, e->value, &format_flags);
+ e = av_dict_get(ost->encoder_opts, "flags", NULL, 0);
+ const AVOption *o = av_opt_find(ost->enc_ctx, "flags", NULL, 0, 0);
+ av_opt_eval_flags(ost->enc_ctx, o, e->value, &codec_flags);
+ encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(ost->enc->name) + 2;
+ encoder_string = av_mallocz(encoder_string_len);
+ if (!encoder_string)
+ if (!(format_flags & AVFMT_FLAG_BITEXACT) && !(codec_flags & AV_CODEC_FLAG_BITEXACT))
+ av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len);
+ av_strlcpy(encoder_string, "Lavc ", encoder_string_len);
+ av_strlcat(encoder_string, ost->enc->name, encoder_string_len);
+ av_dict_set(&ost->st->metadata, "encoder", encoder_string,
+ AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
+static void parse_forced_key_frames(char *kf, OutputStream *ost,
+ AVCodecContext *avctx)
+ char *p;
+ int n = 1, i, size, index = 0;
+ int64_t t, *pts;
+ for (p = kf; *p; p++)
+ if (*p == ',')
+ n++;
+ size = n;
+ pts = av_malloc_array(size, sizeof(*pts));
+ if (!pts) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
+ p = kf;
+ for (i = 0; i < n; i++) {
+ char *next = strchr(p, ',');
+ if (next)
+ *next++ = 0;
+ if (!memcmp(p, "chapters", 8)) {
+ AVFormatContext *avf = output_files[ost->file_index]->ctx;
+ if (avf->nb_chapters > INT_MAX - size ||
+ !(pts = av_realloc_f(pts, size += avf->nb_chapters - 1,
+ sizeof(*pts)))) {
+ "Could not allocate forced key frames array.\n");
+ t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
+ t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
+ for (j = 0; j < avf->nb_chapters; j++) {
+ AVChapter *c = avf->chapters[j];
+ av_assert1(index < size);
+ pts[index++] = av_rescale_q(c->start, c->time_base,
+ avctx->time_base) + t;
+ t = parse_time_or_die("force_key_frames", p, 1);
+ pts[index++] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
+ p = next;
+ av_assert0(index == size);
+ qsort(pts, size, sizeof(*pts), compare_int64);
+ ost->forced_kf_count = size;
+ ost->forced_kf_pts = pts;
+static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
+ AVCodecContext *enc_ctx = ost->enc_ctx;
+ if (ost->enc_timebase.num > 0) {
+ enc_ctx->time_base = ost->enc_timebase;
+ if (ost->enc_timebase.num < 0) {
+ if (ist) {
+ enc_ctx->time_base = ist->st->time_base;
+ oc = output_files[ost->file_index]->ctx;
+ av_log(oc, AV_LOG_WARNING, "Input stream data not available, using default time base\n");
+ enc_ctx->time_base = default_time_base;
+static int init_output_stream_encode(OutputStream *ost)
+ AVCodecContext *dec_ctx = NULL;
+ AVFormatContext *oc = output_files[ost->file_index]->ctx;
+ int j, ret;
+ set_encoder_id(output_files[ost->file_index], ost);
+ // Muxers use AV_PKT_DATA_DISPLAYMATRIX to signal rotation. On the other
+ // hand, the legacy API makes demuxers set "rotate" metadata entries,
+ // which have to be filtered out to prevent leaking them to output files.
+ av_dict_set(&ost->st->metadata, "rotate", NULL, 0);
+ dec_ctx = ist->dec_ctx;
+ enc_ctx->chroma_sample_location = dec_ctx->chroma_sample_location;
+ for (j = 0; j < oc->nb_streams; j++) {
+ AVStream *st = oc->streams[j];
+ if (st != ost->st && st->codecpar->codec_type == ost->st->codecpar->codec_type)
+ if (j == oc->nb_streams)
+ if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ||
+ ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+ ost->st->disposition = AV_DISPOSITION_DEFAULT;
+ if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+ ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
+ if (ist && !ost->frame_rate.num)
+ ost->frame_rate = ist->st->r_frame_rate;
+ if (ist && !ost->frame_rate.num) {
+ ost->frame_rate = (AVRational){25, 1};
+ "No information "
+ "about the input framerate is available. Falling "
+ "back to a default value of 25fps for output stream #%d:%d. Use the -r option "
+ "if you want a different framerate.\n",
+ ost->file_index, ost->index);
+ if (ost->enc->supported_framerates && !ost->force_fps) {
+ int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
+ ost->frame_rate = ost->enc->supported_framerates[idx];
+ // reduce frame rate for mpeg4 to be within the spec limits
+ if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) {
+ av_reduce(&ost->frame_rate.num, &ost->frame_rate.den,
+ ost->frame_rate.num, ost->frame_rate.den, 65535);
+ switch (enc_ctx->codec_type) {
+ enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter);
+ if (dec_ctx)
+ enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
+ av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
+ enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter);
+ enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter);
+ enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter);
+ init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
+ init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
+ if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
+ enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
+ if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH
+ && (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){
+ av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n"
+ "Please consider specifying a lower framerate, a different muxer or -vsync 2\n");
+ for (j = 0; j < ost->forced_kf_count; j++)
+ ost->forced_kf_pts[j] = av_rescale_q(ost->forced_kf_pts[j],
+ AV_TIME_BASE_Q,
+ enc_ctx->time_base);
+ enc_ctx->width = av_buffersink_get_w(ost->filter->filter);
+ enc_ctx->height = av_buffersink_get_h(ost->filter->filter);
+ enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
+ ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
+ av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
+ av_buffersink_get_sample_aspect_ratio(ost->filter->filter);
+ enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter);
+ av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
+ enc_ctx->framerate = ost->frame_rate;
+ if (!dec_ctx ||
+ enc_ctx->width != dec_ctx->width ||
+ enc_ctx->height != dec_ctx->height ||
+ enc_ctx->pix_fmt != dec_ctx->pix_fmt) {
+ enc_ctx->bits_per_raw_sample = frame_bits_per_raw_sample;
+ if (ost->top_field_first == 0) {
+ enc_ctx->field_order = AV_FIELD_BB;
+ } else if (ost->top_field_first == 1) {
+ enc_ctx->field_order = AV_FIELD_TT;
+ if (ost->forced_keyframes) {
+ if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
+ ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,
+ forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL);
+ "Invalid force_key_frames expression '%s'\n", ost->forced_keyframes+5);
+ ost->forced_keyframes_expr_const_values[FKF_N] = 0;
+ ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0;
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN;
+ ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN;
+ // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
+ // parse it only for static kf timings
+ } else if(strncmp(ost->forced_keyframes, "source", 6)) {
+ parse_forced_key_frames(ost->forced_keyframes, ost, ost->enc_ctx);
+ enc_ctx->time_base = AV_TIME_BASE_Q;
+ if (!enc_ctx->width) {
+ enc_ctx->width = input_streams[ost->source_index]->st->codecpar->width;
+ enc_ctx->height = input_streams[ost->source_index]->st->codecpar->height;
+ case AVMEDIA_TYPE_DATA:
+ abort();
+ ost->mux_timebase = enc_ctx->time_base;
+static int init_output_stream(OutputStream *ost, char *error, int error_len)
+ AVCodec *codec = ost->enc;
+ AVCodecContext *dec = NULL;
+ InputStream *ist;
+ ret = init_output_stream_encode(ost);
+ if ((ist = get_input_stream(ost)))
+ dec = ist->dec_ctx;
+ if (dec && dec->subtitle_header) {
+ /* ASS code assumes this buffer is null terminated so add extra byte. */
+ ost->enc_ctx->subtitle_header = av_mallocz(dec->subtitle_header_size + 1);
+ if (!ost->enc_ctx->subtitle_header)
+ memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
+ ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;
+ if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
+ av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
+ if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
+ !codec->defaults &&
+ !av_dict_get(ost->encoder_opts, "b", NULL, 0) &&
+ !av_dict_get(ost->encoder_opts, "ab", NULL, 0))
+ av_dict_set(&ost->encoder_opts, "b", "128000", 0);
+ if (ost->filter && av_buffersink_get_hw_frames_ctx(ost->filter->filter) &&
+ ((AVHWFramesContext*)av_buffersink_get_hw_frames_ctx(ost->filter->filter)->data)->format ==
+ av_buffersink_get_format(ost->filter->filter)) {
+ ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter));
+ if (!ost->enc_ctx->hw_frames_ctx)
+ ret = hw_device_setup_for_encode(ost);
+ "encoder on output stream #%d:%d : %s",
+ ost->file_index, ost->index, av_err2str(ret));
+ if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && ost->enc->type == AVMEDIA_TYPE_SUBTITLE) {
+ int input_props = 0, output_props = 0;
+ AVCodecDescriptor const *input_descriptor =
+ avcodec_descriptor_get(dec->codec_id);
+ AVCodecDescriptor const *output_descriptor =
+ avcodec_descriptor_get(ost->enc_ctx->codec_id);
+ if (input_descriptor)
+ input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+ if (output_descriptor)
+ output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+ if (input_props && output_props && input_props != output_props) {
+ "Subtitle encoding currently only possible from text to text "
+ "or bitmap to bitmap");
+ if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
+ abort_codec_experimental(codec, 1);
+ "Error while opening encoder for output stream #%d:%d - "
+ "maybe incorrect parameters such as bit_rate, rate, width or height",
+ !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
+ av_buffersink_set_frame_size(ost->filter->filter,
+ ost->enc_ctx->frame_size);
+ assert_avoptions(ost->encoder_opts);
+ if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 &&
+ ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 700 bit/s modes */)
+ av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
+ " It takes bits/s as argument, not kbits/s\n");
+ ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx);
+ "Error initializing the output stream codec context.\n");
+ * FIXME: ost->st->codec should't be needed here anymore.
+ ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
+ if (ost->enc_ctx->nb_coded_side_data) {
+ for (i = 0; i < ost->enc_ctx->nb_coded_side_data; i++) {
+ const AVPacketSideData *sd_src = &ost->enc_ctx->coded_side_data[i];
+ * Add global input side data. For now this is naive, and copies it
+ * from the input stream's global side data. All side data should
+ * really be funneled over AVFrame and libavfilter, then added back to
+ * packet side data, and then potentially using the first packet for
+ * global side data.
+ AVPacketSideData *sd = &ist->st->side_data[i];
+ uint8_t *dst = av_stream_new_side_data(ost->st, sd->type, sd->size);
+ if (!dst)
+ memcpy(dst, sd->data, sd->size);
+ if (ist->autorotate && sd->type == AV_PKT_DATA_DISPLAYMATRIX)
+ av_display_rotation_set((uint32_t *)dst, 0);
+ ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1});
+ if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
+ ost->st->codec->codec= ost->enc_ctx->codec;
+ } else if (ost->stream_copy) {
+ ret = init_output_stream_streamcopy(ost);
+ // parse user provided disposition, and update stream values
+ if (ost->disposition) {
+ static const AVOption opts[] = {
+ { "disposition" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
+ { "default" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "flags" },
+ { "dub" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "flags" },
+ { "original" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "flags" },
+ { "comment" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "flags" },
+ { "lyrics" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "flags" },
+ { "karaoke" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "flags" },
+ { "forced" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "flags" },
+ { "hearing_impaired" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "flags" },
+ { "visual_impaired" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "flags" },
+ { "clean_effects" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "flags" },
+ { "attached_pic" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "flags" },
+ { "captions" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "flags" },
+ { "descriptions" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "flags" },
+ { "dependent" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "flags" },
+ { "metadata" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .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;
+ ret = av_opt_eval_flags(&pclass, &opts[0], ost->disposition, &ost->st->disposition);
+ /* initialize bitstream filters for the output stream
+ * needs to be done here, because the codec id for streamcopy is not
+ * known until now */
+ ret = init_output_bsfs(ost);
+ ost->initialized = 1;
+ ret = check_init_output_file(output_files[ost->file_index], ost->file_index);
+static void report_new_stream(int input_index, AVPacket *pkt)
+ InputFile *file = input_files[input_index];
+ AVStream *st = file->ctx->streams[pkt->stream_index];
+ if (pkt->stream_index < file->nb_streams_warn)
+ av_log(file->ctx, AV_LOG_WARNING,
+ "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
+ av_get_media_type_string(st->codecpar->codec_type),
+ input_index, pkt->stream_index,
+ pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
+ file->nb_streams_warn = pkt->stream_index + 1;
+static int transcode_init(void)
+ int ret = 0, i, j, k;
+ char error[1024] = {0};
+ OutputFilter *ofilter = fg->outputs[j];
+ if (!ofilter->ost || ofilter->ost->source_index >= 0)
+ if (fg->nb_inputs != 1)
+ for (k = nb_input_streams-1; k >= 0 ; k--)
+ if (fg->inputs[0]->ist == input_streams[k])
+ ofilter->ost->source_index = k;
+ /* init framerate emulation */
+ InputFile *ifile = input_files[i];
+ if (ifile->rate_emu)
+ for (j = 0; j < ifile->nb_streams; j++)
+ input_streams[j + ifile->ist_index]->start = av_gettime_relative();
+ /* init input streams */
+ for (i = 0; i < nb_input_streams; i++)
+ if ((ret = init_input_stream(i, error, sizeof(error))) < 0) {
+ avcodec_close(ost->enc_ctx);
+ goto dump_format;
+ /* open each encoder */
+ // skip streams fed from filtergraphs until we have a frame for them
+ if (output_streams[i]->filter)
+ ret = init_output_stream(output_streams[i], error, sizeof(error));
+ /* discard unused programs */
+ for (j = 0; j < ifile->ctx->nb_programs; j++) {
+ AVProgram *p = ifile->ctx->programs[j];
+ int discard = AVDISCARD_ALL;
+ for (k = 0; k < p->nb_stream_indexes; k++)
+ if (!input_streams[ifile->ist_index + p->stream_index[k]]->discard) {
+ discard = AVDISCARD_DEFAULT;
+ p->discard = discard;
+ /* write headers for files with no streams */
+ oc = output_files[i]->ctx;
+ if (oc->oformat->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
+ ret = check_init_output_file(output_files[i], i);
+ dump_format:
+ /* dump the stream mapping */
+ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
+ ist = input_streams[i];
+ for (j = 0; j < ist->nb_filters; j++) {
+ if (!filtergraph_is_simple(ist->filters[j]->graph)) {
+ av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s",
+ ist->file_index, ist->st->index, ist->dec ? ist->dec->name : "?",
+ ist->filters[j]->name);
+ if (nb_filtergraphs > 1)
+ av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index);
+ if (ost->attachment_filename) {
+ /* an attached file */
+ av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n",
+ ost->attachment_filename, ost->file_index, ost->index);
+ if (ost->filter && !filtergraph_is_simple(ost->filter->graph)) {
+ /* output from a complex graph */
+ av_log(NULL, AV_LOG_INFO, " %s", ost->filter->name);
+ av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index);
+ av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\n", ost->file_index,
+ ost->index, ost->enc ? ost->enc->name : "?");
+ av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d",
+ input_streams[ost->source_index]->file_index,
+ input_streams[ost->source_index]->st->index,
+ ost->file_index,
+ ost->index);
+ if (ost->sync_ist != input_streams[ost->source_index])
+ av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]",
+ ost->sync_ist->file_index,
+ ost->sync_ist->st->index);
+ if (ost->stream_copy)
+ av_log(NULL, AV_LOG_INFO, " (copy)");
+ else {
+ const AVCodec *in_codec = input_streams[ost->source_index]->dec;
+ const AVCodec *out_codec = ost->enc;
+ const char *decoder_name = "?";
+ const char *in_codec_name = "?";
+ const char *encoder_name = "?";
+ const char *out_codec_name = "?";
+ if (in_codec) {
+ decoder_name = in_codec->name;
+ desc = avcodec_descriptor_get(in_codec->id);
+ if (desc)
+ in_codec_name = desc->name;
+ if (!strcmp(decoder_name, in_codec_name))
+ decoder_name = "native";
+ if (out_codec) {
+ encoder_name = out_codec->name;
+ desc = avcodec_descriptor_get(out_codec->id);
+ out_codec_name = desc->name;
+ if (!strcmp(encoder_name, out_codec_name))
+ encoder_name = "native";
+ av_log(NULL, AV_LOG_INFO, " (%s (%s) -> %s (%s))",
+ in_codec_name, decoder_name,
+ out_codec_name, encoder_name);
+ if (ret) {
+ av_log(NULL, AV_LOG_ERROR, "%s\n", error);
+ atomic_store(&transcode_init_done, 1);
+/* Return 1 if there remain streams where more output is wanted, 0 otherwise. */
+static int need_output(void)
+ AVFormatContext *os = output_files[ost->file_index]->ctx;
+ if (ost->finished ||
+ (os->pb && avio_tell(os->pb) >= of->limit_filesize))
+ for (j = 0; j < of->ctx->nb_streams; j++)
+ close_output_stream(output_streams[of->ost_index + j]);
+ * Select the output stream to process.
+ * @return selected output stream, or NULL if none available
+static OutputStream *choose_output(void)
+ int64_t opts_min = INT64_MAX;
+ OutputStream *ost_min = NULL;
+ int64_t opts = ost->st->cur_dts == AV_NOPTS_VALUE ? INT64_MIN :
+ av_rescale_q(ost->st->cur_dts, ost->st->time_base,
+ AV_TIME_BASE_Q);
+ if (ost->st->cur_dts == AV_NOPTS_VALUE)
+ av_log(NULL, AV_LOG_DEBUG,
+ "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
+ ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished);
+ if (!ost->initialized && !ost->inputs_done)
+ return ost;
+ if (!ost->finished && opts < opts_min) {
+ opts_min = opts;
+ ost_min = ost->unavailable ? NULL : ost;
+ return ost_min;
+static void set_tty_echo(int on)
+ if (tcgetattr(0, &tty) == 0) {
+ if (on) tty.c_lflag |= ECHO;
+ else tty.c_lflag &= ~ECHO;
+ tcsetattr(0, TCSANOW, &tty);
+static int check_keyboard_interaction(int64_t cur_time)
+ int i, ret, key;
+ static int64_t last_time;
+ if (received_nb_signals)
+ return AVERROR_EXIT;
+ /* read_key() returns 0 on EOF */
+ if(cur_time - last_time >= 100000 && !run_as_daemon){
+ key = read_key();
+ key = -1;
+ if (key == 'q')
+ if (key == '+') av_log_set_level(av_log_get_level()+10);
+ if (key == '-') av_log_set_level(av_log_get_level()-10);
+ if (key == 's') qp_hist ^= 1;
+ if (key == 'h'){
+ if (do_hex_dump){
+ do_hex_dump = do_pkt_dump = 0;
+ } else if(do_pkt_dump){
+ do_hex_dump = 1;
+ do_pkt_dump = 1;
+ if (key == 'c' || key == 'C'){
+ char buf[4096], target[64], command[256], arg[256] = {0};
+ double time;
+ int k, n = 0;
+ fprintf(stderr, "\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
+ i = 0;
+ set_tty_echo(1);
+ while ((k = read_key()) != '\n' && k != '\r' && i < sizeof(buf)-1)
+ if (k > 0)
+ buf[i++] = k;
+ buf[i] = 0;
+ set_tty_echo(0);
+ fprintf(stderr, "\n");
+ if (k > 0 &&
+ (n = sscanf(buf, "%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
+ av_log(NULL, AV_LOG_DEBUG, "Processing command target:%s time:%f command:%s arg:%s",
+ target, time, command, arg);
+ if (fg->graph) {
+ if (time < 0) {
+ ret = avfilter_graph_send_command(fg->graph, target, command, arg, buf, sizeof(buf),
+ key == 'c' ? AVFILTER_CMD_FLAG_ONE : 0);
+ fprintf(stderr, "Command reply for stream %d: ret:%d res:\n%s", i, ret, buf);
+ } else if (key == 'c') {
+ fprintf(stderr, "Queuing commands only on filters supporting the specific command is unsupported\n");
+ ret = AVERROR_PATCHWELCOME;
+ ret = avfilter_graph_queue_command(fg->graph, target, command, arg, 0, time);
+ fprintf(stderr, "Queuing command failed with error %s\n", av_err2str(ret));
+ "Parse error, at least 3 arguments were expected, "
+ "only %d given in string '%s'\n", n, buf);
+ if (key == 'd' || key == 'D'){
+ int debug=0;
+ if(key == 'D') {
+ debug = input_streams[0]->st->codec->debug<<1;
+ if(!debug) debug = 1;
+ while(debug & (FF_DEBUG_DCT_COEFF
+#if FF_API_DEBUG_MV
+ |FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE
+ )) //unsupported, would just crash
+ debug += debug;
+ char buf[32];
+ int k = 0;
+ if (k <= 0 || sscanf(buf, "%d", &debug)!=1)
+ fprintf(stderr,"error parsing debug value\n");
+ for(i=0;i<nb_input_streams;i++) {
+ input_streams[i]->st->codec->debug = debug;
+ for(i=0;i<nb_output_streams;i++) {
+ ost->enc_ctx->debug = debug;
+ if(debug) av_log_set_level(AV_LOG_DEBUG);
+ fprintf(stderr,"debug=%d\n", debug);
+ if (key == '?'){
+ fprintf(stderr, "key function\n"
+ "? show this help\n"
+ "+ increase verbosity\n"
+ "- decrease verbosity\n"
+ "c Send command to first matching filter supporting it\n"
+ "C Send/Queue command to all matching filters\n"
+ "D cycle through available debug modes\n"
+ "h dump packets/hex press to cycle through the 3 states\n"
+ "q quit\n"
+ "s Show QP histogram\n"
+static void *input_thread(void *arg)
+ InputFile *f = arg;
+ unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
+ ret = av_read_frame(f->ctx, &pkt);
+ av_usleep(10000);
+ av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
+ ret = av_thread_message_queue_send(f->in_thread_queue, &pkt, flags);
+ if (flags && ret == AVERROR(EAGAIN)) {
+ flags = 0;
+ av_log(f->ctx, AV_LOG_WARNING,
+ "Thread message queue blocking; consider raising the "
+ "thread_queue_size option (current value: %d)\n",
+ f->thread_queue_size);
+ av_log(f->ctx, AV_LOG_ERROR,
+ "Unable to send packet to main thread: %s\n",
+static void free_input_thread(int i)
+ if (!f || !f->in_thread_queue)
+ av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
+ while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
+ pthread_join(f->thread, NULL);
+ f->joined = 1;
+ av_thread_message_queue_free(&f->in_thread_queue);
+static void free_input_threads(void)
+ for (i = 0; i < nb_input_files; i++)
+ free_input_thread(i);
+static int init_input_thread(int i)
+ if (nb_input_files == 1)
+ if (f->ctx->pb ? !f->ctx->pb->seekable :
+ strcmp(f->ctx->iformat->name, "lavfi"))
+ f->non_blocking = 1;
+ ret = av_thread_message_queue_alloc(&f->in_thread_queue,
+ f->thread_queue_size, sizeof(AVPacket));
+ if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
+ av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
+ return AVERROR(ret);
+static int init_input_threads(void)
+ ret = init_input_thread(i);
+static int get_input_packet_mt(InputFile *f, AVPacket *pkt)
+ return av_thread_message_queue_recv(f->in_thread_queue, pkt,
+ f->non_blocking ?
+ AV_THREAD_MESSAGE_NONBLOCK : 0);
+static int get_input_packet(InputFile *f, AVPacket *pkt)
+ if (f->rate_emu) {
+ for (i = 0; i < f->nb_streams; i++) {
+ InputStream *ist = input_streams[f->ist_index + i];
+ int64_t pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
+ int64_t now = av_gettime_relative() - ist->start;
+ if (pts > now)
+ return AVERROR(EAGAIN);
+ if (nb_input_files > 1)
+ return get_input_packet_mt(f, pkt);
+ return av_read_frame(f->ctx, pkt);
+static int got_eagain(void)
+ for (i = 0; i < nb_output_streams; i++)
+ if (output_streams[i]->unavailable)
+static void reset_eagain(void)
+ input_files[i]->eagain = 0;
+ output_streams[i]->unavailable = 0;
+// set duration to max(tmp, duration) in a proper time base and return duration's time_base
+static AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base,
+ AVRational time_base)
+ if (!*duration) {
+ *duration = tmp;
+ return tmp_time_base;
+ ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base);
+ return time_base;
+static int seek_to_start(InputFile *ifile, AVFormatContext *is)
+ AVCodecContext *avctx;
+ int i, ret, has_audio = 0;
+ int64_t duration = 0;
+ ret = av_seek_frame(is, -1, is->start_time, 0);
+ for (i = 0; i < ifile->nb_streams; i++) {
+ ist = input_streams[ifile->ist_index + i];
+ avctx = ist->dec_ctx;
+ /* duration is the length of the last frame in a stream
+ * when audio stream is present we don't care about
+ * last video frame length because it's not defined exactly */
+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples)
+ has_audio = 1;
+ if (has_audio) {
+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) {
+ AVRational sample_rate = {1, avctx->sample_rate};
+ duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base);
+ duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
+ } else if (ist->st->avg_frame_rate.num) {
+ duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base);
+ duration = 1;
+ if (!ifile->duration)
+ ifile->time_base = ist->st->time_base;
+ /* the total duration of the stream, max_pts - min_pts is
+ * the duration of the stream without the last frame */
+ if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration)
+ duration += ist->max_pts - ist->min_pts;
+ ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base,
+ ifile->time_base);
+ if (ifile->loop > 0)
+ ifile->loop--;
+ * Return
+ * - 0 -- one packet was read and processed
+ * - AVERROR(EAGAIN) -- no packets were available for selected file,
+ * this function should be called again
+ * - AVERROR_EOF -- this function should not be called again
+static int process_input(int file_index)
+ InputFile *ifile = input_files[file_index];
+ AVFormatContext *is;
+ int ret, thread_ret, i, j;
+ int64_t duration;
+ int64_t pkt_dts;
+ is = ifile->ctx;
+ ret = get_input_packet(ifile, &pkt);
+ ifile->eagain = 1;
+ if (ret < 0 && ifile->loop) {
+ ret = process_input_packet(ist, NULL, 1);
+ if (ret>0)
+ avcodec_flush_buffers(avctx);
+ free_input_thread(file_index);
+ ret = seek_to_start(ifile, is);
+ thread_ret = init_input_thread(file_index);
+ if (thread_ret < 0)
+ return thread_ret;
+ av_log(NULL, AV_LOG_WARNING, "Seek to start failed.\n");
+ if (ret != AVERROR_EOF) {
+ print_error(is->url, ret);
+ ret = process_input_packet(ist, NULL, 0);
+ /* mark all outputs that don't go through lavfi as finished */
+ for (j = 0; j < nb_output_streams; j++) {
+ OutputStream *ost = output_streams[j];
+ if (ost->source_index == ifile->ist_index + i &&
+ (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE))
+ ifile->eof_reached = 1;
+ reset_eagain();
+ if (do_pkt_dump) {
+ av_pkt_dump_log2(NULL, AV_LOG_INFO, &pkt, do_hex_dump,
+ is->streams[pkt.stream_index]);
+ /* the following test is needed in case new streams appear
+ dynamically in stream : we ignore them */
+ if (pkt.stream_index >= ifile->nb_streams) {
+ report_new_stream(file_index, &pkt);
+ goto discard_packet;
+ ist = input_streams[ifile->ist_index + pkt.stream_index];
+ ist->data_size += pkt.size;
+ ist->nb_packets++;
+ if (ist->discard)
+ if (pkt.flags & AV_PKT_FLAG_CORRUPT) {
+ "%s: corrupt input packet in stream %d\n", is->url, pkt.stream_index);
+ av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s "
+ "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
+ ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->dec_ctx->codec_type),
+ av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q),
+ av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q),
+ av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base),
+ av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base),
+ av_ts2str(input_files[ist->file_index]->ts_offset),
+ av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
+ if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){
+ int64_t stime, stime2;
+ // Correcting starttime based on the enabled streams
+ // FIXME this ideally should be done before the first use of starttime but we do not know which are the enabled streams at that point.
+ // so we instead do it here as part of discontinuity handling
+ if ( ist->next_dts == AV_NOPTS_VALUE
+ && ifile->ts_offset == -is->start_time
+ && (is->iformat->flags & AVFMT_TS_DISCONT)) {
+ int64_t new_start_time = INT64_MAX;
+ for (i=0; i<is->nb_streams; i++) {
+ AVStream *st = is->streams[i];
+ if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
+ new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
+ if (new_start_time > is->start_time) {
+ av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time);
+ ifile->ts_offset = -new_start_time;
+ stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->st->time_base);
+ stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
+ ist->wrap_correction_done = 1;
+ if(stime2 > stime && pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
+ pkt.dts -= 1ULL<<ist->st->pts_wrap_bits;
+ ist->wrap_correction_done = 0;
+ if(stime2 > stime && pkt.pts != AV_NOPTS_VALUE && pkt.pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
+ pkt.pts -= 1ULL<<ist->st->pts_wrap_bits;
+ /* add the stream-global side data to the first packet */
+ if (ist->nb_packets == 1) {
+ AVPacketSideData *src_sd = &ist->st->side_data[i];
+ if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX)
+ if (av_packet_get_side_data(&pkt, src_sd->type, NULL))
+ dst_data = av_packet_new_side_data(&pkt, src_sd->type, src_sd->size);
+ memcpy(dst_data, src_sd->data, src_sd->size);
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+ if (pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+ pkt.pts *= ist->ts_scale;
+ pkt.dts *= ist->ts_scale;
+ pkt_dts = av_rescale_q_rnd(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+ if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
+ ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
+ pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts
+ && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) {
+ int64_t delta = pkt_dts - ifile->last_ts;
+ if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
+ delta > 1LL*dts_delta_threshold*AV_TIME_BASE){
+ ifile->ts_offset -= delta;
+ "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+ delta, ifile->ts_offset);
+ pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+ pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
+ duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base);
+ if (pkt.pts != AV_NOPTS_VALUE) {
+ pkt.pts += duration;
+ ist->max_pts = FFMAX(pkt.pts, ist->max_pts);
+ ist->min_pts = FFMIN(pkt.pts, ist->min_pts);
+ pkt.dts += duration;
+ pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
+ !copy_ts) {
+ int64_t delta = pkt_dts - ist->next_dts;
+ if (is->iformat->flags & AVFMT_TS_DISCONT) {
+ delta > 1LL*dts_delta_threshold*AV_TIME_BASE ||
+ pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->pts, ist->dts)) {
+ "timestamp discontinuity for stream #%d:%d "
+ "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
+ ist->file_index, ist->st->index, ist->st->id,
+ av_get_media_type_string(ist->dec_ctx->codec_type),
+ if ( delta < -1LL*dts_error_threshold*AV_TIME_BASE ||
+ delta > 1LL*dts_error_threshold*AV_TIME_BASE) {
+ av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt.dts, ist->next_dts, pkt.stream_index);
+ pkt.dts = AV_NOPTS_VALUE;
+ if (pkt.pts != AV_NOPTS_VALUE){
+ int64_t pkt_pts = av_rescale_q(pkt.pts, ist->st->time_base, AV_TIME_BASE_Q);
+ delta = pkt_pts - ist->next_dts;
+ av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt.pts, ist->next_dts, pkt.stream_index);
+ pkt.pts = AV_NOPTS_VALUE;
+ ifile->last_ts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
+ av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
+ sub2video_heartbeat(ist, pkt.pts);
+ process_input_packet(ist, &pkt, 0);
+discard_packet:
+ * Perform a step of transcoding for the specified filter graph.
+ * @param[in] graph filter graph to consider
+ * @param[out] best_ist input stream where a frame would allow to continue
+ * @return 0 for success, <0 for error
+static int transcode_from_filter(FilterGraph *graph, InputStream **best_ist)
+ int nb_requests, nb_requests_max = 0;
+ InputFilter *ifilter;
+ *best_ist = NULL;
+ ret = avfilter_graph_request_oldest(graph->graph);
+ return reap_filters(0);
+ for (i = 0; i < graph->nb_outputs; i++)
+ close_output_stream(graph->outputs[i]->ost);
+ if (ret != AVERROR(EAGAIN))
+ for (i = 0; i < graph->nb_inputs; i++) {
+ ifilter = graph->inputs[i];
+ ist = ifilter->ist;
+ if (input_files[ist->file_index]->eagain ||
+ input_files[ist->file_index]->eof_reached)
+ nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->filter);
+ if (nb_requests > nb_requests_max) {
+ nb_requests_max = nb_requests;
+ *best_ist = ist;
+ if (!*best_ist)
+ graph->outputs[i]->ost->unavailable = 1;
+ * Run a single step of transcoding.
+static int transcode_step(void)
+ ost = choose_output();
+ if (!ost) {
+ if (got_eagain()) {
+ av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
+ return AVERROR_EOF;
+ if (ost->filter && !ost->filter->graph->graph) {
+ if (ifilter_has_all_input_formats(ost->filter->graph)) {
+ ret = configure_filtergraph(ost->filter->graph);
+ if (ost->filter && ost->filter->graph->graph) {
+ if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0)
+ if (!ist)
+ } else if (ost->filter) {
+ for (i = 0; i < ost->filter->graph->nb_inputs; i++) {
+ InputFilter *ifilter = ost->filter->graph->inputs[i];
+ if (!ifilter->ist->got_output && !input_files[ifilter->ist->file_index]->eof_reached) {
+ if (!ist) {
+ ost->inputs_done = 1;
+ av_assert0(ost->source_index >= 0);
+ ret = process_input(ist->file_index);
+ if (input_files[ist->file_index]->eagain)
+ ost->unavailable = 1;
+ return ret == AVERROR_EOF ? 0 : ret;
+ * The following code is the main loop of the file converter
+static int transcode(void)
+ AVFormatContext *os;
+ int64_t timer_start;
+ int64_t total_packets_written = 0;
+ ret = transcode_init();
+ if (stdin_interaction) {
+ av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
+ timer_start = av_gettime_relative();
+ if ((ret = init_input_threads()) < 0)
+ while (!received_sigterm) {
+ int64_t cur_time= av_gettime_relative();
+ /* if 'q' pressed, exits */
+ if (stdin_interaction)
+ if (check_keyboard_interaction(cur_time) < 0)
+ /* check if there's any stream where output is still needed */
+ if (!need_output()) {
+ av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n");
+ ret = transcode_step();
+ /* dump report by using the output first video and audio streams */
+ print_report(0, timer_start, cur_time);
+ /* at the end of stream, we must flush the decoder buffers */
+ if (!input_files[ist->file_index]->eof_reached) {
+ process_input_packet(ist, NULL, 0);
+ flush_encoders();
+ /* write the trailer if needed and close file */
+ os = output_files[i]->ctx;
+ if (!output_files[i]->header_written) {
+ "Nothing was written into output file %d (%s), because "
+ "at least one of its streams received no packets.\n",
+ i, os->url);
+ if ((ret = av_write_trailer(os)) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error writing trailer of %s: %s\n", os->url, av_err2str(ret));
+ /* dump report by using the first video and audio streams */
+ print_report(1, timer_start, av_gettime_relative());
+ /* close each encoder */
+ av_freep(&ost->enc_ctx->stats_in);
+ total_packets_written += ost->packets_written;
+ if (!total_packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT)) {
+ av_log(NULL, AV_LOG_FATAL, "Empty output\n");
+ /* close each decoder */
+ avcodec_close(ist->dec_ctx);
+ if (ist->hwaccel_uninit)
+ ist->hwaccel_uninit(ist->dec_ctx);
+ av_buffer_unref(&hw_device_ctx);
+ hw_device_free_all();
+ /* finished ! */
+ if (output_streams) {
+ if (ost) {
+ if (ost->logfile) {
+ if (fclose(ost->logfile))
+ "Error closing logfile, loss of information possible: %s\n",
+ ost->logfile = NULL;
+ av_freep(&ost->forced_kf_pts);
+ av_freep(&ost->apad);
+ av_freep(&ost->disposition);
+ av_dict_free(&ost->resample_opts);
+static BenchmarkTimeStamps get_benchmark_time_stamps(void)
+ BenchmarkTimeStamps time_stamps = { av_gettime_relative() };
+#if HAVE_GETRUSAGE
+ struct rusage rusage;
+ getrusage(RUSAGE_SELF, &rusage);
+ time_stamps.user_usec =
+ (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
+ time_stamps.sys_usec =
+ (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
+ HANDLE proc;
+ FILETIME c, e, k, u;
+ proc = GetCurrentProcess();
+ GetProcessTimes(proc, &c, &e, &k, &u);
+ ((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
+ ((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
+ time_stamps.user_usec = time_stamps.sys_usec = 0;
+ return time_stamps;
+static int64_t getmaxrss(void)
+#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
+ return (int64_t)rusage.ru_maxrss * 1024;
+#elif HAVE_GETPROCESSMEMORYINFO
+ PROCESS_MEMORY_COUNTERS memcounters;
+ memcounters.cb = sizeof(memcounters);
+ GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
+ return memcounters.PeakPagefileUsage;
+static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
+int main(int argc, char **argv)
+ BenchmarkTimeStamps ti;
+ init_dynload();
+ register_exit(ffmpeg_cleanup);
+ setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
+ av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ parse_loglevel(argc, argv, options);
+ if(argc>1 && !strcmp(argv[1], "-d")){
+ run_as_daemon=1;
+ av_log_set_callback(log_callback_null);
+ argc--;
+ argv++;
+ avdevice_register_all();
+ avformat_network_init();
+ show_banner(argc, argv, options);
+ /* parse options and open all input/output files */
+ ret = ffmpeg_parse_options(argc, argv);
+ if (nb_output_files <= 0 && nb_input_files == 0) {
+ show_usage();
+ av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
+ /* file converter / grab */
+ if (nb_output_files <= 0) {
+ av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
+ if (strcmp(output_files[i]->ctx->oformat->name, "rtp"))
+ want_sdp = 0;
+ current_time = ti = get_benchmark_time_stamps();
+ if (transcode() < 0)
+ int64_t utime, stime, rtime;
+ current_time = get_benchmark_time_stamps();
+ utime = current_time.user_usec - ti.user_usec;
+ stime = current_time.sys_usec - ti.sys_usec;
+ rtime = current_time.real_usec - ti.real_usec;
+ "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
+ utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
+ av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, %"PRIu64" decoding errors\n",
+ decode_error_stat[0], decode_error_stat[1]);
+ if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
+ exit_program(69);
+ exit_program(received_nb_signals ? 255 : main_return_code);
+ return main_return_code;
@@ -0,0 +1,668 @@
+#ifndef FFTOOLS_FFMPEG_H
+#define FFTOOLS_FFMPEG_H
+#include <stdio.h>
+#include <signal.h>
+#include "libavformat/avio.h"
+#include "libavutil/avutil.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
+#define VSYNC_AUTO -1
+#define VSYNC_PASSTHROUGH 0
+#define VSYNC_CFR 1
+#define VSYNC_VFR 2
+#define VSYNC_VSCFR 0xfe
+#define VSYNC_DROP 0xff
+#define MAX_STREAMS 1024 /* arbitrary sanity check value */
+enum HWAccelID {
+ HWACCEL_NONE = 0,
+ HWACCEL_AUTO,
+ HWACCEL_GENERIC,
+ HWACCEL_VIDEOTOOLBOX,
+ HWACCEL_QSV,
+ HWACCEL_CUVID,
+typedef struct HWAccel {
+ int (*init)(AVCodecContext *s);
+ enum HWAccelID id;
+ enum AVPixelFormat pix_fmt;
+} HWAccel;
+typedef struct HWDevice {
+ enum AVHWDeviceType type;
+ AVBufferRef *device_ref;
+} HWDevice;
+/* select an input stream for an output stream */
+typedef struct StreamMap {
+ int disabled; /* 1 is this mapping is disabled by a negative map */
+ int file_index;
+ int stream_index;
+ int sync_file_index;
+ int sync_stream_index;
+ char *linklabel; /* name of an output link, for mapping lavfi outputs */
+} StreamMap;
+typedef struct {
+ int file_idx, stream_idx, channel_idx; // input
+ int ofile_idx, ostream_idx; // output
+} AudioChannelMap;
+typedef struct OptionsContext {
+ /* input/output options */
+ int64_t start_time;
+ int64_t start_time_eof;
+ int seek_timestamp;
+ const char *format;
+ SpecifierOpt *codec_names;
+ int nb_codec_names;
+ SpecifierOpt *audio_channels;
+ int nb_audio_channels;
+ SpecifierOpt *audio_sample_rate;
+ int nb_audio_sample_rate;
+ SpecifierOpt *frame_rates;
+ int nb_frame_rates;
+ SpecifierOpt *frame_sizes;
+ int nb_frame_sizes;
+ SpecifierOpt *frame_pix_fmts;
+ int nb_frame_pix_fmts;
+ /* input options */
+ int64_t input_ts_offset;
+ int loop;
+ int rate_emu;
+ int accurate_seek;
+ int thread_queue_size;
+ SpecifierOpt *ts_scale;
+ int nb_ts_scale;
+ SpecifierOpt *dump_attachment;
+ int nb_dump_attachment;
+ SpecifierOpt *hwaccels;
+ int nb_hwaccels;
+ SpecifierOpt *hwaccel_devices;
+ int nb_hwaccel_devices;
+ SpecifierOpt *hwaccel_output_formats;
+ int nb_hwaccel_output_formats;
+ SpecifierOpt *autorotate;
+ int nb_autorotate;
+ /* output options */
+ StreamMap *stream_maps;
+ int nb_stream_maps;
+ AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */
+ int nb_audio_channel_maps; /* number of (valid) -map_channel settings */
+ int metadata_global_manual;
+ int metadata_streams_manual;
+ int metadata_chapters_manual;
+ const char **attachments;
+ int nb_attachments;
+ int chapters_input_file;
+ int64_t recording_time;
+ int64_t stop_time;
+ uint64_t limit_filesize;
+ float mux_preload;
+ float mux_max_delay;
+ int shortest;
+ int bitexact;
+ int video_disable;
+ int audio_disable;
+ int subtitle_disable;
+ int data_disable;
+ /* indexed by output file stream index */
+ int *streamid_map;
+ int nb_streamid_map;
+ SpecifierOpt *metadata;
+ int nb_metadata;
+ SpecifierOpt *max_frames;
+ int nb_max_frames;
+ SpecifierOpt *bitstream_filters;
+ int nb_bitstream_filters;
+ SpecifierOpt *codec_tags;
+ int nb_codec_tags;
+ SpecifierOpt *sample_fmts;
+ int nb_sample_fmts;
+ SpecifierOpt *qscale;
+ int nb_qscale;
+ SpecifierOpt *forced_key_frames;
+ int nb_forced_key_frames;
+ SpecifierOpt *force_fps;
+ int nb_force_fps;
+ SpecifierOpt *frame_aspect_ratios;
+ int nb_frame_aspect_ratios;
+ SpecifierOpt *rc_overrides;
+ int nb_rc_overrides;
+ SpecifierOpt *intra_matrices;
+ int nb_intra_matrices;
+ SpecifierOpt *inter_matrices;
+ int nb_inter_matrices;
+ SpecifierOpt *chroma_intra_matrices;
+ int nb_chroma_intra_matrices;
+ SpecifierOpt *top_field_first;
+ int nb_top_field_first;
+ SpecifierOpt *metadata_map;
+ int nb_metadata_map;
+ SpecifierOpt *presets;
+ int nb_presets;
+ SpecifierOpt *copy_initial_nonkeyframes;
+ int nb_copy_initial_nonkeyframes;
+ SpecifierOpt *copy_prior_start;
+ int nb_copy_prior_start;
+ SpecifierOpt *filters;
+ int nb_filters;
+ SpecifierOpt *filter_scripts;
+ int nb_filter_scripts;
+ SpecifierOpt *reinit_filters;
+ int nb_reinit_filters;
+ SpecifierOpt *fix_sub_duration;
+ int nb_fix_sub_duration;
+ SpecifierOpt *canvas_sizes;
+ int nb_canvas_sizes;
+ SpecifierOpt *pass;
+ int nb_pass;
+ SpecifierOpt *passlogfiles;
+ int nb_passlogfiles;
+ SpecifierOpt *max_muxing_queue_size;
+ int nb_max_muxing_queue_size;
+ SpecifierOpt *guess_layout_max;
+ int nb_guess_layout_max;
+ SpecifierOpt *apad;
+ int nb_apad;
+ SpecifierOpt *discard;
+ int nb_discard;
+ SpecifierOpt *disposition;
+ int nb_disposition;
+ SpecifierOpt *program;
+ int nb_program;
+ SpecifierOpt *time_bases;
+ int nb_time_bases;
+ SpecifierOpt *enc_time_bases;
+ int nb_enc_time_bases;
+} OptionsContext;
+typedef struct InputFilter {
+ struct InputStream *ist;
+ struct FilterGraph *graph;
+ uint8_t *name;
+ enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video
+ AVFifoBuffer *frame_queue;
+ // parameters configured for this input
+ int format;
+ int width, height;
+ AVRational sample_aspect_ratio;
+ int sample_rate;
+ int channels;
+ uint64_t channel_layout;
+ AVBufferRef *hw_frames_ctx;
+ int eof;
+} InputFilter;
+typedef struct OutputFilter {
+ struct OutputStream *ost;
+ /* temporary storage until stream maps are processed */
+ AVFilterInOut *out_tmp;
+ enum AVMediaType type;
+ /* desired output stream properties */
+ // those are only set if no format is specified and the encoder gives us multiple options
+ int *formats;
+ uint64_t *channel_layouts;
+ int *sample_rates;
+} OutputFilter;
+typedef struct FilterGraph {
+ int index;
+ const char *graph_desc;
+ AVFilterGraph *graph;
+ int reconfiguration;
+ InputFilter **inputs;
+ int nb_inputs;
+ OutputFilter **outputs;
+ int nb_outputs;
+} FilterGraph;
+typedef struct InputStream {
+ AVStream *st;
+ int discard; /* true if stream data should be discarded */
+ int user_set_discard;
+ int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
+#define DECODING_FOR_OST 1
+#define DECODING_FOR_FILTER 2
+ AVCodecContext *dec_ctx;
+ AVCodec *dec;
+ AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
+ int64_t start; /* time when read started */
+ /* predicted dts of the next packet read for this stream or (when there are
+ * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
+ int64_t next_dts;
+ int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
+ int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
+ int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
+ int wrap_correction_done;
+ int64_t filter_in_rescale_delta_last;
+ int64_t min_pts; /* pts with the smallest value in a current stream */
+ int64_t max_pts; /* pts with the higher value in a current stream */
+ // when forcing constant input framerate through -r,
+ // this contains the pts that will be given to the next decoded frame
+ int64_t cfr_next_pts;
+ int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
+ double ts_scale;
+ int saw_first_ts;
+ AVDictionary *decoder_opts;
+ AVRational framerate; /* framerate forced with -r */
+ int top_field_first;
+ int guess_layout_max;
+ int autorotate;
+ int fix_sub_duration;
+ struct { /* previous decoded subtitle and related variables */
+ int got_output;
+ } prev_sub;
+ struct sub2video {
+ int64_t last_pts;
+ int64_t end_pts;
+ AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init
+ int w, h;
+ } sub2video;
+ int dr1;
+ /* decoded data from this stream goes into all those filters
+ * currently video and audio only */
+ InputFilter **filters;
+ int reinit_filters;
+ /* hwaccel options */
+ enum HWAccelID hwaccel_id;
+ enum AVHWDeviceType hwaccel_device_type;
+ char *hwaccel_device;
+ enum AVPixelFormat hwaccel_output_format;
+ /* hwaccel context */
+ void *hwaccel_ctx;
+ void (*hwaccel_uninit)(AVCodecContext *s);
+ int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
+ int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
+ enum AVPixelFormat hwaccel_pix_fmt;
+ enum AVPixelFormat hwaccel_retrieved_pix_fmt;
+ /* stats */
+ // combined size of all the packets read
+ uint64_t data_size;
+ /* number of packets successfully read for this stream */
+ uint64_t nb_packets;
+ // number of frames/samples retrieved from the decoder
+ uint64_t frames_decoded;
+ uint64_t samples_decoded;
+ int64_t *dts_buffer;
+ int nb_dts_buffer;
+} InputStream;
+typedef struct InputFile {
+ AVFormatContext *ctx;
+ int eof_reached; /* true if eof reached */
+ int eagain; /* true if last read attempt returned EAGAIN */
+ int ist_index; /* index of first stream in input_streams */
+ int loop; /* set number of times input stream should be looped */
+ int64_t duration; /* actual duration of the longest stream in a file
+ at the moment when looping happens */
+ AVRational time_base; /* time base of the duration */
+ int64_t ts_offset;
+ int64_t last_ts;
+ int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
+ int nb_streams; /* number of stream that ffmpeg is aware of; may be different
+ from ctx.nb_streams if new streams appear during av_read_frame() */
+ int nb_streams_warn; /* number of streams that the user was warned of */
+ AVThreadMessageQueue *in_thread_queue;
+ pthread_t thread; /* thread reading from this file */
+ int non_blocking; /* reading packets from the thread should not block */
+ int joined; /* the thread has been joined */
+ int thread_queue_size; /* maximum number of queued packets */
+} InputFile;
+enum forced_keyframes_const {
+ FKF_N,
+ FKF_N_FORCED,
+ FKF_PREV_FORCED_N,
+ FKF_PREV_FORCED_T,
+ FKF_T,
+ FKF_NB
+#define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0)
+extern const char *const forced_keyframes_const_names[];
+typedef enum {
+ ENCODER_FINISHED = 1,
+ MUXER_FINISHED = 2,
+} OSTFinished ;
+typedef struct OutputStream {
+ int file_index; /* file index */
+ int index; /* stream index in the output file */
+ int source_index; /* InputStream index */
+ AVStream *st; /* stream in the output file */
+ int encoding_needed; /* true if encoding needed for this stream */
+ /* input pts and corresponding output pts
+ for A/V sync */
+ struct InputStream *sync_ist; /* input stream to sync against */
+ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
+ /* pts of the first frame encoded for this stream, used for limiting
+ * recording time */
+ int64_t first_pts;
+ /* dts of the last packet sent to the muxer */
+ int64_t last_mux_dts;
+ // the timebase of the packets sent to the muxer
+ AVRational mux_timebase;
+ AVRational enc_timebase;
+ AVBSFContext **bsf_ctx;
+ AVCodecContext *enc_ctx;
+ AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */
+ AVCodec *enc;
+ int64_t max_frames;
+ AVFrame *filtered_frame;
+ AVFrame *last_frame;
+ int last_dropped;
+ int last_nb0_frames[3];
+ /* video only */
+ int is_cfr;
+ int force_fps;
+ int rotate_overridden;
+ double rotate_override_value;
+ AVRational frame_aspect_ratio;
+ /* forced key frames */
+ int64_t forced_kf_ref_pts;
+ int64_t *forced_kf_pts;
+ int forced_kf_count;
+ int forced_kf_index;
+ char *forced_keyframes;
+ AVExpr *forced_keyframes_pexpr;
+ double forced_keyframes_expr_const_values[FKF_NB];
+ /* audio only */
+ int *audio_channels_map; /* list of the channels id to pick from the source stream */
+ int audio_channels_mapped; /* number of channels in audio_channels_map */
+ char *logfile_prefix;
+ FILE *logfile;
+ OutputFilter *filter;
+ char *avfilter;
+ char *filters; ///< filtergraph associated to the -filter option
+ char *filters_script; ///< filtergraph script associated to the -filter_script option
+ AVDictionary *encoder_opts;
+ char *apad;
+ OSTFinished finished; /* no more packets should be written for this stream */
+ int unavailable; /* true if the steram is unavailable (possibly temporarily) */
+ int stream_copy;
+ // init_output_stream() has been called for this stream
+ // The encoder and the bitstream filters have been initialized and the stream
+ // parameters are set in the AVStream.
+ int initialized;
+ int inputs_done;
+ const char *attachment_filename;
+ int copy_initial_nonkeyframes;
+ int copy_prior_start;
+ char *disposition;
+ int keep_pix_fmt;
+ // combined size of all the packets written
+ // number of packets send to the muxer
+ uint64_t packets_written;
+ // number of frames/samples sent to the encoder
+ uint64_t frames_encoded;
+ uint64_t samples_encoded;
+ /* packet quality factor */
+ int quality;
+ int max_muxing_queue_size;
+ /* the packets are buffered here until the muxer is ready to be initialized */
+ AVFifoBuffer *muxing_queue;
+ /* packet picture type */
+ int pict_type;
+ /* frame encode sum of squared error values */
+ int64_t error[4];
+} OutputStream;
+typedef struct OutputFile {
+ AVDictionary *opts;
+ int ost_index; /* index of the first stream in output_streams */
+ int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
+ int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
+ uint64_t limit_filesize; /* filesize limit expressed in bytes */
+ int header_written;
+} OutputFile;
+extern InputStream **input_streams;
+extern int nb_input_streams;
+extern InputFile **input_files;
+extern int nb_input_files;
+extern OutputStream **output_streams;
+extern int nb_output_streams;
+extern OutputFile **output_files;
+extern int nb_output_files;
+extern FilterGraph **filtergraphs;
+extern int nb_filtergraphs;
+extern char *vstats_filename;
+extern char *sdp_filename;
+extern float audio_drift_threshold;
+extern float dts_delta_threshold;
+extern float dts_error_threshold;
+extern int audio_volume;
+extern int audio_sync_method;
+extern int video_sync_method;
+extern float frame_drop_threshold;
+extern int do_benchmark;
+extern int do_benchmark_all;
+extern int do_deinterlace;
+extern int do_hex_dump;
+extern int do_pkt_dump;
+extern int copy_ts;
+extern int start_at_zero;
+extern int copy_tb;
+extern int debug_ts;
+extern int exit_on_error;
+extern int abort_on_flags;
+extern int print_stats;
+extern int qp_hist;
+extern int stdin_interaction;
+extern int frame_bits_per_raw_sample;
+extern AVIOContext *progress_avio;
+extern float max_error_rate;
+extern char *videotoolbox_pixfmt;
+extern int filter_nbthreads;
+extern int filter_complex_nbthreads;
+extern int vstats_version;
+extern const AVIOInterruptCB int_cb;
+extern const OptionDef options[];
+extern const HWAccel hwaccels[];
+extern AVBufferRef *hw_device_ctx;
+#if CONFIG_QSV
+extern char *qsv_device;
+extern HWDevice *filter_hw_device;
+void term_init(void);
+void term_exit(void);
+void reset_options(OptionsContext *o, int is_input);
+void show_usage(void);
+void opt_output_file(void *optctx, const char *filename);
+void remove_avoptions(AVDictionary **a, AVDictionary *b);
+void assert_avoptions(AVDictionary *m);
+int guess_input_channel_layout(InputStream *ist);
+enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *avctx, AVCodec *codec, enum AVPixelFormat target);
+void choose_sample_fmt(AVStream *st, AVCodec *codec);
+int configure_filtergraph(FilterGraph *fg);
+int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
+void check_filter_outputs(void);
+int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
+int filtergraph_is_simple(FilterGraph *fg);
+int init_simple_filtergraph(InputStream *ist, OutputStream *ost);
+int init_complex_filtergraph(FilterGraph *fg);
+void sub2video_update(InputStream *ist, AVSubtitle *sub);
+int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
+int ffmpeg_parse_options(int argc, char **argv);
+int videotoolbox_init(AVCodecContext *s);
+int qsv_init(AVCodecContext *s);
+int cuvid_init(AVCodecContext *s);
+HWDevice *hw_device_get_by_name(const char *name);
+int hw_device_init_from_string(const char *arg, HWDevice **dev);
+void hw_device_free_all(void);
+int hw_device_setup_for_decode(InputStream *ist);
+int hw_device_setup_for_encode(OutputStream *ost);
+int hwaccel_decode_init(AVCodecContext *avctx);
+#endif /* FFTOOLS_FFMPEG_H */
@@ -0,0 +1,73 @@
+static void cuvid_uninit(AVCodecContext *avctx)
+ InputStream *ist = avctx->opaque;
+ av_buffer_unref(&ist->hw_frames_ctx);
+int cuvid_init(AVCodecContext *avctx)
+ AVHWFramesContext *frames_ctx;
+ av_log(avctx, AV_LOG_VERBOSE, "Initializing cuvid hwaccel\n");
+ if (!hw_device_ctx) {
+ ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA,
+ ist->hwaccel_device, NULL, 0);
+ av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n");
+ ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
+ if (!ist->hw_frames_ctx) {
+ av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n");
+ frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
+ frames_ctx->format = AV_PIX_FMT_CUDA;
+ frames_ctx->sw_format = avctx->sw_pix_fmt;
+ frames_ctx->width = avctx->width;
+ frames_ctx->height = avctx->height;
+ av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n",
+ av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height);
+ ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
+ av_log(avctx, AV_LOG_ERROR, "Error initializing a CUDA frame pool\n");
+ ist->hwaccel_uninit = cuvid_uninit;
@@ -0,0 +1,1220 @@
+ * ffmpeg filter configuration
+#include "libavfilter/buffersink.h"
+#include "libavfilter/buffersrc.h"
+static const enum AVPixelFormat *get_compliance_unofficial_pix_fmts(enum AVCodecID codec_id, const enum AVPixelFormat default_formats[])
+ static const enum AVPixelFormat mjpeg_formats[] =
+ { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
+ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
+ AV_PIX_FMT_NONE };
+ static const enum AVPixelFormat ljpeg_formats[] =
+ { AV_PIX_FMT_BGR24 , AV_PIX_FMT_BGRA , AV_PIX_FMT_BGR0,
+ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
+ AV_PIX_FMT_YUV420P , AV_PIX_FMT_YUV444P , AV_PIX_FMT_YUV422P,
+ AV_PIX_FMT_NONE};
+ if (codec_id == AV_CODEC_ID_MJPEG) {
+ return mjpeg_formats;
+ } else if (codec_id == AV_CODEC_ID_LJPEG) {
+ return ljpeg_formats;
+ return default_formats;
+enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, AVCodec *codec, enum AVPixelFormat target)
+ if (codec && codec->pix_fmts) {
+ const enum AVPixelFormat *p = codec->pix_fmts;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
+ //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
+ int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
+ enum AVPixelFormat best= AV_PIX_FMT_NONE;
+ if (enc_ctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
+ p = get_compliance_unofficial_pix_fmts(enc_ctx->codec_id, p);
+ for (; *p != AV_PIX_FMT_NONE; p++) {
+ best= avcodec_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
+ if (*p == target)
+ if (*p == AV_PIX_FMT_NONE) {
+ if (target != AV_PIX_FMT_NONE)
+ "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
+ av_get_pix_fmt_name(target),
+ codec->name,
+ av_get_pix_fmt_name(best));
+ return best;
+ return target;
+void choose_sample_fmt(AVStream *st, AVCodec *codec)
+ if (codec && codec->sample_fmts) {
+ const enum AVSampleFormat *p = codec->sample_fmts;
+ for (; *p != -1; p++) {
+ if (*p == st->codecpar->format)
+ if (*p == -1) {
+ if((codec->capabilities & AV_CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codecpar->format) > av_get_sample_fmt_name(codec->sample_fmts[0]))
+ av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n");
+ if(av_get_sample_fmt_name(st->codecpar->format))
+ "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
+ av_get_sample_fmt_name(st->codecpar->format),
+ av_get_sample_fmt_name(codec->sample_fmts[0]));
+ st->codecpar->format = codec->sample_fmts[0];
+static char *choose_pix_fmts(OutputFilter *ofilter)
+ OutputStream *ost = ofilter->ost;
+ AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
+ if (strict_dict)
+ // used by choose_pixel_fmt() and below
+ av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
+ if (ost->keep_pix_fmt) {
+ avfilter_graph_set_auto_convert(ofilter->graph->graph,
+ AVFILTER_AUTO_CONVERT_NONE);
+ if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
+ return av_strdup(av_get_pix_fmt_name(ost->enc_ctx->pix_fmt));
+ if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
+ return av_strdup(av_get_pix_fmt_name(choose_pixel_fmt(ost->st, ost->enc_ctx, ost->enc, ost->enc_ctx->pix_fmt)));
+ } else if (ost->enc && ost->enc->pix_fmts) {
+ AVIOContext *s = NULL;
+ uint8_t *ret;
+ int len;
+ if (avio_open_dyn_buf(&s) < 0)
+ p = ost->enc->pix_fmts;
+ if (ost->enc_ctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
+ p = get_compliance_unofficial_pix_fmts(ost->enc_ctx->codec_id, p);
+ const char *name = av_get_pix_fmt_name(*p);
+ avio_printf(s, "%s|", name);
+ len = avio_close_dyn_buf(s, &ret);
+ ret[len - 1] = 0;
+/* Define a function for building a string containing a list of
+ * allowed formats. */
+#define DEF_CHOOSE_FORMAT(suffix, type, var, supported_list, none, get_name) \
+static char *choose_ ## suffix (OutputFilter *ofilter) \
+ if (ofilter->var != none) { \
+ get_name(ofilter->var); \
+ return av_strdup(name); \
+ } else if (ofilter->supported_list) { \
+ const type *p; \
+ AVIOContext *s = NULL; \
+ uint8_t *ret; \
+ int len; \
+ if (avio_open_dyn_buf(&s) < 0) \
+ exit_program(1); \
+ for (p = ofilter->supported_list; *p != none; p++) { \
+ avio_printf(s, "%s|", name); \
+ len = avio_close_dyn_buf(s, &ret); \
+ ret[len - 1] = 0; \
+ } else \
+ return NULL; \
+//DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, AV_PIX_FMT_NONE,
+// GET_PIX_FMT_NAME)
+DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
+ AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME)
+DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
+ GET_SAMPLE_RATE_NAME)
+DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0,
+ GET_CH_LAYOUT_NAME)
+int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
+ FilterGraph *fg = av_mallocz(sizeof(*fg));
+ if (!fg)
+ fg->index = nb_filtergraphs;
+ GROW_ARRAY(fg->outputs, fg->nb_outputs);
+ if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
+ fg->outputs[0]->ost = ost;
+ fg->outputs[0]->graph = fg;
+ fg->outputs[0]->format = -1;
+ ost->filter = fg->outputs[0];
+ GROW_ARRAY(fg->inputs, fg->nb_inputs);
+ if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
+ fg->inputs[0]->ist = ist;
+ fg->inputs[0]->graph = fg;
+ fg->inputs[0]->format = -1;
+ fg->inputs[0]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ if (!fg->inputs[0]->frame_queue)
+ GROW_ARRAY(ist->filters, ist->nb_filters);
+ ist->filters[ist->nb_filters - 1] = fg->inputs[0];
+ GROW_ARRAY(filtergraphs, nb_filtergraphs);
+ filtergraphs[nb_filtergraphs - 1] = fg;
+static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
+ AVFilterContext *ctx = inout->filter_ctx;
+ AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
+ int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
+ AVIOContext *pb;
+ uint8_t *res = NULL;
+ if (avio_open_dyn_buf(&pb) < 0)
+ avio_printf(pb, "%s", ctx->filter->name);
+ if (nb_pads > 1)
+ avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));
+ avio_w8(pb, 0);
+ avio_close_dyn_buf(pb, &res);
+ return res;
+static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
+ enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
+ // TODO: support other filter types
+ if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
+ av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
+ "currently.\n");
+ if (in->name) {
+ AVStream *st = NULL;
+ int file_idx = strtol(in->name, &p, 0);
+ if (file_idx < 0 || file_idx >= nb_input_files) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
+ file_idx, fg->graph_desc);
+ s = input_files[file_idx]->ctx;
+ for (i = 0; i < s->nb_streams; i++) {
+ enum AVMediaType stream_type = s->streams[i]->codecpar->codec_type;
+ if (stream_type != type &&
+ !(stream_type == AVMEDIA_TYPE_SUBTITLE &&
+ type == AVMEDIA_TYPE_VIDEO /* sub2video hack */))
+ if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
+ st = s->streams[i];
+ if (!st) {
+ av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
+ "matches no streams.\n", p, fg->graph_desc);
+ ist = input_streams[input_files[file_idx]->ist_index + st->index];
+ if (ist->user_set_discard == AVDISCARD_ALL) {
+ "matches a disabled input stream.\n", p, fg->graph_desc);
+ /* find the first unused stream of corresponding type */
+ if (ist->user_set_discard == AVDISCARD_ALL)
+ if (ist->dec_ctx->codec_type == type && ist->discard)
+ if (i == nb_input_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
+ "unlabeled input pad %d on filter %s\n", in->pad_idx,
+ in->filter_ctx->name);
+ av_assert0(ist);
+ ist->discard = 0;
+ ist->decoding_needed |= DECODING_FOR_FILTER;
+ ist->st->discard = AVDISCARD_NONE;
+ if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
+ fg->inputs[fg->nb_inputs - 1]->ist = ist;
+ fg->inputs[fg->nb_inputs - 1]->graph = fg;
+ fg->inputs[fg->nb_inputs - 1]->format = -1;
+ fg->inputs[fg->nb_inputs - 1]->type = ist->st->codecpar->codec_type;
+ fg->inputs[fg->nb_inputs - 1]->name = describe_filter_link(fg, in, 1);
+ fg->inputs[fg->nb_inputs - 1]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ if (!fg->inputs[fg->nb_inputs - 1]->frame_queue)
+ ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
+int init_complex_filtergraph(FilterGraph *fg)
+ AVFilterInOut *inputs, *outputs, *cur;
+ /* this graph is only used for determining the kinds of inputs
+ * and outputs we have, and is discarded on exit from this function */
+ graph = avfilter_graph_alloc();
+ if (!graph)
+ graph->nb_threads = 1;
+ ret = avfilter_graph_parse2(graph, fg->graph_desc, &inputs, &outputs);
+ for (cur = inputs; cur; cur = cur->next)
+ init_input_filter(fg, cur);
+ for (cur = outputs; cur;) {
+ fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]));
+ if (!fg->outputs[fg->nb_outputs - 1])
+ fg->outputs[fg->nb_outputs - 1]->graph = fg;
+ fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
+ fg->outputs[fg->nb_outputs - 1]->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
+ cur->pad_idx);
+ fg->outputs[fg->nb_outputs - 1]->name = describe_filter_link(fg, cur, 0);
+ cur = cur->next;
+ fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
+ avfilter_inout_free(&inputs);
+ avfilter_graph_free(&graph);
+static int insert_trim(int64_t start_time, int64_t duration,
+ AVFilterContext **last_filter, int *pad_idx,
+ const char *filter_name)
+ AVFilterGraph *graph = (*last_filter)->graph;
+ AVFilterContext *ctx;
+ const AVFilter *trim;
+ enum AVMediaType type = avfilter_pad_get_type((*last_filter)->output_pads, *pad_idx);
+ const char *name = (type == AVMEDIA_TYPE_VIDEO) ? "trim" : "atrim";
+ if (duration == INT64_MAX && start_time == AV_NOPTS_VALUE)
+ trim = avfilter_get_by_name(name);
+ if (!trim) {
+ av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
+ "recording time.\n", name);
+ return AVERROR_FILTER_NOT_FOUND;
+ ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);
+ if (!ctx)
+ if (duration != INT64_MAX) {
+ ret = av_opt_set_int(ctx, "durationi", duration,
+ AV_OPT_SEARCH_CHILDREN);
+ if (ret >= 0 && start_time != AV_NOPTS_VALUE) {
+ ret = av_opt_set_int(ctx, "starti", start_time,
+ av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
+ ret = avfilter_init_str(ctx, NULL);
+ ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
+ *last_filter = ctx;
+ *pad_idx = 0;
+static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
+ const char *filter_name, const char *args)
+ ret = avfilter_graph_create_filter(&ctx,
+ avfilter_get_by_name(filter_name),
+ filter_name, args, NULL, graph);
+static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
+ char *pix_fmts;
+ AVFilterContext *last_filter = out->filter_ctx;
+ int pad_idx = out->pad_idx;
+ char name[255];
+ snprintf(name, sizeof(name), "out_%d_%d", ost->file_index, ost->index);
+ ret = avfilter_graph_create_filter(&ofilter->filter,
+ avfilter_get_by_name("buffersink"),
+ name, NULL, NULL, fg->graph);
+ if (ofilter->width || ofilter->height) {
+ char args[255];
+ AVDictionaryEntry *e = NULL;
+ snprintf(args, sizeof(args), "%d:%d",
+ ofilter->width, ofilter->height);
+ while ((e = av_dict_get(ost->sws_dict, "", e,
+ AV_DICT_IGNORE_SUFFIX))) {
+ av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
+ snprintf(name, sizeof(name), "scaler_out_%d_%d",
+ if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
+ name, args, NULL, fg->graph)) < 0)
+ if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
+ last_filter = filter;
+ pad_idx = 0;
+ if ((pix_fmts = choose_pix_fmts(ofilter))) {
+ snprintf(name, sizeof(name), "format_out_%d_%d",
+ ret = avfilter_graph_create_filter(&filter,
+ avfilter_get_by_name("format"),
+ "format", pix_fmts, NULL, fg->graph);
+ av_freep(&pix_fmts);
+ if (ost->frame_rate.num && 0) {
+ AVFilterContext *fps;
+ snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
+ ost->frame_rate.den);
+ snprintf(name, sizeof(name), "fps_out_%d_%d",
+ ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
+ name, args, NULL, fg->graph);
+ ret = avfilter_link(last_filter, pad_idx, fps, 0);
+ last_filter = fps;
+ snprintf(name, sizeof(name), "trim_out_%d_%d",
+ ret = insert_trim(of->start_time, of->recording_time,
+ &last_filter, &pad_idx, name);
+ if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)
+static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
+ AVCodecContext *codec = ost->enc_ctx;
+ char *sample_fmts, *sample_rates, *channel_layouts;
+ avfilter_get_by_name("abuffersink"),
+ if ((ret = av_opt_set_int(ofilter->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
+#define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
+ AVFilterContext *filt_ctx; \
+ av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
+ "similarly to -af " filter_name "=%s.\n", arg); \
+ ret = avfilter_graph_create_filter(&filt_ctx, \
+ avfilter_get_by_name(filter_name), \
+ filter_name, arg, NULL, fg->graph); \
+ if (ret < 0) \
+ ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
+ last_filter = filt_ctx; \
+ pad_idx = 0; \
+ if (ost->audio_channels_mapped) {
+ AVBPrint pan_buf;
+ av_bprint_init(&pan_buf, 256, 8192);
+ av_bprintf(&pan_buf, "0x%"PRIx64,
+ av_get_default_channel_layout(ost->audio_channels_mapped));
+ for (i = 0; i < ost->audio_channels_mapped; i++)
+ if (ost->audio_channels_map[i] != -1)
+ av_bprintf(&pan_buf, "|c%d=c%d", i, ost->audio_channels_map[i]);
+ AUTO_INSERT_FILTER("-map_channel", "pan", pan_buf.str);
+ av_bprint_finalize(&pan_buf, NULL);
+ if (codec->channels && !codec->channel_layout)
+ codec->channel_layout = av_get_default_channel_layout(codec->channels);
+ sample_fmts = choose_sample_fmts(ofilter);
+ sample_rates = choose_sample_rates(ofilter);
+ channel_layouts = choose_channel_layouts(ofilter);
+ if (sample_fmts || sample_rates || channel_layouts) {
+ AVFilterContext *format;
+ char args[256];
+ args[0] = 0;
+ if (sample_fmts)
+ av_strlcatf(args, sizeof(args), "sample_fmts=%s:",
+ sample_fmts);
+ if (sample_rates)
+ av_strlcatf(args, sizeof(args), "sample_rates=%s:",
+ sample_rates);
+ if (channel_layouts)
+ av_strlcatf(args, sizeof(args), "channel_layouts=%s:",
+ channel_layouts);
+ av_freep(&sample_fmts);
+ av_freep(&sample_rates);
+ av_freep(&channel_layouts);
+ ret = avfilter_graph_create_filter(&format,
+ avfilter_get_by_name("aformat"),
+ ret = avfilter_link(last_filter, pad_idx, format, 0);
+ last_filter = format;
+ if (audio_volume != 256 && 0) {
+ snprintf(args, sizeof(args), "%f", audio_volume / 256.);
+ AUTO_INSERT_FILTER("-vol", "volume", args);
+ if (ost->apad && of->shortest) {
+ for (i=0; i<of->ctx->nb_streams; i++)
+ if (of->ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (i<of->ctx->nb_streams) {
+ snprintf(args, sizeof(args), "%s", ost->apad);
+ AUTO_INSERT_FILTER("-apad", "apad", args);
+ snprintf(name, sizeof(name), "trim for output stream %d:%d",
+int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
+ if (!ofilter->ost) {
+ av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
+ switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
+ case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out);
+ case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out);
+ default: av_assert0(0);
+void check_filter_outputs(void)
+ int n;
+ for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
+ OutputFilter *output = filtergraphs[i]->outputs[n];
+ if (!output->ost) {
+ av_log(NULL, AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name);
+static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
+ AVFormatContext *avf = input_files[ist->file_index]->ctx;
+ int i, w, h;
+ /* Compute the size of the canvas for the subtitles stream.
+ If the subtitles codecpar has set a size, use it. Otherwise use the
+ maximum dimensions of the video streams in the same file. */
+ w = ifilter->width;
+ h = ifilter->height;
+ if (!(w && h)) {
+ for (i = 0; i < avf->nb_streams; i++) {
+ if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+ w = FFMAX(w, avf->streams[i]->codecpar->width);
+ h = FFMAX(h, avf->streams[i]->codecpar->height);
+ w = FFMAX(w, 720);
+ h = FFMAX(h, 576);
+ av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
+ ist->sub2video.w = ifilter->width = w;
+ ist->sub2video.h = ifilter->height = h;
+ ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
+ ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
+ /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
+ palettes for all rectangles are identical or compatible */
+ ifilter->format = AV_PIX_FMT_RGB32;
+ ist->sub2video.frame = av_frame_alloc();
+ if (!ist->sub2video.frame)
+ ist->sub2video.last_pts = INT64_MIN;
+ ist->sub2video.end_pts = INT64_MIN;
+static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
+ AVFilterInOut *in)
+ AVFilterContext *last_filter;
+ const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
+ InputStream *ist = ifilter->ist;
+ InputFile *f = input_files[ist->file_index];
+ AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
+ ist->st->time_base;
+ AVRational fr = ist->framerate;
+ AVBPrint args;
+ int ret, pad_idx = 0;
+ int64_t tsoffset = 0;
+ AVBufferSrcParameters *par = av_buffersrc_parameters_alloc();
+ if (!par)
+ memset(par, 0, sizeof(*par));
+ par->format = AV_PIX_FMT_NONE;
+ if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot connect video filter to audio input\n");
+ ret = AVERROR(EINVAL);
+ if (!fr.num)
+ fr = av_guess_frame_rate(input_files[ist->file_index]->ctx, ist->st, NULL);
+ if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ ret = sub2video_prepare(ist, ifilter);
+ sar = ifilter->sample_aspect_ratio;
+ if(!sar.den)
+ sar = (AVRational){0,1};
+ av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ av_bprintf(&args,
+ "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
+ "pixel_aspect=%d/%d:sws_param=flags=%d",
+ ifilter->width, ifilter->height, ifilter->format,
+ tb.num, tb.den, sar.num, sar.den,
+ SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
+ if (fr.num && fr.den)
+ av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
+ snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
+ if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name,
+ args.str, NULL, fg->graph)) < 0)
+ par->hw_frames_ctx = ifilter->hw_frames_ctx;
+ ret = av_buffersrc_parameters_set(ifilter->filter, par);
+ av_freep(&par);
+ last_filter = ifilter->filter;
+ if (ist->autorotate) {
+ double theta = get_rotation(ist->st);
+ if (fabs(theta - 90) < 1.0) {
+ ret = insert_filter(&last_filter, &pad_idx, "transpose", "clock");
+ } else if (fabs(theta - 180) < 1.0) {
+ ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
+ ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
+ } else if (fabs(theta - 270) < 1.0) {
+ ret = insert_filter(&last_filter, &pad_idx, "transpose", "cclock");
+ } else if (fabs(theta) > 1.0) {
+ char rotate_buf[64];
+ snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
+ ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf);
+ if (do_deinterlace) {
+ AVFilterContext *yadif;
+ snprintf(name, sizeof(name), "deinterlace_in_%d_%d",
+ if ((ret = avfilter_graph_create_filter(&yadif,
+ avfilter_get_by_name("yadif"),
+ name, "", NULL,
+ fg->graph)) < 0)
+ if ((ret = avfilter_link(last_filter, 0, yadif, 0)) < 0)
+ last_filter = yadif;
+ snprintf(name, sizeof(name), "trim_in_%d_%d",
+ if (copy_ts) {
+ tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
+ if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
+ tsoffset += f->ctx->start_time;
+ ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
+ AV_NOPTS_VALUE : tsoffset, f->recording_time,
+ if ((ret = avfilter_link(last_filter, 0, in->filter_ctx, in->pad_idx)) < 0)
+static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
+ const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
+ if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
+ av_log(NULL, AV_LOG_ERROR, "Cannot connect audio filter to non audio input\n");
+ av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
+ 1, ifilter->sample_rate,
+ ifilter->sample_rate,
+ av_get_sample_fmt_name(ifilter->format));
+ if (ifilter->channel_layout)
+ av_bprintf(&args, ":channel_layout=0x%"PRIx64,
+ ifilter->channel_layout);
+ av_bprintf(&args, ":channels=%d", ifilter->channels);
+ snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
+ if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt,
+ name, args.str, NULL,
+#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
+ snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
+ fg->index, filter_name, ist->file_index, ist->st->index); \
+ name, arg, NULL, fg->graph); \
+ ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
+ if (audio_sync_method > 0) {
+ char args[256] = {0};
+ av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
+ if (audio_drift_threshold != 0.1)
+ av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", audio_drift_threshold);
+ if (!fg->reconfiguration)
+ av_strlcatf(args, sizeof(args), ":first_pts=0");
+ AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
+// if (ost->audio_channels_mapped) {
+// int i;
+// AVBPrint pan_buf;
+// av_bprint_init(&pan_buf, 256, 8192);
+// av_bprintf(&pan_buf, "0x%"PRIx64,
+// av_get_default_channel_layout(ost->audio_channels_mapped));
+// for (i = 0; i < ost->audio_channels_mapped; i++)
+// if (ost->audio_channels_map[i] != -1)
+// av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]);
+// AUTO_INSERT_FILTER_INPUT("-map_channel", "pan", pan_buf.str);
+// av_bprint_finalize(&pan_buf, NULL);
+// }
+ av_log(NULL, AV_LOG_WARNING, "-vol has been deprecated. Use the volume "
+ "audio filter instead.\n");
+ AUTO_INSERT_FILTER_INPUT("-vol", "volume", args);
+ snprintf(name, sizeof(name), "trim for input stream %d:%d",
+static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter,
+ if (!ifilter->ist->dec) {
+ "No decoder for stream #%d:%d, filtering impossible\n",
+ ifilter->ist->file_index, ifilter->ist->st->index);
+ return AVERROR_DECODER_NOT_FOUND;
+ switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) {
+ case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in);
+ case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in);
+static void cleanup_filtergraph(FilterGraph *fg)
+ for (i = 0; i < fg->nb_outputs; i++)
+ fg->outputs[i]->filter = (AVFilterContext *)NULL;
+ for (i = 0; i < fg->nb_inputs; i++)
+ fg->inputs[i]->filter = (AVFilterContext *)NULL;
+int configure_filtergraph(FilterGraph *fg)
+ int ret, i, simple = filtergraph_is_simple(fg);
+ const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
+ fg->graph_desc;
+ cleanup_filtergraph(fg);
+ if (!(fg->graph = avfilter_graph_alloc()))
+ if (simple) {
+ OutputStream *ost = fg->outputs[0]->ost;
+ char args[512];
+ fg->graph->nb_threads = filter_nbthreads;
+ av_strlcatf(args, sizeof(args), "%s=%s:", e->key, e->value);
+ if (strlen(args))
+ args[strlen(args)-1] = 0;
+ fg->graph->scale_sws_opts = av_strdup(args);
+ while ((e = av_dict_get(ost->swr_opts, "", e,
+ av_opt_set(fg->graph, "aresample_swr_opts", args, 0);
+ args[0] = '\0';
+ while ((e = av_dict_get(fg->outputs[0]->ost->resample_opts, "", e,
+ args[strlen(args) - 1] = '\0';
+ e = av_dict_get(ost->encoder_opts, "threads", NULL, 0);
+ if (e)
+ av_opt_set(fg->graph, "threads", e->value, 0);
+ fg->graph->nb_threads = filter_complex_nbthreads;
+ if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
+ if (filter_hw_device || hw_device_ctx) {
+ AVBufferRef *device = filter_hw_device ? filter_hw_device->device_ref
+ : hw_device_ctx;
+ for (i = 0; i < fg->graph->nb_filters; i++) {
+ fg->graph->filters[i]->hw_device_ctx = av_buffer_ref(device);
+ if (!fg->graph->filters[i]->hw_device_ctx) {
+ ret = AVERROR(ENOMEM);
+ if (simple && (!inputs || inputs->next || !outputs || outputs->next)) {
+ const char *num_inputs;
+ const char *num_outputs;
+ if (!outputs) {
+ num_outputs = "0";
+ } else if (outputs->next) {
+ num_outputs = ">1";
+ num_outputs = "1";
+ if (!inputs) {
+ num_inputs = "0";
+ } else if (inputs->next) {
+ num_inputs = ">1";
+ num_inputs = "1";
+ av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected "
+ "to have exactly 1 input and 1 output."
+ " However, it had %s input(s) and %s output(s)."
+ " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
+ graph_desc, num_inputs, num_outputs);
+ for (cur = inputs, i = 0; cur; cur = cur->next, i++)
+ if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
+ avfilter_inout_free(&outputs);
+ for (cur = outputs, i = 0; cur; cur = cur->next, i++)
+ configure_output_filter(fg, fg->outputs[i], cur);
+ if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
+ /* limit the lists of allowed formats to the ones selected, to
+ * make sure they stay the same if the filtergraph is reconfigured later */
+ for (i = 0; i < fg->nb_outputs; i++) {
+ OutputFilter *ofilter = fg->outputs[i];
+ AVFilterContext *sink = ofilter->filter;
+ ofilter->format = av_buffersink_get_format(sink);
+ ofilter->width = av_buffersink_get_w(sink);
+ ofilter->height = av_buffersink_get_h(sink);
+ ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
+ ofilter->channel_layout = av_buffersink_get_channel_layout(sink);
+ fg->reconfiguration = 1;
+ OutputStream *ost = fg->outputs[i]->ost;
+ if (!ost->enc) {
+ /* identical to the same check in ffmpeg.c, needed because
+ complex filter graphs are initialized earlier */
+ av_log(NULL, AV_LOG_ERROR, "Encoder (codec %s) not found for output stream #%d:%d\n",
+ avcodec_get_name(ost->st->codecpar->codec_id), ost->file_index, ost->index);
+ while (av_fifo_size(fg->inputs[i]->frame_queue)) {
+ AVFrame *tmp;
+ av_fifo_generic_read(fg->inputs[i]->frame_queue, &tmp, sizeof(tmp), NULL);
+ ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
+ /* send the EOFs for the finished inputs */
+ if (fg->inputs[i]->eof) {
+ ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL);
+ /* process queued up subtitle packets */
+ InputStream *ist = fg->inputs[i]->ist;
+ if (ist->sub2video.sub_queue && ist->sub2video.frame) {
+ while (av_fifo_size(ist->sub2video.sub_queue)) {
+ AVSubtitle tmp;
+ av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
+ sub2video_update(ist, &tmp);
+ avsubtitle_free(&tmp);
+int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
+ av_buffer_unref(&ifilter->hw_frames_ctx);
+ ifilter->format = frame->format;
+ ifilter->width = frame->width;
+ ifilter->height = frame->height;
+ ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
+ ifilter->sample_rate = frame->sample_rate;
+ ifilter->channels = frame->channels;
+ ifilter->channel_layout = frame->channel_layout;
+ if (frame->hw_frames_ctx) {
+ ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
+ if (!ifilter->hw_frames_ctx)
+int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
+ if (fg->inputs[i]->ist == ist)
+int filtergraph_is_simple(FilterGraph *fg)
+ return !fg->graph_desc;
@@ -0,0 +1,482 @@
+static int nb_hw_devices;
+static HWDevice **hw_devices;
+static HWDevice *hw_device_get_by_type(enum AVHWDeviceType type)
+ HWDevice *found = NULL;
+ for (i = 0; i < nb_hw_devices; i++) {
+ if (hw_devices[i]->type == type) {
+ if (found)
+ found = hw_devices[i];
+ return found;
+HWDevice *hw_device_get_by_name(const char *name)
+ if (!strcmp(hw_devices[i]->name, name))
+ return hw_devices[i];
+static HWDevice *hw_device_add(void)
+ int err;
+ err = av_reallocp_array(&hw_devices, nb_hw_devices + 1,
+ sizeof(*hw_devices));
+ if (err) {
+ nb_hw_devices = 0;
+ hw_devices[nb_hw_devices] = av_mallocz(sizeof(HWDevice));
+ if (!hw_devices[nb_hw_devices])
+ return hw_devices[nb_hw_devices++];
+static char *hw_device_default_name(enum AVHWDeviceType type)
+ // Make an automatic name of the form "type%d". We arbitrarily
+ // limit at 1000 anonymous devices of the same type - there is
+ // probably something else very wrong if you get to this limit.
+ const char *type_name = av_hwdevice_get_type_name(type);
+ char *name;
+ size_t index_pos;
+ int index, index_limit = 1000;
+ index_pos = strlen(type_name);
+ name = av_malloc(index_pos + 4);
+ for (index = 0; index < index_limit; index++) {
+ snprintf(name, index_pos + 4, "%s%d", type_name, index);
+ if (!hw_device_get_by_name(name))
+ if (index >= index_limit) {
+ av_freep(&name);
+ return name;
+int hw_device_init_from_string(const char *arg, HWDevice **dev_out)
+ // "type=name:device,key=value,key2=value2"
+ // "type:device,key=value,key2=value2"
+ // -> av_hwdevice_ctx_create()
+ // "type=name@name"
+ // "type@name"
+ // -> av_hwdevice_ctx_create_derived()
+ AVDictionary *options = NULL;
+ const char *type_name = NULL, *name = NULL, *device = NULL;
+ HWDevice *dev, *src;
+ AVBufferRef *device_ref = NULL;
+ const char *errmsg, *p, *q;
+ size_t k;
+ k = strcspn(arg, ":=@");
+ p = arg + k;
+ type_name = av_strndup(arg, k);
+ if (!type_name) {
+ err = AVERROR(ENOMEM);
+ type = av_hwdevice_find_type_by_name(type_name);
+ if (type == AV_HWDEVICE_TYPE_NONE) {
+ errmsg = "unknown device type";
+ goto invalid;
+ if (*p == '=') {
+ k = strcspn(p + 1, ":@");
+ name = av_strndup(p + 1, k);
+ if (hw_device_get_by_name(name)) {
+ errmsg = "named device already exists";
+ p += 1 + k;
+ name = hw_device_default_name(type);
+ // New device with no parameters.
+ err = av_hwdevice_ctx_create(&device_ref, type,
+ NULL, NULL, 0);
+ } else if (*p == ':') {
+ // New device with some parameters.
+ ++p;
+ q = strchr(p, ',');
+ if (q) {
+ if (q - p > 0) {
+ device = av_strndup(p, q - p);
+ if (!device) {
+ err = av_dict_parse_string(&options, q + 1, "=", ",", 0);
+ if (err < 0) {
+ errmsg = "failed to parse options";
+ q ? device : p[0] ? p : NULL,
+ options, 0);
+ } else if (*p == '@') {
+ // Derive from existing device.
+ src = hw_device_get_by_name(p + 1);
+ if (!src) {
+ errmsg = "invalid source device name";
+ err = av_hwdevice_ctx_create_derived(&device_ref, type,
+ src->device_ref, 0);
+ errmsg = "parse error";
+ dev = hw_device_add();
+ if (!dev) {
+ dev->name = name;
+ dev->type = type;
+ dev->device_ref = device_ref;
+ if (dev_out)
+ *dev_out = dev;
+ name = NULL;
+ err = 0;
+done:
+ av_freep(&type_name);
+ av_freep(&device);
+ av_dict_free(&options);
+ return err;
+invalid:
+ "Invalid device specification \"%s\": %s\n", arg, errmsg);
+ err = AVERROR(EINVAL);
+ goto done;
+ "Device creation failed: %d.\n", err);
+ av_buffer_unref(&device_ref);
+static int hw_device_init_from_type(enum AVHWDeviceType type,
+ const char *device,
+ HWDevice **dev_out)
+ HWDevice *dev;
+ err = av_hwdevice_ctx_create(&device_ref, type, device, NULL, 0);
+void hw_device_free_all(void)
+ av_freep(&hw_devices[i]->name);
+ av_buffer_unref(&hw_devices[i]->device_ref);
+ av_freep(&hw_devices[i]);
+ av_freep(&hw_devices);
+static HWDevice *hw_device_match_by_codec(const AVCodec *codec)
+ const AVCodecHWConfig *config;
+ config = avcodec_get_hw_config(codec, i);
+ if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
+ dev = hw_device_get_by_type(config->device_type);
+ if (dev)
+ return dev;
+int hw_device_setup_for_decode(InputStream *ist)
+ HWDevice *dev = NULL;
+ int err, auto_device = 0;
+ if (ist->hwaccel_device) {
+ dev = hw_device_get_by_name(ist->hwaccel_device);
+ if (ist->hwaccel_id == HWACCEL_AUTO) {
+ auto_device = 1;
+ } else if (ist->hwaccel_id == HWACCEL_GENERIC) {
+ type = ist->hwaccel_device_type;
+ err = hw_device_init_from_type(type, ist->hwaccel_device,
+ &dev);
+ // This will be dealt with by API-specific initialisation
+ // (using hwaccel_device), so nothing further needed here.
+ ist->hwaccel_device_type = dev->type;
+ } else if (ist->hwaccel_device_type != dev->type) {
+ av_log(ist->dec_ctx, AV_LOG_ERROR, "Invalid hwaccel device "
+ "specified for decoder: device %s of type %s is not "
+ "usable with hwaccel %s.\n", dev->name,
+ av_hwdevice_get_type_name(dev->type),
+ av_hwdevice_get_type_name(ist->hwaccel_device_type));
+ dev = hw_device_get_by_type(type);
+ if (!dev)
+ err = hw_device_init_from_type(type, NULL, &dev);
+ dev = hw_device_match_by_codec(ist->dec);
+ // No device for this codec, but not using generic hwaccel
+ // and therefore may well not need one - ignore.
+ if (auto_device) {
+ if (!avcodec_get_hw_config(ist->dec, 0)) {
+ // Decoder does not support any hardware devices.
+ for (i = 0; !dev; i++) {
+ config = avcodec_get_hw_config(ist->dec, i);
+ type = config->device_type;
+ if (dev) {
+ av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto "
+ "hwaccel type %s with existing device %s.\n",
+ av_hwdevice_get_type_name(type), dev->name);
+ // Try to make a new device of this type.
+ // Can't make a device of this type.
+ "hwaccel type %s with new device created "
+ "from %s.\n", av_hwdevice_get_type_name(type),
+ ist->hwaccel_device);
+ "hwaccel type %s with new default device.\n",
+ av_hwdevice_get_type_name(type));
+ ist->hwaccel_device_type = type;
+ av_log(ist->dec_ctx, AV_LOG_INFO, "Auto hwaccel "
+ "disabled: no device found.\n");
+ ist->hwaccel_id = HWACCEL_NONE;
+ av_log(ist->dec_ctx, AV_LOG_ERROR, "No device available "
+ "for decoder: device type %s needed for codec %s.\n",
+ av_hwdevice_get_type_name(type), ist->dec->name);
+ ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
+ if (!ist->dec_ctx->hw_device_ctx)
+int hw_device_setup_for_encode(OutputStream *ost)
+ dev = hw_device_match_by_codec(ost->enc);
+ ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
+ if (!ost->enc_ctx->hw_device_ctx)
+ // No device required, or no device available.
+static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
+ AVFrame *output = NULL;
+ enum AVPixelFormat output_format = ist->hwaccel_output_format;
+ if (input->format == output_format) {
+ // Nothing to do.
+ output = av_frame_alloc();
+ if (!output)
+ output->format = output_format;
+ err = av_hwframe_transfer_data(output, input, 0);
+ av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
+ "output frame: %d.\n", err);
+ err = av_frame_copy_props(output, input);
+ av_frame_unref(output);
+ av_frame_unref(input);
+ av_frame_move_ref(input, output);
+ av_frame_free(&output);
+int hwaccel_decode_init(AVCodecContext *avctx)
+ ist->hwaccel_retrieve_data = &hwaccel_retrieve_data;
@@ -0,0 +1,3772 @@
+
+ * ffmpeg option parsing
+#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
+#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
+{\
+ int i, ret;\
+ for (i = 0; i < o->nb_ ## name; i++) {\
+ char *spec = o->name[i].specifier;\
+ if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
+ outvar = o->name[i].u.type;\
+ else if (ret < 0)\
+ exit_program(1);\
+ }\
+#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
+ int i;\
+ if (!strcmp(spec, mediatype))\
+const HWAccel hwaccels[] = {
+#if CONFIG_VIDEOTOOLBOX
+ { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX },
+#if CONFIG_LIBMFX
+ { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
+#if CONFIG_CUVID
+ { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA },
+ { 0 },
+AVBufferRef *hw_device_ctx;
+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;
+int audio_volume = 256;
+int audio_sync_method = 0;
+int video_sync_method = VSYNC_AUTO;
+float frame_drop_threshold = 0;
+int do_deinterlace = 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;
+int frame_bits_per_raw_sample = 0;
+float max_error_rate = 2.0/3;
+int filter_nbthreads = 0;
+int filter_complex_nbthreads = 0;
+int vstats_version = 2;
+static int intra_only = 0;
+static int file_overwrite = 0;
+static int no_file_overwrite = 0;
+static int do_psnr = 0;
+static int input_sync;
+static int input_stream_potentially_available = 0;
+static int ignore_unknown_streams = 0;
+static int copy_unknown_streams = 0;
+static int find_stream_info = 1;
+static void uninit_options(OptionsContext *o)
+ const OptionDef *po = options;
+ /* all OPT_SPEC and OPT_STRING can be freed in generic way */
+ void *dst = (uint8_t*)o + po->u.off;
+ 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)
+ for (i = 0; i < o->nb_stream_maps; i++)
+ av_freep(&o->stream_maps[i].linklabel);
+ av_freep(&o->stream_maps);
+ av_freep(&o->audio_channel_maps);
+ 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 = UINT64_MAX;
+ o->chapters_input_file = INT_MAX;
+ o->accurate_seek = 1;
+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));
+ for (i = 0; hwaccels[i].name; i++)
+ printf("%s\n", hwaccels[i].name);
+/* return a copy of the input with the stream specifiers removed from the keys */
+static AVDictionary *strip_specifiers(AVDictionary *dict)
+ while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
+ char *p = strchr(e->key, ':');
+ *p = 0;
+ av_dict_set(&ret, e->key, e->value, 0);
+static int opt_abort_on(void *optctx, const char *opt, const char *arg)
+ { "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" },
+ return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
+static int opt_sameq(void *optctx, const char *opt, const char *arg)
+ av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
+ "If you are looking for an option to preserve the quality (which is not "
+ "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
+ opt, opt);
+static int opt_video_channel(void *optctx, const char *opt, const char *arg)
+ av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
+ return opt_default(optctx, "channel", arg);
+static int opt_video_standard(void *optctx, const char *opt, const char *arg)
+ av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
+ return opt_default(optctx, "standard", arg);
+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)
+ return parse_option(o, "codec:v", arg, options);
+static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "codec:s", arg, options);
+static int opt_data_codec(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "codec:d", arg, options);
+static int opt_map(void *optctx, const char *opt, const char *arg)
+ StreamMap *m = NULL;
+ int i, negative = 0, file_idx, disabled = 0;
+ int sync_file_idx = -1, sync_stream_idx = 0;
+ char *p, *sync;
+ char *map;
+ char *allow_unused;
+ if (*arg == '-') {
+ negative = 1;
+ map = av_strdup(arg);
+ if (!map)
+ /* parse sync stream first, just pick first matching stream */
+ if (sync = strchr(map, ',')) {
+ *sync = 0;
+ sync_file_idx = strtol(sync + 1, &sync, 0);
+ if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
+ if (*sync)
+ sync++;
+ for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
+ if (check_stream_specifier(input_files[sync_file_idx]->ctx,
+ input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
+ sync_stream_idx = i;
+ if (i == input_files[sync_file_idx]->nb_streams) {
+ av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
+ "match any streams.\n", arg);
+ if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
+ av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
+ "stream.\n", arg);
+ 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);
+ 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);
+ 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;
+ 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)
+ if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
+ disabled = 1;
+ m->file_index = file_idx;
+ m->stream_index = i;
+ if (sync_file_idx >= 0) {
+ m->sync_file_index = sync_file_idx;
+ m->sync_stream_index = sync_stream_idx;
+ m->sync_file_index = file_idx;
+ m->sync_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);
+ av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
+ av_freep(&map);
+static int opt_attach(void *optctx, const char *opt, const char *arg)
+ GROW_ARRAY(o->attachments, o->nb_attachments);
+ o->attachments[o->nb_attachments - 1] = arg;
+static int opt_map_channel(void *optctx, const char *opt, const char *arg)
+ AudioChannelMap *m;
+ char *mapchan;
+ mapchan = av_strdup(arg);
+ if (!mapchan)
+ 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;
+ m->ofile_idx = m->ostream_idx = -1;
+ av_free(mapchan);
+ /* 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");
+ if (n != 5) // only file.stream.channel specified
+ /* 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);
+ 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);
+ 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",
+ /* allow trailing ? to map_channel */
+ if (allow_unused = strchr(mapchan, '?'))
+ if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
+ input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
+ av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
+ m->file_idx, m->stream_idx, m->channel_idx);
+ 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",
+static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
+ av_free(sdp_filename);
+ sdp_filename = av_strdup(arg);
+#if CONFIG_VAAPI
+static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
+ const char *prefix = "vaapi:";
+ char *tmp;
+ tmp = av_asprintf("%s%s", prefix, arg);
+ err = hw_device_init_from_string(tmp, &dev);
+ av_free(tmp);
+ hw_device_ctx = av_buffer_ref(dev->device_ref);
+ if (!hw_device_ctx)
+static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
+ if (!strcmp(arg, "list")) {
+ printf("Supported hardware device types:\n");
+ 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");
+ 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);
+ * Parse a metadata specifier passed as 'arg' parameter.
+ * @param arg metadata string to parse
+ * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
+ * @param index for type c/p, chapter/program index is written here
+ * @param stream_spec for type s, the stream specifier is written here
+static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
+ if (*arg) {
+ *type = *arg;
+ switch (*arg) {
+ case 'g':
+ case 's':
+ if (*(++arg) && *arg != ':') {
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
+ *stream_spec = *arg == ':' ? arg + 1 : "";
+ case 'c':
+ if (*(++arg) == ':')
+ *index = strtol(++arg, NULL, 0);
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
+ *type = 'g';
+static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
+ AVDictionary **meta_in = NULL;
+ AVDictionary **meta_out = NULL;
+ int i, ret = 0;
+ char type_in, type_out;
+ const char *istream_spec = NULL, *ostream_spec = NULL;
+ int idx_in = 0, idx_out = 0;
+ parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
+ parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
+ if (!ic) {
+ if (type_out == 'g' || !*outspec)
+ o->metadata_global_manual = 1;
+ if (type_out == 's' || !*outspec)
+ o->metadata_streams_manual = 1;
+ if (type_out == 'c' || !*outspec)
+ o->metadata_chapters_manual = 1;
+ if (type_in == 'g' || type_out == 'g')
+ if (type_in == 's' || type_out == 's')
+ if (type_in == 'c' || type_out == 'c')
+ /* ic is NULL when just disabling automatic mappings */
+ if (!ic)
+#define METADATA_CHECK_INDEX(index, nb_elems, desc)\
+ if ((index) < 0 || (index) >= (nb_elems)) {\
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
+ (desc), (index));\
+#define SET_DICT(type, meta, context, index)\
+ switch (type) {\
+ case 'g':\
+ meta = &context->metadata;\
+ break;\
+ case 'c':\
+ METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
+ meta = &context->chapters[index]->metadata;\
+ case 'p':\
+ METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
+ meta = &context->programs[index]->metadata;\
+ case 's':\
+ break; /* handled separately below */ \
+ default: av_assert0(0);\
+ SET_DICT(type_in, meta_in, ic, idx_in);
+ SET_DICT(type_out, meta_out, oc, idx_out);
+ /* for input streams choose first matching stream */
+ if (type_in == 's') {
+ for (i = 0; i < ic->nb_streams; i++) {
+ if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
+ meta_in = &ic->streams[i]->metadata;
+ if (!meta_in) {
+ av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
+ if (type_out == 's') {
+ for (i = 0; i < oc->nb_streams; i++) {
+ if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
+ meta_out = &oc->streams[i]->metadata;
+ av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
+//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 int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
+ 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))
+ parse_option(o, "metadata", buf, options);
+ av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
+ "tag instead.\n", opt);
+static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
+ const char *codec_string = encoder ? "encoder" : "decoder";
+ AVCodec *codec;
+ codec = encoder ?
+ avcodec_find_encoder_by_name(name) :
+ if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
+ codec = encoder ? avcodec_find_encoder(desc->id) :
+ avcodec_find_decoder(desc->id);
+ av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
+ codec_string, codec->name, desc->name);
+ av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
+ if (codec->type != type) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
+ return codec;
+static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
+ char *codec_name = NULL;
+ MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
+ if (codec_name) {
+ AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
+ st->codecpar->codec_id = codec->id;
+ return avcodec_find_decoder(st->codecpar->codec_id);
+/* 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)
+ AVStream *st = ic->streams[i];
+ AVCodecParameters *par = st->codecpar;
+ InputStream *ist = av_mallocz(sizeof(*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 AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
+ GROW_ARRAY(input_streams, nb_input_streams);
+ input_streams[nb_input_streams - 1] = ist;
+ ist->st = st;
+ ist->file_index = nb_input_files;
+ ist->discard = 1;
+ st->discard = AVDISCARD_ALL;
+ ist->nb_samples = 0;
+ 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;
+ ist->dec = choose_decoder(o, ic, st);
+ 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);
+ ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
+ ist->dec_ctx = avcodec_alloc_context3(ist->dec);
+ if (!ist->dec_ctx) {
+ av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
+ ret = avcodec_parameters_to_context(ist->dec_ctx, par);
+ av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
+ if (o->bitexact)
+ ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
+ switch (par->codec_type) {
+ if(!ist->dec)
+ ist->dec = avcodec_find_decoder(par->codec_id);
+#if FF_API_LOWRES
+ if (st->codec->lowres) {
+ ist->dec_ctx->lowres = st->codec->lowres;
+ ist->dec_ctx->width = st->codec->width;
+ ist->dec_ctx->height = st->codec->height;
+ ist->dec_ctx->coded_width = st->codec->coded_width;
+ ist->dec_ctx->coded_height = st->codec->coded_height;
+ // 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);
+ ist->top_field_first = -1;
+ MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
+ MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
+ if (hwaccel) {
+ // The NVDEC hwaccels use a CUDA device, so remap the name here.
+ if (!strcmp(hwaccel, "nvdec"))
+ hwaccel = "cuda";
+ if (!strcmp(hwaccel, "none"))
+ else if (!strcmp(hwaccel, "auto"))
+ ist->hwaccel_id = HWACCEL_AUTO;
+ if (!strcmp(hwaccels[i].name, hwaccel)) {
+ ist->hwaccel_id = hwaccels[i].id;
+ if (!ist->hwaccel_id) {
+ type = av_hwdevice_find_type_by_name(hwaccel);
+ if (type != AV_HWDEVICE_TYPE_NONE) {
+ ist->hwaccel_id = HWACCEL_GENERIC;
+ av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
+ hwaccel);
+ av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
+ type = AV_HWDEVICE_TYPE_NONE;
+ av_log(NULL, AV_LOG_FATAL, "%s ",
+ av_log(NULL, AV_LOG_FATAL, "%s ", hwaccels[i].name);
+ av_log(NULL, AV_LOG_FATAL, "\n");
+ 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)
+ MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
+ hwaccel_output_format, ic, st);
+ 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);
+ ist->hwaccel_output_format = AV_PIX_FMT_NONE;
+ ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
+ 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);
+ 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);
+ case AVMEDIA_TYPE_ATTACHMENT:
+ case AVMEDIA_TYPE_UNKNOWN:
+ ret = avcodec_parameters_from_context(par, ist->dec_ctx);
+static 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");
+ 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);
+ signal(SIGINT, SIG_DFL);
+ if (!read_yesno()) {
+ av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
+ term_init();
+ av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
+ 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)
+ 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");
+static void dump_attachment(AVStream *st, const char *filename)
+ AVIOContext *out = NULL;
+ 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);
+ 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);
+ 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);
+ 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;
+ AVInputFormat *file_iformat = NULL;
+ int err, i, ret;
+ int64_t timestamp;
+ AVDictionary *unused_opts = 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) {
+ 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");
+ 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);
+ 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();
+ print_error(filename, 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) {
+ /* because we set audio_channels based on both the "ac" and
+ * "channel_layout" options, we need to check that the specified
+ * demuxer actually has the "channels" option before setting it */
+ if (file_iformat && file_iformat->priv_class &&
+ av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
+ AV_OPT_SEARCH_FAKE_OBJ)) {
+ av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
+ if (o->nb_frame_rates) {
+ /* set the format-level framerate option;
+ * this is important for video grabbers, e.g. x11 */
+ av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,
+ 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;
+ 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);
+ print_error(filename, err);
+ if (err == AVERROR_PROTOCOL_NOT_FOUND)
+ av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
+ 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]);
+ if (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);
+ av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
+ if (ic->nb_streams == 0) {
+ avformat_close_input(&ic);
+ 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);
+ 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");
+ 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);
+ 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;
+ if (dts_heuristic) {
+ seek_timestamp -= 3*AV_TIME_BASE / 23;
+ ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 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);
+ GROW_ARRAY(input_files, nb_input_files);
+ f = av_mallocz(sizeof(*f));
+ if (!f)
+ input_files[nb_input_files - 1] = f;
+ f->ctx = ic;
+ f->ist_index = nb_input_streams - ic->nb_streams;
+ f->start_time = o->start_time;
+ f->recording_time = o->recording_time;
+ 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->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
+ /* 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);
+ 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,
+ if (!option || foption)
+ 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 : "", nb_input_files - 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 : "", nb_input_files - 1, filename);
+ av_dict_free(&unused_opts);
+ for (i = 0; i < o->nb_dump_attachment; i++) {
+ 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;
+static uint8_t *get_line(AVIOContext *s)
+ AVIOContext *line;
+ uint8_t *buf;
+ char c;
+ if (avio_open_dyn_buf(&line) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
+ while ((c = avio_r8(s)) && c != '\n')
+ avio_w8(line, c);
+ avio_w8(line, 0);
+ avio_close_dyn_buf(line, &buf);
+ return buf;
+static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
+ int i, ret = -1;
+ char filename[1000];
+ const char *base[3] = { getenv("AVCONV_DATADIR"),
+ AVCONV_DATADIR,
+ for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
+ snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", codec_name, preset_name);
+ ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
+ snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
+ i != 1 ? "" : "/.avconv", preset_name);
+static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
+ enum AVMediaType type = ost->st->codecpar->codec_type;
+ if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
+ MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
+ if (!codec_name) {
+ ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
+ NULL, ost->st->codecpar->codec_type);
+ ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
+ av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
+ "output stream #%d:%d. Default encoder for format %s (codec %s) is "
+ "probably disabled. Please choose an encoder manually.\n",
+ ost->file_index, ost->index, s->oformat->name,
+ avcodec_get_name(ost->st->codecpar->codec_id));
+ return AVERROR_ENCODER_NOT_FOUND;
+ } else if (!strcmp(codec_name, "copy"))
+ ost->stream_copy = 1;
+ ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
+ ost->st->codecpar->codec_id = ost->enc->id;
+ ost->encoding_needed = !ost->stream_copy;
+ /* no encoding supported for other media types */
+ ost->encoding_needed = 0;
+static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
+ AVStream *st = avformat_new_stream(oc, NULL);
+ int idx = oc->nb_streams - 1, ret = 0;
+ const char *bsfs = NULL, *time_base = NULL;
+ char *next, *codec_tag = NULL;
+ double qscale = -1;
+ av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
+ if (oc->nb_streams - 1 < o->nb_streamid_map)
+ st->id = o->streamid_map[oc->nb_streams - 1];
+ GROW_ARRAY(output_streams, nb_output_streams);
+ if (!(ost = av_mallocz(sizeof(*ost))))
+ output_streams[nb_output_streams - 1] = ost;
+ ost->file_index = nb_output_files - 1;
+ ost->index = idx;
+ ost->st = st;
+ ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
+ st->codecpar->codec_type = type;
+ ret = choose_encoder(o, oc, ost);
+ av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
+ "%d:%d\n", ost->file_index, ost->index);
+ ost->enc_ctx = avcodec_alloc_context3(ost->enc);
+ if (!ost->enc_ctx) {
+ av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
+ ost->enc_ctx->codec_type = type;
+ ost->ref_par = avcodec_parameters_alloc();
+ if (!ost->ref_par) {
+ av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
+ if (ost->enc) {
+ char *buf = NULL, *arg = NULL, *preset = NULL;
+ ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
+ MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
+ if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
+ buf = get_line(s);
+ if (!buf[0] || buf[0] == '#') {
+ av_free(buf);
+ if (!(arg = strchr(buf, '='))) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
+ *arg++ = 0;
+ av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
+ } while (!s->eof_reached);
+ avio_closep(&s);
+ "Preset %s specified for stream %d:%d, but could not be opened.\n",
+ preset, ost->file_index, ost->index);
+ ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
+ ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
+ MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
+ if (time_base) {
+ AVRational q;
+ if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
+ q.num <= 0 || q.den <= 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
+ st->time_base = q;
+ MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
+ q.den <= 0) {
+ ost->enc_timebase = q;
+ ost->max_frames = INT64_MAX;
+ MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
+ for (i = 0; i<o->nb_max_frames; i++) {
+ char *p = o->max_frames[i].specifier;
+ if (!*p && type != AVMEDIA_TYPE_VIDEO) {
+ av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
+ ost->copy_prior_start = -1;
+ MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
+ MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
+ while (bsfs && *bsfs) {
+ const AVBitStreamFilter *filter;
+ char *bsf, *bsf_options_str, *bsf_name;
+ bsf = av_get_token(&bsfs, ",");
+ if (!bsf)
+ bsf_name = av_strtok(bsf, "=", &bsf_options_str);
+ if (!bsf_name)
+ filter = av_bsf_get_by_name(bsf_name);
+ if (!filter) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
+ ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
+ ost->nb_bitstream_filters + 1,
+ sizeof(*ost->bsf_ctx));
+ if (!ost->bsf_ctx)
+ ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
+ av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
+ ost->nb_bitstream_filters++;
+ if (bsf_options_str && filter->priv_class) {
+ const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL);
+ const char * shorthand[2] = {NULL};
+ if (opt)
+ shorthand[0] = opt->name;
+ ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":");
+ av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
+ av_freep(&bsf);
+ if (*bsfs)
+ bsfs++;
+ MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
+ ost->st->codecpar->codec_tag =
+ ost->enc_ctx->codec_tag = tag;
+ MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
+ if (qscale >= 0) {
+ ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
+ ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
+ MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
+ ost->disposition = av_strdup(ost->disposition);
+ ost->max_muxing_queue_size = 128;
+ MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
+ ost->max_muxing_queue_size *= sizeof(AVPacket);
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+ ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
+ av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
+ av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
+ if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
+ av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
+ av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
+ ost->source_index = source_index;
+ if (source_index >= 0) {
+ ost->sync_ist = input_streams[source_index];
+ input_streams[source_index]->discard = 0;
+ input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
+ ost->last_mux_dts = AV_NOPTS_VALUE;
+ ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
+ if (!ost->muxing_queue)
+static void parse_matrix_coeffs(uint16_t *dest, const char *str)
+ const char *p = str;
+ dest[i] = atoi(p);
+ if (i == 63)
+ p = strchr(p, ',');
+ if (!p) {
+ av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
+ p++;
+/* read file contents into a string */
+static uint8_t *read_file(const char *filename)
+ AVIOContext *pb = NULL;
+ AVIOContext *dyn_buf = NULL;
+ int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
+ uint8_t buf[1024], *str;
+ av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
+ ret = avio_open_dyn_buf(&dyn_buf);
+ avio_closep(&pb);
+ while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+ avio_write(dyn_buf, buf, ret);
+ avio_w8(dyn_buf, 0);
+ ret = avio_close_dyn_buf(dyn_buf, &str);
+ return str;
+static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
+ OutputStream *ost)
+ if (ost->filters_script && ost->filters) {
+ av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
+ "output stream #%d:%d.\n", nb_output_files, st->index);
+ if (ost->filters_script)
+ return read_file(ost->filters_script);
+ else if (ost->filters)
+ return av_strdup(ost->filters);
+ return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
+ "null" : "anull");
+static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
+ const OutputStream *ost, enum AVMediaType type)
+ if (ost->filters_script || ost->filters) {
+ "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
+ "Filtering and streamcopy cannot be used together.\n",
+ ost->filters ? "Filtergraph" : "Filtergraph script",
+ ost->filters ? ost->filters : ost->filters_script,
+ av_get_media_type_string(type), ost->file_index, ost->index);
+static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ AVCodecContext *video_enc;
+ char *frame_rate = NULL, *frame_aspect_ratio = NULL;
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
+ st = ost->st;
+ video_enc = ost->enc_ctx;
+ MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
+ if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
+ if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
+ av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid output files\n");
+ MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
+ if (frame_aspect_ratio) {
+ if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
+ av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
+ ost->frame_aspect_ratio = q;
+ MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
+ MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
+ if (o->nb_filters > 1)
+ av_log(NULL, AV_LOG_ERROR, "Only '-vf %s' read, ignoring remaining -vf options: Use ',' to separate filters\n", ost->filters);
+ if (!ost->stream_copy) {
+ const char *p = NULL;
+ char *frame_size = NULL;
+ char *frame_pix_fmt = NULL;
+ char *intra_matrix = NULL, *inter_matrix = NULL;
+ char *chroma_intra_matrix = NULL;
+ int do_pass = 0;
+ MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
+ if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
+ video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
+ MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
+ if (frame_pix_fmt && *frame_pix_fmt == '+') {
+ ost->keep_pix_fmt = 1;
+ if (!*++frame_pix_fmt)
+ frame_pix_fmt = NULL;
+ if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
+ st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
+ if (intra_only)
+ video_enc->gop_size = 0;
+ MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
+ if (intra_matrix) {
+ if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
+ parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
+ MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
+ if (chroma_intra_matrix) {
+ uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
+ video_enc->chroma_intra_matrix = p;
+ parse_matrix_coeffs(p, chroma_intra_matrix);
+ MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
+ if (inter_matrix) {
+ if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
+ parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
+ MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
+ for (i = 0; p; i++) {
+ int start, end, q;
+ int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
+ if (e != 3) {
+ av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
+ video_enc->rc_override =
+ av_realloc_array(video_enc->rc_override,
+ i + 1, sizeof(RcOverride));
+ if (!video_enc->rc_override) {
+ av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
+ video_enc->rc_override[i].start_frame = start;
+ video_enc->rc_override[i].end_frame = end;
+ if (q > 0) {
+ video_enc->rc_override[i].qscale = q;
+ video_enc->rc_override[i].quality_factor = 1.0;
+ video_enc->rc_override[i].qscale = 0;
+ video_enc->rc_override[i].quality_factor = -q/100.0;
+ p = strchr(p, '/');
+ if (p) p++;
+ video_enc->rc_override_count = i;
+ if (do_psnr)
+ video_enc->flags|= AV_CODEC_FLAG_PSNR;
+ /* two pass mode */
+ MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
+ if (do_pass) {
+ if (do_pass & 1) {
+ video_enc->flags |= AV_CODEC_FLAG_PASS1;
+ av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
+ if (do_pass & 2) {
+ video_enc->flags |= AV_CODEC_FLAG_PASS2;
+ av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
+ MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
+ if (ost->logfile_prefix &&
+ !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
+ char logfilename[1024];
+ FILE *f;
+ snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
+ ost->logfile_prefix ? ost->logfile_prefix :
+ DEFAULT_PASS_LOGFILENAME_PREFIX,
+ i);
+ if (!strcmp(ost->enc->name, "libx264")) {
+ av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
+ if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
+ char *logbuffer = read_file(logfilename);
+ if (!logbuffer) {
+ av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
+ logfilename);
+ video_enc->stats_in = logbuffer;
+ if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
+ f = av_fopen_utf8(logfilename, "wb");
+ if (!f) {
+ "Cannot write log file '%s' for pass-1 encoding: %s\n",
+ logfilename, strerror(errno));
+ ost->logfile = f;
+ MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
+ if (ost->forced_keyframes)
+ ost->forced_keyframes = av_strdup(ost->forced_keyframes);
+ MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
+ ost->top_field_first = -1;
+ MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
+ ost->avfilter = get_ost_filters(o, oc, ost);
+ if (!ost->avfilter)
+ MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
+ check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
+static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ AVCodecContext *audio_enc;
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
+ audio_enc = ost->enc_ctx;
+ audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
+ av_log(NULL, AV_LOG_ERROR, "Only '-af %s' read, ignoring remaining -af options: Use ',' to separate filters\n", ost->filters);
+ char *sample_fmt = NULL;
+ MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
+ MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
+ if (sample_fmt &&
+ (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
+ MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
+ MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
+ ost->apad = av_strdup(ost->apad);
+ /* check for channel mapping for this audio stream */
+ for (n = 0; n < o->nb_audio_channel_maps; n++) {
+ AudioChannelMap *map = &o->audio_channel_maps[n];
+ if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
+ (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
+ if (map->channel_idx == -1) {
+ ist = NULL;
+ } else if (ost->source_index < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
+ if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
+ if (av_reallocp_array(&ost->audio_channels_map,
+ ost->audio_channels_mapped + 1,
+ sizeof(*ost->audio_channels_map)
+ ) < 0 )
+ ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
+ check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
+static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
+ av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
+static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
+ av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
+static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
+ ost->finished = 1;
+static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
+ AVCodecContext *subtitle_enc;
+ ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
+ subtitle_enc = ost->enc_ctx;
+ subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
+ if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
+/* arg format is "output-stream-index:streamid-value". */
+static int opt_streamid(void *optctx, const char *opt, const char *arg)
+ char idx_str[16];
+ av_strlcpy(idx_str, arg, sizeof(idx_str));
+ p = strchr(idx_str, ':');
+ "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
+ arg, opt);
+ *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);
+static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
+ AVFormatContext *is = ifile->ctx;
+ AVFormatContext *os = ofile->ctx;
+ AVChapter **tmp;
+ tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
+ os->chapters = tmp;
+ for (i = 0; i < is->nb_chapters; i++) {
+ AVChapter *in_ch = is->chapters[i], *out_ch;
+ int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
+ int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
+ AV_TIME_BASE_Q, in_ch->time_base);
+ int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
+ av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
+ if (in_ch->end < ts_off)
+ if (rt != INT64_MAX && in_ch->start > rt + ts_off)
+ out_ch = av_mallocz(sizeof(AVChapter));
+ if (!out_ch)
+ out_ch->id = in_ch->id;
+ out_ch->time_base = in_ch->time_base;
+ out_ch->start = FFMAX(0, in_ch->start - ts_off);
+ out_ch->end = FFMIN(rt, in_ch->end - ts_off);
+ if (copy_metadata)
+ av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
+ os->chapters[os->nb_chapters++] = out_ch;
+static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
+ AVFormatContext *oc)
+ switch (ofilter->type) {
+ case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
+ case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
+ av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
+ ost->source_index = -1;
+ ost->filter = ofilter;
+ ofilter->ost = ost;
+ ofilter->format = -1;
+ if (ost->stream_copy) {
+ av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
+ "which is fed from a complex filtergraph. Filtering and streamcopy "
+ "cannot be used together.\n", ost->file_index, ost->index);
+ if (ost->avfilter && (ost->filters || ost->filters_script)) {
+ const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
+ "%s '%s' was specified through the %s option "
+ "for output stream %d:%d, which is fed from a complex filtergraph.\n"
+ "%s and -filter_complex cannot be used together for the same stream.\n",
+ opt, ost->file_index, ost->index, opt);
+ avfilter_inout_free(&ofilter->out_tmp);
+static int init_complex_filters(void)
+ ret = init_complex_filtergraph(filtergraphs[i]);
+static int open_output_file(OptionsContext *o, const char *filename)
+ int i, j, err;
+ OutputFile *of;
+ GROW_ARRAY(output_files, nb_output_files);
+ of = av_mallocz(sizeof(*of));
+ output_files[nb_output_files - 1] = of;
+ of->ost_index = nb_output_streams;
+ of->recording_time = o->recording_time;
+ of->start_time = o->start_time;
+ of->limit_filesize = o->limit_filesize;
+ of->shortest = o->shortest;
+ av_dict_copy(&of->opts, o->g->format_opts, 0);
+ err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
+ if (!oc) {
+ of->ctx = oc;
+ if (o->recording_time != INT64_MAX)
+ oc->duration = o->recording_time;
+ oc->interrupt_callback = int_cb;
+ e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
+ const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
+ av_opt_eval_flags(oc, o, e->value, &format_flags);
+ if (o->bitexact) {
+ format_flags |= AVFMT_FLAG_BITEXACT;
+ oc->flags |= AVFMT_FLAG_BITEXACT;
+ /* create streams for all unlabeled output pads */
+ if (!ofilter->out_tmp || ofilter->out_tmp->name)
+ case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
+ case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
+ case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
+ init_output_filter(ofilter, o, oc);
+ if (!o->nb_stream_maps) {
+ /* pick the "best" stream of each type */
+ /* video: highest resolution */
+ if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
+ int area = 0, idx = -1;
+ int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
+ int new_area;
+ new_area = ist->st->codecpar->width * ist->st->codecpar->height + 100000000*!!ist->st->codec_info_nb_frames
+ + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
+ if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ new_area = 1;
+ if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+ new_area > area) {
+ if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
+ area = new_area;
+ idx = i;
+ if (idx >= 0)
+ new_video_stream(o, oc, idx);
+ /* audio: most channels */
+ if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
+ int best_score = 0, idx = -1;
+ int score;
+ score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames
+ if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ score > best_score) {
+ best_score = score;
+ new_audio_stream(o, oc, idx);
+ /* subtitles: pick first */
+ MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
+ if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
+ if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
+ AVCodecDescriptor const *output_descriptor = NULL;
+ AVCodec const *output_codec =
+ avcodec_find_encoder(oc->oformat->subtitle_codec);
+ if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
+ if (output_codec)
+ output_descriptor = avcodec_descriptor_get(output_codec->id);
+ if (subtitle_codec_name ||
+ input_props & output_props ||
+ // Map dvb teletext which has neither property to any output subtitle encoder
+ input_descriptor && output_descriptor &&
+ (!input_descriptor->props ||
+ !output_descriptor->props)) {
+ new_subtitle_stream(o, oc, i);
+ /* Data only if codec id match */
+ if (!o->data_disable ) {
+ enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
+ for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
+ if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
+ && input_streams[i]->st->codecpar->codec_id == codec_id )
+ new_data_stream(o, oc, i);
+ StreamMap *map = &o->stream_maps[i];
+ if (map->disabled)
+ if (map->linklabel) {
+ FilterGraph *fg;
+ OutputFilter *ofilter = NULL;
+ int j, k;
+ for (j = 0; j < nb_filtergraphs; j++) {
+ fg = filtergraphs[j];
+ for (k = 0; k < fg->nb_outputs; k++) {
+ AVFilterInOut *out = fg->outputs[k]->out_tmp;
+ if (out && !strcmp(out->name, map->linklabel)) {
+ ofilter = fg->outputs[k];
+ goto loop_end;
+loop_end:
+ if (!ofilter) {
+ av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
+ "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
+ int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
+ ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
+ av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
+ map->file_index, map->stream_index);
+ if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
+ if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+ if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+ if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+ ost = NULL;
+ switch (ist->st->codecpar->codec_type) {
+ case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
+ case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
+ if (copy_unknown_streams) {
+ ost = new_unknown_stream (o, oc, src_idx);
+ av_log(NULL, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
+ "Cannot map stream #%d:%d - unsupported type.\n",
+ if (!ignore_unknown_streams) {
+ "If you want unsupported types ignored instead "
+ "of failing, please use the -ignore_unknown option\n"
+ "If you want them copied, please use -copy_unknown\n");
+ if (ost)
+ ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
+ + map->sync_stream_index];
+ /* handle attached files */
+ for (i = 0; i < o->nb_attachments; i++) {
+ uint8_t *attachment;
+ int64_t len;
+ if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
+ o->attachments[i]);
+ if ((len = avio_size(pb)) <= 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
+ if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
+ !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
+ av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
+ avio_read(pb, attachment, len);
+ memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+ ost = new_attachment_stream(o, oc, -1);
+ ost->stream_copy = 0;
+ ost->attachment_filename = o->attachments[i];
+ ost->st->codecpar->extradata = attachment;
+ ost->st->codecpar->extradata_size = len;
+ p = strrchr(o->attachments[i], '/');
+ av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
+#if FF_API_LAVF_AVCTX
+ for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
+ if ((ost->stream_copy || ost->attachment_filename)
+ && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
+ && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
+ if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
+ if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
+ av_dump_format(oc, nb_output_files - 1, oc->url, 1);
+ av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
+ for (i = of->ost_index; i < nb_output_streams; i++) {
+ while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
+ if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
+ "output file #%d (%s) is not an encoding option.\n", e->key,
+ option->help ? option->help : "", nb_output_files - 1,
+ // gop_timecode is injected by generic code but not always used
+ if (!strcmp(e->key, "gop_timecode"))
+ "output file #%d (%s) has not been used for any stream. The most "
+ "no video streams) or that it is a private option of some encoder "
+ option->help ? option->help : "", nb_output_files - 1, filename);
+ /* set the decoding_needed flags and create simple filtergraphs */
+ if (ost->encoding_needed && ost->source_index >= 0) {
+ InputStream *ist = input_streams[ost->source_index];
+ ist->decoding_needed |= DECODING_FOR_OST;
+ if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
+ ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+ err = init_simple_filtergraph(ist, ost);
+ "Error initializing a simple filtergraph between streams "
+ "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
+ nb_output_files - 1, ost->st->index);
+ /* set the filter output constraints */
+ if (ost->filter) {
+ OutputFilter *f = ost->filter;
+ int count;
+ f->frame_rate = ost->frame_rate;
+ f->width = ost->enc_ctx->width;
+ f->height = ost->enc_ctx->height;
+ f->format = ost->enc_ctx->pix_fmt;
+ } else if (ost->enc->pix_fmts) {
+ count = 0;
+ while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
+ f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
+ if (!f->formats)
+ memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
+ if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
+ f->format = ost->enc_ctx->sample_fmt;
+ } else if (ost->enc->sample_fmts) {
+ while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
+ memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
+ if (ost->enc_ctx->sample_rate) {
+ f->sample_rate = ost->enc_ctx->sample_rate;
+ } else if (ost->enc->supported_samplerates) {
+ while (ost->enc->supported_samplerates[count])
+ f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
+ if (!f->sample_rates)
+ memcpy(f->sample_rates, ost->enc->supported_samplerates,
+ (count + 1) * sizeof(*f->sample_rates));
+ if (ost->enc_ctx->channels) {
+ f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
+ } else if (ost->enc->channel_layouts) {
+ while (ost->enc->channel_layouts[count])
+ f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
+ if (!f->channel_layouts)
+ memcpy(f->channel_layouts, ost->enc->channel_layouts,
+ (count + 1) * sizeof(*f->channel_layouts));
+ /* check filename in case of an image number is expected */
+ if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
+ if (!av_filename_number_test(oc->url)) {
+ print_error(oc->url, AVERROR(EINVAL));
+ if (!(oc->oformat->flags & AVFMT_NOSTREAMS) && !input_stream_potentially_available) {
+ "No input streams but output needs an input stream\n");
+ if (!(oc->oformat->flags & AVFMT_NOFILE)) {
+ /* test if it already exists to avoid losing precious files */
+ /* open the file */
+ if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
+ &oc->interrupt_callback,
+ &of->opts)) < 0) {
+ } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
+ if (o->mux_preload) {
+ av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
+ oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
+ /* copy metadata */
+ for (i = 0; i < o->nb_metadata_map; i++) {
+ int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
+ if (in_file_index >= nb_input_files) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
+ copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
+ in_file_index >= 0 ?
+ input_files[in_file_index]->ctx : NULL, o);
+ /* copy chapters */
+ if (o->chapters_input_file >= nb_input_files) {
+ if (o->chapters_input_file == INT_MAX) {
+ /* copy chapters from the first input file that has them*/
+ o->chapters_input_file = -1;
+ if (input_files[i]->ctx->nb_chapters) {
+ o->chapters_input_file = i;
+ av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
+ o->chapters_input_file);
+ if (o->chapters_input_file >= 0)
+ copy_chapters(input_files[o->chapters_input_file], of,
+ !o->metadata_chapters_manual);
+ /* copy global metadata by default */
+ if (!o->metadata_global_manual && nb_input_files){
+ av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata,
+ AV_DICT_DONT_OVERWRITE);
+ if(o->recording_time != INT64_MAX)
+ av_dict_set(&oc->metadata, "duration", NULL, 0);
+ av_dict_set(&oc->metadata, "creation_time", NULL, 0);
+ if (!o->metadata_streams_manual)
+ if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
+ ist = input_streams[output_streams[i]->source_index];
+ av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
+ if (!output_streams[i]->stream_copy) {
+ av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
+ /* process manually set programs */
+ for (i = 0; i < o->nb_program; i++) {
+ const char *p = o->program[i].u.str;
+ int progid = i+1;
+ AVProgram *program;
+ while(*p) {
+ const char *p2 = av_get_token(&p, ":");
+ const char *to_dealloc = p2;
+ char *key;
+ if (!p2)
+ if(*p) p++;
+ key = av_get_token(&p2, "=");
+ if (!key || !*p2) {
+ av_freep(&to_dealloc);
+ av_freep(&key);
+ p2++;
+ if (!strcmp(key, "program_num"))
+ progid = strtol(p2, NULL, 0);
+ program = av_new_program(oc, progid);
+ p = o->program[i].u.str;
+ if (!key) {
+ "No '=' character in program string %s.\n",
+ p2);
+ if (!*p2)
+ if (!strcmp(key, "title")) {
+ av_dict_set(&program->metadata, "title", p2, 0);
+ } else if (!strcmp(key, "program_num")) {
+ } else if (!strcmp(key, "st")) {
+ int st_num = strtol(p2, NULL, 0);
+ av_program_add_stream_index(oc, progid, st_num);
+ av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
+ /* process manually set metadata */
+ for (i = 0; i < o->nb_metadata; i++) {
+ AVDictionary **m;
+ char type, *val;
+ const char *stream_spec;
+ int index = 0, j, ret = 0;
+ val = strchr(o->metadata[i].u.str, '=');
+ if (!val) {
+ av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
+ o->metadata[i].u.str);
+ *val++ = 0;
+ parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
+ if (type == 's') {
+ ost = output_streams[nb_output_streams - oc->nb_streams + j];
+ if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
+ if (!strcmp(o->metadata[i].u.str, "rotate")) {
+ double theta = av_strtod(val, &tail);
+ if (!*tail) {
+ ost->rotate_overridden = 1;
+ ost->rotate_override_value = theta;
+ av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
+ m = &oc->metadata;
+ if (index < 0 || index >= oc->nb_chapters) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
+ m = &oc->chapters[index]->metadata;
+ if (index < 0 || index >= oc->nb_programs) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
+ m = &oc->programs[index]->metadata;
+ av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
+ av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
+static int opt_target(void *optctx, const char *opt, const char *arg)
+ 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;
+ /* Try to determine PAL/NTSC by peeking in the input files */
+ if (nb_input_files) {
+ 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)
+ fr = st->time_base.den * 1000LL / st->time_base.num;
+ if (fr == 25000) {
+ } else if ((fr == 29970) || (fr == 23976)) {
+ 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");
+ 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");
+ parse_option(o, "f", "svcd", options);
+ parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
+ parse_option(o, "pix_fmt", "yuv420p", options);
+ 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");
+ } else if (!strcmp(arg, "dvd")) {
+ opt_audio_codec(o, "c:a", "ac3");
+ parse_option(o, "f", "dvd", options);
+ parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+ opt_default(NULL, "b:v", "6000000");
+ opt_default(NULL, "maxrate:v", "9000000");
+ opt_default(NULL, "minrate:v", "0"); // 1500000;
+ 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, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
+ norm == PAL ? "yuv420p" : "yuv411p", options);
+ av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
+ 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);
+static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
+ av_free (vstats_filename);
+ vstats_filename = av_strdup (arg);
+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));
+ 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)
+ return parse_option(o, "frames:v", arg, options);
+static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "frames:a", arg, options);
+static int opt_data_frames(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "frames:d", arg, options);
+static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
+ AVDictionary *cbak = codec_opts;
+ AVDictionary *fbak = format_opts;
+ 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);
+ codec_opts = cbak;
+ format_opts = fbak;
+static int opt_preset(void *optctx, const char *opt, const char *arg)
+ 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");
+ av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
+ while (fgets(line, sizeof(line), f)) {
+ char *key = tmp_line, *value, *endptr;
+ if (strcspn(line, "#\n\r") == 0)
+ 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);
+ 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);
+ fclose(f);
+static int opt_old2new(void *optctx, const char *opt, const char *arg)
+ char *s = av_asprintf("%s:%c", opt + 1, *opt);
+ int ret = parse_option(o, s, arg, options);
+ av_free(s);
+static int opt_bitrate(void *optctx, const char *opt, const char *arg)
+ if(!strcmp(opt, "ab")){
+ av_dict_set(&o->g->codec_opts, "b:a", arg, 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);
+ av_dict_set(&o->g->codec_opts, opt, arg, 0);
+static int opt_qscale(void *optctx, const char *opt, const char *arg)
+ char *s;
+ 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);
+ ret = parse_option(o, s, arg, options);
+static int opt_profile(void *optctx, const char *opt, const char *arg)
+ 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);
+static int opt_video_filters(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "filter:v", arg, options);
+static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "filter:a", arg, options);
+static int opt_vsync(void *optctx, const char *opt, const char *arg)
+ if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
+ else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
+ else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
+ else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
+ if (video_sync_method == VSYNC_AUTO)
+ video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
+static int opt_timecode(void *optctx, const char *opt, const char *arg)
+ char *tcr = av_asprintf("timecode=%s", arg);
+ int ret = parse_option(o, "metadata:g", tcr, options);
+ ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
+ av_free(tcr);
+static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
+ char layout_str[32];
+ char *stream_str;
+ char *ac_str;
+ int ret, channels, ac_str_size;
+ uint64_t layout;
+ layout = av_get_channel_layout(arg);
+ if (!layout) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
+ snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
+ ret = opt_default_new(o, opt, layout_str);
+ /* set 'ac' option based on channel layout */
+ channels = av_get_channel_layout_nb_channels(layout);
+ snprintf(layout_str, sizeof(layout_str), "%d", channels);
+ stream_str = strchr(opt, ':');
+ ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
+ ac_str = av_mallocz(ac_str_size);
+ if (!ac_str)
+ av_strlcpy(ac_str, "ac", 3);
+ if (stream_str)
+ av_strlcat(ac_str, stream_str, ac_str_size);
+ ret = parse_option(o, ac_str, layout_str, options);
+ av_free(ac_str);
+static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
+ return parse_option(o, "q:a", arg, options);
+static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
+ if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
+ filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;
+ filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg);
+ if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
+static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
+ uint8_t *graph_desc = read_file(arg);
+ if (!graph_desc)
+ filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
+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;
+ av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
+ 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\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);
+ 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);
+ 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);
+ show_help_options(options, "Advanced Audio options:",
+ OPT_EXPERT | OPT_AUDIO, OPT_VIDEO, 0);
+ show_help_options(options, "Subtitle options:",
+ OPT_SUBTITLE, 0, 0);
+ 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);
+ show_help_children(sws_get_class(), flags);
+ show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
+ 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);
+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*))
+ 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);
+ av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
+ "%s.\n", inout, g->arg);
+ av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
+ ret = open_file(&o, g->arg);
+ uninit_options(&o);
+ av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
+ inout, g->arg);
+ av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
+int ffmpeg_parse_options(int argc, char **argv)
+ OptionParseContext octx;
+ uint8_t error[128];
+ memset(&octx, 0, sizeof(octx));
+ /* split the commandline into an internal representation */
+ ret = split_commandline(&octx, argc, argv, options, groups,
+ FF_ARRAY_ELEMS(groups));
+ av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
+ /* apply global options */
+ ret = parse_optgroup(NULL, &octx.global_opts);
+ av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
+ /* configure terminal and setup signal handlers */
+ /* open input files */
+ ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
+ av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
+ /* create the complex filtergraphs */
+ ret = init_complex_filters();
+ av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
+ /* open output files */
+ ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
+ av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
+ check_filter_outputs();
+ uninit_parse_context(&octx);
+ av_strerror(ret, error, sizeof(error));
+ av_log(NULL, AV_LOG_FATAL, "%s\n", error);
+static int opt_progress(void *optctx, const char *opt, const char *arg)
+ AVIOContext *avio = NULL;
+ if (!strcmp(arg, "-"))
+ arg = "pipe:";
+ ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
+ av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
+ arg, av_err2str(ret));
+ progress_avio = avio;
+#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" },
+ { "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 |
+ { "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]]" },
+ { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
+ "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
+ { "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" },
+ { "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", "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", "" },
+ { "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 },
+ "video sync method", "" },
+ { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
+ "frame drop threshold", "" },
+ { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
+ "audio sync method", "" },
+ { "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" },
+ { "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 },
+ { "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 | OPT_INT, { &filter_nbthreads },
+ "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 },
+ { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
+ "read complex filtergraph description from a file", "filename" },
+ { "stats", OPT_BOOL, { &print_stats },
+ "print progress report during encoding", },
+ { "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 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,
+ { .off = OFFSET(thread_queue_size) },
+ "set the maximum number of queued packets from the demuxer" },
+ { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
+ "read and decode the streams to fill missing information with heuristics" },
+ /* 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" },
+ { "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" },
+ { "bits_per_raw_sample", OPT_VIDEO | OPT_INT | HAS_ARG, { &frame_bits_per_raw_sample },
+ "set the number of bits per raw sample", "number" },
+ { "intra", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &intra_only },
+ "deprecated use -g 1" },
+ { "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" },
+ { "sameq", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
+ "Removed" },
+ { "same_quant", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
+ { "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" },
+ { "deinterlace", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_deinterlace },
+ "this option is deprecated, use the yadif filter instead" },
+ { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
+ "calculate PSNR of compressed frames" },
+ { "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) },
+ { "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" },
+ { "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" },
+ { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" },
+ { "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" },
+ /* 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" },
+ { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
+ "change audio volume (256=normal)" , "volume" },
+ { "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_PERFILE |
+ OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout },
+ "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" },
+ /* grab options */
+ { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_channel },
+ "deprecated, use -channel", "channel" },
+ { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_standard },
+ "deprecated, use -standard", "standard" },
+ { "isync", OPT_BOOL | OPT_EXPERT, { &input_sync }, "this option is deprecated and does nothing", "" },
+ /* 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" },
+ /* 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" },
+ { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
+ "set VAAPI hardware device (DRM path or X11 display name)", "device" },
+ { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
+ "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
+ { "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, },
@@ -0,0 +1,251 @@
+ * simple math operations
+ * Copyright (c) 2001, 2002 Fabrice Bellard
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
+#ifndef AVCODEC_MATHOPS_H
+#define AVCODEC_MATHOPS_H
+#include "libavutil/common.h"
+#include "libavutil/reverse.h"
+#define MAX_NEG_CROP 1024
+extern const uint32_t ff_inverse[257];
+extern const uint8_t ff_sqrt_tab[256];
+extern const uint8_t ff_crop_tab[256 + 2 * MAX_NEG_CROP];
+extern const uint8_t ff_zigzag_direct[64];
+extern const uint8_t ff_zigzag_scan[16+1];
+#if ARCH_ARM
+# include "arm/mathops.h"
+#elif ARCH_AVR32
+# include "avr32/mathops.h"
+#elif ARCH_MIPS
+# include "mips/mathops.h"
+#elif ARCH_PPC
+# include "ppc/mathops.h"
+#elif ARCH_X86
+# include "x86/mathops.h"
+/* generic implementation */
+#ifndef MUL64
+# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
+#ifndef MULL
+# define MULL(a,b,s) (MUL64(a, b) >> (s))
+#ifndef MULH
+static av_always_inline int MULH(int a, int b){
+ return MUL64(a, b) >> 32;
+#ifndef UMULH
+static av_always_inline unsigned UMULH(unsigned a, unsigned b){
+ return ((uint64_t)(a) * (uint64_t)(b))>>32;
+#ifndef MAC64
+# define MAC64(d, a, b) ((d) += MUL64(a, b))
+#ifndef MLS64
+# define MLS64(d, a, b) ((d) -= MUL64(a, b))
+/* signed 16x16 -> 32 multiply add accumulate */
+#ifndef MAC16
+# define MAC16(rt, ra, rb) rt += (ra) * (rb)
+/* signed 16x16 -> 32 multiply */
+#ifndef MUL16
+# define MUL16(ra, rb) ((ra) * (rb))
+#ifndef MLS16
+# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
+/* median of 3 */
+#ifndef mid_pred
+#define mid_pred mid_pred
+static inline av_const int mid_pred(int a, int b, int c)
+ if(a>b){
+ if(c>b){
+ if(c>a) b=a;
+ else b=c;
+ if(b>c){
+ if(c>a) b=c;
+ else b=a;
+ return b;
+#ifndef median4
+#define median4 median4
+static inline av_const int median4(int a, int b, int c, int d)
+ if (a < b) {
+ if (c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
+ else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
+ if (c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
+ else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
+#ifndef sign_extend
+static inline av_const int sign_extend(int val, unsigned bits)
+ unsigned shift = 8 * sizeof(int) - bits;
+ union { unsigned u; int s; } v = { (unsigned) val << shift };
+ return v.s >> shift;
+#ifndef zero_extend
+static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
+ return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
+#ifndef COPY3_IF_LT
+#define COPY3_IF_LT(x, y, a, b, c, d)\
+if ((y) < (x)) {\
+ (x) = (y);\
+ (a) = (b);\
+ (c) = (d);\
+#ifndef MASK_ABS
+#define MASK_ABS(mask, level) do { \
+ mask = level >> 31; \
+ level = (level ^ mask) - mask; \
+ } while (0)
+#ifndef NEG_SSR32
+# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
+#ifndef NEG_USR32
+# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
+#if HAVE_BIGENDIAN
+# ifndef PACK_2U8
+# define PACK_2U8(a,b) (((a) << 8) | (b))
+# ifndef PACK_4U8
+# define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
+# ifndef PACK_2U16
+# define PACK_2U16(a,b) (((a) << 16) | (b))
+# define PACK_2U8(a,b) (((b) << 8) | (a))
+# ifndef PACK_4U2
+# define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
+# define PACK_2U16(a,b) (((b) << 16) | (a))
+#ifndef PACK_2S8
+# define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)
+#ifndef PACK_4S8
+# define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)
+#ifndef PACK_2S16
+# define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)
+#ifndef FASTDIV
+# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
+#endif /* FASTDIV */
+#ifndef ff_sqrt
+#define ff_sqrt ff_sqrt
+static inline av_const unsigned int ff_sqrt(unsigned int a)
+ unsigned int b;
+ if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
+ else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
+#if !CONFIG_SMALL
+ else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
+ else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ;
+ int s = av_log2_16bit(a >> 16) >> 1;
+ unsigned int c = a >> (s + 2);
+ b = ff_sqrt_tab[c >> (s + 8)];
+ b = FASTDIV(c,b) + (b << s);
+ return b - (a < b * b);
+static inline av_const float ff_sqrf(float a)
+ return a*a;
+static inline int8_t ff_u8_to_s8(uint8_t a)
+ uint8_t u8;
+ int8_t s8;
+ } b;
+ b.u8 = a;
+ return b.s8;
+static av_always_inline uint32_t bitswap_32(uint32_t x)
+ return (uint32_t)ff_reverse[ x & 0xFF] << 24 |
+ (uint32_t)ff_reverse[(x >> 8) & 0xFF] << 16 |
+ (uint32_t)ff_reverse[(x >> 16) & 0xFF] << 8 |
+ (uint32_t)ff_reverse[ x >> 24];
+#endif /* AVCODEC_MATHOPS_H */
@@ -0,0 +1,133 @@
+#ifndef AVCODEC_X86_MATHOPS_H
+#define AVCODEC_X86_MATHOPS_H
+#include "libavutil/x86/asm.h"
+#if HAVE_INLINE_ASM
+#if ARCH_X86_32
+#define MULL MULL
+static av_always_inline av_const int MULL(int a, int b, unsigned shift)
+ int rt, dummy;
+ __asm__ (
+ "imull %3 \n\t"
+ "shrdl %4, %%edx, %%eax \n\t"
+ :"=a"(rt), "=d"(dummy)
+ :"a"(a), "rm"(b), "ci"((uint8_t)shift)
+ return rt;
+#define MULH MULH
+static av_always_inline av_const int MULH(int a, int b)
+ "imull %3"
+ :"=d"(rt), "=a"(dummy)
+ :"a"(a), "rm"(b)
+#define MUL64 MUL64
+static av_always_inline av_const int64_t MUL64(int a, int b)
+ int64_t rt;
+ "imull %2"
+ :"=A"(rt)
+#endif /* ARCH_X86_32 */
+#if HAVE_I686
+ int i=b;
+ "cmp %2, %1 \n\t"
+ "cmovg %1, %0 \n\t"
+ "cmovg %2, %1 \n\t"
+ "cmp %3, %1 \n\t"
+ "cmovl %3, %1 \n\t"
+ "cmp %1, %0 \n\t"
+ :"+&r"(i), "+&r"(a)
+ :"r"(b), "r"(c)
+#if HAVE_6REGS
+__asm__ volatile(\
+ "cmpl %0, %3 \n\t"\
+ "cmovl %3, %0 \n\t"\
+ "cmovl %4, %1 \n\t"\
+ "cmovl %5, %2 \n\t"\
+ : "+&r" (x), "+&r" (a), "+r" (c)\
+ : "r" (y), "r" (b), "r" (d)\
+);
+#endif /* HAVE_6REGS */
+#endif /* HAVE_I686 */
+#define MASK_ABS(mask, level) \
+ __asm__ ("cdq \n\t" \
+ "xorl %1, %0 \n\t" \
+ "subl %1, %0 \n\t" \
+ : "+a"(level), "=&d"(mask))
+// avoid +32 for shift optimization (gcc should do that ...)
+#define NEG_SSR32 NEG_SSR32
+static inline int32_t NEG_SSR32( int32_t a, int8_t s){
+ __asm__ ("sarl %1, %0\n\t"
+ : "+r" (a)
+ : "ic" ((uint8_t)(-s))
+ return a;
+#define NEG_USR32 NEG_USR32
+static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
+ __asm__ ("shrl %1, %0\n\t"
+#endif /* HAVE_INLINE_ASM */
+#endif /* AVCODEC_X86_MATHOPS_H */
+ * Copyright (c) 2007 The FFmpeg Project
+#ifndef AVFORMAT_NETWORK_H
+#define AVFORMAT_NETWORK_H
+#include "libavutil/error.h"
+#include "os_support.h"
+#include "avio.h"
+#include "url.h"
+#if HAVE_WINSOCK2_H
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#ifndef EPROTONOSUPPORT
+#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+#ifndef ETIMEDOUT
+#define ETIMEDOUT WSAETIMEDOUT
+#ifndef ECONNREFUSED
+#define ECONNREFUSED WSAECONNREFUSED
+#ifndef EINPROGRESS
+#define EINPROGRESS WSAEINPROGRESS
+#define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
+#define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
+int ff_neterrno(void);
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#define ff_neterrno() AVERROR(errno)
+#endif /* HAVE_WINSOCK2_H */
+#if HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#if HAVE_POLL_H
+#include <poll.h>
+int ff_socket_nonblock(int socket, int enable);
+int ff_network_init(void);
+void ff_network_close(void);
+int ff_tls_init(void);
+void ff_tls_deinit(void);
+int ff_network_wait_fd(int fd, int write);
+ * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds
+ * Uses ff_network_wait_fd in a loop
+ * @param fd Socket descriptor
+ * @param write Set 1 to wait for socket able to be read, 0 to be written
+ * @param timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
+ * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd call
+ * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code
+int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb);
+ * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and
+ * triggered, return before that.
+ * @param timeout Timeout in microseconds. Maybe have lower actual precision.
+ * @param int_cb Interrupt callback, is checked regularly.
+ * @return AVERROR(ETIMEDOUT) if timeout expirted, AVERROR_EXIT if interrupted by int_cb
+int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb);
+#if !HAVE_STRUCT_SOCKADDR_STORAGE
+struct sockaddr_storage {
+#if HAVE_STRUCT_SOCKADDR_SA_LEN
+ uint8_t ss_len;
+ uint8_t ss_family;
+ uint16_t ss_family;
+#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
+ char ss_pad1[6];
+ int64_t ss_align;
+ char ss_pad2[112];
+#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
+typedef union sockaddr_union {
+ struct sockaddr_storage storage;
+ struct sockaddr_in in;
+#if HAVE_STRUCT_SOCKADDR_IN6
+ struct sockaddr_in6 in6;
+} sockaddr_union;
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#if !HAVE_STRUCT_ADDRINFO
+struct addrinfo {
+ int ai_flags;
+ int ai_family;
+ int ai_socktype;
+ int ai_protocol;
+ int ai_addrlen;
+ struct sockaddr *ai_addr;
+ char *ai_canonname;
+ struct addrinfo *ai_next;
+#endif /* !HAVE_STRUCT_ADDRINFO */
+/* getaddrinfo constants */
+#ifndef EAI_AGAIN
+#define EAI_AGAIN 2
+#ifndef EAI_BADFLAGS
+#define EAI_BADFLAGS 3
+#ifndef EAI_FAIL
+#define EAI_FAIL 4
+#ifndef EAI_FAMILY
+#define EAI_FAMILY 5
+#ifndef EAI_MEMORY
+#define EAI_MEMORY 6
+#ifndef EAI_NODATA
+#define EAI_NODATA 7
+#ifndef EAI_NONAME
+#define EAI_NONAME 8
+#ifndef EAI_SERVICE
+#define EAI_SERVICE 9
+#ifndef EAI_SOCKTYPE
+#define EAI_SOCKTYPE 10
+#ifndef AI_PASSIVE
+#define AI_PASSIVE 1
+#ifndef AI_CANONNAME
+#define AI_CANONNAME 2
+#ifndef AI_NUMERICHOST
+#define AI_NUMERICHOST 4
+#ifndef NI_NOFQDN
+#define NI_NOFQDN 1
+#ifndef NI_NUMERICHOST
+#define NI_NUMERICHOST 2
+#ifndef NI_NAMERQD
+#define NI_NAMERQD 4
+#ifndef NI_NUMERICSERV
+#define NI_NUMERICSERV 8
+#ifndef NI_DGRAM
+#define NI_DGRAM 16
+#if !HAVE_GETADDRINFO
+int ff_getaddrinfo(const char *node, const char *service,
+ const struct addrinfo *hints, struct addrinfo **res);
+void ff_freeaddrinfo(struct addrinfo *res);
+int ff_getnameinfo(const struct sockaddr *sa, int salen,
+ char *host, int hostlen,
+ char *serv, int servlen, int flags);
+#define getaddrinfo ff_getaddrinfo
+#define freeaddrinfo ff_freeaddrinfo
+#define getnameinfo ff_getnameinfo
+#endif /* !HAVE_GETADDRINFO */
+#if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
+const char *ff_gai_strerror(int ecode);
+#undef gai_strerror
+#define gai_strerror ff_gai_strerror
+#endif /* !HAVE_GETADDRINFO || HAVE_WINSOCK2_H */
+#ifndef INADDR_LOOPBACK
+#define INADDR_LOOPBACK 0x7f000001
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN 16
+#ifndef INET6_ADDRSTRLEN
+#define INET6_ADDRSTRLEN INET_ADDRSTRLEN
+#ifndef IN_MULTICAST
+#define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
+#ifndef IN6_IS_ADDR_MULTICAST
+#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
+int ff_is_multicast_address(struct sockaddr *addr);
+#define POLLING_TIME 100 /// Time in milliseconds between interrupt check
+ * Bind to a file descriptor and poll for a connection.
+ * @param fd First argument of bind().
+ * @param addr Second argument of bind().
+ * @param addrlen Third argument of bind().
+ * @param timeout Polling timeout in milliseconds.
+ * @param h URLContext providing interrupt check
+ * callback and logging context.
+ * @return A non-blocking file descriptor on success
+ * or an AVERROR on failure.
+int ff_listen_bind(int fd, const struct sockaddr *addr,
+ socklen_t addrlen, int timeout,
+ URLContext *h);
+ * Bind to a file descriptor to an address without accepting connections.
+ * @return 0 on success or an AVERROR on failure.
+int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen);
+ * Poll for a single connection on the passed file descriptor.
+ * @param fd The listening socket file descriptor.
+int ff_accept(int fd, int timeout, URLContext *h);
+ * Connect to a file descriptor and poll for result.
+ * @param fd First argument of connect(),
+ * will be set as non-blocking.
+ * @param addr Second argument of connect().
+ * @param addrlen Third argument of connect().
+ * @param will_try_next Whether the caller will try to connect to another
+ * address for the same host name, affecting the form of
+ * logged errors.
+ * @return 0 on success, AVERROR on failure.
+int ff_listen_connect(int fd, const struct sockaddr *addr,
+ URLContext *h, int will_try_next);
+int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
+int ff_socket(int domain, int type, int protocol);
+void ff_log_net_error(void *ctx, int level, const char* prefix);
+ * Connect to any of the given addrinfo addresses, with multiple attempts
+ * running in parallel.
+ * @param addrs The list of addresses to try to connect to.
+ * This list will be mutated internally, but the list head
+ * will remain as such, so this doesn't affect the caller
+ * freeing the list afterwards.
+ * @param timeout_ms_per_address The number of milliseconds to wait for each
+ * connection attempt. Since multiple addresses are tried,
+ * some of them in parallel, the total run time will at most
+ * be timeout_ms_per_address*ceil(nb_addrs/parallel) +
+ * (parallel - 1) * NEXT_ATTEMPT_DELAY_MS.
+ * @param parallel The maximum number of connections to attempt in parallel.
+ * This is limited to an internal maximum capacity.
+ * @param fd If successful, the connected socket is returned here.
+ * @param customize_fd Function that will be called for each socket created,
+ * to allow the caller to set socket options before calling
+ * connect() on it, may be NULL.
+ * @param customize_ctx Context parameter passed to customize_fd.
+int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
+ int parallel, URLContext *h, int *fd,
+ void (*customize_fd)(void *, int), void *customize_ctx);
+#endif /* AVFORMAT_NETWORK_H */
@@ -0,0 +1,250 @@
+ * various OS-feature replacement utilities
+ * copyright (c) 2000, 2001, 2002 Fabrice Bellard
+#ifndef AVFORMAT_OS_SUPPORT_H
+#define AVFORMAT_OS_SUPPORT_H
+ * miscellaneous OS support macros and functions.
+#include <sys/stat.h>
+#if HAVE_DIRECT_H
+#include <direct.h>
+# include <fcntl.h>
+# ifdef lseek
+# undef lseek
+# define lseek(f,p,w) _lseeki64((f), (p), (w))
+# ifdef stat
+# undef stat
+# define stat _stati64
+# ifdef fstat
+# undef fstat
+# define fstat(f,s) _fstati64((f), (s))
+#endif /* defined(_WIN32) */
+#ifdef __ANDROID__
+# if HAVE_UNISTD_H
+# include <unistd.h>
+# define lseek(f,p,w) lseek64((f), (p), (w))
+static inline int is_dos_path(const char *path)
+#if HAVE_DOS_PATHS
+ if (path[0] && path[1] == ':')
+#if defined(_WIN32)
+#ifndef S_IRUSR
+#define S_IRUSR S_IREAD
+#ifndef S_IWUSR
+#define S_IWUSR S_IWRITE
+#define SHUT_RD SD_RECEIVE
+#define SHUT_WR SD_SEND
+#define SHUT_RDWR SD_BOTH
+#if !defined(SHUT_RD) /* OS/2, DJGPP */
+#define SHUT_RD 0
+#define SHUT_WR 1
+#define SHUT_RDWR 2
+#if !HAVE_SOCKLEN_T
+typedef int socklen_t;
+/* most of the time closing a socket is just closing an fd */
+#if !HAVE_CLOSESOCKET
+#define closesocket close
+#if !HAVE_POLL_H
+typedef unsigned long nfds_t;
+#if !HAVE_STRUCT_POLLFD
+struct pollfd {
+ int fd;
+ short events; /* events to look for */
+ short revents; /* events that occurred */
+/* events & revents */
+#define POLLIN 0x0001 /* any readable data available */
+#define POLLOUT 0x0002 /* file descriptor is writeable */
+#define POLLRDNORM POLLIN
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0008 /* priority readable data */
+#define POLLWRBAND 0x0010 /* priority data can be written */
+#define POLLPRI 0x0020 /* high priority readable data */
+/* revents only */
+#define POLLERR 0x0004 /* errors pending */
+#define POLLHUP 0x0080 /* disconnected */
+#define POLLNVAL 0x1000 /* invalid file descriptor */
+int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout);
+#define poll ff_poll
+#endif /* HAVE_POLL_H */
+#endif /* CONFIG_NETWORK */
+#include "libavutil/wchar_filename.h"
+#define DEF_FS_FUNCTION(name, wfunc, afunc) \
+static inline int win32_##name(const char *filename_utf8) \
+ wchar_t *filename_w; \
+ int ret; \
+ if (utf8towchar(filename_utf8, &filename_w)) \
+ return -1; \
+ if (!filename_w) \
+ goto fallback; \
+ ret = wfunc(filename_w); \
+ av_free(filename_w); \
+fallback: \
+ /* filename may be be in CP_ACP */ \
+ return afunc(filename_utf8); \
+DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
+DEF_FS_FUNCTION(mkdir, _wmkdir, _mkdir)
+DEF_FS_FUNCTION(rmdir, _wrmdir , _rmdir)
+#define DEF_FS_FUNCTION2(name, wfunc, afunc, partype) \
+static inline int win32_##name(const char *filename_utf8, partype par) \
+ ret = wfunc(filename_w, par); \
+ return afunc(filename_utf8, par); \
+DEF_FS_FUNCTION2(access, _waccess, _access, int)
+DEF_FS_FUNCTION2(stat, _wstati64, _stati64, struct stat*)
+static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
+ wchar_t *src_w, *dest_w;
+ if (utf8towchar(src_utf8, &src_w))
+ if (utf8towchar(dest_utf8, &dest_w)) {
+ av_free(src_w);
+ if (!src_w || !dest_w) {
+ av_free(dest_w);
+ goto fallback;
+ ret = MoveFileExW(src_w, dest_w, MOVEFILE_REPLACE_EXISTING);
+ // Lacking proper mapping from GetLastError() error codes to errno codes
+ if (ret)
+ errno = EPERM;
+fallback:
+ /* filename may be be in CP_ACP */
+#if !HAVE_UWP
+ ret = MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING);
+ /* Windows Phone doesn't have MoveFileExA, and for Windows Store apps,
+ * it is available but not allowed by the app certification kit. However,
+ * it's unlikely that anybody would input filenames in CP_ACP there, so this
+ * fallback is kept mostly for completeness. Alternatively we could
+ * do MultiByteToWideChar(CP_ACP) and use MoveFileExW, but doing
+ * explicit conversions with CP_ACP is allegedly forbidden in windows
+ * store apps (or windows phone), and the notion of a native code page
+ * doesn't make much sense there. */
+ ret = rename(src_utf8, dest_utf8);
+#define mkdir(a, b) win32_mkdir(a)
+#define rename win32_rename
+#define rmdir win32_rmdir
+#define unlink win32_unlink
+#define access win32_access
+#endif /* AVFORMAT_OS_SUPPORT_H */
@@ -0,0 +1,343 @@
+ * unbuffered private I/O API
+#ifndef AVFORMAT_URL_H
+#define AVFORMAT_URL_H
+#include "libavformat/version.h"
+#include "libavutil/log.h"
+#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
+#define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */
+extern const AVClass ffurl_context_class;
+typedef struct URLContext {
+ const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
+ const struct URLProtocol *prot;
+ void *priv_data;
+ char *filename; /**< specified URL */
+ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
+ int is_streamed; /**< true if streamed (no seek possible), default = false */
+ int is_connected;
+ AVIOInterruptCB interrupt_callback;
+ int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */
+ const char *protocol_whitelist;
+ const char *protocol_blacklist;
+ int min_packet_size; /**< if non zero, the stream is packetized with this min packet size */
+} URLContext;
+typedef struct URLProtocol {
+ int (*url_open)( URLContext *h, const char *url, int flags);
+ * This callback is to be used by protocols which open further nested
+ * protocols. options are then to be passed to ffurl_open()/ffurl_connect()
+ * for those nested protocols.
+ int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
+ int (*url_accept)(URLContext *s, URLContext **c);
+ int (*url_handshake)(URLContext *c);
+ * Read data from the protocol.
+ * If data is immediately available (even less than size), EOF is
+ * reached or an error occurs (including EINTR), return immediately.
+ * Otherwise:
+ * In non-blocking mode, return AVERROR(EAGAIN) immediately.
+ * In blocking mode, wait for data/EOF/error with a short timeout (0.1s),
+ * and return AVERROR(EAGAIN) on timeout.
+ * Checking interrupt_callback, looping on EINTR and EAGAIN and until
+ * enough data has been read is left to the calling function; see
+ * retry_transfer_wrapper in avio.c.
+ int (*url_read)( URLContext *h, unsigned char *buf, int size);
+ int (*url_write)(URLContext *h, const unsigned char *buf, int size);
+ int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
+ int (*url_close)(URLContext *h);
+ int (*url_read_pause)(URLContext *h, int pause);
+ int64_t (*url_read_seek)(URLContext *h, int stream_index,
+ int64_t timestamp, int flags);
+ int (*url_get_file_handle)(URLContext *h);
+ int (*url_get_multi_file_handle)(URLContext *h, int **handles,
+ int *numhandles);
+ int (*url_get_short_seek)(URLContext *h);
+ int (*url_shutdown)(URLContext *h, int flags);
+ int priv_data_size;
+ const AVClass *priv_data_class;
+ int (*url_check)(URLContext *h, int mask);
+ int (*url_open_dir)(URLContext *h);
+ int (*url_read_dir)(URLContext *h, AVIODirEntry **next);
+ int (*url_close_dir)(URLContext *h);
+ int (*url_delete)(URLContext *h);
+ int (*url_move)(URLContext *h_src, URLContext *h_dst);
+ const char *default_whitelist;
+} URLProtocol;
+ * Create a URLContext for accessing to the resource indicated by
+ * url, but do not initiate the connection yet.
+ * @param puc pointer to the location where, in case of success, the
+ * function puts the pointer to the created URLContext
+ * @param flags flags which control how the resource indicated by url
+ * is to be opened
+ * @param int_cb interrupt callback to use for the URLContext, may be
+ * NULL
+ * @return >= 0 in case of success, a negative value corresponding to an
+ * AVERROR code in case of failure
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
+ const AVIOInterruptCB *int_cb);
+ * Connect an URLContext that has been allocated by ffurl_alloc
+ * @param options A dictionary filled with options for nested protocols,
+ * i.e. it will be passed to url_open2() for protocols implementing it.
+ * This parameter will be destroyed and replaced with a dict containing options
+ * that were not found. May be NULL.
+int ffurl_connect(URLContext *uc, AVDictionary **options);
+ * Create an URLContext for accessing to the resource indicated by
+ * url, and open it.
+ * @param options A dictionary filled with protocol-private options. On return
+ * this parameter will be destroyed and replaced with a dict containing options
+ * @param parent An enclosing URLContext, whose generic options should
+ * be applied to this URLContext as well.
+int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags,
+ const AVIOInterruptCB *int_cb, AVDictionary **options,
+ const char *whitelist, const char* blacklist,
+ URLContext *parent);
+int ffurl_open(URLContext **puc, const char *filename, int flags,
+ const AVIOInterruptCB *int_cb, AVDictionary **options);
+ * Accept an URLContext c on an URLContext s
+ * @param s server context
+ * @param c client context, must be unallocated.
+ * @return >= 0 on success, ff_neterrno() on failure.
+int ffurl_accept(URLContext *s, URLContext **c);
+ * Perform one step of the protocol handshake to accept a new client.
+ * See avio_handshake() for details.
+ * Implementations should try to return decreasing values.
+ * If the protocol uses an underlying protocol, the underlying handshake is
+ * usually the first step, and the return value can be:
+ * (largest value for this protocol) + (return value from other protocol)
+ * @param c the client context
+ * @return >= 0 on success or a negative value corresponding
+ * to an AVERROR code on failure
+int ffurl_handshake(URLContext *c);
+ * Read up to size bytes from the resource accessed by h, and store
+ * the read bytes in buf.
+ * @return The number of bytes actually read, or a negative value
+ * corresponding to an AVERROR code in case of error. A value of zero
+ * indicates that it is not possible to read more from the accessed
+ * resource (except if the value of the size argument is also zero).
+int ffurl_read(URLContext *h, unsigned char *buf, int size);
+ * Read as many bytes as possible (up to size), calling the
+ * read function multiple times if necessary.
+ * This makes special short-read handling in applications
+ * unnecessary, if the return value is < size then it is
+ * certain there was either an error or the end of file was reached.
+int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
+ * Write size bytes from buf to the resource accessed by h.
+ * @return the number of bytes actually written, or a negative value
+ * corresponding to an AVERROR code in case of failure
+int ffurl_write(URLContext *h, const unsigned char *buf, int size);
+ * Change the position that will be used by the next read/write
+ * operation on the resource accessed by h.
+ * @param pos specifies the new position to set
+ * @param whence specifies how pos should be interpreted, it must be
+ * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
+ * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
+ * (return the filesize of the requested resource, pos is ignored).
+ * @return a negative value corresponding to an AVERROR code in case
+ * of failure, or the resulting file position, measured in bytes from
+ * the beginning of the file. You can use this feature together with
+ * SEEK_CUR to read the current file position.
+int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
+ * Close the resource accessed by the URLContext h, and free the
+ * memory used by it. Also set the URLContext pointer to NULL.
+ * @return a negative value if an error condition occurred, 0
+ * otherwise
+int ffurl_closep(URLContext **h);
+int ffurl_close(URLContext *h);
+ * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
+ * if the operation is not supported by h, or another negative value
+ * corresponding to an AVERROR error code in case of failure.
+int64_t ffurl_size(URLContext *h);
+ * Return the file descriptor associated with this URL. For RTP, this
+ * will return only the RTP file descriptor, not the RTCP file descriptor.
+ * @return the file descriptor associated with this URL, or <0 on error.
+int ffurl_get_file_handle(URLContext *h);
+ * Return the file descriptors associated with this URL.
+ * @return 0 on success or <0 on error.
+int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles);
+ * Return the current short seek threshold value for this URL.
+ * @return threshold (>0) on success or <=0 on error.
+int ffurl_get_short_seek(URLContext *h);
+ * Signal the URLContext that we are done reading or writing the stream.
+ * @param h pointer to the resource
+ * is to be shutdown
+int ffurl_shutdown(URLContext *h, int flags);
+ * Check if the user has requested to interrupt a blocking function
+ * associated with cb.
+int ff_check_interrupt(AVIOInterruptCB *cb);
+/* udp.c */
+int ff_udp_set_remote_url(URLContext *h, const char *uri);
+int ff_udp_get_local_port(URLContext *h);
+ * Assemble a URL string from components. This is the reverse operation
+ * of av_url_split.
+ * Note, this requires networking to be initialized, so the caller must
+ * ensure ff_network_init has been called.
+ * @see av_url_split
+ * @param str the buffer to fill with the url
+ * @param size the size of the str buffer
+ * @param proto the protocol identifier, if null, the separator
+ * after the identifier is left out, too
+ * @param authorization an optional authorization string, may be null.
+ * An empty string is treated the same as a null string.
+ * @param hostname the host name string
+ * @param port the port number, left out from the string if negative
+ * @param fmt a generic format string for everything to add after the
+ * host/port, may be null
+ * @return the number of characters written to the destination buffer
+int ff_url_join(char *str, int size, const char *proto,
+ const char *authorization, const char *hostname,
+ int port, const char *fmt, ...) av_printf_format(7, 8);
+ * Convert a relative url into an absolute url, given a base url.
+ * @param buf the buffer where output absolute url is written
+ * @param size the size of buf
+ * @param base the base url, may be equal to buf.
+ * @param rel the new url, which is interpreted relative to base
+void ff_make_absolute_url(char *buf, int size, const char *base,
+ const char *rel);
+ * Allocate directory entry with default values.
+ * @return entry or NULL on error
+AVIODirEntry *ff_alloc_dir_entry(void);
+const AVClass *ff_urlcontext_child_class_next(const AVClass *prev);
+ * Construct a list of protocols matching a given whitelist and/or blacklist.
+ * @param whitelist a comma-separated list of allowed protocol names or NULL. If
+ * this is a non-empty string, only protocols in this list will
+ * be included.
+ * @param blacklist a comma-separated list of forbidden protocol names or NULL.
+ * If this is a non-empty string, all protocols in this list
+ * will be excluded.
+ * @return a NULL-terminated array of matching protocols. The array must be
+ * freed by the caller.
+const URLProtocol **ffurl_get_protocols(const char *whitelist,
+ const char *blacklist);
+#endif /* AVFORMAT_URL_H */
@@ -0,0 +1,595 @@
+ * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
+#ifndef AVRESAMPLE_AVRESAMPLE_H
+#define AVRESAMPLE_AVRESAMPLE_H
+ * @ingroup lavr
+ * external API header
+ * @defgroup lavr libavresample
+ * @{
+ * Libavresample (lavr) is a library that handles audio resampling, sample
+ * format conversion and mixing.
+ * Interaction with lavr is done through AVAudioResampleContext, which is
+ * allocated with avresample_alloc_context(). It is opaque, so all parameters
+ * must be set with the @ref avoptions API.
+ * For example the following code will setup conversion from planar float sample
+ * format to interleaved signed 16-bit integer, downsampling from 48kHz to
+ * 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing
+ * matrix):
+ * @code
+ * AVAudioResampleContext *avr = avresample_alloc_context();
+ * av_opt_set_int(avr, "in_channel_layout", AV_CH_LAYOUT_5POINT1, 0);
+ * av_opt_set_int(avr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
+ * av_opt_set_int(avr, "in_sample_rate", 48000, 0);
+ * av_opt_set_int(avr, "out_sample_rate", 44100, 0);
+ * av_opt_set_int(avr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
+ * av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
+ * @endcode
+ * Once the context is initialized, it must be opened with avresample_open(). If
+ * you need to change the conversion parameters, you must close the context with
+ * avresample_close(), change the parameters as described above, then reopen it
+ * again.
+ * The conversion itself is done by repeatedly calling avresample_convert().
+ * Note that the samples may get buffered in two places in lavr. The first one
+ * is the output FIFO, where the samples end up if the output buffer is not
+ * large enough. The data stored in there may be retrieved at any time with
+ * avresample_read(). The second place is the resampling delay buffer,
+ * applicable only when resampling is done. The samples in it require more input
+ * before they can be processed. Their current amount is returned by
+ * avresample_get_delay(). At the end of conversion the resampling buffer can be
+ * flushed by calling avresample_convert() with NULL input.
+ * The following code demonstrates the conversion loop assuming the parameters
+ * from above and caller-defined functions get_input() and handle_output():
+ * uint8_t **input;
+ * int in_linesize, in_samples;
+ * while (get_input(&input, &in_linesize, &in_samples)) {
+ * uint8_t *output
+ * int out_linesize;
+ * int out_samples = avresample_get_out_samples(avr, in_samples);
+ * av_samples_alloc(&output, &out_linesize, 2, out_samples,
+ * AV_SAMPLE_FMT_S16, 0);
+ * out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
+ * input, in_linesize, in_samples);
+ * handle_output(output, out_linesize, out_samples);
+ * av_freep(&output);
+ * }
+ * When the conversion is finished and the FIFOs are flushed if required, the
+ * conversion context and everything associated with it must be freed with
+ * avresample_free().
+#include "libavutil/frame.h"
+#define AVRESAMPLE_MAX_CHANNELS 32
+typedef struct AVAudioResampleContext AVAudioResampleContext;
+ * @deprecated use libswresample
+ * Mixing Coefficient Types */
+enum attribute_deprecated AVMixCoeffType {
+ AV_MIX_COEFF_TYPE_Q8, /** 16-bit 8.8 fixed-point */
+ AV_MIX_COEFF_TYPE_Q15, /** 32-bit 17.15 fixed-point */
+ AV_MIX_COEFF_TYPE_FLT, /** floating-point */
+ AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */
+ * Resampling Filter Types */
+enum attribute_deprecated AVResampleFilterType {
+ AV_RESAMPLE_FILTER_TYPE_CUBIC, /**< Cubic */
+ AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */
+ AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */
+enum attribute_deprecated AVResampleDitherMethod {
+ AV_RESAMPLE_DITHER_NONE, /**< Do not use dithering */
+ AV_RESAMPLE_DITHER_RECTANGULAR, /**< Rectangular Dither */
+ AV_RESAMPLE_DITHER_TRIANGULAR, /**< Triangular Dither*/
+ AV_RESAMPLE_DITHER_TRIANGULAR_HP, /**< Triangular Dither with High Pass */
+ AV_RESAMPLE_DITHER_TRIANGULAR_NS, /**< Triangular Dither with Noise Shaping */
+ AV_RESAMPLE_DITHER_NB, /**< Number of dither types. Not part of ABI. */
+ * Return the LIBAVRESAMPLE_VERSION_INT constant.
+attribute_deprecated
+unsigned avresample_version(void);
+ * Return the libavresample build-time configuration.
+ * @return configure string
+const char *avresample_configuration(void);
+ * Return the libavresample license.
+const char *avresample_license(void);
+ * Get the AVClass for AVAudioResampleContext.
+ * Can be used in combination with AV_OPT_SEARCH_FAKE_OBJ for examining options
+ * without allocating a context.
+ * @see av_opt_find().
+ * @return AVClass for AVAudioResampleContext
+const AVClass *avresample_get_class(void);
+ * Allocate AVAudioResampleContext and set options.
+ * @return allocated audio resample context, or NULL on failure
+AVAudioResampleContext *avresample_alloc_context(void);
+ * Initialize AVAudioResampleContext.
+ * @note The context must be configured using the AVOption API.
+ * @note The fields "in_channel_layout", "out_channel_layout",
+ * "in_sample_rate", "out_sample_rate", "in_sample_fmt",
+ * "out_sample_fmt" must be set.
+ * @see av_opt_set_int()
+ * @see av_opt_set_dict()
+ * @see av_get_default_channel_layout()
+ * @param avr audio resample context
+ * @return 0 on success, negative AVERROR code on failure
+int avresample_open(AVAudioResampleContext *avr);
+ * Check whether an AVAudioResampleContext is open or closed.
+ * @param avr AVAudioResampleContext to check
+ * @return 1 if avr is open, 0 if avr is closed.
+int avresample_is_open(AVAudioResampleContext *avr);
+ * Close AVAudioResampleContext.
+ * This closes the context, but it does not change the parameters. The context
+ * can be reopened with avresample_open(). It does, however, clear the output
+ * FIFO and any remaining leftover samples in the resampling delay buffer. If
+ * there was a custom matrix being used, that is also cleared.
+ * @see avresample_convert()
+ * @see avresample_set_matrix()
+void avresample_close(AVAudioResampleContext *avr);
+ * Free AVAudioResampleContext and associated AVOption values.
+ * This also calls avresample_close() before freeing.
+void avresample_free(AVAudioResampleContext **avr);
+ * Generate a channel mixing matrix.
+ * This function is the one used internally by libavresample for building the
+ * default mixing matrix. It is made public just as a utility function for
+ * building custom matrices.
+ * @param in_layout input channel layout
+ * @param out_layout output channel layout
+ * @param center_mix_level mix level for the center channel
+ * @param surround_mix_level mix level for the surround channel(s)
+ * @param lfe_mix_level mix level for the low-frequency effects channel
+ * @param normalize if 1, coefficients will be normalized to prevent
+ * overflow. if 0, coefficients will not be
+ * normalized.
+ * @param[out] matrix mixing coefficients; matrix[i + stride * o] is
+ * the weight of input channel i in output channel o.
+ * @param stride distance between adjacent input channels in the
+ * matrix array
+ * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
+int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
+ double center_mix_level, double surround_mix_level,
+ double lfe_mix_level, int normalize, double *matrix,
+ int stride, enum AVMatrixEncoding matrix_encoding);
+ * Get the current channel mixing matrix.
+ * If no custom matrix has been previously set or the AVAudioResampleContext is
+ * not open, an error is returned.
+ * @param matrix mixing coefficients; matrix[i + stride * o] is the weight of
+ * input channel i in output channel o.
+ * @param stride distance between adjacent input channels in the matrix array
+int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix,
+ int stride);
+ * Set channel mixing matrix.
+ * Allows for setting a custom mixing matrix, overriding the default matrix
+ * generated internally during avresample_open(). This function can be called
+ * anytime on an allocated context, either before or after calling
+ * avresample_open(), as long as the channel layouts have been set.
+ * avresample_convert() always uses the current matrix.
+ * Calling avresample_close() on the context will clear the current matrix.
+ * @see avresample_close()
+int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
+ * Set a customized input channel mapping.
+ * This function can only be called when the allocated context is not open.
+ * Also, the input channel layout must have already been set.
+ * Calling avresample_close() on the context will clear the channel mapping.
+ * The map for each input channel specifies the channel index in the source to
+ * use for that particular channel, or -1 to mute the channel. Source channels
+ * can be duplicated by using the same index for multiple input channels.
+ * Examples:
+ * Reordering 5.1 AAC order (C,L,R,Ls,Rs,LFE) to FFmpeg order (L,R,C,LFE,Ls,Rs):
+ * { 1, 2, 0, 5, 3, 4 }
+ * Muting the 3rd channel in 4-channel input:
+ * { 0, 1, -1, 3 }
+ * Duplicating the left channel of stereo input:
+ * { 0, 0 }
+ * @param channel_map customized input channel mapping
+int avresample_set_channel_mapping(AVAudioResampleContext *avr,
+ const int *channel_map);
+ * Set compensation for resampling.
+ * This can be called anytime after avresample_open(). If resampling is not
+ * automatically enabled because of a sample rate conversion, the
+ * "force_resampling" option must have been set to 1 when opening the context
+ * in order to use resampling compensation.
+ * @param sample_delta compensation delta, in samples
+ * @param compensation_distance compensation distance, in samples
+int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta,
+ int compensation_distance);
+ * Provide the upper bound on the number of samples the configured
+ * conversion would output.
+ * @param in_nb_samples number of input samples
+ * @return number of samples or AVERROR(EINVAL) if the value
+ * would exceed INT_MAX
+int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples);
+ * Convert input samples and write them to the output FIFO.
+ * The upper bound on the number of output samples can be obtained through
+ * avresample_get_out_samples().
+ * The output data can be NULL or have fewer allocated samples than required.
+ * In this case, any remaining samples not written to the output will be added
+ * to an internal FIFO buffer, to be returned at the next call to this function
+ * or to avresample_read().
+ * If converting sample rate, there may be data remaining in the internal
+ * resampling delay buffer. avresample_get_delay() tells the number of remaining
+ * samples. To get this data as output, call avresample_convert() with NULL
+ * input.
+ * At the end of the conversion process, there may be data remaining in the
+ * internal FIFO buffer. avresample_available() tells the number of remaining
+ * samples. To get this data as output, either call avresample_convert() with
+ * NULL input or call avresample_read().
+ * @see avresample_get_out_samples()
+ * @see avresample_read()
+ * @see avresample_get_delay()
+ * @param output output data pointers
+ * @param out_plane_size output plane size, in bytes.
+ * This can be 0 if unknown, but that will lead to
+ * optimized functions not being used directly on the
+ * output, which could slow down some conversions.
+ * @param out_samples maximum number of samples that the output buffer can hold
+ * @param input input data pointers
+ * @param in_plane_size input plane size, in bytes
+ * input, which could slow down some conversions.
+ * @param in_samples number of input samples to convert
+ * @return number of samples written to the output buffer,
+ * not including converted samples added to the internal
+ * output FIFO
+int avresample_convert(AVAudioResampleContext *avr, uint8_t **output,
+ int out_plane_size, int out_samples,
+ uint8_t * const *input, int in_plane_size,
+ int in_samples);
+ * Return the number of samples currently in the resampling delay buffer.
+ * When resampling, there may be a delay between the input and output. Any
+ * unconverted samples in each call are stored internally in a delay buffer.
+ * This function allows the user to determine the current number of samples in
+ * the delay buffer, which can be useful for synchronization.
+ * @return number of samples currently in the resampling delay buffer
+int avresample_get_delay(AVAudioResampleContext *avr);
+ * Return the number of available samples in the output FIFO.
+ * During conversion, if the user does not specify an output buffer or
+ * specifies an output buffer that is smaller than what is needed, remaining
+ * samples that are not written to the output are stored to an internal FIFO
+ * buffer. The samples in the FIFO can be read with avresample_read() or
+ * avresample_convert().
+ * @return number of samples available for reading
+int avresample_available(AVAudioResampleContext *avr);
+ * Read samples from the output FIFO.
+ * buffer. This function can be used to read samples from that internal FIFO.
+ * @see avresample_available()
+ * @param output output data pointers. May be NULL, in which case
+ * nb_samples of data is discarded from output FIFO.
+ * @param nb_samples number of samples to read from the FIFO
+ * @return the number of samples written to output
+int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples);
+ * Convert the samples in the input AVFrame and write them to the output AVFrame.
+ * Input and output AVFrames must have channel_layout, sample_rate and format set.
+ * The upper bound on the number of output samples is obtained through
+ * If the output AVFrame does not have the data pointers allocated the nb_samples
+ * field will be set using avresample_get_out_samples() and av_frame_get_buffer()
+ * is called to allocate the frame.
+ * The output AVFrame can be NULL or have fewer allocated samples than required.
+ * or to avresample_convert() or to avresample_read().
+ * resampling delay buffer. avresample_get_delay() tells the number of
+ * remaining samples. To get this data as output, call this function or
+ * avresample_convert() with NULL input.
+ * samples. To get this data as output, either call this function or
+ * avresample_convert() with NULL input or call avresample_read().
+ * If the AVAudioResampleContext configuration does not match the output and
+ * input AVFrame settings the conversion does not take place and depending on
+ * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED
+ * or AVERROR_OUTPUT_CHANGED|AVERROR_INPUT_CHANGED is returned.
+ * @param output output AVFrame
+ * @param input input AVFrame
+ * @return 0 on success, AVERROR on failure or nonmatching
+ * configuration.
+int avresample_convert_frame(AVAudioResampleContext *avr,
+ AVFrame *output, AVFrame *input);
+ * Configure or reconfigure the AVAudioResampleContext using the information
+ * provided by the AVFrames.
+ * The original resampling context is reset even on failure.
+ * The function calls avresample_close() internally if the context is open.
+ * @see avresample_open();
+ * @see avresample_close();
+ * @param out output AVFrame
+ * @param in input AVFrame
+int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in);
+ * @}
+#endif /* AVRESAMPLE_AVRESAMPLE_H */
@@ -0,0 +1,50 @@
+#ifndef AVRESAMPLE_VERSION_H
+#define AVRESAMPLE_VERSION_H
+ * Libavresample version macros.
+#define LIBAVRESAMPLE_VERSION_MAJOR 4
+#define LIBAVRESAMPLE_VERSION_MINOR 0
+#define LIBAVRESAMPLE_VERSION_MICRO 0
+#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \
+ LIBAVRESAMPLE_VERSION_MINOR, \
+ LIBAVRESAMPLE_VERSION_MICRO)
+#define LIBAVRESAMPLE_VERSION AV_VERSION(LIBAVRESAMPLE_VERSION_MAJOR, \
+#define LIBAVRESAMPLE_BUILD LIBAVRESAMPLE_VERSION_INT
+#define LIBAVRESAMPLE_IDENT "Lavr" AV_STRINGIFY(LIBAVRESAMPLE_VERSION)
+ * FF_API_* defines may be placed below to indicate public API that will be
+ * dropped at a future version bump. The defines themselves are not part of
+ * the public API and may change, break or disappear at any time.
+#endif /* AVRESAMPLE_VERSION_H */
@@ -0,0 +1,372 @@
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ * common internal API header
+#ifndef AVUTIL_INTERNAL_H
+#define AVUTIL_INTERNAL_H
+#if !defined(DEBUG) && !defined(NDEBUG)
+# define NDEBUG
+// This can be enabled to allow detection of additional integer overflows with ubsan
+//#define CHECKED
+#include <assert.h>
+#include "attributes.h"
+#include "timer.h"
+#include "cpu.h"
+#include "dict.h"
+#include "macros.h"
+#include "mem.h"
+#include "pixfmt.h"
+#include "version.h"
+#if ARCH_X86
+# include "x86/emms.h"
+#ifndef emms_c
+# define emms_c() do {} while(0)
+#ifndef attribute_align_arg
+#if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
+# define attribute_align_arg __attribute__((force_align_arg_pointer))
+# define attribute_align_arg
+#if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avutil)
+# define av_export_avutil __declspec(dllimport)
+# define av_export_avutil
+#if HAVE_PRAGMA_DEPRECATED
+# if defined(__ICL) || defined (__INTEL_COMPILER)
+# define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
+# define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
+# elif defined(_MSC_VER)
+# define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
+# else
+# define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+# define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
+# define FF_DISABLE_DEPRECATION_WARNINGS
+# define FF_ENABLE_DEPRECATION_WARNINGS
+#define FF_MEMORY_POISON 0x2a
+#define MAKE_ACCESSORS(str, name, type, field) \
+ type av_##name##_get_##field(const str *s) { return s->field; } \
+ void av_##name##_set_##field(str *s, type v) { s->field = v; }
+// Some broken preprocessors need a second expansion
+// to be forced to tokenize __VA_ARGS__
+#define E1(x) x
+/* Check if the hard coded offset of a struct member still matches reality.
+ * Induce a compilation failure if not.
+#define AV_CHECK_OFFSET(s, m, o) struct check_##o { \
+ int x_##o[offsetof(s, m) == o? 1: -1]; \
+#define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
+ uint8_t la_##v[sizeof(t s o) + (a)]; \
+ t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
+#define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
+ DECLARE_ALIGNED(a, t, la_##v) s o; \
+ t (*v) o = la_##v
+#define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
+#if HAVE_LOCAL_ALIGNED
+# define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
+# define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
+#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
+ p = av_malloc(size);\
+ if (!(p) && (size) != 0) {\
+ av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
+ goto label;\
+#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
+ p = av_mallocz(size);\
+#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
+ p = av_malloc_array(nelem, elsize);\
+ if (!p) {\
+#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
+ p = av_mallocz_array(nelem, elsize);\
+#include "libm.h"
+ * Return NULL if CONFIG_SMALL is true, otherwise the argument
+ * without modification. Used to disable the definition of strings
+ * (for example AVCodec long_names).
+#if CONFIG_SMALL
+# define NULL_IF_CONFIG_SMALL(x) NULL
+# define NULL_IF_CONFIG_SMALL(x) x
+ * Define a function with only the non-default version specified.
+ * On systems with ELF shared libraries, all symbols exported from
+ * FFmpeg libraries are tagged with the name and major version of the
+ * library to which they belong. If a function is moved from one
+ * library to another, a wrapper must be retained in the original
+ * location to preserve binary compatibility.
+ * Functions defined with this macro will never be used to resolve
+ * symbols by the build-time linker.
+ * @param type return type of function
+ * @param name name of function
+ * @param args argument list of function
+ * @param ver version tag to assign function
+#if HAVE_SYMVER_ASM_LABEL
+# define FF_SYMVER(type, name, args, ver) \
+ type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
+ type ff_##name args
+#elif HAVE_SYMVER_GNU_ASM
+ __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
+ type ff_##name args; \
+ * Return NULL if a threading library has not been enabled.
+ * Used to disable threading functions in AVCodec definitions
+ * when not needed.
+# define ONLY_IF_THREADS_ENABLED(x) x
+# define ONLY_IF_THREADS_ENABLED(x) NULL
+ * Log a generic warning message about a missing feature.
+ * @param[in] avc a pointer to an arbitrary struct of which the first
+ * field is a pointer to an AVClass struct
+ * @param[in] msg string containing the name of the missing feature
+void avpriv_report_missing_feature(void *avc,
+ const char *msg, ...) av_printf_format(2, 3);
+ * Additionally request that a sample showcasing the feature be uploaded.
+ * @param[in] avc a pointer to an arbitrary struct of which the first field is
+ * a pointer to an AVClass struct
+void avpriv_request_sample(void *avc,
+#if HAVE_LIBC_MSVCRT
+#include <crtversion.h>
+#if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
+#pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
+#pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
+#define avpriv_open ff_open
+#define avpriv_tempfile ff_tempfile
+#define PTRDIFF_SPECIFIER "Id"
+#define SIZE_SPECIFIER "Iu"
+#define PTRDIFF_SPECIFIER "td"
+#define SIZE_SPECIFIER "zu"
+#ifdef DEBUG
+# define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
+# define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
+// For debuging we use signed operations so overflows can be detected (by ubsan)
+// For production we use unsigned so there are no undefined operations
+#ifdef CHECKED
+#define SUINT int
+#define SUINT32 int32_t
+#define SUINT unsigned
+#define SUINT32 uint32_t
+ * Clip and convert a double value into the long long amin-amax range.
+ * This function is needed because conversion of floating point to integers when
+ * it does not fit in the integer's representation does not necessarily saturate
+ * correctly (usually converted to a cvttsd2si on x86) which saturates numbers
+ * > INT64_MAX to INT64_MIN. The standard marks such conversions as undefined
+ * behavior, allowing this sort of mathematically bogus conversions. This provides
+ * a safe alternative that is slower obviously but assures safety and better
+ * mathematical behavior.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+static av_always_inline av_const int64_t ff_rint64_clip(double a, int64_t amin, int64_t amax)
+ int64_t res;
+#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
+ if (amin > amax) abort();
+ // INT64_MAX+1,INT64_MIN are exactly representable as IEEE doubles
+ // do range checks first
+ if (a >= 9223372036854775808.0)
+ return amax;
+ if (a <= -9223372036854775808.0)
+ return amin;
+ // safe to call llrint and clip accordingly
+ res = llrint(a);
+ if (res > amax)
+ if (res < amin)
+ * A wrapper for open() setting O_CLOEXEC.
+av_warn_unused_result
+int avpriv_open(const char *filename, int flags, ...);
+ * Wrapper to work around the lack of mkstemp() on mingw.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * @return file descriptor of opened file (or negative value corresponding to an
+ * AVERROR code on error)
+ * and opened file name in **filename.
+ * @note On very old libcs it is necessary to set a secure umask before
+ * calling this, av_tempfile() can't call umask itself as it is used in
+ * libraries and could interfere with the calling application.
+int avpriv_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
+int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
+static av_always_inline av_const int avpriv_mirror(int x, int w)
+ if (!w)
+ while ((unsigned)x > (unsigned)w) {
+ x = -x;
+ if (x < 0)
+ x += 2 * w;
+ return x;
+void ff_check_pixfmt_descriptors(void);
+ * Set a dictionary value to an ISO-8601 compliant timestamp string.
+ * @param s AVFormatContext
+ * @param key metadata key
+ * @param timestamp unix timestamp in microseconds
+ * @return <0 on error
+int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp);
+// Helper macro for AV_PIX_FMT_FLAG_PSEUDOPAL deprecation. Code inside FFmpeg
+// should always use FF_PSEUDOPAL. Once the public API flag gets removed, all
+// code using it is dead code.
+#if FF_API_PSEUDOPAL
+#define FF_PSEUDOPAL AV_PIX_FMT_FLAG_PSEUDOPAL
+#define FF_PSEUDOPAL 0
+#endif /* AVUTIL_INTERNAL_H */
@@ -0,0 +1,471 @@
+ * erf function: Copyright (c) 2006 John Maddock
+ * Replacements for frequently missing libm functions
+#ifndef AVUTIL_LIBM_H
+#define AVUTIL_LIBM_H
+#include "intfloat.h"
+#include "mathematics.h"
+#if HAVE_MIPSFPU && HAVE_INLINE_ASM
+#include "libavutil/mips/libm_mips.h"
+#endif /* HAVE_MIPSFPU && HAVE_INLINE_ASM*/
+#if !HAVE_ATANF
+#undef atanf
+#define atanf(x) ((float)atan(x))
+#endif /* HAVE_ATANF */
+#if !HAVE_ATAN2F
+#undef atan2f
+#define atan2f(y, x) ((float)atan2(y, x))
+#endif /* HAVE_ATAN2F */
+#if !HAVE_POWF
+#undef powf
+#define powf(x, y) ((float)pow(x, y))
+#endif /* HAVE_POWF */
+#if !HAVE_CBRT
+static av_always_inline double cbrt(double x)
+ return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
+#endif /* HAVE_CBRT */
+#if !HAVE_CBRTF
+static av_always_inline float cbrtf(float x)
+ return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
+#endif /* HAVE_CBRTF */
+#if !HAVE_COPYSIGN
+static av_always_inline double copysign(double x, double y)
+ uint64_t vx = av_double2int(x);
+ uint64_t vy = av_double2int(y);
+ return av_int2double((vx & UINT64_C(0x7fffffffffffffff)) | (vy & UINT64_C(0x8000000000000000)));
+#endif /* HAVE_COPYSIGN */
+#if !HAVE_COSF
+#undef cosf
+#define cosf(x) ((float)cos(x))
+#endif /* HAVE_COSF */
+#if !HAVE_ERF
+static inline double ff_eval_poly(const double *coeff, int size, double x) {
+ double sum = coeff[size-1];
+ for (i = size-2; i >= 0; --i) {
+ sum *= x;
+ sum += coeff[i];
+ return sum;
+ * erf function
+ * Algorithm taken from the Boost project, source:
+ * http://www.boost.org/doc/libs/1_46_1/boost/math/special_functions/erf.hpp
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0 (see notice below).
+ * Boost Software License - Version 1.0 - August 17th, 2003
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+static inline double erf(double z)
+#ifndef FF_ARRAY_ELEMS
+#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
+ double result;
+ /* handle the symmetry: erf(-x) = -erf(x) */
+ if (z < 0)
+ return -erf(-z);
+ /* branch based on range of z, and pick appropriate approximation */
+ if (z == 0)
+ else if (z < 1e-10)
+ return z * 1.125 + z * 0.003379167095512573896158903121545171688;
+ else if (z < 0.5) {
+ // Maximum Deviation Found: 1.561e-17
+ // Expected Error Term: 1.561e-17
+ // Maximum Relative Change in Control Points: 1.155e-04
+ // Max Error found at double precision = 2.961182e-17
+ static const double y = 1.044948577880859375;
+ static const double p[] = {
+ 0.0834305892146531832907,
+ -0.338165134459360935041,
+ -0.0509990735146777432841,
+ -0.00772758345802133288487,
+ -0.000322780120964605683831,
+ static const double q[] = {
+ 1,
+ 0.455004033050794024546,
+ 0.0875222600142252549554,
+ 0.00858571925074406212772,
+ 0.000370900071787748000569,
+ double zz = z * z;
+ return z * (y + ff_eval_poly(p, FF_ARRAY_ELEMS(p), zz) / ff_eval_poly(q, FF_ARRAY_ELEMS(q), zz));
+ /* here onwards compute erfc */
+ else if (z < 1.5) {
+ // Maximum Deviation Found: 3.702e-17
+ // Expected Error Term: 3.702e-17
+ // Maximum Relative Change in Control Points: 2.845e-04
+ // Max Error found at double precision = 4.841816e-17
+ static const double y = 0.405935764312744140625;
+ -0.098090592216281240205,
+ 0.178114665841120341155,
+ 0.191003695796775433986,
+ 0.0888900368967884466578,
+ 0.0195049001251218801359,
+ 0.00180424538297014223957,
+ 1.84759070983002217845,
+ 1.42628004845511324508,
+ 0.578052804889902404909,
+ 0.12385097467900864233,
+ 0.0113385233577001411017,
+ 0.337511472483094676155e-5,
+ result = y + ff_eval_poly(p, FF_ARRAY_ELEMS(p), z - 0.5) / ff_eval_poly(q, FF_ARRAY_ELEMS(q), z - 0.5);
+ result *= exp(-z * z) / z;
+ return 1 - result;
+ else if (z < 2.5) {
+ // Max Error found at double precision = 6.599585e-18
+ // Maximum Deviation Found: 3.909e-18
+ // Expected Error Term: 3.909e-18
+ // Maximum Relative Change in Control Points: 9.886e-05
+ static const double y = 0.50672817230224609375;
+ -0.0243500476207698441272,
+ 0.0386540375035707201728,
+ 0.04394818964209516296,
+ 0.0175679436311802092299,
+ 0.00323962406290842133584,
+ 0.000235839115596880717416,
+ 1.53991494948552447182,
+ 0.982403709157920235114,
+ 0.325732924782444448493,
+ 0.0563921837420478160373,
+ 0.00410369723978904575884,
+ result = y + ff_eval_poly(p, FF_ARRAY_ELEMS(p), z - 1.5) / ff_eval_poly(q, FF_ARRAY_ELEMS(q), z - 1.5);
+ else if (z < 4.5) {
+ // Maximum Deviation Found: 1.512e-17
+ // Expected Error Term: 1.512e-17
+ // Maximum Relative Change in Control Points: 2.222e-04
+ // Max Error found at double precision = 2.062515e-17
+ static const double y = 0.5405750274658203125;
+ 0.00295276716530971662634,
+ 0.0137384425896355332126,
+ 0.00840807615555585383007,
+ 0.00212825620914618649141,
+ 0.000250269961544794627958,
+ 0.113212406648847561139e-4,
+ 1.04217814166938418171,
+ 0.442597659481563127003,
+ 0.0958492726301061423444,
+ 0.0105982906484876531489,
+ 0.000479411269521714493907,
+ result = y + ff_eval_poly(p, FF_ARRAY_ELEMS(p), z - 3.5) / ff_eval_poly(q, FF_ARRAY_ELEMS(q), z - 3.5);
+ /* differ from Boost here, the claim of underflow of erfc(x) past 5.8 is
+ * slightly incorrect, change to 5.92
+ * (really somewhere between 5.9125 and 5.925 is when it saturates) */
+ else if (z < 5.92) {
+ // Max Error found at double precision = 2.997958e-17
+ // Maximum Deviation Found: 2.860e-17
+ // Expected Error Term: 2.859e-17
+ // Maximum Relative Change in Control Points: 1.357e-05
+ static const double y = 0.5579090118408203125;
+ 0.00628057170626964891937,
+ 0.0175389834052493308818,
+ -0.212652252872804219852,
+ -0.687717681153649930619,
+ -2.5518551727311523996,
+ -3.22729451764143718517,
+ -2.8175401114513378771,
+ 2.79257750980575282228,
+ 11.0567237927800161565,
+ 15.930646027911794143,
+ 22.9367376522880577224,
+ 13.5064170191802889145,
+ 5.48409182238641741584,
+ result = y + ff_eval_poly(p, FF_ARRAY_ELEMS(p), 1 / z) / ff_eval_poly(q, FF_ARRAY_ELEMS(q), 1 / z);
+ /* handle the nan case, but don't use isnan for max portability */
+ else if (z != z)
+ return z;
+ /* finally return saturated result */
+#endif /* HAVE_ERF */
+#if !HAVE_EXPF
+#undef expf
+#define expf(x) ((float)exp(x))
+#endif /* HAVE_EXPF */
+#if !HAVE_EXP2
+#undef exp2
+#define exp2(x) exp((x) * M_LN2)
+#endif /* HAVE_EXP2 */
+#if !HAVE_EXP2F
+#undef exp2f
+#define exp2f(x) ((float)exp2(x))
+#endif /* HAVE_EXP2F */
+#if !HAVE_ISINF
+#undef isinf
+/* Note: these do not follow the BSD/Apple/GNU convention of returning -1 for
+-Inf, +1 for Inf, 0 otherwise, but merely follow the POSIX/ISO mandated spec of
+returning a non-zero value for +/-Inf, 0 otherwise. */
+static av_always_inline av_const int avpriv_isinff(float x)
+ uint32_t v = av_float2int(x);
+ if ((v & 0x7f800000) != 0x7f800000)
+ return !(v & 0x007fffff);
+static av_always_inline av_const int avpriv_isinf(double x)
+ uint64_t v = av_double2int(x);
+ if ((v & 0x7ff0000000000000) != 0x7ff0000000000000)
+ return !(v & 0x000fffffffffffff);
+#define isinf(x) \
+ (sizeof(x) == sizeof(float) \
+ ? avpriv_isinff(x) \
+ : avpriv_isinf(x))
+#endif /* HAVE_ISINF */
+#if !HAVE_ISNAN
+static av_always_inline av_const int avpriv_isnanf(float x)
+ return v & 0x007fffff;
+static av_always_inline av_const int avpriv_isnan(double x)
+ return (v & 0x000fffffffffffff) && 1;
+#define isnan(x) \
+ ? avpriv_isnanf(x) \
+ : avpriv_isnan(x))
+#endif /* HAVE_ISNAN */
+#if !HAVE_ISFINITE
+static av_always_inline av_const int avpriv_isfinitef(float x)
+ return (v & 0x7f800000) != 0x7f800000;
+static av_always_inline av_const int avpriv_isfinite(double x)
+ return (v & 0x7ff0000000000000) != 0x7ff0000000000000;
+#define isfinite(x) \
+ ? avpriv_isfinitef(x) \
+ : avpriv_isfinite(x))
+#endif /* HAVE_ISFINITE */
+#if !HAVE_HYPOT
+static inline av_const double hypot(double x, double y)
+ double ret, temp;
+ x = fabs(x);
+ y = fabs(y);
+ if (isinf(x) || isinf(y))
+ return av_int2double(0x7ff0000000000000);
+ if (x == 0 || y == 0)
+ return x + y;
+ if (x < y) {
+ temp = x;
+ x = y;
+ y = temp;
+ y = y/x;
+ return x*sqrt(1 + y*y);
+#endif /* HAVE_HYPOT */
+#if !HAVE_LDEXPF
+#undef ldexpf
+#define ldexpf(x, exp) ((float)ldexp(x, exp))
+#endif /* HAVE_LDEXPF */
+#if !HAVE_LLRINT
+#undef llrint
+#define llrint(x) ((long long)rint(x))
+#endif /* HAVE_LLRINT */
+#if !HAVE_LLRINTF
+#undef llrintf
+#define llrintf(x) ((long long)rint(x))
+#if !HAVE_LOG2
+#undef log2
+#define log2(x) (log(x) * 1.44269504088896340736)
+#endif /* HAVE_LOG2 */
+#if !HAVE_LOG2F
+#undef log2f
+#define log2f(x) ((float)log2(x))
+#endif /* HAVE_LOG2F */
+#if !HAVE_LOG10F
+#undef log10f
+#define log10f(x) ((float)log10(x))
+#endif /* HAVE_LOG10F */
+#if !HAVE_SINF
+#undef sinf
+#define sinf(x) ((float)sin(x))
+#endif /* HAVE_SINF */
+#if !HAVE_RINT
+static inline double rint(double x)
+ return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+#endif /* HAVE_RINT */
+#if !HAVE_LRINT
+static av_always_inline av_const long int lrint(double x)
+ return rint(x);
+#endif /* HAVE_LRINT */
+#if !HAVE_LRINTF
+static av_always_inline av_const long int lrintf(float x)
+ return (int)(rint(x));
+#endif /* HAVE_LRINTF */
+#if !HAVE_ROUND
+static av_always_inline av_const double round(double x)
+ return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
+#endif /* HAVE_ROUND */
+#if !HAVE_ROUNDF
+static av_always_inline av_const float roundf(float x)
+#endif /* HAVE_ROUNDF */
+#if !HAVE_TRUNC
+static av_always_inline av_const double trunc(double x)
+ return (x > 0) ? floor(x) : ceil(x);
+#endif /* HAVE_TRUNC */
+#if !HAVE_TRUNCF
+static av_always_inline av_const float truncf(float x)
+#endif /* HAVE_TRUNCF */
+#endif /* AVUTIL_LIBM_H */
@@ -0,0 +1,28 @@
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+#ifndef AVUTIL_REVERSE_H
+#define AVUTIL_REVERSE_H
+extern const uint8_t ff_reverse[256];
+#endif /* AVUTIL_REVERSE_H */
+// This header should only be used to simplify code where
+// threading is optional, not as a generic threading abstraction.
+#ifndef AVUTIL_THREAD_H
+#define AVUTIL_THREAD_H
+#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
+#if HAVE_PTHREADS
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
+#include "log.h"
+#define ASSERT_PTHREAD_NORET(func, ...) do { \
+ int ret = func(__VA_ARGS__); \
+ if (ret) { \
+ char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \
+ av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \
+ " failed with error: %s\n", \
+ av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \
+ AVERROR(ret))); \
+ abort(); \
+#define ASSERT_PTHREAD(func, ...) do { \
+ ASSERT_PTHREAD_NORET(func, __VA_ARGS__); \
+ return 0; \
+static inline int strict_pthread_join(pthread_t thread, void **value_ptr)
+ ASSERT_PTHREAD(pthread_join, thread, value_ptr);
+static inline int strict_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
+ if (attr) {
+ ASSERT_PTHREAD_NORET(pthread_mutex_init, mutex, attr);
+ pthread_mutexattr_t local_attr;
+ ASSERT_PTHREAD_NORET(pthread_mutexattr_init, &local_attr);
+ ASSERT_PTHREAD_NORET(pthread_mutexattr_settype, &local_attr, PTHREAD_MUTEX_ERRORCHECK);
+ ASSERT_PTHREAD_NORET(pthread_mutex_init, mutex, &local_attr);
+ ASSERT_PTHREAD_NORET(pthread_mutexattr_destroy, &local_attr);
+static inline int strict_pthread_mutex_destroy(pthread_mutex_t *mutex)
+ ASSERT_PTHREAD(pthread_mutex_destroy, mutex);
+static inline int strict_pthread_mutex_lock(pthread_mutex_t *mutex)
+ ASSERT_PTHREAD(pthread_mutex_lock, mutex);
+static inline int strict_pthread_mutex_unlock(pthread_mutex_t *mutex)
+ ASSERT_PTHREAD(pthread_mutex_unlock, mutex);
+static inline int strict_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
+ ASSERT_PTHREAD(pthread_cond_init, cond, attr);
+static inline int strict_pthread_cond_destroy(pthread_cond_t *cond)
+ ASSERT_PTHREAD(pthread_cond_destroy, cond);
+static inline int strict_pthread_cond_signal(pthread_cond_t *cond)
+ ASSERT_PTHREAD(pthread_cond_signal, cond);
+static inline int strict_pthread_cond_broadcast(pthread_cond_t *cond)
+ ASSERT_PTHREAD(pthread_cond_broadcast, cond);
+static inline int strict_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
+ ASSERT_PTHREAD(pthread_cond_wait, cond, mutex);
+static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
+ ASSERT_PTHREAD(pthread_once, once_control, init_routine);
+#define pthread_join strict_pthread_join
+#define pthread_mutex_init strict_pthread_mutex_init
+#define pthread_mutex_destroy strict_pthread_mutex_destroy
+#define pthread_mutex_lock strict_pthread_mutex_lock
+#define pthread_mutex_unlock strict_pthread_mutex_unlock
+#define pthread_cond_init strict_pthread_cond_init
+#define pthread_cond_destroy strict_pthread_cond_destroy
+#define pthread_cond_signal strict_pthread_cond_signal
+#define pthread_cond_broadcast strict_pthread_cond_broadcast
+#define pthread_cond_wait strict_pthread_cond_wait
+#define pthread_once strict_pthread_once
+#elif HAVE_OS2THREADS
+#include "compat/os2threads.h"
+#include "compat/w32pthreads.h"
+#define AVMutex pthread_mutex_t
+#define AV_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define ff_mutex_init pthread_mutex_init
+#define ff_mutex_lock pthread_mutex_lock
+#define ff_mutex_unlock pthread_mutex_unlock
+#define ff_mutex_destroy pthread_mutex_destroy
+#define AVOnce pthread_once_t
+#define AV_ONCE_INIT PTHREAD_ONCE_INIT
+#define ff_thread_once(control, routine) pthread_once(control, routine)
+#define AVMutex char
+#define AV_MUTEX_INITIALIZER 0
+static inline int ff_mutex_init(AVMutex *mutex, const void *attr){ return 0; }
+static inline int ff_mutex_lock(AVMutex *mutex){ return 0; }
+static inline int ff_mutex_unlock(AVMutex *mutex){ return 0; }
+static inline int ff_mutex_destroy(AVMutex *mutex){ return 0; }
+#define AVOnce char
+#define AV_ONCE_INIT 0
+static inline int ff_thread_once(char *control, void (*routine)(void))
+ if (!*control) {
+ routine();
+ *control = 1;
+#endif /* AVUTIL_THREAD_H */
@@ -0,0 +1,141 @@
+ * high precision timer, useful to profile code
+#ifndef AVUTIL_TIMER_H
+#define AVUTIL_TIMER_H
+#if CONFIG_LINUX_PERF
+# ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+# include <unistd.h> // read(3)
+# include <sys/ioctl.h>
+# include <asm/unistd.h>
+# include <linux/perf_event.h>
+#include <inttypes.h>
+#if HAVE_MACH_ABSOLUTE_TIME
+#include <mach/mach_time.h>
+#if ARCH_AARCH64
+# include "aarch64/timer.h"
+#elif ARCH_ARM
+# include "arm/timer.h"
+# include "ppc/timer.h"
+# include "x86/timer.h"
+#if !defined(AV_READ_TIME)
+# if HAVE_GETHRTIME
+# define AV_READ_TIME gethrtime
+# elif HAVE_MACH_ABSOLUTE_TIME
+# define AV_READ_TIME mach_absolute_time
+#ifndef FF_TIMER_UNITS
+# define FF_TIMER_UNITS "UNITS"
+#define TIMER_REPORT(id, tdiff) \
+ { \
+ static uint64_t tsum = 0; \
+ static int tcount = 0; \
+ static int tskip_count = 0; \
+ static int thistogram[32] = {0}; \
+ thistogram[av_log2(tdiff)]++; \
+ if (tcount < 2 || \
+ (tdiff) < 8 * tsum / tcount || \
+ (tdiff) < 2000) { \
+ tsum += (tdiff); \
+ tcount++; \
+ tskip_count++; \
+ if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \
+ int i; \
+ av_log(NULL, AV_LOG_ERROR, \
+ "%7"PRIu64" " FF_TIMER_UNITS " in %s,%8d runs,%7d skips", \
+ tsum * 10 / tcount, id, tcount, tskip_count); \
+ for (i = 0; i < 32; i++) \
+ av_log(NULL, AV_LOG_VERBOSE, " %2d", av_log2(2*thistogram[i]));\
+ av_log(NULL, AV_LOG_ERROR, "\n"); \
+#define START_TIMER \
+ static int linux_perf_fd; \
+ uint64_t tperf; \
+ if (!linux_perf_fd) { \
+ struct perf_event_attr attr = { \
+ .type = PERF_TYPE_HARDWARE, \
+ .size = sizeof(struct perf_event_attr), \
+ .config = PERF_COUNT_HW_CPU_CYCLES, \
+ .disabled = 1, \
+ .exclude_kernel = 1, \
+ .exclude_hv = 1, \
+ }; \
+ linux_perf_fd = syscall(__NR_perf_event_open, &attr, \
+ 0, -1, -1, 0); \
+ if (linux_perf_fd == -1) { \
+ av_log(NULL, AV_LOG_ERROR, "perf_event_open failed: %s\n", \
+ av_err2str(AVERROR(errno))); \
+ } else { \
+ ioctl(linux_perf_fd, PERF_EVENT_IOC_RESET, 0); \
+ ioctl(linux_perf_fd, PERF_EVENT_IOC_ENABLE, 0); \
+#define STOP_TIMER(id) \
+ ioctl(linux_perf_fd, PERF_EVENT_IOC_DISABLE, 0); \
+ read(linux_perf_fd, &tperf, sizeof(tperf)); \
+ TIMER_REPORT(id, tperf)
+#elif defined(AV_READ_TIME)
+ uint64_t tend; \
+ uint64_t tstart = AV_READ_TIME(); \
+ tend = AV_READ_TIME(); \
+ TIMER_REPORT(id, tend - tstart)
+#define START_TIMER
+#define STOP_TIMER(id) { }
+#endif /* AVUTIL_TIMER_H */
+#ifndef AVUTIL_WCHAR_FILENAME_H
+#define AVUTIL_WCHAR_FILENAME_H
+static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w)
+ int num_chars;
+ num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
+ if (num_chars <= 0) {
+ *filename_w = NULL;
+ *filename_w = (wchar_t *)av_mallocz_array(num_chars, sizeof(wchar_t));
+ if (!*filename_w) {
+ errno = ENOMEM;
+ MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
+#endif /* AVUTIL_WCHAR_FILENAME_H */
@@ -0,0 +1,154 @@
+#ifndef AVUTIL_X86_ASM_H
+#define AVUTIL_X86_ASM_H
+typedef struct xmm_reg { uint64_t a, b; } xmm_reg;
+typedef struct ymm_reg { uint64_t a, b, c, d; } ymm_reg;
+#if ARCH_X86_64
+# define FF_OPSIZE "q"
+# define FF_REG_a "rax"
+# define FF_REG_b "rbx"
+# define FF_REG_c "rcx"
+# define FF_REG_d "rdx"
+# define FF_REG_D "rdi"
+# define FF_REG_S "rsi"
+# define FF_PTR_SIZE "8"
+typedef int64_t x86_reg;
+/* FF_REG_SP is defined in Solaris sys headers, so use FF_REG_sp */
+# define FF_REG_sp "rsp"
+# define FF_REG_BP "rbp"
+# define FF_REGBP rbp
+# define FF_REGa rax
+# define FF_REGb rbx
+# define FF_REGc rcx
+# define FF_REGd rdx
+# define FF_REGSP rsp
+#elif ARCH_X86_32
+# define FF_OPSIZE "l"
+# define FF_REG_a "eax"
+# define FF_REG_b "ebx"
+# define FF_REG_c "ecx"
+# define FF_REG_d "edx"
+# define FF_REG_D "edi"
+# define FF_REG_S "esi"
+# define FF_PTR_SIZE "4"
+typedef int32_t x86_reg;
+# define FF_REG_sp "esp"
+# define FF_REG_BP "ebp"
+# define FF_REGBP ebp
+# define FF_REGa eax
+# define FF_REGb ebx
+# define FF_REGc ecx
+# define FF_REGd edx
+# define FF_REGSP esp
+typedef int x86_reg;
+#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))
+#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE))
+#if ARCH_X86_64 && defined(PIC)
+# define BROKEN_RELOCATIONS 1
+ * If gcc is not set to support sse (-msse) it will not accept xmm registers
+ * in the clobber list for inline asm. XMM_CLOBBERS takes a list of xmm
+ * registers to be marked as clobbered and evaluates to nothing if they are
+ * not supported, or to the list itself if they are supported. Since a clobber
+ * list may not be empty, XMM_CLOBBERS_ONLY should be used if the xmm
+ * registers are the only in the clobber list.
+ * For example a list with "eax" and "xmm0" as clobbers should become:
+ * : XMM_CLOBBERS("xmm0",) "eax"
+ * and a list with only "xmm0" should become:
+ * XMM_CLOBBERS_ONLY("xmm0")
+#if HAVE_XMM_CLOBBERS
+# define XMM_CLOBBERS(...) __VA_ARGS__
+# define XMM_CLOBBERS_ONLY(...) : __VA_ARGS__
+# define XMM_CLOBBERS(...)
+# define XMM_CLOBBERS_ONLY(...)
+/* Use to export labels from asm. */
+#define LABEL_MANGLE(a) EXTERN_PREFIX #a
+// Use rip-relative addressing if compiling PIC code on x86-64.
+# define LOCAL_MANGLE(a) #a "(%%rip)"
+# define LOCAL_MANGLE(a) #a
+#if HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS
+# define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
+# define NAMED_CONSTRAINTS_ADD(...)
+# define NAMED_CONSTRAINTS(...)
+# define NAMED_CONSTRAINTS_ARRAY_ADD(...)
+# define NAMED_CONSTRAINTS_ARRAY(...)
+ /* When direct symbol references are used in code passed to a compiler that does not support them
+ * then these references need to be converted to named asm constraints instead.
+ * Instead of returning a direct symbol MANGLE now returns a named constraint for that specific symbol.
+ * In order for this to work there must also be a corresponding entry in the asm-interface. To add this
+ * entry use the macro NAMED_CONSTRAINTS() and pass in a list of each symbol reference used in the
+ * corresponding block of code. (e.g. NAMED_CONSTRAINTS(var1,var2,var3) where var1 is the first symbol etc. ).
+ * If there are already existing constraints then use NAMED_CONSTRAINTS_ADD to add to the existing constraint list.
+# define MANGLE(a) "%["#a"]"
+ // Intel/MSVC does not correctly expand va-args so we need a rather ugly hack in order to get it to work
+# define FE_0(P,X) P(X)
+# define FE_1(P,X,X1) P(X), FE_0(P,X1)
+# define FE_2(P,X,X1,X2) P(X), FE_1(P,X1,X2)
+# define FE_3(P,X,X1,X2,X3) P(X), FE_2(P,X1,X2,X3)
+# define FE_4(P,X,X1,X2,X3,X4) P(X), FE_3(P,X1,X2,X3,X4)
+# define FE_5(P,X,X1,X2,X3,X4,X5) P(X), FE_4(P,X1,X2,X3,X4,X5)
+# define FE_6(P,X,X1,X2,X3,X4,X5,X6) P(X), FE_5(P,X1,X2,X3,X4,X5,X6)
+# define FE_7(P,X,X1,X2,X3,X4,X5,X6,X7) P(X), FE_6(P,X1,X2,X3,X4,X5,X6,X7)
+# define FE_8(P,X,X1,X2,X3,X4,X5,X6,X7,X8) P(X), FE_7(P,X1,X2,X3,X4,X5,X6,X7,X8)
+# define FE_9(P,X,X1,X2,X3,X4,X5,X6,X7,X8,X9) P(X), FE_8(P,X1,X2,X3,X4,X5,X6,X7,X8,X9)
+# define GET_FE_IMPL(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
+# define GET_FE(A) GET_FE_IMPL A
+# define GET_FE_GLUE(x, y) x y
+# define FOR_EACH_VA(P,...) GET_FE_GLUE(GET_FE((__VA_ARGS__,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)), (P,__VA_ARGS__))
+# define NAME_CONSTRAINT(x) [x] "m"(x)
+ // Parameters are a list of each symbol reference required
+# define NAMED_CONSTRAINTS_ADD(...) , FOR_EACH_VA(NAME_CONSTRAINT,__VA_ARGS__)
+ // Same but without comma for when there are no previously defined constraints
+# define NAMED_CONSTRAINTS(...) FOR_EACH_VA(NAME_CONSTRAINT,__VA_ARGS__)
+ // Same as above NAMED_CONSTRAINTS except used for passing arrays/pointers instead of normal variables
+# define NAME_CONSTRAINT_ARRAY(x) [x] "m"(*x)
+# define NAMED_CONSTRAINTS_ARRAY_ADD(...) , FOR_EACH_VA(NAME_CONSTRAINT_ARRAY,__VA_ARGS__)
+# define NAMED_CONSTRAINTS_ARRAY(...) FOR_EACH_VA(NAME_CONSTRAINT_ARRAY,__VA_ARGS__)
+#endif /* AVUTIL_X86_ASM_H */
@@ -0,0 +1,55 @@
+#ifndef AVUTIL_X86_EMMS_H
+#define AVUTIL_X86_EMMS_H
+void avpriv_emms_asm(void);
+#if HAVE_MMX_INLINE
+# define emms_c emms_c
+ * Empty mmx state.
+ * this must be called between any dsp function and float/double code.
+ * for example sin(); dsp->idct_put(); emms_c(); cos()
+ * Note, *alloc() and *free() also use float code in some libc implementations
+ * thus this also applies to them or any function using them.
+static av_always_inline void emms_c(void)
+/* Some inlined functions may also use mmx instructions regardless of
+ * runtime cpuflags. With that in mind, we unconditionally empty the
+ * mmx state if the target cpu chosen at configure time supports it.
+#if !defined(__MMX__)
+ if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
+ __asm__ volatile ("emms" ::: "memory");
+#elif HAVE_MMX && HAVE_MM_EMPTY
+# include <mmintrin.h>
+# define emms_c _mm_empty
+#elif HAVE_MMX_EXTERNAL
+# define emms_c avpriv_emms_asm
+#endif /* HAVE_MMX_INLINE */
+#endif /* AVUTIL_X86_EMMS_H */
+#ifndef AVUTIL_X86_TIMER_H
+#define AVUTIL_X86_TIMER_H
+#define FF_TIMER_UNITS "decicycles"
+#define AV_READ_TIME read_time
+static inline uint64_t read_time(void)
+ uint32_t a, d;
+ __asm__ volatile(
+#if ARCH_X86_64 || defined(__SSE2__)
+ "lfence \n\t"
+ "rdtsc \n\t"
+ : "=a" (a), "=d" (d));
+ return ((uint64_t)d << 32) + a;
+#elif HAVE_RDTSC
+#include <intrin.h>
+#define AV_READ_TIME __rdtsc
+#endif /* AVUTIL_X86_TIMER_H */
@@ -6,4 +6,4 @@
# 3.VideoEncode 视频编码例子
-
+# 4.FFMPEG_Qt Qt下编译ffmpeg.exe