3

I an interfacing with a type of video stream that is about 30fps of video that is mostly static (like a still picture). I only get updates from the stream when there is movement in the video. So if the video is static for 5 minutes, I only get the data for those 5 minutes as a single frame of data. Then if there is movement on the video stream for 5 seconds, I get each of those frame's data as well (about 150 frames, for example). Then if it is still for another 5 minutes, I will get 1 single frame's data for that entire time. So the video would be 10 minutes and 5 seconds, but I would get 152 frames of data for that time period.

I'm trying to create a realtime video file from this data but when I encode it, the first and last 5 minutes of video only exist as a single frame, so instead of 5 minutes of still video, it goes straight to the 2 seconds where I had that actual realtime frames.

What would be the best approach to creating an actual, full length/real time video from this information? I'm currently using C++.

NotDan
  • 31,709
  • 36
  • 116
  • 156

1 Answers1

0

You didn't mention anything about codecs or tools, but you implied you were already doing encoding.

Most video encoders expect a fixed frame rate. So the easy solution is to just keep feeding it the same frame until enough "frame time" has elapsed to get to the next still in your set.

Here's some pseudo code:

frames_per_second = 30;
encoder  = CreateEncoder(frames_per_second, width, height);
milliseconds_per_frame = 1000.0/fps;
timestamp = frameset[0].timestamp;
x = 0;

while (x < frameset.count)
{
   AddNextFrameToEncoder(encoder, frameset[x].framedata);
   timestamp += milliseconds_per_frame;

   if ((x < frameset.count-1) && (timestamp >= frameset[x+1].timestamp))
   {
      x++;
   }
   // else - keep repeating the same source frame until "timestamp" is incremented to the timestamp of the next still
}
selbie
  • 100,020
  • 15
  • 103
  • 173