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>
120 static struct termios oldtty;
121 static int restore_tty;
128 tcsetattr (0, TCSANOW, &oldtty);
152 ret = write(2,
"Received > 3 system signals, hard exiting\n",
153 strlen(
"Received > 3 system signals, hard exiting\n"));
159 #if HAVE_SETCONSOLECTRLHANDLER
160 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
167 case CTRL_BREAK_EVENT:
171 case CTRL_CLOSE_EVENT:
172 case CTRL_LOGOFF_EVENT:
173 case CTRL_SHUTDOWN_EVENT:
192 #define SIGNAL(sig, func) \
194 action.sa_handler = func; \
195 sigaction(sig, &action, NULL); \
198 #define SIGNAL(sig, func) \
204 #if defined __linux__
205 struct sigaction action = {0};
209 sigfillset(&action.sa_mask);
212 action.sa_flags = SA_RESTART;
218 if (tcgetattr (0, &tty) == 0) {
222 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
223 |INLCR|IGNCR|ICRNL|IXON);
224 tty.c_oflag |= OPOST;
225 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
226 tty.c_cflag &= ~(CSIZE|PARENB);
231 tcsetattr (0, TCSANOW, &tty);
243 signal(SIGPIPE, SIG_IGN);
245 #if HAVE_SETCONSOLECTRLHANDLER
246 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
253 unsigned char ch = -1;
263 n = select(1, &rfds,
NULL,
NULL, &tv);
272 # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
274 static HANDLE input_handle;
277 input_handle = GetStdHandle(STD_INPUT_HANDLE);
278 is_pipe = !GetConsoleMode(input_handle, &dw);
283 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
289 if (
read(0, &ch, 1) == 1)
337 "Error closing vstats file, loss of information possible: %s\n",
369 int of_idx = prev ? prev->
file->
index : 0;
370 int ost_idx = prev ? prev->
index + 1 : 0;
385 int if_idx = prev ? prev->
file->
index : 0;
386 int ist_idx = prev ? prev->
index + 1 : 0;
391 return f->streams[ist_idx];
431 memcpy(fd, fd_src,
sizeof(*fd));
433 fd->side_data =
NULL;
434 fd->nb_side_data = 0;
462 fd->dec.frame_num = UINT64_MAX;
466 fd->wallclock[
i] = INT64_MIN;
518 p = strchr(optname,
':');
533 decode ?
"decoding" :
"encoding");
538 "for any stream. The most likely reason is either wrong type "
539 "(e.g. a video option with no video streams) or that it is a "
540 "private option of some decoder which was not actually used "
559 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
570 AVBPrint buf, buf_script;
576 static int first_report = 1;
577 uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
578 int mins, secs, ms,
us;
580 const char *hours_sign;
587 if (!is_last_report) {
588 if (last_time == -1) {
589 last_time = cur_time;
591 if (((cur_time - last_time) <
stats_period && !first_report) ||
594 last_time = cur_time;
597 t = (cur_time-timer_start) / 1000000.0;
608 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
615 fps = t > 1 ? frame_number / t : 0;
616 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
617 frame_number, fps < 9.95, fps, q);
618 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
620 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
645 hours_sign = (
pts < 0) ?
"-" :
"";
650 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
651 else av_bprintf(&buf,
"size=%8.0fKiB time=", total_size / 1024.0);
655 av_bprintf(&buf,
"%s%02"PRId64
":%02d:%02d.%02d ",
667 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
668 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
676 av_bprintf(&buf_script,
"out_time=%s%02"PRId64
":%02d:%02d.%06d\n",
677 hours_sign, hours, mins, secs,
us);
680 if (nb_frames_dup || nb_frames_drop)
681 av_bprintf(&buf,
" dup=%"PRId64
" drop=%"PRId64, nb_frames_dup, nb_frames_drop);
682 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n", nb_frames_dup);
683 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n", nb_frames_drop);
690 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
694 ms = (int)((t - secs) * 1000);
700 av_bprintf(&buf,
" elapsed=%"PRId64
":%02d:%02d.%02d", hours, mins, secs, ms / 10);
703 const char end = is_last_report ?
'\n' :
'\r';
705 fprintf(stderr,
"%s %c", buf.str, end);
715 is_last_report ?
"end" :
"continue");
717 FFMIN(buf_script.len, buf_script.size - 1));
720 if (is_last_report) {
723 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
734 for (
int j = 0; j < ist->nb_filters; j++) {
737 ist->file->index, ist->index, ist->dec ? ist->dec->name :
"?",
738 ist->filters[j]->name);
747 if (
ost->attachment_filename) {
772 const AVCodec *out_codec =
ost->enc->enc_ctx->codec;
773 const char *decoder_name =
"?";
774 const char *in_codec_name =
"?";
775 const char *encoder_name =
"?";
776 const char *out_codec_name =
"?";
780 decoder_name = in_codec->
name;
783 in_codec_name =
desc->name;
784 if (!strcmp(decoder_name, in_codec_name))
785 decoder_name =
"native";
789 encoder_name = out_codec->
name;
792 out_codec_name =
desc->name;
793 if (!strcmp(encoder_name, out_codec_name))
794 encoder_name =
"native";
798 in_codec_name, decoder_name,
799 out_codec_name, encoder_name);
810 if (tcgetattr(0, &tty) == 0) {
811 if (
on) tty.c_lflag |=
ECHO;
812 else tty.c_lflag &= ~
ECHO;
813 tcsetattr(0, TCSANOW, &tty);
823 if (cur_time - last_time >= 100000) {
825 last_time = cur_time;
834 if (
key ==
'c' ||
key ==
'C'){
835 char buf[4096], target[64],
command[256],
arg[256] = {0};
838 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
841 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
846 fprintf(stderr,
"\n");
848 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
861 "Parse error, at least 3 arguments were expected, "
862 "only %d given in string '%s'\n", n, buf);
866 fprintf(stderr,
"key function\n"
868 "+ increase verbosity\n"
869 "- decrease verbosity\n"
870 "c Send command to first matching filter supporting it\n"
871 "C Send/Queue command to all matching filters\n"
872 "h dump packets/hex press to cycle through the 3 states\n"
874 "s Show QP histogram\n"
886 int64_t timer_start, transcode_ts = 0;
937 struct rusage rusage;
939 getrusage(RUSAGE_SELF, &rusage);
941 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
943 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
944 #elif HAVE_GETPROCESSTIMES
947 proc = GetCurrentProcess();
948 GetProcessTimes(proc, &
c, &e, &k, &
u);
950 ((
int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
952 ((
int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
961 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
962 struct rusage rusage;
963 getrusage(RUSAGE_SELF, &rusage);
964 return (
int64_t)rusage.ru_maxrss * 1024;
965 #elif HAVE_GETPROCESSMEMORYINFO
967 PROCESS_MEMORY_COUNTERS memcounters;
968 proc = GetCurrentProcess();
969 memcounters.cb =
sizeof(memcounters);
970 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
971 return memcounters.PeakPagefileUsage;
977 int main(
int argc,
char **argv)
986 setvbuf(stderr,
NULL,_IONBF,0);
1031 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
1032 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.
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.
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 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)
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)
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)
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.