1
votes

I am working on a project in which I am receiving raw frames from some input video devices. I am trying to write those frames in a video files using FFMPEG library. I have no control over the frame rate i am getting from my input sources. This frame rate varies in run-time also. Now my problem is how do i sync between recorded video and coming video. Depending upon frame-rate i set in FFMPEG and actual frame rate that i am receiving playback of recorded video is either fast or slow than input video. I tried to add timestamps (as numOfFrames) in encoded video as per following link but that didn't help.

ffmpeg speed encoding problem

Please tell me a way to synchronize both. This is my first time with FFMPEG or any multimedia libraries so any examples will be highly appreciated.

I am using directshow ISampleGrabber interface to capture those frames. Thank You

1
You have timestamps with every frame, what else you needRoman R.
I am sorry but i didn't get you. I am working on this for first time. Where am i having time stamp on each frame? Are you referring to ISampleGrabber output ?Abhishek Bansal
You have frames with ISampleGrabber::SampleCB . Each media sample has a time stamp IMediaSample::GetTime attached (it is optional, however it is almost always there, or it is a live feed).Roman R.
I am working on live feed. Can I use same timestamp in FFMPEG encoding ?Abhishek Bansal
okay! i did some quick tests IMediaSample::GetTime in SampleCB is returning VFW_E_SAMPLE_TIME_NOT_SET for me which means this sample is not time stamped. What should i do in this situation ?Abhishek Bansal

1 Answers

1
votes

So Finally i figured out how to do this. Here is how..

First i was taking preview from PREVIEW pin of source filter which do not give timestamps to frames. So one should take frames from capture pin of the source filter. Than in SampleCB callback function we cant get time using IMediaSample::GetTime(). But this function will return time in unit of 100ns. FFMPEG requires it in units of 1/time_base. Here time_base is desired frame rate. So directshow timestamp needs to be converted in FFMPEG units first. Than we can set pts in AVFrame::pts variable of ffmpeg. One more thing that needs to be considered is first frame of video shoul have timestamp of 0 in FFMPEG so that needs to be taken care of while converting from directshow timestamp to FFMPEG one.

Thank You