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>
140 static struct termios oldtty;
141 static int restore_tty;
148 tcsetattr (0, TCSANOW, &oldtty);
172 ret = write(2,
"Received > 3 system signals, hard exiting\n",
173 strlen(
"Received > 3 system signals, hard exiting\n"));
179 #if HAVE_SETCONSOLECTRLHANDLER
180 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
187 case CTRL_BREAK_EVENT:
191 case CTRL_CLOSE_EVENT:
192 case CTRL_LOGOFF_EVENT:
193 case CTRL_SHUTDOWN_EVENT:
212 #define SIGNAL(sig, func) \
214 action.sa_handler = func; \
215 sigaction(sig, &action, NULL); \
218 #define SIGNAL(sig, func) \
224 #if defined __linux__
225 struct sigaction action = {0};
229 sigfillset(&action.sa_mask);
232 action.sa_flags = SA_RESTART;
238 if (tcgetattr (0, &tty) == 0) {
242 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
243 |INLCR|IGNCR|ICRNL|IXON);
244 tty.c_oflag |= OPOST;
245 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
246 tty.c_cflag &= ~(CSIZE|PARENB);
251 tcsetattr (0, TCSANOW, &tty);
263 signal(SIGPIPE, SIG_IGN);
265 #if HAVE_SETCONSOLECTRLHANDLER
266 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
283 n = select(1, &rfds,
NULL,
NULL, &tv);
292 # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
294 static HANDLE input_handle;
297 input_handle = GetStdHandle(STD_INPUT_HANDLE);
298 is_pipe = !GetConsoleMode(input_handle, &dw);
303 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
309 if (
read(0, &ch, 1) == 1)
354 "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];
444 memcpy(fd, fd_src,
sizeof(*fd));
463 fd->dec.frame_num = UINT64_MAX;
467 fd->wallclock[
i] = INT64_MIN;
530 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
541 AVBPrint buf, buf_script;
547 static int first_report = 1;
548 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
551 const char *hours_sign;
558 if (!is_last_report) {
559 if (last_time == -1) {
560 last_time = cur_time;
562 if (((cur_time - last_time) <
stats_period && !first_report) ||
565 last_time = cur_time;
568 t = (cur_time-timer_start) / 1000000.0;
578 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
585 fps = t > 1 ? frame_number / t : 0;
586 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
587 frame_number, fps < 9.95, fps, q);
588 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
590 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
613 hours_sign = (
pts < 0) ?
"-" :
"";
618 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
619 else av_bprintf(&buf,
"size=%8.0fKiB time=", total_size / 1024.0);
623 av_bprintf(&buf,
"%s%02"PRId64
":%02d:%02d.%02d ",
635 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
636 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
644 av_bprintf(&buf_script,
"out_time=%s%02"PRId64
":%02d:%02d.%06d\n",
645 hours_sign, hours, mins, secs,
us);
648 if (nb_frames_dup || nb_frames_drop)
649 av_bprintf(&buf,
" dup=%"PRId64
" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
650 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n", nb_frames_dup);
651 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n", nb_frames_drop);
658 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
662 const char end = is_last_report ?
'\n' :
'\r';
664 fprintf(stderr,
"%s %c", buf.str, end);
674 is_last_report ?
"end" :
"continue");
676 FFMIN(buf_script.len, buf_script.size - 1));
679 if (is_last_report) {
682 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
693 for (
int j = 0; j < ist->nb_filters; j++) {
696 ist->file->index, ist->index, ist->dec ? ist->dec->name :
"?",
697 ist->filters[j]->name);
706 if (
ost->attachment_filename) {
731 const AVCodec *out_codec =
ost->enc_ctx->codec;
732 const char *decoder_name =
"?";
733 const char *in_codec_name =
"?";
734 const char *encoder_name =
"?";
735 const char *out_codec_name =
"?";
739 decoder_name = in_codec->
name;
742 in_codec_name =
desc->name;
743 if (!strcmp(decoder_name, in_codec_name))
744 decoder_name =
"native";
748 encoder_name = out_codec->
name;
751 out_codec_name =
desc->name;
752 if (!strcmp(encoder_name, out_codec_name))
753 encoder_name =
"native";
757 in_codec_name, decoder_name,
758 out_codec_name, encoder_name);
769 if (tcgetattr(0, &tty) == 0) {
770 if (
on) tty.c_lflag |=
ECHO;
771 else tty.c_lflag &= ~
ECHO;
772 tcsetattr(0, TCSANOW, &tty);
784 if (cur_time - last_time >= 100000) {
786 last_time = cur_time;
795 if (
key ==
'c' ||
key ==
'C'){
796 char buf[4096], target[64],
command[256],
arg[256] = {0};
799 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
802 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
807 fprintf(stderr,
"\n");
809 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
817 "Parse error, at least 3 arguments were expected, "
818 "only %d given in string '%s'\n", n, buf);
822 fprintf(stderr,
"key function\n"
824 "+ increase verbosity\n"
825 "- decrease verbosity\n"
826 "c Send command to first matching filter supporting it\n"
827 "C Send/Queue command to all matching filters\n"
828 "h dump packets/hex press to cycle through the 3 states\n"
830 "s Show QP histogram\n"
842 int64_t timer_start, transcode_ts = 0;
890 struct rusage rusage;
892 getrusage(RUSAGE_SELF, &rusage);
894 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
896 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
897 #elif HAVE_GETPROCESSTIMES
900 proc = GetCurrentProcess();
901 GetProcessTimes(proc, &
c, &e, &k, &
u);
903 ((
int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
905 ((
int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
914 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
915 struct rusage rusage;
916 getrusage(RUSAGE_SELF, &rusage);
917 return (
int64_t)rusage.ru_maxrss * 1024;
918 #elif HAVE_GETPROCESSMEMORYINFO
920 PROCESS_MEMORY_COUNTERS memcounters;
921 proc = GetCurrentProcess();
922 memcounters.cb =
sizeof(memcounters);
923 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
924 return memcounters.PeakPagefileUsage;
930 int main(
int argc,
char **argv)
939 setvbuf(stderr,
NULL,_IONBF,0);
984 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
985 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
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)
#define u(width, name, range_min, range_max)
#define AV_LOG_QUIET
Print no output.
uint8_t * data
The data buffer.
void fg_free(FilterGraph **pfg)
void remove_avoptions(AVDictionary **a, AVDictionary *b)
static void frame_data_free(void *opaque, uint8_t *data)
InputStream * ist_iter(InputStream *prev)
This structure describes decoded (raw) audio or video data.
int64_t of_filesize(OutputFile *of)
static BenchmarkTimeStamps current_time
#define ATOMIC_VAR_INIT(value)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
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.
AVBufferRef * opaque_ref
Frame owner's private data.
int sch_stop(Scheduler *sch, int64_t *finish_ts)
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
#define AV_BPRINT_SIZE_AUTOMATIC
const FrameData * packet_data_c(AVPacket *pkt)
void update_benchmark(const char *fmt,...)
#define us(width, name, range_min, range_max, subs,...)
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.
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
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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.
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)
OutputStream * ost_iter(OutputStream *prev)
static volatile int received_nb_signals
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.
static int decode_interrupt_cb(void *ctx)
const OptionDef options[]
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time, int64_t pts)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
OutputFile ** output_files
#define SIGNAL(sig, func)
#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.
int check_avoptions(AVDictionary *m)
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)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#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.
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
static void sigterm_handler(int sig)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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)
void hw_device_free_all(void)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
#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...
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
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
const char program_name[]
program name, defined by the program for show_version().
int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
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...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
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.