38 printf(
"%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",
46 int main(
int argc,
char **argv)
51 const char *in_filename, *out_filename;
55 printf(
"usage: %s input output\n"
56 "API example program to remux a media file with libavformat and libavcodec.\n"
57 "The output format is guessed according to the file extension.\n"
62 in_filename = argv[1];
63 out_filename = argv[2];
68 fprintf(stderr,
"Could not open input file '%s'", in_filename);
73 fprintf(stderr,
"Failed to retrieve input stream information");
81 fprintf(stderr,
"Could not create output context\n");
86 ofmt = ofmt_ctx->oformat;
92 fprintf(stderr,
"Failed allocating output stream\n");
99 fprintf(stderr,
"Failed to copy context from input to output stream codec context\n");
111 fprintf(stderr,
"Could not open output file '%s'", out_filename);
118 fprintf(stderr,
"Error occurred when opening output file\n");
143 fprintf(stderr,
"Error muxing packet\n");
160 fprintf(stderr,
"Error occurred: %s\n",
av_err2str(ret));
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
const struct AVCodec * codec
void av_free_packet(AVPacket *pkt)
Free a packet.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int64_t pos
byte position in stream, -1 if unknown
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static AVFormatContext * fmt_ctx
#define AVIO_FLAG_WRITE
write-only
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
int main(int argc, char **argv)
timestamp utils, mostly useful for debugging/logging purposes
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static av_cold int end(AVCodecContext *avctx)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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 AVFormatContext * ifmt_ctx
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Round to nearest and halfway cases away from zero.
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt, const char *tag)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
rational number numerator/denominator
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.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE...
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
static AVFormatContext * ofmt_ctx
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...