At every call to av_write_frame I am getting lots of messages like the 
following 

[svcd @ 0089E7C0]buffer underflow i=0 bufi=0 size=9304
[svcd @ 0089E7C0]buffer underflow i=0 bufi=0 size=9304
[svcd @ 0089E7C0]buffer underflow i=0 bufi=2016 size=9304
[svcd @ 0089E7C0]buffer underflow i=0 bufi=4040 size=9304
[svcd @ 0089E7C0]buffer underflow i=0 bufi=6064 size=9304
[svcd @ 0089E7C0]buffer underflow i=0 bufi=8088 size=9304

I am capturing the MPEG2 Transport Stream from a DVB-S card. FFmpeg functions 
are used for writing elementary stream data to a file. 
Transport stream is parsed with my code, not FFmpeg's functions.
I have to save only part of the transport stream to a file (one video stream 
from user defined program and one of accompanying audio streams, also user-
defined)

My code is the following:

m_pFormatCtx = av_alloc_format_context();
m_outfmt = guess_format("svcd", (const char *)m_filename, NULL); //m_filename 
is "p8201.mpg"
m_pFormatCtx->oformat = m_outfmt;

int codec_id   = CODEC_ID_MPEG2VIDEO;
int codec_type = CODEC_TYPE_VIDEO;
AVCodec *codec = avcodec_find_decoder(codec_id);
if(codec == NULL) {
 [handle error]
}
AVStream *st = av_new_stream(m_pFormatCtx,m_pFormatCtx->nb_streams);
AVCodecContext *ctx=st->codec;
ctx->codec_id   = codec_id;
ctx->codec_type = codec_type;
ctx->time_base.den      = 1;
ctx->time_base.num  = 90000; 
ctx->width =720;
ctx->height=576;
ctx->sample_rate=48000; //for future audio
if(avcodec_open(ctx, codec) < 0) {
 [handle error]
}

AVFormatParameters format_params;
format_params.width =720;
format_params.height=576;
format_params.sample_rate=48000;
format_params.time_base.den     = 1;
format_params.time_base.num  = 90000;
format_params.channels=1; // while struggling with FFmpeg I limit to video only
format_params.video_codec_id=CODEC_ID_MPEG2VIDEO;
format_params.audio_codec_id=CODEC_ID_MP3;
        
int r=av_set_parameters(m_pFormatCtx,&format_params);

  ....

AVPacket avpacket;
av_init_packet(&avpacket);
avpacket.stream_index = avstream->index; 

//el_pkt is a class storing PES packet
buffer=el_pkt.GetPayloadData(&buffer_size);
avpacket.pts=(el_pkt.m_PTS_DTS_flags & 0x02) ? el_pkt.m_PTS : AV_NOPTS_VALUE;
avpacket.dts=(el_pkt.m_PTS_DTS_flags & 0x01) ? el_pkt.m_DTS : AV_NOPTS_VALUE;
avpacket.duration=(int64_t)0;   //TODO: 
avpacket.data=buffer;
avpacket.size=buffer_size;

int r = av_write_frame(m_pFormatCtx, &avpacket);

buffer contains a pointer to a valid MPEG-2 video, I've checked its bytes.
They are 00 00 01 and then either 00, or b3 or other MPEG's

buffer_size contains correct number of bytes, allocated to the payload. The 
next PES packet begins after this buffer.

Everything looks correct... 
I find the MPEG PS header in the resulting file, and something looking like the 
MPEG data, which I supplied (I didn't check if there are the same data, will 
do) however, VLC doesn't play this file.

What's wrong??

What else didn't I set in the output AVFormatContext??

Vladimir.

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to