I have a raw h264 file that I can display with VLC, on a mac:

open -a VLC file.h264

I can convert this to mp4 with the command line

ffmpeg -f h264 -i file.h264 -c:v copy file.mp4

But what I really want to do is something like:

cat file.h264 | ffmpeg > file.mp4

Reason being that the input is coming over a socket and I want to convert it and send it to a video tag in an html file on the fly.

An alternative solution would be a way to display the raw h264 in a web page without converting it to mp4 first.

The input is coming in frame by frame, the first four bytes are 0,0,0,1. My understanding is that this h264 Annex B format.

I know nothing about video formats, I would grateful to be pointed in a direction to look.

Should I look into writing code using libavcodec like this quuesion or is there an off-the-shelf solution?

H.264 muxed to MP4 using libavformat not playing back


  • Just use “-i -“ – szatmary Apr 16 at 0:38
  • That works for the input, for the output it seems that ffmpeg can't write to a pipe because it needs to seek the outout. 'muxer does not support non seekable output'. – Charlie Burns Apr 16 at 2:47
  • 1
    Correct, mp4 can not be written via a pipe. Use a format like flv, or mkv that can. – szatmary Apr 16 at 2:49
  • Good idea to use another format. This command line seems to work as a filter. 'cat A4DA2229AEBD.h264 | ffmpeg -i - -f h264 -vcodec libtheora -f ogv - > x.ogv' – Charlie Burns Apr 16 at 4:23

The command line below will create a fragmented MP4 (Windows cmd)

type test.h264 | ffmpeg -i - -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov pipe:1 > test_frag.mp4

You should be able to find lot's of JavaScript code to play fragmented MP4s.

For example: https://github.com/chriswiggins/videojs-fmp4

  • 1
    Thanks! That's way faster than the filter I used to make .ogv files. – Charlie Burns Apr 16 at 22:51

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.