2

I have a rasp pi B+ model with the camera module installed. When I use the following basic cmd

raspivid -o v.h264 -t 10000

If I export v.h264 to my windows machine and play it back with VLC, I see that the video timebar remains at 00:00 throughout the whole video, also the end timer is always fixed at 00:00, when usually this end timer shows the total runtime of the video file.(which in this case should be 00:10)

Is there a way to get this information up, or tell raspivid to store the data in the file without taking the raw footage and encoding it with ffmpeg and the likes.

3

The H.264 encoder on the Pi outputs an H.264 NAL stream which lacks all sorts of information including (rather importantly) the framerate, without which one cannot calculate the video length. This is why you can, for example, record a video with raspivid at 1fps but if you play it back in VLC it'll play back at 24fps because that's what VLC defaults to in the absence of such information.

This is why it's generally necessary to use some tool to wrap the output up in something more useful like an MP4 container (which will contain things like framerate). The easiest method for doing this at the moment (on a Pi) is to use MP4Box:

$ sudo apt-get install gpac
$ MP4Box -add v.h264 v.mp4

This doesn't perform any re-encoding; it simply wraps the raspivid output in an MP4, so it's an extremely fast operation.

Why does the Pi's camera produce such a low level stream instead of something like an MP4 file? I don't know for certain but this would be my guess:

Remember that the Pi's camera is fundamentally a mobile phone camera. On a mobile phone one would want to combine the video output of the H.264 encoder with some encoded audio stream (something like AAC) and output the result as an MP4 file. In such cases you wouldn't want the camera firmware to produce an MP4 file as you'd just have to decode that to extract the video stream before muxing it with the audio stream. Hence, the camera's encoder firmware produces this relatively low level stream and expects the caller to handle wrapping it up in something more end user friendly like an MP4 file.

  • So when I am wrapping h264 in mp4 is there any loss of information? any compression ? – Coderaemon Feb 13 '15 at 9:12
  • You'll be adding information, not removing it. As a result there will be a tiny loss of compression, but nothing that should affect any application – Dave Jones Feb 13 '15 at 12:26
0

If you use MP4Box, I recommend adding the frame rate to the command:

MP4Box -add vid.h264:fps=60 vid.mp4

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.