How to wrap H264 into a mp4 container? - ffmpeg

I have a program generating a bunch of raw H264 frames and would like to place that into a mp4 container for streaming.
Anyone know how to do that?
I was thinking I'd use ffmpeg however, this needs to be used commercially and it seems like ffmpeg can only do this through it's x264 library... which uses a GPL license.
Thank you!

If you're looking for the FFMPEG command line to do that, then try the following:
ffmpeg -i "source.h264" -c:v copy -f mp4 "myOutputFile.mp4"
If you have a separate audio file you can add it too:
ffmpeg -i "source.h264" -i "myAudio" -c:v copy -c:a copy -f mp4 "myOutputFile.mp4"
If your audio needs to be encoded as well (for instance codec AAC-LC, bitrate 256kbps):
ffmpeg -i "source.h264" -i "myAudio" -c:v copy -c:a aac -b:a 256k -strict -2 -f mp4 "myOutputFile.mp4"

libmp4v2 is under the MPL and can be used as part of a larger work commercially. It is much lighter than libavformat also.

Related

ffmpeg Will stream be copied if same codec is requested?

I loop over some files and convert them with ffmpeg. I provide -vcodec h264. When the input video already is encoded with that codec: will the video stream be copied? How to make sure it's not reencoded in that case? Is it what -sameq was used previously?
You need to use -c:v copy if you want the raw H.264 stream to be passed on without re-encoding:
ffmpeg -i myh264file.mp4 -c:v copy -c:a copy myh264output.mp4
-c:a copy will also copy the audio
-c copy will copy both audio and video as in:
ffmpeg -i myh264file.mp4 -c copy myh264output.mp4
Detecting H.264 streams is not straight forward. You will need to code this.
For the -sameq settings please refer to this statement.
I would recommend upgrading to a recent version of ffmpeg if it is not already done as -vcodec is not used anymore, now it is -c:v.
The documentation on ffmpeg could help you.

How add scale in my ffmpeg command

i want convert video from any format to mp4. so i am using command:
ffmpeg -i ttt.mp4 -vcodec copy -acodec copy test.mp4
this is working perftectly but now i also add scale in this -s 320:240.
There also many other command for convert LIKE :
ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
but after convert by this command video not play in html5 player
BUT this is not working so tell me in my command how i add scale;
So please provide me solution for this .
Thanks in advance.
You have several problems:
In your command, you have -vcodec copy you cannot scale video without reencoding.
In the command you randomly found on the Internet, they are using AVI, which is not HTML5-compatible.
What you should do is:
ffmpeg -i INPUT -s 320x240 -acodec copy OUT.mp4
Adding to Timothy_G:
Video copy will ignore the video filter chain of ffmpeg, so no scaling is available (man ffmpeg is a great source of information that you will not find on Google). Notice that once you start decoding-filtering-encoding (i.e., no copy) the process will be much slower (x100 time slower or even more). The libx264 is recommended if you want compatibility with all browsers.
$ ffmpeg -i INPUT -s 320x240 -threads 4 -c:a copy -c:v libx264 OUT.mp4
vp9 will provide nearly 50% extra bandwidth saving, but only for supported browsers (Firefox/Chrome), and the encoding will much slower compared to libx264 (that itself is much slower that v:c copy):
$ ffmpeg -i INPUT -s 320x240 -c:a copy -c:v vp9 OUT.webm
Notice that there is a set of formats (containers) accepted by browsers (most admit mp4, some also webm, ...) and for each format there is a set of audio/video codecs accepted. For example you can use mp3 or aac with an mp4 file (container), but not with webm files.
http://en.wikipedia.org/wiki/HTML5_video#Supported_video_formats

Converted mp4 h264 baseline format loads long time

I have converted my video to mp4 x264 baseline format and it works fine with all pc/mobile phones , the problem is it takes long time to load the video while googling came to know that ffmpeg converts and sets the index file at the eof the video so it loads to the end to read and then plays the video, So any advices would be appreciatable to cut short the loading time.
Note:tryied out QT index swapper2 but dint give much difference , please advice .
this is the cmd i used to convert -
ffmpeg -i … -c:v libx264 -profile:v baseline -level 1 …
Thanks for your time .
You have several options to relocate the moov atom so the video can begin playback before it is completely downloaded by the client.
-movflags faststart
The easiest is the option -movflags faststart when re-encoding:
ffmpeg -i input -c:v libx264 -profile:v baseline -movflags faststart output.mp4
If you already encoded your .mp4 file, but simply want to move the atom:
ffmpeg -i input.mp4 -codec copy -movflags faststart output.mp4
You may need to get a more recent ffmpeg version to use this option. See the FFmpeg download page for links to ffmpeg builds for Linux, OS X, and Windows, or you can follow a step-by-step guide to compile ffmpeg.
qt-faststart
Alternatively you can use the qt-faststart tool that comes with the ffmpeg source:
cd ~/ffmpeg/tools
make qt-faststart
./qt-faststart input.mp4 output.mp4
MP4Box
Or you could use MP4Box (usually provided by the gpac package depending on your distro):
MP4Box -add input.mp4 output.mp4
Also See
FFmpeg and x264 Encoding Guide
FFmpeg and AAC Audio Encoding Guide

FMS FLV (Speex) to mp3/mp4/acc/wav

I'm trying to decode an FLV's audio to a playable format. I attempted to use this SO post: FMS FLV to mp3.. as an example, but my FLV is encoded in Speex.
I have compiled ffmpeg with --enable-libspeex on a Fedora 15 machine.
I believe this can be done with ffmpeg but I'm having a hard time figuring out how to do it.
Any thoughts? Thanks
Your ffmpeg needs to be configured with --enable-libspeex to support Speex decoding. Since you did not provide your OS I can not give any more specific instructions. Once you have a build of ffmpeg that can decode speex the most simple command would be:
ffmpeg -i input.flv output.wav
while reencoding flv file (speex to mp3) if you get sample rate error try this:
ffmpeg -i c:\in.flv -acodec libmp3lame -ar 44100 -vcodec copy c:\out.flv
It does not matter what your input. As long as you have the decoder and encoder enabled in your ffmpeg it will do it.
ffmpeg -i inputfile.flv -acodec libmp3lame any_other_parameters_you_want -vcodec copy out.flv
will do the trick.
run ffmpeg -codecs to see the codecs supported and ffmpeg -formats to see the formats supported in your install.

FMS FLV to mp3/aac/wav

How can I decode a FLV's audio if it's recorded from a live stream using Flash Media Server and uses NellyMoser codec?
I'm writing a script that process several FLVs, using FFmpeg, so I need a command line solution.
Any ideas?
This should work for you, since NellyMoser is supported by FFmpeg.
1. Using mp3
ffmpeg -i yourinput.flv -vn -acodec libmp3lame output.flv
2. Using AAC (switch aac with libfaac depending on which you have loaded)
ffmpeg -i yourinput.flv -vn -acodec libfaac output.mp4
I'm assuming of course you dont care about video.

Resources