2

How do I insert key frames in a Raspivid stream not just periodically, but also at particular times, e.g., 0, 15, 30 and 45 seconds of each minute ? I want to do this so that breaking the stream into files gives files that always start at particular seconds. I don't want, for example, 15-second files that start at 7, 22, 37 and 52 seconds of each minute.

Thank you in advance for your help.

NewtownGuy
  • 119
  • 7

1 Answers1

2

From the Raspivid documentation page:

--intra, -g Specify the intra refresh period (key frame rate/GoP)

Sets the intra refresh period (GoP) rate for the recorded video. H264 video uses a complete frame (I-frame) every intra refresh period from which subsequent frames are based. This options specifies the numbers of frames between each I-frame. Larger numbers here will reduce the size of the resulting video, smaller numbers make the stream more robust to error.

A sample command line to set I-frames at each 15 second interval (when recording at 25 fps) might look like this:

raspivid -g 375 -w 1280 -h 720 -fps 25 -t 10000 -b 3000000 -o test.h264
  • -g 375: Set 375 frames between each I-frame (15 seconds @ 25 fps)
  • -w 1280: width=1280 pixels
  • -h 720: height=720 pixels
  • -fps 25: 25 frames per second
  • -t 10000: record for 10000 milliseconds/10 seconds
  • -b 3000000: bitrate of 3000000 bits per second
  • -o test.h264: output to file 'test.h264'

While, from the looks of things, your videos are going to be very short, I think I'd be inclined towards a higher I-frame rate if I were ever planning on seeking through the clips. Media players tend to 'snap' to I-frame intervals, meaning that your sub-divided clips will effectively be un-seekable. You could perhaps aim for 3 or 5 second intervals, which would still allow for accurate 15 second divisions.

goobering
  • 10,750
  • 4
  • 40
  • 64