Skip to content

Simple tools for h264 raw video and converting it for use in standard browsers

License

Notifications You must be signed in to change notification settings

hamishcoleman/h264mux

Repository files navigation

As part of streamlining a raspberry pi webcam setup, I would like to take the
stream output of raspivid and encapsulate it in normal framing for simpler
playback on multiple devices.

This can be done with vlc using something like:
    raspivid -o - -t 0 -vf -hf -w 1280 -h 720 | \
    cvlc stream:///dev/stdin \
        --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

However, vlc is a large program and slow to run, so it would be nice to have
something more targeted.

The raqspivid output is recognised by file(1) as:
    "JVT NAL sequence, H.264 video @ L 40"

The stream generated by cvlc with mux=ts (as above) is a MPEG transport stream.

A MP4 container stream can be generated by cvlc with mux=mux_mp4 - this format
has much better support in browsers, but is much worse for streaming.  (Note
that generating a mp4 file to a non seekable stream will result in a non
quickstart file format - ie, with the required index headers at the end of
the file)

Eventually, it would be nice to update raspivid with some additional output
format options, but first - I need to understand the bitstream format.

To explore the problem and gain understanding into the format, two dump
programs have been written - these are neither fast, nor feature complete
and are not intended for use to fix the raspivid pipeline.

dump_mpegnal
    Dump the packets seen in a MPEG H.264 raw "NAL" stream - as output by the
    raspivid program

dump_mpegps
    Dump the packets seen in a MPEG2 PES stream - as is output by the cvls
    conversion above (and is understood by far more programs than the NAL
    stream is)

dump_mpeg4
    Dump out the component packets seen in a MP4 file

hack_mux_mpeg2pes
    A quick and dirty hack to take a h264 NAL file and wrap it in a MPEG2
    PES stream.

hack_mux_mp4
    A quick and dirty hack to take a h264 NAL file and wrap it in a MP4
    container.

Generating test data:
Some example commands I have used for generating my test files:
    raspivid -o - -t 60000 -vf -hf -w 1280 -h 720 \
        -fps 25 -ih -g 25 >test.03.raspivid.out

An example HLS streamer:

    raspivid -t 0 -w 1280 -h 720 -fps 25 \
    -o - | ffmpeg -nostats -loglevel 1 -i - \
            -vcodec copy \
            -f hls -hls_time 10 -hls_list_size 10 -hls_flags delete_segments \
            /dev/shm/hls/movie.m3u8

References:
- DVB ETSI EN 300 468
- ISO13818-1

About

Simple tools for h264 raw video and converting it for use in standard browsers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages