[Libav-user] muxing an .mp4 file with timestamps?
Max Göttner - d.stream
max.goettner at dstream.de
Wed Dec 21 16:43:34 CET 2011
Hi
I use the following sequence in order to create .mp4 files with timestamp
information passed for each frame. With these settings, the value
AVPacket.pts is interpreted as a frame index, like when writing an .avi
file. If I pass packet1 with pts=0 and packet2 with pts = 10, than frame one
is repeated 10 times in the outfile. When I write .mkv files the result is
like you'd expect: a variable framerate video.
Here is the outformat relevant code:
// get output format
AVOutputFormat* fmt = NULL;
fmt = av_oformat_next(fmt);
while(strcmp(fmt->name, "mp4"))
{
fmt = av_oformat_next(fmt);
}
fmt->video_codec = CODEC_ID_MPEG4;
// create output format context
AVFormatContext* outFmtCtx = avformat_alloc_context();
outFmtCtx->oformat = fmt;
// set parameters and init codec context
// open file and write header
avio_open(outFmtCtx->pb, filename, AVIO_FLAG_WRITE);
avformat_write_header(outFmtCtx, NULL);
// write frames with pts multiple times
while(...)
{
// encode packet AVPacket encoded_pkt
encoded_pkt.pts = pts;
r = av_write_frame(outFmtCtx, &encoded_pkt);
}
// close file
av_write_trailer(outFmtCtx);
I'd appreciate any help. Is the interpretation of AVPacket.pts a
muxer/encoder setting, or is VFR .mp4 not possible with libav?
Thanks in advance.
Max
More information about the Libav-user
mailing list