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>
97 static int transcoding_finished;
100 #define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
153 for (j = 0; j < filtergraphs[i]->
nb_inputs; j++) {
158 for (j = 0; j < filtergraphs[i]->
nb_outputs; j++) {
186 av_freep(&output_streams[i]->forced_keyframes);
187 av_freep(&output_streams[i]->avfilter);
188 av_freep(&output_streams[i]->logfile_prefix);
199 av_freep(&input_streams[i]->filters);
235 const char *codec_string = encoder ?
"encoder" :
"decoder";
238 "results.\nAdd '-strict experimental' if you want to use it.\n",
239 codec_string, c->
name);
243 codec_string, codec->
name);
268 int min_dec = INT_MAX, min_inc = INT_MAX;
280 int fmt_diff = 32 * abs(dfmt - efmt);
287 }
else if (dfmt > efmt) {
288 if (fmt_diff < min_inc) {
293 if (fmt_diff < min_dec) {
353 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
360 "in incorrect timestamps in the output file.\n",
445 picture2 = &picture_tmp;
460 if (picture != picture2)
461 *picture = *picture2;
472 int subtitle_out_max_size = 1024 * 1024;
473 int subtitle_out_size, nb, i;
487 subtitle_out =
av_malloc(subtitle_out_max_size);
498 for (i = 0; i < nb; i++) {
509 subtitle_out_max_size, sub);
510 if (subtitle_out_size < 0) {
516 pkt.
data = subtitle_out;
517 pkt.
size = subtitle_out_size;
536 int ret, format_video_sync;
588 big_picture = *in_picture;
620 *frame_size = pkt.
size;
640 return -10.0 * log(d) / log(10.0);
647 double ti1, bitrate, avg_bitrate;
672 avg_bitrate = (double)(
video_size * 8) / ti1 / 1000.0;
673 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
674 (
double)
video_size / 1024, ti1, bitrate, avg_bitrate);
769 int64_t min_pts = INT64_MAX;
773 int64_t pts = output_streams[i]->
sync_opts;
775 if (!output_streams[i]->
filter || output_streams[i]->finished)
778 pts =
av_rescale_q(pts, output_streams[i]->st->codec->time_base,
782 ost = output_streams[i];
794 }
else if (ret ==
AVERROR(EAGAIN))
808 int frame_number, vid, i;
809 double bitrate, ti1, pts;
810 static int64_t last_time = -1;
811 static int qp_histogram[52];
816 if (!is_last_report) {
820 if (last_time == -1) {
824 if ((cur_time - last_time) < 500000)
830 oc = output_files[0]->
ctx;
835 if (total_size < 0) {
839 "avio_tell() failed: %s\n", errbuf);
848 ost = output_streams[i];
853 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
856 float t = (
av_gettime() - timer_start) / 1000000.0;
859 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3d q=%3.1f ",
860 frame_number, (t > 1) ? (
int)(frame_number / t + 0.5) : 0, q);
862 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
868 for (j = 0; j < 32; j++)
869 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(
log2(qp_histogram[j] + 1)));
873 double error, error_sum = 0;
874 double scale, scale_sum = 0;
875 char type[3] = {
'Y',
'U',
'V' };
876 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
877 for (j = 0; j < 3; j++) {
878 if (is_last_report) {
879 error = enc->
error[j];
880 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
889 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j],
psnr(error / scale));
891 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
897 if ((pts < ti1) && (pts > 0))
903 bitrate = (double)(total_size * 8) / ti1 / 1000.0;
905 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
906 "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
907 (
double)total_size / 1024, ti1, bitrate);
910 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" dup=%d drop=%d",
917 if (is_last_report) {
920 av_log(
NULL,
AV_LOG_INFO,
"video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
924 100.0 * (total_size - raw) / raw
937 int stop_encoding = 0;
974 ret = encode(enc, &pkt,
NULL, &got_packet);
1054 opkt.
dts -= ost_tb_start_time;
1091 char layout_name[256];
1108 int i, ret, resample_changed;
1115 if (!*got_output || ret < 0) {
1128 decoded_frame->
pts = pkt->
pts;
1138 if (resample_changed) {
1139 char layout1[64], layout2[64];
1143 "layout for Input Stream #%d.%d\n", ist->
file_index,
1155 "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",
1179 for (i = 0; i < ist->nb_filters; i++)
1188 void *buffer_to_free =
NULL;
1189 int i, ret = 0, resample_changed;
1196 decoded_frame, got_output, pkt);
1197 if (!*got_output || ret < 0) {
1218 if (resample_changed) {
1220 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1268 &subtitle, got_output, pkt);
1321 "Multiple frames in a packet from stream %d\n", pkt->
stream_index);
1401 avc[i] = output_files[i]->ctx;
1404 printf(
"SDP:\n%s\n", sdp);
1416 snprintf(error, error_len,
"Decoder (codec id %d) not found for input stream #%d:%d",
1442 snprintf(error, error_len,
"Error while opening decoder for input stream #%d:%d",
1481 for (p = kf; *p; p++)
1492 for (i = 0; i < n; i++) {
1493 char *next = strchr(p,
',');
1507 int ret = 0, i, j, k;
1525 oc = output_files[i]->
ctx;
1541 ost = output_streams[i];
1565 if (extra_size > INT_MAX) {
1637 snprintf(error,
sizeof(error),
"Automatic encoder selection "
1638 "failed for output stream #%d:%d. Default encoder for "
1639 "format %s is probably disabled. Please choose an "
1728 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
1732 if (!strcmp(ost->
enc->
name,
"libx264")) {
1736 f = fopen(logfilename,
"wb");
1739 logfilename, strerror(errno));
1745 size_t logbuffer_size;
1760 ost = output_streams[i];
1781 snprintf(error,
sizeof(error),
"Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height",
1788 "It takes bits/s as argument, not kbits/s\n");
1819 oc = output_files[i]->
ctx;
1823 const char *errbuf_ptr = errbuf;
1826 snprintf(error,
sizeof(error),
"Could not write header for output file #%d (incorrect codec parameters ?): %s", i, errbuf_ptr);
1840 av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);
1846 ist = input_streams[i];
1853 if (nb_filtergraphs > 1)
1861 ost = output_streams[i];
1873 if (nb_filtergraphs > 1)
1940 int64_t ipts_min = INT64_MAX;
1950 if (ipts < ipts_min) {
1961 static void *input_thread(
void *arg)
1966 while (!transcoding_finished && ret >= 0) {
1991 static void free_input_threads(
void)
1998 transcoding_finished = 1;
2004 if (!f->fifo || f->joined)
2026 static int init_input_threads(
void)
2030 if (nb_input_files == 1)
2073 if (nb_input_files > 1)
2074 return get_input_packet_mt(f, pkt);
2083 if (input_files[i]->eagain)
2092 input_files[i]->eagain = 0;
2144 ist = input_streams[ifile->
ist_index + i];
2170 goto discard_packet;
2174 goto discard_packet;
2194 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
2221 int ret, i, need_input = 1;
2225 int64_t timer_start;
2237 if ((ret = init_input_threads()) < 0)
2268 free_input_threads();
2273 ist = input_streams[i];
2285 os = output_files[i]->
ctx;
2294 ost = output_streams[i];
2303 ist = input_streams[i];
2314 free_input_threads();
2317 if (output_streams) {
2319 ost = output_streams[i];
2339 struct rusage rusage;
2341 getrusage(RUSAGE_SELF, &rusage);
2342 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
2343 #elif HAVE_GETPROCESSTIMES
2345 FILETIME c, e, k, u;
2346 proc = GetCurrentProcess();
2347 GetProcessTimes(proc, &c, &e, &k, &u);
2348 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
2356 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
2357 struct rusage rusage;
2358 getrusage(RUSAGE_SELF, &rusage);
2359 return (int64_t)rusage.ru_maxrss * 1024;
2360 #elif HAVE_GETPROCESSMEMORYINFO
2362 PROCESS_MEMORY_COUNTERS memcounters;
2363 proc = GetCurrentProcess();
2364 memcounters.cb =
sizeof(memcounters);
2365 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
2366 return memcounters.PeakPagefileUsage;
2405 fprintf(stderr,
"At least one output file must be specified\n");
2415 printf(
"bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
#define CODEC_FLAG_INTERLACED_DCT
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
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)
static int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **pbuf, int nb_samples)
Same as av_buffersink_read, but with the ability to specify the number of samples read...
int64_t avio_size(AVIOContext *s)
Get the filesize.
void avfilter_register_all(void)
Initialize the filter system.
void av_free_packet(AVPacket *pkt)
Free a packet.
static int got_eagain(void)
This structure describes decoded (raw) audio or video data.
static void pthread_join(pthread_t thread, void **value_ptr)
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
int av_buffersrc_write_frame(AVFilterContext *buffer_filter, const AVFrame *frame)
Add a frame to the buffer source.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
#define CODEC_FLAG_INTERLACED_ME
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
AVFilterBufferRefVideoProps * video
video buffer specific properties
uint64_t error[AV_NUM_DATA_POINTERS]
error
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int avpicture_fill(AVPicture *picture, uint8_t *ptr, enum AVPixelFormat pix_fmt, int width, int height)
Fill in the AVPicture fields.
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static const AVFilterPad outputs[]
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
static void flush_encoders(void)
int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
Get a buffer with filtered data from sink and put it in buf.
Memory buffer source API.
AVFrame * coded_frame
the picture in the bitstream
void show_banner(void)
Print the program banner to stderr.
static void term_exit(void)
int h
agreed upon image height
static int nb_frames_drop
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
void * opaque
for some private data of the user
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
void * priv
private data to be used by a custom free function
Various defines for YUV<->RGB conversion.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
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
int av_usleep(unsigned usec)
Sleep for a period of time.
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.
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dup_packet(AVPacket *pkt)
four components are given, that's all.
static volatile int received_sigterm
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.
void avfilter_unref_buffer(AVFilterBufferRef *ref)
Remove a reference to a buffer.
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.
#define AV_PERM_READ
can read from the buffer
unsigned int nb_stream_indexes
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)
enum AVSampleFormat sample_fmt
audio sample format
Opaque data information usually continuous.
static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
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
void filter_release_buffer(AVFilterBuffer *fb)
A callback to be used for AVFilterBuffer.free.
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
static double av_q2d(AVRational a)
Convert rational to double.
static void term_init(void)
static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
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.
static int pthread_create(pthread_t *thread, const void *unused_attr, void *(*start_routine)(void *), void *arg)
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.
#define AV_LOG_SKIP_REPEATED
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)
int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
Get a frame from the pool.
AVRational pixel_aspect
pixel aspect ratio
struct AVOutputFormat * oformat
int64_t pts
presentation timestamp.
int configure_filtergraph(FilterGraph *fg)
static void pthread_cond_signal(pthread_cond_t *cond)
void(* destruct)(struct AVPacket *)
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)
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...
int width
width and height of the video frame
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(). ...
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
static int64_t extra_size
int sample_rate
samples per second
#define AVERROR_EXPERIMENTAL
AVFilterBuffer * buf
the buffer that this is a reference to
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.
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.
static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
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
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
int main(int argc, char **argv)
const char * name
Name of the codec implementation.
static void rate_emu_sleep(InputStream *ist)
struct AVPicture AVPicture
four components are given, that's all.
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height)
deinterlace - if not supported return -1
static char logfilename[1024]
void avfilter_uninit(void)
Uninitialize the filter system.
int flags
A combination of AV_PKT_FLAG values.
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
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.
void free_buffer_pool(FrameBuffer **pool)
Free all the buffers in the pool.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
unsigned int nb_streams
A list of all streams in the file.
struct AVRational AVRational
rational number numerator/denominator
int bit_rate
the average bitrate
static int64_t audio_size
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, see ?_TYPE below.
const AVIOInterruptCB int_cb
char filename[1024]
input or output filename
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)
int width
picture width / height.
static void do_video_stats(OutputStream *ost, int frame_size)
static void do_video_out(AVFormatContext *s, OutputStream *ost, AVFrame *in_picture, int *frame_size)
#define CODEC_CAP_EXPERIMENTAL
static av_always_inline av_const long int lrintf(float x)
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
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.
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.
int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
Copy the frame properties of src to dst, without copying the actual image data.
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 AVFMT_NOTIMESTAMPS
void(* free)(struct AVFilterBuffer *buf)
A pointer to the function to deallocate this buffer if the default function is not sufficient...
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...
A reference to an AVFilterBuffer.
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.
static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx)
static int pthread_mutex_lock(pthread_mutex_t *m)
static int output_packet(InputStream *ist, const AVPacket *pkt)
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)
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
struct InputStream * sync_ist
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}
#define DEFAULT_PASS_LOGFILENAME_PREFIX
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
AVIOContext * pb
I/O context.
OutputStream ** output_streams
void av_log_set_flags(int arg)
void av_destruct_packet(AVPacket *pkt)
Default packet destructor.
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
static void exit_program(void)
#define AV_DICT_IGNORE_SUFFIX
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
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
int sample_rate
Sample rate of the audio data.
#define FF_ARRAY_ELEMS(a)
static const AVFilterPad inputs[]
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
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)
#define FF_INPUT_BUFFER_PADDING_SIZE
discard useless packets like 0 size packets in avi
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int poll_filter(OutputStream *ost)
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 av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int64_t pkt_pts
pts copied from the AVPacket that was decoded to produce this frame
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.
#define AV_PERM_PRESERVE
nobody else can overwrite the buffer
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static const uint16_t scale[4]
enum AVMediaType type
filter media type
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
const OptionDef options[]
static int poll_filters(void)
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 ...
#define CODEC_CAP_VARIABLE_FRAME_SIZE
int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
Add a buffer to the filtergraph s.
struct FilterGraph * graph
static void reset_eagain(void)
InputStream ** input_streams
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
AVSampleFormat
Audio Sample Formats.
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.
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
AVFilterBufferRef * avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, int w, int h, enum AVPixelFormat format)
Create a buffer reference wrapped around an already allocated image buffer.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
struct AVFrac pts
encoding: pts generation when outputting stream
int channels
number of audio channels
static int64_t video_size
struct AVCodecParserContext * parser
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
#define AVFMT_VARIABLE_FPS
#define AVFMT_TS_NONSTRICT
static int transcode(void)
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.
void avcodec_free_frame(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
int frame_number
Frame counter, set by libavcodec.
int repeat_pict
This field is used for proper frame duration computation in lavf.
#define AV_DICT_DONT_OVERWRITE
enum AVFieldOrder field_order
Field order.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
void codec_release_buffer(AVCodecContext *s, AVFrame *frame)
A callback to be used for AVCodecContext.release_buffer along with codec_get_buffer().
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.
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)
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.
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.
int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src)
Copy the frame properties and data pointers of src to dst, without copying the actual data...
uint8_t * subtitle_header
Header containing style information for text subtitles.
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)
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.