[FFmpeg-user] ffmpeg recording problem while
Mehmet Ali
mehmetalilk at hotmail.com
Thu Aug 15 14:04:58 CEST 2013
Hi there,
I demux from an ip cam h264 video stream and draw it on screen. It is working well but when i record the same stream ( just demux and record not decode) ffplay.exe cant play the file..Why this code doesnt work? If i have to write somethings like header before frames to file please clarify me.. Thank you for your help..
My Code like this:
//create file pVideo=fopen("VideoTest.264","ab+"); //start a loop and using demux of stream capture video and decode by decoder of stream if(!stream.mDecoder.AllocateFrame(frame)) { TRACE("frame Allocate error\n"); return 0; } if(!stream.mDecoder.AllocateFrame(scaledFrame)) { TRACE("scaledFrame Allocate Error\n"); return 0; }
if(!stream.mDecoder.InitializeFrame(scaledFrame,stream.mDemuxer.mStreamInfo.mWidth,stream.mDemuxer.mStreamInfo.mHeight,mPxl)) { TRACE("scaledFrame İnitialize Error\n"); return 0; } DWORD start,end,onesecst; int framerate=0; bool startmes=true; CString frm; bool isRun=true; int ret=-1;
static int frameno=0; while(isRun) { if(startmes) { onesecst=GetTickCount(); startmes=false; } start=GetTickCount(); ret=WaitForSingleObject(stream.mHandletoStop,1); //HACK timeout ile çıkmalı reset event çağırılınca if(ret==WAIT_OBJECT_0) { TRACE("Exit event fired!.\n"); isRun=false; }
memset(videoBuffer,0,256*1024);
if((encodedFrameSize=stream.mDemuxer.GetFrame(videoBuffer))<0) { TRACE("GetFrame Error\n"); break; } if(!stream.mDecoder.Decode(videoBuffer,encodedFrameSize,frame)) { TRACE("Decode error\n"); continue; }
if(pthis->WillSend) SetEvent(pthis->SendToCMS);
int totalWritten=0; int rest=encodedFrameSize; DWORD written=0; while(rest>0) { written=fwrite(videoBuffer+totalWritten,1,rest,pVideo); if(written<0) break;
totalWritten+=written; rest-=written; } if(!stream.mDecoder.Scale(frame,scaledFrame,stream.mDemuxer.mStreamInfo.mWidth,stream.mDemuxer.mStreamInfo.mHeight,mPxl)) { TRACE("scale error\n"); break; } stream.mDrawer->Display(scaledFrame->data[0],stream.mRect);
end=GetTickCount(); int abc=end - onesecst; framerate++; totalEncodedSize+=encodedFrameSize; if(end - onesecst>=1000) {
frm.Format("Frame Rate:%d\n",framerate); pthis->sttcFrameRate.SetWindowText(frm); frm.Format("Bit Rate:%lu kBps\n",8*totalEncodedSize/(1024)); pthis->sttcBitRate.SetWindowText(frm); startmes=true; framerate=0; totalEncodedSize=0; }
}
I used to play file with ffplay this string
E:\ffmpeg\20130703\bin>ffplay.exe -f h264 -analyzeduration 258522508 -probesize958852258 VideoTest.264
ffplay.exe return some warnings
[h264 @ 032741a0] non-existing PPS referenced[h264 @ 032741a0] non-existing PPS 0 referenced[h264 @ 032741a0] decode_slice_header error[h264 @ 032741a0] no frame![h264 @ 032741a0] non-existing PPS referenced[h264 @ 032741a0] non-existing PPS 0 referenced[h264 @ 032741a0] decode_slice_header error[h264 @ 032741a0] no frame![h264 @ 032741a0] non-existing PPS referenced[h264 @ 032741a0] non-existing PPS 0 referenced[h264 @ 032741a0] decode_slice_header error[h264 @ 032741a0] no frame![h264 @ 032741a0] non-existing PPS referenced[h264 @ 032741a0] non-existing PPS 0 referenced[h264 @ 032741a0] decode_slice_header error[h264 @ 032741a0] no frame![h264 @ 032741a0] non-existing PPS referenced[h264 @ 032741a0] non-existing PPS 0 referenced[h264 @ 032741a0] decode_slice_header error[h264 @ 032741a0] no frame![h264 @ 032741a0] non-existing PPS referenced[h264 @ 0326bc40] decoding for stream 0 failed[h264 @ 0326bc40] Could not find codec parameters for stream 0 (Video: h264): unspecified sizeConsider increasing the value for the 'analyzeduration' and 'probesize' optionsVideoTest.264: could not find codec parameters
My working environment
FFmpeg version: 2013-07-22 git-419a3d8VS 2012 Mfc App.Windows 8
Mehmet Ali
More information about the ffmpeg-user
mailing list