55 #if HAVE_SYS_RESOURCE_H
57 #include <sys/types.h>
58 #include <sys/resource.h>
59 #elif HAVE_GETPROCESSTIMES
62 #if HAVE_GETPROCESSMEMORYINFO
68 #include <sys/select.h>
93 static int transcoding_finished;
96 #define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
247 const char *codec_string = encoder ?
"encoder" :
"decoder";
250 "results.\nAdd '-strict experimental' if you want to use it.\n",
251 codec_string, c->
name);
255 codec_string, codec->
name);
280 int min_dec = INT_MAX, min_inc = INT_MAX;
292 int fmt_diff = 32 * abs(dfmt - efmt);
299 }
else if (dfmt > efmt) {
300 if (fmt_diff < min_inc) {
305 if (fmt_diff < min_dec) {
368 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
375 "in incorrect timestamps in the output file.\n",
443 int subtitle_out_max_size = 1024 * 1024;
444 int subtitle_out_size, nb, i;
458 subtitle_out =
av_malloc(subtitle_out_max_size);
469 for (i = 0; i < nb; i++) {
483 subtitle_out_max_size, sub);
484 if (subtitle_out_size < 0) {
490 pkt.
data = subtitle_out;
491 pkt.
size = subtitle_out_size;
510 int ret, format_video_sync;
526 "*** dropping frame %d from stream %d at ts %"PRId64
"\n",
586 *frame_size = pkt.
size;
605 return -10.0 * log(d) / log(10.0);
612 double ti1, bitrate, avg_bitrate;
637 avg_bitrate = (double)(ost->
data_size * 8) / ti1 / 1000.0;
638 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
639 (
double)ost->
data_size / 1024, ti1, bitrate, avg_bitrate);
727 int64_t min_pts = INT64_MAX;
731 int64_t pts = output_streams[i]->
sync_opts;
733 if (!output_streams[i]->
filter || output_streams[i]->finished)
736 pts =
av_rescale_q(pts, output_streams[i]->enc_ctx->time_base,
740 ost = output_streams[i];
752 }
else if (ret ==
AVERROR(EAGAIN))
761 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
762 uint64_t data_size = 0;
763 float percent = -1.0;
771 default: other_size += ost->
data_size;
break;
777 if (data_size && total_size >= data_size)
778 percent = 100.0 * (total_size - data_size) / data_size;
781 av_log(
NULL,
AV_LOG_INFO,
"video:%1.0fkB audio:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
785 extra_size / 1024.0);
795 uint64_t total_packets = 0, total_size = 0;
824 total_packets, total_size);
829 uint64_t total_packets = 0, total_size = 0;
858 total_packets, total_size);
869 int frame_number, vid, i;
870 double bitrate, ti1, pts;
871 static int64_t last_time = -1;
872 static int qp_histogram[52];
877 if (!is_last_report) {
881 if (last_time == -1) {
882 last_time = cur_time;
885 if ((cur_time - last_time) < 500000)
887 last_time = cur_time;
891 oc = output_files[0]->
ctx;
896 if (total_size < 0) {
900 "avio_tell() failed: %s\n", errbuf);
909 ost = output_streams[i];
914 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
917 float t = (
av_gettime() - timer_start) / 1000000.0;
920 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3d q=%3.1f ",
921 frame_number, (t > 1) ? (
int)(frame_number / t + 0.5) : 0, q);
923 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
929 for (j = 0; j < 32; j++)
930 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(
log2(qp_histogram[j] + 1)));
934 double error, error_sum = 0;
935 double scale, scale_sum = 0;
936 char type[3] = {
'Y',
'U',
'V' };
937 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
938 for (j = 0; j < 3; j++) {
939 if (is_last_report) {
940 error = enc->
error[j];
941 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
950 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j],
psnr(error / scale));
952 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
958 if ((pts < ti1) && (pts > 0))
964 bitrate = (double)(total_size * 8) / ti1 / 1000.0;
966 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
967 "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
968 (
double)total_size / 1024, ti1, bitrate);
971 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" drop=%d",
991 int stop_encoding = 0;
1025 ret = encode(enc, &pkt,
NULL, &got_packet);
1107 opkt.
dts -= ost_tb_start_time;
1139 char layout_name[256];
1156 int i, ret, err = 0, resample_changed;
1165 if (!*got_output || ret < 0) {
1181 decoded_frame->
pts = pkt->
pts;
1188 if (resample_changed) {
1189 char layout1[64], layout2[64];
1193 "layout for Input Stream #%d.%d\n", ist->
file_index,
1205 "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d chl:%s to rate:%d fmt:%s ch:%d chl:%s\n",
1230 if (i < ist->nb_filters - 1) {
1245 return err < 0 ? err : ret;
1251 int i, ret = 0, err = 0, resample_changed;
1260 decoded_frame, got_output, pkt);
1261 if (!*got_output || ret < 0) {
1288 if (resample_changed) {
1290 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1312 if (i < ist->nb_filters - 1) {
1328 return err < 0 ? err : ret;
1335 &subtitle, got_output, pkt);
1389 "Multiple frames in a packet from stream %d\n", pkt->
stream_index);
1468 avc[i] = output_files[i]->ctx;
1471 printf(
"SDP:\n%s\n", sdp);
1480 if (
hwaccels[i].pix_fmt == pix_fmt)
1491 for (p = pix_fmts; *p != -1; p++) {
1504 ret = hwaccel->
init(s);
1508 "%s hwaccel requested for input stream #%d:%d, "
1509 "but cannot be initialized.\n", hwaccel->
name,
1540 snprintf(error, error_len,
"Decoder (codec id %d) not found for input stream #%d:%d",
1571 snprintf(error, error_len,
1572 "Error while opening decoder for input stream "
1611 for (p = kf; *p; p++)
1622 for (i = 0; i < n; i++) {
1623 char *next = strchr(p,
',');
1640 int encoder_string_len;
1641 int format_flags = 0;
1652 encoder_string =
av_mallocz(encoder_string_len);
1653 if (!encoder_string)
1665 int ret = 0, i, j, k;
1682 oc = output_files[i]->
ctx;
1699 ost = output_streams[i];
1718 uint64_t extra_size;
1724 if (extra_size > INT_MAX) {
1798 snprintf(error,
sizeof(error),
"Automatic encoder selection "
1799 "failed for output stream #%d:%d. Default encoder for "
1800 "format %s is probably disabled. Please choose an "
1833 "for the output stream #%d:%d, but no information "
1834 "about the input framerate is available. Falling "
1835 "back to a default value of 25fps. Use the -r option "
1836 "if you want a different framerate.\n",
1899 char logfilename[1024];
1902 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
1906 if (!strcmp(ost->
enc->
name,
"libx264")) {
1910 f = fopen(logfilename,
"wb");
1913 logfilename, strerror(errno));
1919 size_t logbuffer_size;
1934 ost = output_streams[i];
1957 snprintf(error,
sizeof(error),
"Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height",
1964 "It takes bits/s as argument, not kbits/s\n");
1969 "Error initializing the output stream codec context.\n");
2003 oc = output_files[i]->
ctx;
2008 snprintf(error,
sizeof(error),
2009 "Could not write header for output file #%d "
2010 "(incorrect codec parameters ?): %s",
2025 av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);
2031 ist = input_streams[i];
2038 if (nb_filtergraphs > 1)
2046 ost = output_streams[i];
2058 if (nb_filtergraphs > 1)
2080 const char *decoder_name =
"?";
2081 const char *in_codec_name =
"?";
2082 const char *encoder_name =
"?";
2083 const char *out_codec_name =
"?";
2086 decoder_name = in_codec->
name;
2088 if (!strcmp(decoder_name, in_codec_name))
2089 decoder_name =
"native";
2093 encoder_name = out_codec->
name;
2095 if (!strcmp(encoder_name, out_codec_name))
2096 encoder_name =
"native";
2100 in_codec_name, decoder_name,
2101 out_codec_name, encoder_name);
2147 int64_t ipts_min = INT64_MAX;
2157 if (ipts < ipts_min) {
2168 static void *input_thread(
void *arg)
2173 while (!transcoding_finished && ret >= 0) {
2198 static void free_input_threads(
void)
2205 transcoding_finished = 1;
2211 if (!f->fifo || f->joined)
2233 static int init_input_threads(
void)
2237 if (nb_input_files == 1)
2291 if (nb_input_files > 1)
2292 return get_input_packet_mt(f, pkt);
2301 if (input_files[i]->eagain)
2310 input_files[i]->eagain = 0;
2362 ist = input_streams[ifile->
ist_index + i];
2388 goto discard_packet;
2396 goto discard_packet;
2411 memcpy(dst_data, src_sd->
data, src_sd->
size);
2432 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
2459 int ret, i, need_input = 1;
2463 int64_t timer_start;
2475 if ((ret = init_input_threads()) < 0)
2506 free_input_threads();
2511 ist = input_streams[i];
2523 os = output_files[i]->
ctx;
2532 ost = output_streams[i];
2540 ist = input_streams[i];
2553 free_input_threads();
2556 if (output_streams) {
2558 ost = output_streams[i];
2576 struct rusage rusage;
2578 getrusage(RUSAGE_SELF, &rusage);
2579 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
2580 #elif HAVE_GETPROCESSTIMES
2582 FILETIME c, e, k, u;
2583 proc = GetCurrentProcess();
2584 GetProcessTimes(proc, &c, &e, &k, &u);
2585 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
2593 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
2594 struct rusage rusage;
2595 getrusage(RUSAGE_SELF, &rusage);
2596 return (int64_t)rusage.ru_maxrss * 1024;
2597 #elif HAVE_GETPROCESSMEMORYINFO
2599 PROCESS_MEMORY_COUNTERS memcounters;
2600 proc = GetCurrentProcess();
2601 memcounters.cb =
sizeof(memcounters);
2602 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
2603 return memcounters.PeakPagefileUsage;
2642 fprintf(stderr,
"At least one output file must be specified\n");
2652 printf(
"bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
static av_unused void pthread_cond_signal(pthread_cond_t *cond)
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static int need_output(void)
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int transcode_init(void)
static int check_output_constraints(InputStream *ist, OutputStream *ost)
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_free_packet(AVPacket *pkt)
Free a packet.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static int got_eagain(void)
This structure describes decoded (raw) audio or video data.
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
uint64_t error[AV_NUM_DATA_POINTERS]
error
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
Main libavfilter public API header.
static void flush_encoders(void)
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Memory buffer source API.
AVFrame * coded_frame
the picture in the bitstream
void show_banner(void)
Print the program banner to stderr.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
static void term_exit(void)
int h
agreed upon image height
static int nb_frames_drop
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
AVCodecParserContext * parser
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static void set_encoder_id(OutputFile *of, OutputStream *ost)
int index
stream index in AVFormatContext
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
AVBitStreamFilterContext * bitstream_filters
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
FilterGraph ** filtergraphs
#define FF_ARRAY_ELEMS(a)
int av_usleep(unsigned usec)
Sleep for a period of time.
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
int av_dup_packet(AVPacket *pkt)
four components are given, that's all.
static volatile int received_sigterm
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
static void finish_output_stream(OutputStream *ost)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void init_pts_correction(PtsCorrectionContext *ctx)
Reset the state of the PtsCorrectionContext.
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
float dts_delta_threshold
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
unsigned int nb_stream_indexes
#define AV_LOG_QUIET
Print no output.
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int copy_initial_nonkeyframes
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Opaque data information usually continuous.
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
miscellaneous OS support macros and functions.
#define VSYNC_PASSTHROUGH
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int nb_side_data
The number of elements in the AVStream.side_data array.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream ** streams
A list of all streams in the file.
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
void avfilter_register_all(void)
Initialize the filter system.
static av_unused int pthread_create(pthread_t *thread, const void *unused_attr, void *(*start_routine)(void *), void *arg)
static double av_q2d(AVRational a)
Convert rational to double.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static void term_init(void)
AVDictionary * resample_opts
int avformat_network_init(void)
Do global initialization of network components.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
int interlaced_frame
The content of the picture is interlaced.
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
external api for the swscale stuff
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
enum AVDiscard discard
selects which program to discard and which to feed to the caller
char * stats_out
pass1 encoding statistics output buffer
static FILE * vstats_file
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
struct AVBitStreamFilterContext * next
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
unsigned int * stream_index
static int decode_interrupt_cb(void *ctx)
struct AVOutputFormat * oformat
The output container format.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int configure_filtergraph(FilterGraph *fg)
const OptionDef options[]
void av_buffer_default_free(void *opaque, uint8_t *data)
Default free callback, which calls av_free() on the buffer data.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void abort_codec_experimental(AVCodec *c, int encoder)
static const uint8_t frame_size[4]
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
Main libavdevice API header.
Callback for checking whether to abort blocking functions.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
static int64_t start_time
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...
int sample_rate
samples per second
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
enum AVSampleFormat request_sample_fmt
Used to request a sample format from the decoder.
static int pthread_mutex_init(pthread_mutex_t *m, void *attr)
static int pthread_mutex_unlock(pthread_mutex_t *m)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec, AVCodecContext *enc)
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
#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...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int rc_max_rate
maximum bitrate
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
simple assert() macros that are a bit more flexible than ISO C assert().
enum AVPacketSideDataType type
void av_log(void *avcl, int level, const char *fmt,...)
int main(int argc, char **argv)
const char * name
Name of the codec implementation.
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int flags
A combination of AV_PKT_FLAG values.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
uint64_t channel_layout
Audio channel layout.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
uint32_t end_display_time
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
int64_t pts
Same as packet pts, in AV_TIME_BASE.
AVCodecContext * codec
Codec context associated with this stream.
int rc_buffer_size
decoder bitstream buffer size
static av_unused void pthread_join(pthread_t thread, void **value_ptr)
uint64_t channel_layout
Channel layout of the audio data.
int w
agreed upon image width
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
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 FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int bit_rate
the average bitrate
audio channel layout utility functions
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
static void do_audio_out(AVFormatContext *s, OutputStream *ost, AVFrame *frame)
enum AVPictureType pict_type
Picture type of the frame.
const AVIOInterruptCB int_cb
char filename[1024]
input or output filename
const char * media_type_string(enum AVMediaType media_type)
Get a string describing a media type.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static InputStream * get_input_stream(OutputStream *ost)
#define AV_TIME_BASE
Internal time base represented as integer.
static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
int width
picture width / height.
static int process_input_packet(InputStream *ist, const AVPacket *pkt)
static void do_video_stats(OutputStream *ost, int frame_size)
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples)
Same as av_buffersink_get_frame(), but with the ability to specify the number of samples read...
static void do_video_out(AVFormatContext *s, OutputStream *ost, AVFrame *in_picture, int *frame_size)
void av_parser_close(AVCodecParserContext *s)
static av_always_inline av_const long int lrintf(float x)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub, int64_t pts)
static volatile int received_nb_signals
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Opaque data information usually sparse.
enum AVPixelFormat pix_fmt
preferred ID for MPEG-1/2 video decoding
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the nearest value in q_list to q.
int format
agreed upon media format
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
if(ac->has_optimized_func)
static void print_sdp(void)
int64_t av_gettime(void)
Get the current time in microseconds.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int frame_size
Number of samples per channel in an audio frame.
int(* init)(AVCodecContext *s)
static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx)
static int pthread_mutex_lock(pthread_mutex_t *m)
int av_fifo_space(AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
static int64_t getmaxrss(void)
#define AV_LOG_INFO
Standard information.
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
uint64_t error[AV_NUM_DATA_POINTERS]
error
AVCodecParserContext * av_parser_init(int codec_id)
struct InputStream * sync_ist
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
OutputFile ** output_files
enum AVMediaType codec_type
int me_threshold
Motion estimation threshold below which no motion estimation is performed, but instead the user speci...
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
AVSampleFormat
Audio Sample Formats.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
#define DEFAULT_PASS_LOGFILENAME_PREFIX
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_opt_set_dict(void *obj, AVDictionary **options)
int sample_rate
samples per second
static void avconv_cleanup(int ret)
AVIOContext * pb
I/O context.
OutputStream ** output_streams
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
static int check_recording_time(OutputStream *ost)
static double psnr(double d)
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
const int program_birth_year
program birth year, defined by the program for show_banner()
const char * attachment_filename
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
a very simple circular buffer FIFO implementation
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Replacements for frequently missing libm functions.
int avconv_parse_options(int argc, char **argv)
struct AVBitStreamFilter * filter
int sample_rate
Sample rate of the audio data.
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
rational number numerator/denominator
const char program_name[]
program name, defined by the program for show_version().
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
static int64_t getutime(void)
discard useless packets like 0 size packets in avi
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int poll_filter(OutputStream *ost)
const char * name
Name of the codec described by this descriptor.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
Read the file with name filename, and put its content in a newly allocated 0-terminated buffer...
int global_quality
Global quality for codecs which cannot change it per frame.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
enum AVMediaType type
filter media type
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
static int process_input(void)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static int poll_filters(void)
#define CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
static const HWAccel * get_hwaccel(enum AVPixelFormat pix_fmt)
static int get_input_packet(InputFile *f, AVPacket *pkt)
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
int guess_input_channel_layout(InputStream *ist)
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
int av_fifo_size(AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
struct FilterGraph * graph
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
static void reset_eagain(void)
InputStream ** input_streams
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static InputFile * select_input_file(void)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
struct AVInputFormat * iformat
The input container format.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
int channels
number of audio channels
struct AVCodecParserContext * parser
void av_log_set_flags(int arg)
static int transcode(void)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVDictionary * encoder_opts
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
int repeat_pict
This field is used for proper frame duration computation in lavf.
static void print_final_stats(int64_t total_size)
enum AVFieldOrder field_order
Field order.
#define AV_DICT_IGNORE_SUFFIX
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
static void sigterm_handler(int sig)
static int init_input_stream(int ist_index, char *error, int error_len)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, AVStream *st)
Send a nice dump of a packet to the log.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
void assert_avoptions(AVDictionary *m)
int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
Get a frame with filtered data from sink and put it in frame.
AVPixelFormat
Pixel format.
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
static void print_report(int is_last_report, int64_t timer_start)
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * opaque
Private data of the user, can be used to carry app specific stuff.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
uint8_t * subtitle_header
Header containing style information for text subtitles.
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.