Thursday, August 13, 2020

The power of ffmpeg

Editing Recordings (on Mac OS)

ffmpeg comes with homebrew https://brew.sh/. Install brew and then use brew to install useful packages.
brew install ffmpeg
or if you have a python distribution installed you can use pip
pip install ffmpeg
The zeroth step... you probably should install Xcode (sadly Xcode is massive and uses up to 20GB of disk).

The man page contains descriptions of commands
$ man ffmpeg

Example: Extract audio from a video (mp4) quicktime file.

Using QuickTime Player. File > Export
From the menu choose Audio Only. Name the file and click Export. The file will be exported as a 256kbps AAC audio file (m4a). A selection converting mp4 or m4a files to mp3 from the command line...
ffmpeg -i input.mp4 output.mp3

ffmpeg -i input.m4a output.mp3 
m4a is an Apple format, lossless compression. mp3 is the most common audio format, lossy compression.

Example: Converting and manipulating video formats like mov and mp4

Screen capture using QuickTime and manipulate with Trim (in QuickTime) and ffmpeg (from the command line)
ffmpeg -i EpicKartJump.mov EpicKartJump.mp4
Is it possible to speed up a video? https://video.stackexchange.com/questions/18469/is-it-possible-to-speed-up-a-video-using-handbrake
ffmpeg -i EpicKartJump.mov -vf "setpts=(PTS-STARTPTS)/10" -crf 18 EpicKartJumpFast.mp4
Example (best): How to join  and audio file (mp3) with a video file (mp4)?
ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a copy output.mp4 

Note: the syntax is -i for input file, -c:v copy; for convert video, in this case 'copy' means no stream format conversion, it just copies; -c:a copy; and to convert audio -c:a aac would convert the audio file to aac format.

Example: To remove audio track from mp4 video file

ffmpeg -i input_file.mp4 -an -vcodec copy output_file.mp4

Example (?): To join multiple files into a single file (can be audio or video)

ffmpeg -i "concat:audio1.mp3|audio2.mp3|audio3.mp3" -c copy output.mp3

or 

ffmpeg -f concat -safe 0 -i FileList.txt -c copy mergedVideo.mp4 

Where FileList.txt contains paths in the local dir, something like:

file 'FirstFileInSequence.mp4'
file 'SecondFileInSequence.mp4'

Example: To speed/timelapse the video

ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4
Example: To slowmo the video
ffmpeg -i input.mp4 -filter:v "setpts=2*PTS" output.mp4
Example: To add blur effect to video
ffmpeg -i intro.mov -vf "boxblur=5:1" intro-blur.mov

Example: ffmpeg can make mp4 smaller by varying the Constant Rate Factor, using:

ffmpeg -i $infile -vcodec libx264 -crf 23 $outfile

Example (best): fmpeg can make mp4 smaller by changing the video screen-size (for example to half its pixel size), using:

ffmpeg -i $infile -vf "scale=iw/2:ih/2" $outfile

Sharing 360° video?

So, you've got a 360 degree video file from your GoPro. What to do with it? Well, share it on YouTube. YouTube supports uploading and pl...