Create mp4 file from raw h264 using a pipe instead of files
Asked Answered
T

1

6

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

Thanks!

Trainor answered 15/4, 2019 at 23:33 Comment(4)
Just use “-i -“Deign
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'.Trainor
Correct, mp4 can not be written via a pipe. Use a format like flv, or mkv that can.Deign
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'Trainor
I
8

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

Infold answered 16/4, 2019 at 15:54 Comment(2)
Thanks! That's way faster than the filter I used to make .ogv files.Trainor
can the native <video> tag play this?Sabellian

© 2022 - 2024 — McMap. All rights reserved.