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>
119 static struct termios oldtty;
120 static int restore_tty;
127 tcsetattr (0, TCSANOW, &oldtty);
151 ret = write(2,
"Received > 3 system signals, hard exiting\n",
152 strlen(
"Received > 3 system signals, hard exiting\n"));
158 #if HAVE_SETCONSOLECTRLHANDLER
159 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
166 case CTRL_BREAK_EVENT:
170 case CTRL_CLOSE_EVENT:
171 case CTRL_LOGOFF_EVENT:
172 case CTRL_SHUTDOWN_EVENT:
191 #define SIGNAL(sig, func) \
193 action.sa_handler = func; \
194 sigaction(sig, &action, NULL); \
197 #define SIGNAL(sig, func) \
203 #if defined __linux__
204 struct sigaction action = {0};
208 sigfillset(&action.sa_mask);
211 action.sa_flags = SA_RESTART;
217 if (tcgetattr (0, &tty) == 0) {
221 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
222 |INLCR|IGNCR|ICRNL|IXON);
223 tty.c_oflag |= OPOST;
224 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
225 tty.c_cflag &= ~(CSIZE|PARENB);
230 tcsetattr (0, TCSANOW, &tty);
242 signal(SIGPIPE, SIG_IGN);
244 #if HAVE_SETCONSOLECTRLHANDLER
245 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
262 n = select(1, &rfds,
NULL,
NULL, &tv);
271 # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
273 static HANDLE input_handle;
276 input_handle = GetStdHandle(STD_INPUT_HANDLE);
277 is_pipe = !GetConsoleMode(input_handle, &dw);
282 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
288 if (
read(0, &ch, 1) == 1)
333 "Error closing vstats file, loss of information possible: %s\n",
362 int of_idx = prev ? prev->
file->
index : 0;
363 int ost_idx = prev ? prev->
index + 1 : 0;
378 int if_idx = prev ? prev->
file->
index : 0;
379 int ist_idx = prev ? prev->
index + 1 : 0;
384 return f->streams[ist_idx];
423 memcpy(fd, fd_src,
sizeof(*fd));
442 fd->dec.frame_num = UINT64_MAX;
446 fd->wallclock[
i] = INT64_MIN;
498 p = strchr(optname,
':');
513 decode ?
"decoding" :
"encoding");
518 "for any stream. The most likely reason is either wrong type "
519 "(e.g. a video option with no video streams) or that it is a "
520 "private option of some decoder which was not actually used "
539 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
550 AVBPrint buf, buf_script;
556 static int first_report = 1;
557 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
560 const char *hours_sign;
567 if (!is_last_report) {
568 if (last_time == -1) {
569 last_time = cur_time;
571 if (((cur_time - last_time) <
stats_period && !first_report) ||
574 last_time = cur_time;
577 t = (cur_time-timer_start) / 1000000.0;
587 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
594 fps = t > 1 ? frame_number / t : 0;
595 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
596 frame_number, fps < 9.95, fps, q);
597 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
599 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
624 hours_sign = (
pts < 0) ?
"-" :
"";
629 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
630 else av_bprintf(&buf,
"size=%8.0fKiB time=", total_size / 1024.0);
634 av_bprintf(&buf,
"%s%02"PRId64
":%02d:%02d.%02d ",
646 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
647 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
655 av_bprintf(&buf_script,
"out_time=%s%02"PRId64
":%02d:%02d.%06d\n",
656 hours_sign, hours, mins, secs,
us);
659 if (nb_frames_dup || nb_frames_drop)
660 av_bprintf(&buf,
" dup=%"PRId64
" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
661 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n", nb_frames_dup);
662 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n", nb_frames_drop);
669 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
673 const char end = is_last_report ?
'\n' :
'\r';
675 fprintf(stderr,
"%s %c", buf.str, end);
685 is_last_report ?
"end" :
"continue");
687 FFMIN(buf_script.len, buf_script.size - 1));
690 if (is_last_report) {
693 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
704 for (
int j = 0; j < ist->nb_filters; j++) {
707 ist->file->index, ist->index, ist->dec ? ist->dec->name :
"?",
708 ist->filters[j]->name);
717 if (
ost->attachment_filename) {
742 const AVCodec *out_codec =
ost->enc->enc_ctx->codec;
743 const char *decoder_name =
"?";
744 const char *in_codec_name =
"?";
745 const char *encoder_name =
"?";
746 const char *out_codec_name =
"?";
750 decoder_name = in_codec->
name;
753 in_codec_name =
desc->name;
754 if (!strcmp(decoder_name, in_codec_name))
755 decoder_name =
"native";
759 encoder_name = out_codec->
name;
762 out_codec_name =
desc->name;
763 if (!strcmp(encoder_name, out_codec_name))
764 encoder_name =
"native";
768 in_codec_name, decoder_name,
769 out_codec_name, encoder_name);
780 if (tcgetattr(0, &tty) == 0) {
781 if (
on) tty.c_lflag |=
ECHO;
782 else tty.c_lflag &= ~
ECHO;
783 tcsetattr(0, TCSANOW, &tty);
795 if (cur_time - last_time >= 100000) {
797 last_time = cur_time;
806 if (
key ==
'c' ||
key ==
'C'){
807 char buf[4096], target[64],
command[256],
arg[256] = {0};
810 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
813 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
818 fprintf(stderr,
"\n");
820 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
833 "Parse error, at least 3 arguments were expected, "
834 "only %d given in string '%s'\n", n, buf);
838 fprintf(stderr,
"key function\n"
840 "+ increase verbosity\n"
841 "- decrease verbosity\n"
842 "c Send command to first matching filter supporting it\n"
843 "C Send/Queue command to all matching filters\n"
844 "h dump packets/hex press to cycle through the 3 states\n"
846 "s Show QP histogram\n"
858 int64_t timer_start, transcode_ts = 0;
906 struct rusage rusage;
908 getrusage(RUSAGE_SELF, &rusage);
910 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
912 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
913 #elif HAVE_GETPROCESSTIMES
916 proc = GetCurrentProcess();
917 GetProcessTimes(proc, &
c, &e, &k, &
u);
919 ((
int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
921 ((
int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
930 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
931 struct rusage rusage;
932 getrusage(RUSAGE_SELF, &rusage);
933 return (
int64_t)rusage.ru_maxrss * 1024;
934 #elif HAVE_GETPROCESSMEMORYINFO
936 PROCESS_MEMORY_COUNTERS memcounters;
937 proc = GetCurrentProcess();
938 memcounters.cb =
sizeof(memcounters);
939 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
940 return memcounters.PeakPagefileUsage;
946 int main(
int argc,
char **argv)
955 setvbuf(stderr,
NULL,_IONBF,0);
1000 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1001 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)
#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)
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)
static BenchmarkTimeStamps current_time
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,...)
#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.
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
#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.
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.
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)
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.
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 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.
#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)
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
const char program_name[]
program name, defined by the program for show_version().
int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
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.
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.