<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<pre>Hello libav users !<br> <br></pre><pre>I tried to create a very simple mpeg2 file : a container with one video stream.<br>But I don't understand very well all API functions needed to perform this operation :<br>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 ?<br>Or some information are missing in my settings ? I have to admit I'm a little bit confused :-(<br></pre><pre>#include "libavutil/opt.h"<br>#include "libavformat/avformat.h"<br>#include "libavcodec/avcodec.h"<br>#include "libavutil/imgutils.h"<br> <br></pre><pre>static const char *video = "video.mpg";<br>static const int fps = 25;<br> <br></pre><pre>int main(int argc, char **argv)<br>{<br> avcodec_register_all();<br> av_register_all();<br> AVFormatContext *outfile;<br> AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);<br> if (codec != NULL)<br> {<br>  avformat_alloc_output_context2(&outfile, NULL, "mpeg2video", NULL);<br>  AVStream *stream = avformat_new_stream(outfile, codec);<br>  stream->codec->codec_id = codec->id;<br>  stream->codec->width = 1920;<br>  stream->codec->height = 1080;<br>  stream->codec->time_base = (AVRational) {1, fps};<br>  stream->codec->pix_fmt = PIX_FMT_YUV422P;<br>  stream->codec->bit_rate = 15 * 1000 * 1000;<br>  stream->codec->gop_size = fps / 2;<br>  stream->codec->max_b_frames = 1;<br>  avio_open(&outfile->pb, video, AVIO_FLAG_WRITE); // Without this line no file created<br>  avformat_write_header(outfile, NULL);<br>  av_dump_format(outfile, 0, video, 1);<br>  avformat_free_context(outfile);<br> }<br> return 0;<br>}<br> <br></pre><pre>Sincerly,<br>Guillaume</pre>                                     </div></body>
</html>