56 #if HAVE_SYS_RESOURCE_H 58 #include <sys/types.h> 59 #include <sys/resource.h> 60 #elif HAVE_GETPROCESSTIMES 63 #if HAVE_GETPROCESSMEMORYINFO 69 #include <sys/select.h> 153 sizeof(frame),
NULL);
266 const char *codec_string = encoder ?
"encoder" :
"decoder";
269 "results.\nAdd '-strict experimental' if you want to use it.\n",
270 codec_string, c->
name);
274 codec_string, codec->
name);
292 "Too many packets buffered for output stream %d:%d.\n",
322 ost->
quality = sd ? *(
int *)sd : -1;
334 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
341 "in incorrect timestamps in the output file.\n",
386 if (idx < ost->nb_bitstream_filters) {
463 int subtitle_out_max_size = 1024 * 1024;
464 int subtitle_out_size, nb, i;
478 subtitle_out =
av_malloc(subtitle_out_max_size);
489 for (i = 0; i < nb; i++) {
503 subtitle_out_max_size, sub);
504 if (subtitle_out_size < 0) {
510 pkt.
data = subtitle_out;
511 pkt.
size = subtitle_out_size;
530 int ret, format_video_sync;
546 "*** dropping frame %d from stream %d at ts %"PRId64
"\n",
598 *frame_size = pkt.
size;
615 #if FF_API_CODED_FRAME && FF_API_ERROR_FRAME 618 return -10.0 * log(d) / log(10.0);
626 double ti1, bitrate, avg_bitrate;
640 fprintf(
vstats_file,
"frame= %5d q= %2.1f ", frame_number,
643 #if FF_API_CODED_FRAME && FF_API_ERROR_FRAME 657 avg_bitrate = (double)(ost->
data_size * 8) / ti1 / 1000.0;
658 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
659 (
double)ost->
data_size / 1024, ti1, bitrate, avg_bitrate);
660 #if FF_API_CODED_FRAME 763 int64_t min_pts = INT64_MAX;
769 if (output_streams[i]->
filter && !output_streams[i]->
filter->graph->graph &&
778 if (!output_streams[i]->
filter || output_streams[i]->finished ||
779 !output_streams[i]->
filter->graph->graph)
782 pts =
av_rescale_q(pts, output_streams[i]->enc_ctx->time_base,
786 ost = output_streams[i];
798 }
else if (ret ==
AVERROR(EAGAIN))
807 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
808 uint64_t data_size = 0;
809 float percent = -1.0;
817 default: other_size += ost->
data_size;
break;
823 if (data_size && total_size >= data_size)
824 percent = 100.0 * (total_size - data_size) / data_size;
827 av_log(
NULL,
AV_LOG_INFO,
"video:%1.0fkB audio:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
831 extra_size / 1024.0);
841 uint64_t total_packets = 0, total_size = 0;
870 total_packets, total_size);
875 uint64_t total_packets = 0, total_size = 0;
904 total_packets, total_size);
915 int frame_number, vid, i;
916 double bitrate, ti1,
pts;
917 static int64_t last_time = -1;
918 static int qp_histogram[52];
923 if (!is_last_report) {
927 if (last_time == -1) {
928 last_time = cur_time;
931 if ((cur_time - last_time) < 500000)
933 last_time = cur_time;
937 oc = output_files[0]->
ctx;
942 if (total_size < 0) {
946 "avio_tell() failed: %s\n", errbuf);
955 ost = output_streams[i];
961 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
967 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3d q=%3.1f ",
968 frame_number, (t > 1) ? (
int)(frame_number / t + 0.5) : 0, q);
970 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
976 for (j = 0; j < 32; j++)
977 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(
log2(qp_histogram[j] + 1)));
980 #if FF_API_CODED_FRAME && FF_API_ERROR_FRAME 984 double error, error_sum = 0;
985 double scale, scale_sum = 0;
986 char type[3] = {
'Y',
'U',
'V' };
987 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
988 for (j = 0; j < 3; j++) {
989 if (is_last_report) {
990 error = enc->
error[j];
991 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
1000 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j],
psnr(error / scale));
1002 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
1010 if ((pts < ti1) && (pts > 0))
1016 bitrate = (double)(total_size * 8) / ti1 / 1000.0;
1018 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1019 "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
1020 (
double)total_size / 1024, ti1, bitrate);
1023 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" drop=%d",
1043 int stop_encoding = 0;
1157 opkt.
dts -= ost_tb_start_time;
1187 int need_reinit, ret, i;
1201 need_reinit |= ifilter->
width != frame->
width ||
1213 if (need_reinit || !fg->
graph) {
1316 char layout_name[256];
1333 int i, ret, err = 0;
1341 ret =
decode(avctx, decoded_frame, got_output, pkt);
1342 if (!*got_output || ret < 0)
1353 decoded_frame->
pts = pkt->
pts;
1362 if (i < ist->nb_filters - 1) {
1377 return err < 0 ? err : ret;
1383 int i, ret = 0, err = 0;
1392 if (!*got_output || ret < 0)
1413 if (i < ist->nb_filters - 1) {
1429 return err < 0 ? err : ret;
1436 &subtitle, got_output, pkt);
1504 if (repeating && !got_output)
1587 if (!output_files[i]->header_written)
1591 avc =
av_malloc(
sizeof(*avc) * nb_output_files);
1595 avc[i] = output_files[i]->
ctx;
1598 printf(
"SDP:\n%s\n", sdp);
1607 if (
hwaccels[i].pix_fmt == pix_fmt)
1618 for (p = pix_fmts; *p != -1; p++) {
1631 ret = hwaccel->
init(s);
1635 "%s hwaccel requested for input stream #%d:%d, " 1636 "but cannot be initialized.\n", hwaccel->
name,
1675 snprintf(error, error_len,
"Decoder (codec id %d) not found for input stream #%d:%d",
1696 snprintf(error, error_len,
1697 "Error while opening decoder for input stream " 1749 "Could not write header for output file #%d " 1750 "(incorrect codec parameters ?): %s",
1751 file_index, errbuf);
1828 uint32_t codec_tag = par_dst->
codec_tag;
1891 int encoder_string_len;
1892 int format_flags = 0;
1903 encoder_string =
av_mallocz(encoder_string_len);
1904 if (!encoder_string)
1921 for (p = kf; *p; p++)
1932 for (i = 0; i < n; i++) {
1933 char *next = strchr(p,
',');
2039 snprintf(error, error_len,
2040 "Error while opening encoder for output stream #%d:%d - " 2041 "maybe incorrect parameters such as bit_rate, rate, width or height",
2048 "It takes bits/s as argument, not kbits/s\n");
2053 "Error initializing the output stream codec context.\n");
2114 int ret = 0, i, j, k;
2135 if (output_streams[i]->
filter)
2164 ist = input_streams[i];
2179 ost = output_streams[i];
2213 const char *decoder_name =
"?";
2214 const char *in_codec_name =
"?";
2215 const char *encoder_name =
"?";
2216 const char *out_codec_name =
"?";
2220 decoder_name = in_codec->
name;
2223 in_codec_name = desc->
name;
2224 if (!strcmp(decoder_name, in_codec_name))
2225 decoder_name =
"native";
2229 encoder_name = out_codec->
name;
2232 out_codec_name = desc->
name;
2233 if (!strcmp(encoder_name, out_codec_name))
2234 encoder_name =
"native";
2238 in_codec_name, decoder_name,
2239 out_codec_name, encoder_name);
2281 int64_t ipts_min = INT64_MAX;
2291 if (ipts < ipts_min) {
2434 if (input_files[i]->eagain)
2443 input_files[i]->eagain = 0;
2454 return tmp_time_base;
2457 ret =
av_compare_ts(*duration, time_base, tmp, tmp_time_base);
2460 return tmp_time_base;
2470 int i, ret, has_audio = 0;
2478 ist = input_streams[ifile->
ist_index + i];
2495 ist = input_streams[ifile->
ist_index + i];
2510 }
else duration = 1;
2521 if (ifile->
loop > 0)
2568 if (ret < 0 && ifile->
loop) {
2582 ist = input_streams[ifile->
ist_index + i];
2608 goto discard_packet;
2616 goto discard_packet;
2633 memcpy(dst_data, src_sd->
data, src_sd->
size);
2656 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
2686 int ret, i, need_input = 1;
2690 int64_t timer_start;
2738 ist = input_streams[i];
2750 os = output_files[i]->
ctx;
2751 if (!output_files[i]->header_written) {
2753 "Nothing was written into output file %d (%s), because " 2754 "at least one of its streams received no packets.\n",
2766 ost = output_streams[i];
2774 ist = input_streams[i];
2792 if (output_streams) {
2794 ost = output_streams[i];
2812 struct rusage rusage;
2814 getrusage(RUSAGE_SELF, &rusage);
2815 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
2816 #elif HAVE_GETPROCESSTIMES 2818 FILETIME c, e, k,
u;
2819 proc = GetCurrentProcess();
2820 GetProcessTimes(proc, &c, &e, &k, &u);
2821 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
2829 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS 2830 struct rusage rusage;
2831 getrusage(RUSAGE_SELF, &rusage);
2832 return (int64_t)rusage.ru_maxrss * 1024;
2833 #elif HAVE_GETPROCESSMEMORYINFO 2835 PROCESS_MEMORY_COUNTERS memcounters;
2836 proc = GetCurrentProcess();
2837 memcounters.cb =
sizeof(memcounters);
2838 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
2839 return memcounters.PeakPagefileUsage;
2878 fprintf(stderr,
"At least one output file must be specified\n");
2893 printf(
"bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
static av_unused void pthread_cond_signal(pthread_cond_t *cond)
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
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.
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
static int check_init_output_file(OutputFile *of, int file_index)
static int need_output(void)
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.
AVCodecParameters * par_out
Parameters of the output stream.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
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 AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
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.
Memory buffer source API.
static const uint8_t frame_size[4]
void show_banner(void)
Print the program banner to stderr.
static void term_exit(void)
AVRational sample_aspect_ratio
Video only.
int h
agreed upon image height
static int nb_frames_drop
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
AVCodecParserContext * parser
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
The bitstream filter state.
static void set_encoder_id(OutputFile *of, OutputStream *ost)
int index
stream index in AVFormatContext
int max_muxing_queue_size
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
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.
const AVBitStreamFilter ** bitstream_filters
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.
static volatile int received_sigterm
static void finish_output_stream(OutputStream *ost)
This struct describes the properties of an encoded stream.
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
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.
int filtergraph_is_simple(FilterGraph *fg)
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
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
unsigned int nb_stream_indexes
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter.
#define AV_LOG_QUIET
Print no output.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
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.
static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *in_picture, int *frame_size)
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
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.
static int transcoding_finished
#define VSYNC_PASSTHROUGH
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
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.
AVStream ** streams
A list of all streams in the file.
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
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
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
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.
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
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
attribute_deprecated uint64_t error[AV_NUM_DATA_POINTERS]
unsigned int * stream_index
static int decode_interrupt_cb(void *ctx)
struct AVOutputFormat * oformat
The output container format.
static int send_filter_eof(InputStream *ist)
#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)
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 void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
static int init_output_stream(OutputStream *ost, char *error, int error_len)
static int64_t start_time
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
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
static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame)
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.
static int get_input_packet_mt(InputFile *f, AVPacket *pkt)
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 avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
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_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.
enum AVMediaType codec_type
General type of the encoded data.
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 flags
AV_CODEC_FLAG_*.
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...
AVRational time_base_in
The timebase used for the timestamps of the input packets.
#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().
static int init_output_stream_streamcopy(OutputStream *ost)
enum AVPacketSideDataType type
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.
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
static int seek_to_start(InputFile *ifile, AVFormatContext *is)
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.
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
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.
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
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.
common internal API header
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVCodecContext * parser_avctx
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.
enum AVPictureType pict_type
Picture type of the frame.
const AVIOInterruptCB int_cb
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
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 void do_subtitle_out(OutputFile *of, OutputStream *ost, InputStream *ist, AVSubtitle *sub, int64_t pts)
static InputStream * get_input_stream(OutputStream *ost)
#define AV_TIME_BASE
Internal time base represented as integer.
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
uint64_t * channel_layouts
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
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 children.
struct OutputStream * ost
int width
picture width / height.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
AVRational time_base_out
The timebase used for the timestamps of the output packets.
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...
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
void av_parser_close(AVCodecParserContext *s)
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
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)
static volatile int received_nb_signals
static void process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
enum AVPixelFormat pix_fmt
preferred ID for MPEG-1/2 video decoding
AVBufferRef * hw_device_ctx
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
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.
static void print_sdp(void)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
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.
static int ifilter_send_eof(InputFilter *ifilter)
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
static int init_input_threads(void)
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
static void avconv_cleanup(int ret)
AVIOContext * pb
I/O context.
OutputStream ** output_streams
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
AVFifoBuffer * muxing_queue
static int init_output_bsfs(OutputStream *ost)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static int check_recording_time(OutputStream *ost)
uint8_t * data
The data buffer.
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
a very simple circular buffer FIFO implementation
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
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)
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().
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
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...
static enum AVPixelFormat pix_fmts[]
This struct describes the properties of a single codec described by an AVCodecID. ...
This side data contains an integer value representing the quality factor of the compressed frame...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int global_quality
Global quality for codecs which cannot change it per frame.
static int64_t pts
Global timestamp for the audio frames.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
static int init_output_stream_encode(OutputStream *ost)
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. ...
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
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)
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
#define FF_DISABLE_DEPRECATION_WARNINGS
static void reset_eagain(void)
InputStream ** input_streams
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
static InputFile * select_input_file(void)
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
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.
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
static void free_input_threads(void)
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
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVDictionary * encoder_opts
static void * av_mallocz_array(size_t nmemb, size_t size)
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 AVRational duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base, AVRational time_base)
static void print_final_stats(int64_t total_size)
#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.
AVCodecParameters * codecpar
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static void sigterm_handler(int sig)
static int init_input_stream(int ist_index, char *error, int error_len)
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...
static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
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.
AVCodecParameters * par_in
Parameters of the input stream.
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.
static void * input_thread(void *arg)
#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.