Remux streams from one container format to another. Data is copied from the input to the output without transcoding.
{
printf(
"%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",
}
int main(
int argc,
char **argv)
{
const char *in_filename, *out_filename;
int stream_index = 0;
int *stream_mapping =
NULL;
int stream_mapping_size = 0;
if (argc < 3) {
printf(
"usage: %s input output\n"
"API example program to remux a media file with libavformat and libavcodec.\n"
"The output format is guessed according to the file extension.\n"
"\n", argv[0]);
return 1;
}
in_filename = argv[1];
out_filename = argv[2];
fprintf(stderr, "Could not allocate AVPacket\n");
return 1;
}
fprintf(stderr, "Could not open input file '%s'", in_filename);
goto end;
}
fprintf(stderr, "Failed to retrieve input stream information");
goto end;
}
fprintf(stderr, "Could not create output context\n");
goto end;
}
stream_mapping =
av_calloc(stream_mapping_size,
sizeof(*stream_mapping));
if (!stream_mapping) {
goto end;
}
continue;
}
stream_mapping[
i] = stream_index++;
if (!out_stream) {
fprintf(stderr, "Failed allocating output stream\n");
goto end;
}
fprintf(stderr, "Failed to copy codec parameters\n");
goto end;
}
}
fprintf(stderr, "Could not open output file '%s'", out_filename);
goto end;
}
}
fprintf(stderr, "Error occurred when opening output file\n");
goto end;
}
while (1) {
break;
continue;
}
fprintf(stderr, "Error muxing packet\n");
break;
}
}
end:
return 1;
}
return 0;
}
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
This struct describes the properties of an encoded stream.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
AVStream ** streams
A list of all streams in the file.
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
int main(int argc, char **argv)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
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,...
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static AVFormatContext * ofmt_ctx
#define AVIO_FLAG_WRITE
write-only
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.
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.
Rational number (pair of numerator and denominator).
AVIOContext * pb
I/O context.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
static AVFormatContext * fmt_ctx
#define av_ts2timestr(ts, tb)
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)
static AVFormatContext * ifmt_ctx
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
printf("static const uint8_t my_array[100] = {\n")
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_calloc(size_t nmemb, size_t size)
const struct AVOutputFormat * oformat
The output container format.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
This structure stores compressed data.
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 av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int64_t pos
byte position in stream, -1 if unknown
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.