43#if HAVE_SYS_RESOURCE_H
46#include <sys/resource.h>
47#elif HAVE_GETPROCESSTIMES
50#if HAVE_GETPROCESSMEMORYINFO
54#if HAVE_SETCONSOLECTRLHANDLER
59#include <sys/select.h>
123static struct termios oldtty;
124static 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
163static 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) \
208 struct sigaction action = {0};
212 sigfillset(&action.sa_mask);
215 action.sa_flags = SA_RESTART;
225 "fd 0 is not an open file descriptor, stdin interaction disabled\n");
231 if (tcgetattr (0, &tty) == 0) {
235 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
236 |INLCR|IGNCR|ICRNL|IXON);
237 tty.c_oflag |= OPOST;
238 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
239 tty.c_cflag &= ~(CSIZE|PARENB);
244 tcsetattr (0, TCSANOW, &tty);
256 signal(SIGPIPE, SIG_IGN);
258#if HAVE_SETCONSOLECTRLHANDLER
259 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
275 n = select(1, &rfds,
NULL,
NULL, &tv);
285# if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
287 static HANDLE input_handle;
290 input_handle = GetStdHandle(STD_INPUT_HANDLE);
291 is_pipe = !GetConsoleMode(input_handle, &dw);
296 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
303 if (
read(0, &ch, 1) == 1)
351 "Error closing vstats file, loss of information possible: %s\n",
383 int of_idx = prev ? prev->
file->
index : 0;
384 int ost_idx = prev ? prev->
index + 1 : 0;
399 int if_idx = prev ? prev->
file->
index : 0;
400 int ist_idx = prev ? prev->
index + 1 : 0;
405 return f->streams[ist_idx];
446 memcpy(fd, fd_src,
sizeof(*fd));
536 p = strchr(optname,
':');
551 decode ?
"decoding" :
"encoding");
556 "for any stream. The most likely reason is either wrong type "
557 "(e.g. a video option with no video streams) or that it is a "
558 "private option of some decoder which was not actually used "
577 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
588 AVBPrint buf, buf_script;
594 static int first_report = 1;
595 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
596 int mins, secs, ms,
us;
598 const char *hours_sign;
605 if (!is_last_report) {
606 if (last_time == -1) {
607 last_time = cur_time;
609 if (((cur_time - last_time) <
stats_period && !first_report) ||
612 last_time = cur_time;
615 t = (cur_time-timer_start) / 1000000.0;
626 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
627 ost->file->index,
ost->index, q);
633 fps = t > 1 ? frame_number / t : 0;
634 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
635 frame_number, fps < 9.95, fps, q);
636 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
638 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
639 ost->file->index,
ost->index, q);
663 hours_sign = (
pts < 0) ?
"-" :
"";
668 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
669 else av_bprintf(&buf,
"size=%8.0fKiB time=", total_size / 1024.0);
673 av_bprintf(&buf,
"%s%02"PRId64
":%02d:%02d.%02d ",
685 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
686 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
694 av_bprintf(&buf_script,
"out_time=%s%02"PRId64
":%02d:%02d.%06d\n",
695 hours_sign, hours, mins, secs,
us);
698 if (nb_frames_dup || nb_frames_drop)
699 av_bprintf(&buf,
" dup=%"PRId64
" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
700 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n", nb_frames_dup);
701 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n", nb_frames_drop);
708 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
712 ms = (int)((t - secs) * 1000);
718 av_bprintf(&buf,
" elapsed=%"PRId64
":%02d:%02d.%02d", hours, mins, secs, ms / 10);
721 const char end = is_last_report ?
'\n' :
'\r';
723 fprintf(stderr,
"%s %c", buf.str, end);
733 is_last_report ?
"end" :
"continue");
735 FFMIN(buf_script.len, buf_script.size - 1));
738 if (is_last_report) {
741 "Error closing progress log, loss of information possible: %s\n",
av_err2str(ret));
752 for (
int j = 0; j < ist->nb_filters; j++) {
755 ist->file->index, ist->index, ist->dec ? ist->dec->name :
"?",
756 ist->filters[j]->name);
765 if (
ost->attachment_filename) {
768 ost->attachment_filename,
ost->file->index,
ost->index);
779 ost->index,
ost->enc->enc_ctx->codec->name);
784 ost->ist->file->index,
790 const AVCodec *out_codec =
ost->enc->enc_ctx->codec;
791 const char *decoder_name =
"?";
792 const char *in_codec_name =
"?";
793 const char *encoder_name =
"?";
794 const char *out_codec_name =
"?";
798 decoder_name = in_codec->
name;
801 in_codec_name =
desc->name;
802 if (!strcmp(decoder_name, in_codec_name))
803 decoder_name =
"native";
807 encoder_name = out_codec->
name;
810 out_codec_name =
desc->name;
811 if (!strcmp(encoder_name, out_codec_name))
812 encoder_name =
"native";
816 in_codec_name, decoder_name,
817 out_codec_name, encoder_name);
828 if (tcgetattr(0, &tty) == 0) {
829 if (on) tty.c_lflag |=
ECHO;
830 else tty.c_lflag &=
~ECHO;
831 tcsetattr(0, TCSANOW, &tty);
841 if (cur_time - last_time >= 100000) {
843 last_time = cur_time;
852 if (
key ==
'c' ||
key ==
'C'){
853 char buf[4096], target[64],
command[256],
arg[256] = {0};
856 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
859 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
864 fprintf(stderr,
"\n");
866 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
879 "Parse error, at least 3 arguments were expected, "
880 "only %d given in string '%s'\n", n, buf);
884 fprintf(stderr,
"key function\n"
886 "+ increase verbosity\n"
887 "- decrease verbosity\n"
888 "c Send command to first matching filter supporting it\n"
889 "C Send/Queue command to all matching filters\n"
890 "h dump packets/hex press to cycle through the 3 states\n"
892 "s Show QP histogram\n"
904 int64_t timer_start, transcode_ts = 0;
955 struct rusage rusage;
957 getrusage(RUSAGE_SELF, &rusage);
959 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
961 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
962#elif HAVE_GETPROCESSTIMES
965 proc = GetCurrentProcess();
966 GetProcessTimes(proc, &
c, &e, &k, &
u);
968 ((
int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
970 ((
int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
979#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
980 struct rusage rusage;
981 getrusage(RUSAGE_SELF, &rusage);
982 return (
int64_t)rusage.ru_maxrss * 1024;
983#elif HAVE_GETPROCESSMEMORYINFO
985 PROCESS_MEMORY_COUNTERS memcounters;
986 proc = GetCurrentProcess();
987 memcounters.cb =
sizeof(memcounters);
988 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
989 return memcounters.PeakPagefileUsage;
1004 setvbuf(stderr,
NULL,_IONBF,0);
1040#if CONFIG_MEDIACODEC
1053 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1054 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define ECHO(name, type, min, max)
Main libavdevice API header.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
void android_binder_threadpool_init_if_required(void)
Initialize Android Binder thread pool.
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.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define i(width, name, range_min, range_max)
void init_dynload(void)
Initialize dynamic library loading.
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
const char program_name[]
program name, defined by the program for show_version().
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
const int program_birth_year
program birth year, defined by the program for show_banner()
AVCodecParameters * avcodec_parameters_alloc(void)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
void avcodec_parameters_free(AVCodecParameters **ppar)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define atomic_store(object, desired)
#define atomic_load(object)
const FrameData * frame_data_c(AVFrame *frame)
AVIOContext * progress_avio
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
static void set_tty_echo(int on)
static int check_keyboard_interaction(int64_t cur_time)
static BenchmarkTimeStamps get_benchmark_time_stamps(void)
static volatile int received_sigterm
static void frame_data_free(void *opaque, uint8_t *data)
FrameData * packet_data(AVPacket *pkt)
static void print_stream_maps(void)
const FrameData * packet_data_c(AVPacket *pkt)
const AVIOInterruptCB int_cb
OutputStream * ost_iter(OutputStream *prev)
static int64_t getmaxrss(void)
FilterGraph ** filtergraphs
static int frame_data_ensure(AVBufferRef **dst, int writable)
static volatile int ffmpeg_exited
static int read_key(void)
atomic_uint nb_output_dumped
#define SIGNAL(sig, func)
static int decode_interrupt_cb(void *ctx)
static void term_exit_sigsafe(void)
static volatile int received_nb_signals
static int64_t copy_ts_first_pts
static BenchmarkTimeStamps current_time
int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used, void *logctx, int decode)
static int transcode(Scheduler *sch)
static void ffmpeg_cleanup(int ret)
void update_benchmark(const char *fmt,...)
OutputFile ** output_files
InputStream * ist_iter(InputStream *prev)
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
static void sigterm_handler(int sig)
static atomic_int transcode_init_done
void dec_free(Decoder **pdec)
int64_t of_filesize(OutputFile *of)
void ifile_close(InputFile **f)
#define FFMPEG_ERROR_RATE_EXCEEDED
void fg_send_command(FilterGraph *fg, double time, const char *target, const char *command, const char *arg, int all_filters)
char * print_graphs_format
void of_free(OutputFile **pof)
int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
void hw_device_free_all(void)
void of_enc_stats_close(void)
int of_write_trailer(OutputFile *of)
int filtergraph_is_simple(const FilterGraph *fg)
void fg_free(FilterGraph **pfg)
Scheduler * sch_alloc(void)
int sch_start(Scheduler *sch)
int sch_stop(Scheduler *sch, int64_t *finish_ts)
int sch_wait(Scheduler *sch, uint64_t timeout_us, int64_t *transcode_ts)
Wait until transcoding terminates or the specified timeout elapses.
void sch_free(Scheduler **psch)
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,...
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.
static unsigned int nb_streams
int print_filtergraphs(FilterGraph **graphs, int nb_graphs, InputFile **ifiles, int nb_ifiles, OutputFile **ofiles, int nb_ofiles)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
FF_VISIBILITY_POP_HIDDEN av_cold void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int avformat_network_init(void)
Do global initialization of network libraries.
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
int av_buffer_is_writable(const AVBufferRef *buf)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
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.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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_LOG_QUIET
Print no output.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_log_set_level(int level)
Set the log level.
#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...
int av_log_get_level(void)
Get the current log level.
void av_log_set_flags(int arg)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
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.
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() or av_opt_set() is fake – only a double pointer to AVClass instead of...
#define u(width, name, range_min, range_max)
#define us(width, name, range_min, range_max, subs,...)
Memory handling functions.
static volatile sig_atomic_t sig
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Describe the class of an AVClass context structure.
This struct describes the properties of a single codec described by an AVCodecID.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
Callback for checking whether to abort blocking functions.
This structure stores compressed data.
struct FrameData::@304126211346234154321045014345346376220164157123 dec
int64_t wallclock[LATENCY_PROBE_NB]
AVCodecParameters * par_enc
AVFrameSideData ** side_data
AVDictionary * reinit_opts
static AVFormatContext * ctx
static AVDictionary * opts
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)