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
  • 111
  • 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,730
  • 4
  • 39
  • 64
  • Whoops! Cheers for the edit. :) – goobering Aug 29 '16 at 17:11
  • 1
    Thank you, but that procedure only sets the interval between I-frames, not the wall clock times at which I-frames occur. If I have key frames every 5 seconds, and I want video clips that are 15 seconds long, hence 3 I-frames per file, I want those video clips to start at 0, 15, 30 and 45 seconds of every minute. So I-frames need to be inserted at precisely 0, 5, 10, 15, 20, ...55 seconds of every minute. How do I control the precise wall clock times of insertion ? – NewtownGuy Aug 29 '16 at 22:14
  • Aaaaaaaah. Gotcha. Goodness, that's much harder, and not achievable with plain old raspivid. Going to need some scripting I think. I'll see if I can come up with something sensible. – goobering Aug 29 '16 at 22:32