0

I want to know if it's possible to record four H264 video files with PiCamera with a specific frame ?

For example, I am recording 10 seconds of video at 4 fps. So normally, I will get a video file of 10 seconds with 40 frames. But now what I am trying to do, it's taking the:

  • 1st frame and put it into CAM1.h264
  • take the 2nd frame and put it into CAM2.h264
  • take the 3rd frame and put in into CAM3.H264
  • take the 4th frame and put it into CAM4.h264
  • take the 5th frame and put in into CAM1.h264
  • take the 6th frame and put in into CAM2.h264
  • take the 7rd frame and put in into CAM3.H264
  • take the 8th frame and put it into CAM4.h264
  • take the 9th frame and put in into CAM1.h264
  • take the 10th frame and put in into CAM2.h264
  • take the 11rd frame and put in into CAM3.H264
  • take the 12th frame and put it into CAM4.h264 etc.

How may I accomplish this ? With a stream ?

  • I don't think you'll be able to do this in real time, but I've got a feeling you might be able to do some frame splicing after recording using ffmpeg. Would that be acceptable? – goobering Apr 6 '16 at 22:23
  • Hi, thanks for your quick reply ! Do you have an example of code that I can use for the Frame Splicing after recording using FFMPEG ? It could be a good idea ! – Alexandre Dupont Apr 6 '16 at 22:33
  • I have a camera that takes pics at slow intervals and ffmpeg combines then into a video. You could dump your video to pics and combine them into four videos with four commands. – PaulF8080 Apr 7 '16 at 1:07
  • Hi PaulF8080, thanks for your fast reply ! Do you have any tutorial or links on how I can acheived this properly ? – Alexandre Dupont Apr 7 '16 at 1:33
  • I do not understand your question, you say you want a new file per frame, but why would you want that in h264 format. When it would be much simpler to write a small script to take 4 photos per second for 10 seconds and a script may give you more control over the file naming. – Mohammad Ali Apr 7 '16 at 3:45
0

OK. Lots of fun head scratching trying to remember how expressions work in ffmpeg!

This is still fairly non-optimal - you need to run a separate ffmpeg pass for the frame 1,5,9... video, the frame 2,6,10... video, the frame 3,7,11 video, etc. This could probably be automated with a small script. I'm also unsure of how long all this will take - the time required will depend on your source footage.

Where in.mp4 is your input video file:

ffmpeg -i in.mp4 -vf "select=not(mod(n\,4))" -vsync vfr out1.mp4
ffmpeg -i in.mp4 -vf "select=not(mod(n+1\,4))" -vsync vfr out2.mp4
ffmpeg -i in.mp4 -vf "select=not(mod(n+2\,4))" -vsync vfr out3.mp4
ffmpeg -i in.mp4 -vf "select=not(mod(n+3\,4))" -vsync vfr out4.mp4

This uses the select filter to define which frames to output. The documentation describes my expression components as:

  • mod(x, y): Compute the remainder of division of x by y.
  • not(expr): Return 1.0 if expr is zero, 0.0 otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.