logo       

MPEG TS: msg#00301

video.ffmpeg.user

Subject: MPEG TS

I'm trying to encode into MPEG TS. I can create a .ts file and send it using
udp (I can see both outputs using VLC). But when I try to stream it again
(using VLC), I get the following errors:

access_output_udp debug: packet has been sent too late (624732071053)
access_output_udp debug: packet has been sent too late (624732034211)
access_output_udp debug: packet has been sent too late (624731997369)
main warning: late buffer for mux input (624732658000)
main warning: late buffer for mux input (624732618000)
main warning: late buffer for mux input (624732578000)
main warning: late buffer for mux input (624732538000)
access_output_udp debug: late packet for udp input (624732148527)
access_output_udp debug: late packet for udp input (624732071334)

I'm not sure where the problem is. Here is my code:

while (WaitForSingleObject(m_Stop,0)==WAIT_TIMEOUT)
{
for (int nTotal=0,nRead=0;nTotal<sizeof(SRCImage) &&
(nRead=Video.Receive(SRCImage+nTotal,sizeof(SRCImage)-nTotal))>0;nTotal+=nRead);
if (nRead<0)
{
ATLTRACE(_T("Aborting\n"));
break;
}
img_resample(pResample,pDSTPicture,pSRCPicture);
AVFrame* pPicture=(AVFrame*)pDSTPicture;
int nCount=((nFrames % 5)<2) ? 2 : 3; // Convert from 10 to 25 FPS
for (int nIndex=0;nIndex<nCount;nIndex++,nFrames++)
{
int
nSize=avcodec_encode_video(&pVideo->codec,VideoBuffer,sizeof(VideoBuffer),pPicture);
if (nSize)
{
AVPacket Packet={0};
av_init_packet(&Packet);
//Packet.dts=Packet.pts=pVideo->codec.coded_frame->pts;
if (pVideo->codec.coded_frame->pts!=AV_NOPTS_VALUE)

Packet.pts=av_rescale_q(pVideo->codec.coded_frame->pts,pVideo->time_base,pVideo->time_base);
if (pVideo->codec.coded_frame->key_frame)
Packet.flags|=PKT_FLAG_KEY;
Packet.stream_index=pVideo->index;
Packet.data=VideoBuffer;
Packet.size=nSize;
ATLVERIFY(av_interleaved_write_frame(m_pContext,&Packet)==0);
ATLTRACE(_T("Encoding frame
%dx%d(%d)\n"),nFrames,nCount,(int)Packet.pts);
}
else
{
ATLTRACE(_T("Encoding frame $\n"));
}
}
pVideo->codec.frame_number++;
}


This is how I initialize the codec:

m_pContext=av_alloc_format_context();
AVOutputFormat* pFormat=guess_format("mpegts",NULL,NULL);
m_pContext->oformat=pFormat;
AVStream* pVideo=av_new_stream(m_pContext,STREAM_TYPE_VIDEO_MPEG2);
pVideo->codec.codec_id=pFormat->video_codec;
pVideo->codec.codec_type=CODEC_TYPE_VIDEO;
pVideo->codec.bit_rate=2048*1024;//400000;
pVideo->codec.width=DST_WIDTH;
pVideo->codec.height=DST_HEIGHT;
pVideo->codec.frame_rate=STREAM_FRAME_RATE; // 25
pVideo->codec.frame_rate_base=1;
pVideo->codec.gop_size=12;
pVideo->codec.max_b_frames=2;


I can play the output using VLC, but the packets are not entirely valid and
don't work on other players.


Regards,
Gilad Novik


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise