Fastest way to add -movflags +faststart to an MP4 using FFMPEG, leaving everything else as-is - ffmpeg

I want to add -movflags +faststart to an mp4 file. Basically that is all I want to do, nothing else should be changed. I am using ffmpeg.
What's the fastest way to do this? Do I have to re-encode the whole video? Or is there a better/easier way?

As simple as:
ffmpeg -i in.mp4 -c copy -map 0 -movflags +faststart out.mp4
Or if you can compile FFmpeg from source, make the tool qt-faststart in the tools/ directory and run it:
qt-faststart in.mp4 out.mp4
You can also use mp4box, which lets you move the MOOV atom to the start via this command:
mp4box -inter 0 in.mp4 -out out.mp4
Or if you want to fully optimize for streaming by also interleaving the audio/video data so that the file can be easily streamed in realtime:
mp4box -inter 500 in.mp4 -out out.mp4

Related

ffmpeg, overlay .mov onto .mp4, way to make faster, without changing preset?

I have the following command, which puts an overlay.mov file ontop of a .mp4 file. It works great but i'm wondering if the command i'm using can be sped up.
ffmpeg -loglevel quiet -i 'assets/videos/background.mp4' -i 'assets/videos/overlay.mov' -filter_complex '[1:v][0:v]scale2ref[ua][b];[ua]setsar=1,format=yuva444p,colorchannelmixer=aa=0.5[u];[b][u]overlay=eof_action=pass[v]' -map [v] -map 0:a -preset medium -y 'assets/videos/output.mov'
I know i can change -preset to ultrafast but is there a way i can improve the above command? Anything obsolete?
If you dont want to reencode video you can use the same codec, ffmpeg just move mov format to mp4 format, and It very fast.
ffmpeg -i input.mov -c:v copy out.mp4

FFMPEG converting MP3 to MP4 is adding blank space, how to fix Terminal command?

I'm creating MP4 files from MP3 files + an image. Searching here at StackOverflow I found a Terminal command that gets me really close:
ffmpeg -loop 1 -r 1 -i pic.jpg -i input.mp3 -c:a copy -shortest -c:v libx264 output.mp4
Works almost perfectly so long as input.mp3 and pic.jpg are in the same folder. The problem is:
It frequently ends up with about 20-40seconds of blank space at the end of the resulting MP4. I can manually chop it off, but I'd love to find out if there's a way to alter this command so that the resulting MP4 file is exactly the length of the input MP3 file.
I don't know the ffmpeg commands well and know just enough Terminal to be dangerous. So I'm hoping it's something obvious haha.
This command should work for you:
ffmpeg -i input.mp3 -loop 1 -i pic.jpg -shortest -c:a copy -c:v mjpeg output.mp4
You do not need to set -r 1 with just one image and -loop 1.
I think -c:v mjpeg is more suitable to encode jpg than -c:v libx264.

Audio conversion and filter application using ffmpeg with 1 command

I have an mp3 file I need to convert to wav, and apply loudnorm filter afterwards. So far i've been doing it with 2 commands.
ffmpeg -i input.mp3 output.wav
and
ffmpeg -y -nostdin -i output.wav -filter_complex "[0:0]FILTER PARAMETER" -map_metadata 0 -map_metadata:s:a:0 0:s:a:0 -map_chapters 0 -map [norm0] -c:a pcm_s16le -ar 1500 -c:s copy out2.wav
Is there anyway to use 1 command instead of 2? I tried converting straight from mp3 to out2.wav by changing output.wav to input.mp3, but when the resulting file is compared with diff, they are different compared to the 2 step process.
I'm fairly new to ffmpeg, and have spent hours on the documentation without really knowing how to accomplish what i'm trying to do.

ffmpeg command to merge file with good quality

I am looking for a better command that can merge both audio & video files into one with a better quality.
I found this command from Muaz Khan's WebRTC APIs.
ffmpeg -i {$audioFile} -i {$videoFile} -map 0:0 -map 1:0 {$mergedFileName}
Later on server i had to add "-strict -2" with this command as on server it says that above command is experimental if I still want to use it you should add "-strict -2" with it.
It is working well but my video file (.webm) with size 2.2MB and audio file (.wav) with size 1.5MB was merged into a new file (.webm) with size 422.5KB. This new video file is having lag.
Also I want the meta information for duration of video is already written on the resulting video file.
Is there any command which can give the merged file without lagging and both video and audio of the new file are of good quality ?
Use
ffmpeg -i {$audioFile} -i {$videoFile} -map 0:0 -c:a libopus -map 1:0 -c:v copy {$mergedFileName}
This will encode only the audio, leaving the video intact. Use libvorbis if libopus isn't present in your FFmpeg.

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

Resources