38 printf(
"%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",
46int main(
int argc,
char **argv)
51 const char *in_filename, *out_filename;
54 int *stream_mapping = NULL;
55 int stream_mapping_size = 0;
58 printf(
"usage: %s input output\n"
59 "API example program to remux a media file with libavformat and libavcodec.\n"
60 "The output format is guessed according to the file extension.\n"
65 in_filename = argv[1];
66 out_filename = argv[2];
70 fprintf(stderr,
"Could not allocate AVPacket\n");
75 fprintf(stderr,
"Could not open input file '%s'", in_filename);
80 fprintf(stderr,
"Failed to retrieve input stream information");
88 fprintf(stderr,
"Could not create output context\n");
94 stream_mapping =
av_calloc(stream_mapping_size,
sizeof(*stream_mapping));
95 if (!stream_mapping) {
110 stream_mapping[i] = -1;
114 stream_mapping[i] = stream_index++;
118 fprintf(stderr,
"Failed allocating output stream\n");
125 fprintf(stderr,
"Failed to copy codec parameters\n");
135 fprintf(stderr,
"Could not open output file '%s'", out_filename);
142 fprintf(stderr,
"Error occurred when opening output file\n");
174 fprintf(stderr,
"Error muxing packet\n");
193 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.
#define AVIO_FLAG_WRITE
write-only
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
static AVFormatContext * fmt_ctx
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
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.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
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_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
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,...
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_freep(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a memory block for an array with av_mallocz().
int main(int argc, char **argv)
static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt, const char *tag)
This struct describes the properties of an encoded stream.
enum AVMediaType codec_type
General type of the encoded data.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVIOContext * pb
I/O context.
const struct AVOutputFormat * oformat
The output container format.
AVStream ** streams
A list of all streams in the file.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int64_t pos
byte position in stream, -1 if unknown
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static AVFormatContext * ifmt_ctx
static AVFormatContext * ofmt_ctx