Go to the documentation of this file.
30 #include <stdatomic.h>
43 #if HAVE_SYS_RESOURCE_H
45 #include <sys/types.h>
46 #include <sys/resource.h>
47 #elif HAVE_GETPROCESSTIMES
50 #if HAVE_GETPROCESSMEMORYINFO
54 #if HAVE_SETCONSOLECTRLHANDLER
59 #include <sys/select.h>
64 #include <sys/ioctl.h>
123 static struct termios oldtty;
124 static int restore_tty;
131 tcsetattr (0, TCSANOW, &oldtty);
155 ret = write(2,
"Received > 3 system signals, hard exiting\n",
156 strlen(
"Received > 3 system signals, hard exiting\n"));
162 #if HAVE_SETCONSOLECTRLHANDLER
163 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
170 case CTRL_BREAK_EVENT:
174 case CTRL_CLOSE_EVENT:
175 case CTRL_LOGOFF_EVENT:
176 case CTRL_SHUTDOWN_EVENT:
195 #define SIGNAL(sig, func) \
197 action.sa_handler = func; \
198 sigaction(sig, &action, NULL); \
201 #define SIGNAL(sig, func) \
207 #if defined __linux__
208 struct sigaction action = {0};
212 sigfillset(&action.sa_mask);
215 action.sa_flags = SA_RESTART;
221 if (tcgetattr (0, &tty) == 0) {
225 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
226 |INLCR|IGNCR|ICRNL|IXON);
227 tty.c_oflag |= OPOST;
228 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
229 tty.c_cflag &= ~(CSIZE|PARENB);
234 tcsetattr (0, TCSANOW, &tty);
246 signal(SIGPIPE, SIG_IGN);
248 #if HAVE_SETCONSOLECTRLHANDLER
249 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
265 n = select(1, &rfds,
NULL,
NULL, &tv);
275 # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
277 static HANDLE input_handle;
280 input_handle = GetStdHandle(STD_INPUT_HANDLE);
281 is_pipe = !GetConsoleMode(input_handle, &dw);
286 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
293 if (
read(0, &ch, 1) == 1)
341 "Error closing vstats file, loss of information possible: %s\n",
373 int of_idx = prev ? prev->
file->
index : 0;
374 int ost_idx = prev ? prev->
index + 1 : 0;
389 int if_idx = prev ? prev->
file->
index : 0;
390 int ist_idx = prev ? prev->
index + 1 : 0;
395 return f->streams[ist_idx];
435 memcpy(fd, fd_src,
sizeof(*fd));
437 fd->side_data =
NULL;
438 fd->nb_side_data = 0;
466 fd->dec.frame_num = UINT64_MAX;
470 fd->wallclock[
i] = INT64_MIN;
522 p = strchr(optname,
':');
537 decode ?
"decoding" :
"encoding");
542 "for any stream. The most likely reason is either wrong type "
543 "(e.g. a video option with no video streams) or that it is a "
544 "private option of some decoder which was not actually used "
563 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
574 AVBPrint buf, buf_script;
580 static int first_report = 1;
581 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
582 int mins, secs, ms,
us;
584 const char *hours_sign;
591 if (!is_last_report) {
592 if (last_time == -1) {
593 last_time = cur_time;
595 if (((cur_time - last_time) <
stats_period && !first_report) ||
598 last_time = cur_time;
601 t = (cur_time-timer_start) / 1000000.0;
612 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
619 fps = t > 1 ? frame_number / t : 0;
620 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
621 frame_number, fps < 9.95, fps, q);
622 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
624 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
649 hours_sign = (
pts < 0) ?
"-" :
"";
654 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
655 else av_bprintf(&buf,
"size=%8.0fKiB time=", total_size / 1024.0);
659 av_bprintf(&buf,
"%s%02"PRId64
":%02d:%02d.%02d ",
671 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
672 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
680 av_bprintf(&buf_script,
"out_time=%s%02"PRId64
":%02d:%02d.%06d\n",
681 hours_sign, hours, mins, secs,
us);
684 if (nb_frames_dup || nb_frames_drop)
685 av_bprintf(&buf,
" dup=%"PRId64
" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
686 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n", nb_frames_dup);
687 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n", nb_frames_drop);
694 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
698 ms = (int)((t - secs) * 1000);
704 av_bprintf(&buf,
" elapsed=%"PRId64
":%02d:%02d.%02d", hours, mins, secs, ms / 10);
707 const char end = is_last_report ?
'\n' :
'\r';
709 fprintf(stderr,
"%s %c", buf.str, end);
719 is_last_report ?
"end" :
"continue");
721 FFMIN(buf_script.len, buf_script.size - 1));
724 if (is_last_report) {
727 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
738 for (
int j = 0; j < ist->nb_filters; j++) {
741 ist->file->index, ist->index, ist->dec ? ist->dec->name :
"?",
742 ist->filters[j]->name);
751 if (
ost->attachment_filename) {
776 const AVCodec *out_codec =
ost->enc->enc_ctx->codec;
777 const char *decoder_name =
"?";
778 const char *in_codec_name =
"?";
779 const char *encoder_name =
"?";
780 const char *out_codec_name =
"?";
784 decoder_name = in_codec->
name;
787 in_codec_name =
desc->name;
788 if (!strcmp(decoder_name, in_codec_name))
789 decoder_name =
"native";
793 encoder_name = out_codec->
name;
796 out_codec_name =
desc->name;
797 if (!strcmp(encoder_name, out_codec_name))
798 encoder_name =
"native";
802 in_codec_name, decoder_name,
803 out_codec_name, encoder_name);
814 if (tcgetattr(0, &tty) == 0) {
815 if (
on) tty.c_lflag |=
ECHO;
816 else tty.c_lflag &= ~
ECHO;
817 tcsetattr(0, TCSANOW, &tty);
827 if (cur_time - last_time >= 100000) {
829 last_time = cur_time;
838 if (
key ==
'c' ||
key ==
'C'){
839 char buf[4096], target[64],
command[256],
arg[256] = {0};
842 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
845 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
850 fprintf(stderr,
"\n");
852 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
865 "Parse error, at least 3 arguments were expected, "
866 "only %d given in string '%s'\n", n, buf);
870 fprintf(stderr,
"key function\n"
872 "+ increase verbosity\n"
873 "- decrease verbosity\n"
874 "c Send command to first matching filter supporting it\n"
875 "C Send/Queue command to all matching filters\n"
876 "h dump packets/hex press to cycle through the 3 states\n"
878 "s Show QP histogram\n"
890 int64_t timer_start, transcode_ts = 0;
941 struct rusage rusage;
943 getrusage(RUSAGE_SELF, &rusage);
945 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
947 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
948 #elif HAVE_GETPROCESSTIMES
951 proc = GetCurrentProcess();
952 GetProcessTimes(proc, &
c, &e, &k, &
u);
954 ((
int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
956 ((
int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
965 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
966 struct rusage rusage;
967 getrusage(RUSAGE_SELF, &rusage);
968 return (
int64_t)rusage.ru_maxrss * 1024;
969 #elif HAVE_GETPROCESSMEMORYINFO
971 PROCESS_MEMORY_COUNTERS memcounters;
972 proc = GetCurrentProcess();
973 memcounters.cb =
sizeof(memcounters);
974 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
975 return memcounters.PeakPagefileUsage;
981 int main(
int argc,
char **argv)
990 setvbuf(stderr,
NULL,_IONBF,0);
1026 #if CONFIG_MEDIACODEC
1039 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1040 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
AVCodecParameters * par_enc
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define atomic_store(object, desired)
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static volatile int ffmpeg_exited
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static int clone_side_data(AVFrameSideData ***dst, int *nb_dst, AVFrameSideData *const *src, int nb_src, unsigned int flags)
Wrapper calling av_frame_side_data_clone() in a loop for all source entries.
#define AV_LOG_QUIET
Print no output.
uint8_t * data
The data buffer.
void fg_free(FilterGraph **pfg)
static void frame_data_free(void *opaque, uint8_t *data)
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
InputStream * ist_iter(InputStream *prev)
This structure describes decoded (raw) audio or video data.
int64_t of_filesize(OutputFile *of)
#define u(width, name, range_min, range_max)
static BenchmarkTimeStamps current_time
#define AV_LOG_VERBOSE
Detailed information.
AVIOContext * progress_avio
const int program_birth_year
program birth year, defined by the program for show_banner()
static void term_exit_sigsafe(void)
#define ECHO(name, type, min, max)
Callback for checking whether to abort blocking functions.
int sch_stop(Scheduler *sch, int64_t *finish_ts)
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
#define AV_BPRINT_SIZE_AUTOMATIC
const FrameData * packet_data_c(AVPacket *pkt)
void update_benchmark(const char *fmt,...)
void fg_send_command(FilterGraph *fg, double time, const char *target, const char *command, const char *arg, int all_filters)
int avformat_network_init(void)
Do global initialization of network libraries.
static int transcode(Scheduler *sch)
static void ffmpeg_cleanup(int ret)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void sch_free(Scheduler **psch)
#define FF_ARRAY_ELEMS(a)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void of_free(OutputFile **pof)
This struct describes the properties of a single codec described by an AVCodecID.
static BenchmarkTimeStamps get_benchmark_time_stamps(void)
Scheduler * sch_alloc(void)
static int64_t copy_ts_first_pts
int print_filtergraphs(FilterGraph **graphs, int nb_graphs, InputFile **ifiles, int nb_ifiles, OutputFile **ofiles, int nb_ofiles)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static AVFormatContext * ctx
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going on
#define atomic_load(object)
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
void of_enc_stats_close(void)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
int av_log_get_level(void)
Get the current log level.
void init_dynload(void)
Initialize dynamic library loading.
static AVDictionary * opts
Describe the class of an AVClass context structure.
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
int main(int argc, char **argv)
atomic_uint nb_output_dumped
static int64_t getmaxrss(void)
static int check_keyboard_interaction(int64_t cur_time)
void av_log_set_flags(int arg)
static void print_stream_maps(void)
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
OutputStream * ost_iter(OutputStream *prev)
static volatile int received_nb_signals
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
char * print_graphs_format
static int decode_interrupt_cb(void *ctx)
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
AVFrameSideData ** side_data
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
OutputFile ** output_files
#define SIGNAL(sig, func)
#define i(width, name, range_min, range_max)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static volatile int received_sigterm
int filtergraph_is_simple(const FilterGraph *fg)
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
#define AV_NOPTS_VALUE
Undefined timestamp value.
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define AV_LOG_INFO
Standard information.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
void av_log_set_level(int level)
Set the log level.
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
#define AV_TIME_BASE
Internal time base represented as integer.
static void sigterm_handler(int sig)
const char * name
Name of the codec implementation.
FilterGraph ** filtergraphs
const AVIOInterruptCB int_cb
static int frame_data_ensure(AVBufferRef **dst, int writable)
int av_buffer_is_writable(const AVBufferRef *buf)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
void dec_free(Decoder **pdec)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
void hw_device_free_all(void)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
void ifile_close(InputFile **f)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int index
stream index in AVFormatContext
static atomic_int transcode_init_done
void android_binder_threadpool_init_if_required(void)
Initialize Android Binder thread pool.
const char program_name[]
program name, defined by the program for show_version().
int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
char * av_strdup(const char *s)
Duplicate a string.
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
#define us(width, name, range_min, range_max, subs,...)
A reference to a data buffer.
int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts)
Wait until transcoding terminates or the specified timeout elapses.
#define FFMPEG_ERROR_RATE_EXCEEDED
This structure stores compressed data.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
FrameData * packet_data(AVPacket *pkt)
int sch_start(Scheduler *sch)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
static void set_tty_echo(int on)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
const FrameData * frame_data_c(AVFrame *frame)
static int read_key(void)
int of_write_trailer(OutputFile *of)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
FF_VISIBILITY_POP_HIDDEN av_cold void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.