[Libav-user] Encoding workflow process and container
CHAUVET Guillaume
cg85 at hotmail.com
Thu Oct 4 14:10:47 CEST 2012
Hello libav users !
I tried to create a very simple mpeg2 file : a container with one video stream.
But I don't understand very well all API functions needed to perform this operation :
When I execute the attached sample program (below) I obtain an empty "video.mpg" file. Is avformat_write_header function who write the media file header ?
Or some information are missing in my settings ? I have to admit I'm a little bit confused :-(
#include "libavutil/opt.h"
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
static const char *video = "video.mpg";
static const int fps = 25;
int main(int argc, char **argv)
{
avcodec_register_all();
av_register_all();
AVFormatContext *outfile;
AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);
if (codec != NULL)
{
avformat_alloc_output_context2(&outfile, NULL, "mpeg2video", NULL);
AVStream *stream = avformat_new_stream(outfile, codec);
stream->codec->codec_id = codec->id;
stream->codec->width = 1920;
stream->codec->height = 1080;
stream->codec->time_base = (AVRational) {1, fps};
stream->codec->pix_fmt = PIX_FMT_YUV422P;
stream->codec->bit_rate = 15 * 1000 * 1000;
stream->codec->gop_size = fps / 2;
stream->codec->max_b_frames = 1;
avio_open(&outfile->pb, video, AVIO_FLAG_WRITE); // Without this line no file created
avformat_write_header(outfile, NULL);
av_dump_format(outfile, 0, video, 1);
avformat_free_context(outfile);
}
return 0;
}
Sincerly,
Guillaume
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121004/0bd42f13/attachment.html>
More information about the Libav-user
mailing list