1

If I record a video with raspivid, the output doesn't seem to be a perfectly valid video file. I can play it with mplayer, but Firefox's <video> tag can't play (although it's supposed to support h264). If I run a ffmpeg -i out.h264 out.mp4, the output file can be played by Firefox.

According to mediainfo, this is the difference between the two files:

General
Complete name                            : out.h264
Format                                   : AVC
Format/Info                              : Advanced Video Codec
File size                                : 230 MiB

Video
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=60
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
General
Complete name                            : out.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 36.1 MiB
Duration                                 : 48s 0ms
Overall bit rate                         : 6 303 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf56.40.101

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 48s 0ms
Bit rate                                 : 6 302 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.122
Stream size                              : 36.1 MiB (100%)
Writing library                          : x264 core 140
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

It seems to me that some kind of header information is missing. Does anybody know an easy way to fix this?

1

I think what you're encountering is the difference between the H.264 compression format, and the MP4 container format. Per this Wikipedia entry, linked from Mozilla's own support pages, Firefox supports MP4, but not H.264 without a container.

The easiest eay to fix it is to encode everything as an MP4 (or another suitable container format). The information attached in the container is non-trivial, and not available in the raw H.264 file.

This page at raspberrypi-spy.co.uk outlines a couple of options for putting raspivid's H.264 output in an MP4 container:

MP4Box:

sudo apt-get update
sudo apt-get install -y gpac
MP4Box -fps 30 -add myvid.h264 myvid.mp4

avconv:

sudo apt-get install -y libav-tools
avconv -r 30 -i myvid.h264 -vcodec copy myvid.mp4
  • 1
    There's no way to directly output MP4 with raspivid, right? – rand Jun 22 '16 at 10:39
  • You know, I'd thought there was but apparently there isn't. I'll add a wee kibble to the answer. – goobering Jun 22 '16 at 10:44
  • 1
    I think raspivid will output mjpeg which according to this firefox supports. It's the most portable format I've found for use with the pi cam without an intermediate conversion in userland like avconv (don't bother if you want streaming) but it might as well be uncompressed, the data rate is so obscene (8-10 MB/s at full resolution and framerate). uv4l will definitely output this. – goldilocks Jun 22 '16 at 13:42

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.