Create mp4 file from raw h264 using a pipe instead of files - ffmpeg

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!

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

Related

Ffmpeg -c copy not carrying over audio track from mkv to hls stream

I am using ffmpeg to create an hls stream. The source is an mkv with multiple audio tracks. I have tried using -map to specify the audio stream as well. I also found that when I point ffmpeg to any other audio stream in the file it works. It's just the first audio stream that does not. At one point I replaced -c copy with -acodec aac -ac 6 on the first stream and I got sound which is great but I am only looking to copy the stream and not re-encode it. The next thing I tried was using other mkv videos I have. All are reflecting the same issue. The mkv's by itself play both audio and video fine in VLC. When playing the output.m3u8 in VLC the option to choose different audio tracks is greyed out. Here is the command I'm using:
ffmpeg -i "./video.mkv" -ss 00:00:00 -t 00:00:30 -c copy -f hls "output.m3u8"
I want the audio of my hls stream to reflect that of the mkv source:
Although what I get returned from the command above gives me no sound and shows me this in mediaInfo:
I've aslo noticed that hls does not support pcm. Is it possible dash could work with this stream because it is pcm?
HLS segments can be either MPEG-TS or fragmented MP4. Neither officially support PCM audio, so you'll have to convert it.
DASH uses fragmented MP4 as segment format.

ffmpeg fails to Play Proxy Avid Interplay

My goal is transcode this file with ffmpeg.
https://drive.google.com/open?id=1ATuPtSbZeQLexB1HBP509hInDOTyfEV8
ffplay fails to analize or play this file and returns:
Invalid pixel format.
This is the simply command:
ffplay -i testproxy.mxf
ffprobe -i testproxy.mxf -show_stream
It has been encoded by avid Interplay whit this targhet quality:
H.264 800Kbps Proxy 1080i 25
Maybe it's a raw file? and need same specification ahead input file?
Any suggestion is appreciated
Either Interplay doesn't write* a standard MXF or there's a limitation in ffmpeg's mxf demuxer.
But you can play the file with
ffplay -vcodec h264 testproxy.mxf
and similarly, you can transcode using
ffmpeg -vcodec h264 -i testproxy.mxf ...
*more likely, as mediainfo also fails to detect the video codec.

ffmpeg pipe to mediainfo

I need to get infos from the raw h264 track of a mkv file.
Some times ago, I used to extract the h264 raw stream, and analyze it by itself.
now, I would like to limit the disk usage, avoiding the extract process, so there are 2 choices:
use ffmpeg to pipe h264 to mediainfo
use a sort of ramdisk
I tried
ffmpeg -i original.mkv -map 0:v:0 -c copy -bsf:v h264_mp4toannexb -f h264 - | mediainfo -
but it returns none
where am I wrong?
mediainfo does not (yet) support pipes (-). You may want to add a feature request on MediaInfo tracker.
but... I don't see which kind of better metadata report you get with that, compared to 'mediainfo original.mkv', as MediaInfo supports parsing of H264 in MKV.

how to save h264 stream into .264 file

I'm using nginx-rtmp-module build hls server, when I play it on safari, it does not shows image,then i use this command ffmpeg -i rtmp://192.168.4.213/hls/testH264 -c copy -map 0 -f segment -segment_list playlist.m3u8 -segment_time 5 output%03d.ts, it shows missing picture in access unit with size 28184,so i think maybe the raw h264 stream has some problem,then i directly save the h264 stream into .264 file,but when i play the .264 file with vlc,the screen is fuzzy,help
should use binary type to save file

Convert a YUV video stream to mp4

How to record YUV video and encode it to mp4 using h264 coded for mac application.
Plz suggest me any link on it.
FFMpeg can encode YUV to mp4(H.264) via libx264 encoder. But you have to specify exact YUV pixel format of your source video. There are several YUV formats.
This command converts rawvideo with pixel format of yuv420p to a MPEG-4 or x264 format.
# Converts the raw yuv420p data to a MPEG-4 video
ffmpeg -f rawvideo -pix_fmt yuv420p -video_size 1280x720 -framerate 25 -i 'in' -f mp4 'out'
Below list shows YUV pixel formats can be decoded by ffmpeg.
$ ffmpeg -pix_fmts 2>&1 | grep yuv
yuv420p
yuv422p
yuv444p
yuv410p
yuv411p
yuvj420p
yuvj422p
yuvj444p
yuv440p
yuvj440p
yuva420p
yuv420p16le
yuv420p16be
yuv422p16le
yuv422p16be
yuv444p16le
yuv444p16be
yuv420p9be
yuv420p9le
yuv420p10be
yuv420p10le
yuv422p10be
yuv422p10le
yuv444p9be
yuv444p9le
yuv444p10be
yuv444p10le
This is the easiest way to convert video formats using MacOSX command line (any version). First download this compressed file and unpack it to your Movies Folder:
https://drive.google.com/file/d/0B3NlLwMD4yd9QU0yVGJyU1NiUDA/view?usp=sharing
You will then have a MMedia_Converter directory with two apps: MMedia_Convert and Android_Converter. Those are my own developed MacOSX open source applications, bassed on FFMpeg Group and HandBrake Group France previous work. Both are fully compliant Mac compilled applications and you´ll have have to do nothing but extract them to your Movies Folder.
You also have there, 3 folders: clip_in, clip_out and scripts.
You must put the videos you want to be converted in the clip_in folder.
The converted output videos, will be generated automatically in the clip_out folder.
In addition you have 2 bash scripts, that you must move to your Mac OSX Desktop.
Once these bash are on desktop, edit them with TextEdit, and change my user name by your Mac name.
In my case, I use one script to generate thumbnails and the other to generate thumbnails too, and to automatically convert videos from any formar to wathever I choose.
"Whatever" means, that if you want to convert mpeg to mkv, you will have to declare it in line: DEST_EXT=mkv (or wathever known video format you want).
Hope this will help you all.
Best Regards, Tomás Hernández

Resources