DIY Video So Easy

Prepare video or audio for LittleFox.

This page introduce some useful commands of the respected FFmpeg library that can be used to prepare video or audio for LittleFox. Before the following tutorial please download FFmpeg from http://ffmpeg.org first if you haven't installed it in your system.

0. Install FFmpeg

Assuming you extracted the ffmpeg install package in ~/ffmpeg.
$ cp ~/.profile ~/Desktop/profile.txt
copy the bash configuration file to your desktop.
PATH="~/ffmpeg/bin:${PATH}"
export PATH
Add above two lines in the file.
$ cp ~/Desktop/profile.txt ~/.profile
Save it back and then you can access ffmpeg anywhere.

If you don't want configure ffmpeg in ~/.profile, open Terminal and execute the following command,
$ export PATH=/Users/yeung/bin/ffmpeg/bin:$PATH
then you can execute ffmpeg commands on command line now.

1. Extract Audio

$ ffmpeg -i videoname.mp4 -vn -acodec copy videoname.aac: extract audio to .aac.
a. iTunes → Preferences → Import Settings → Import Using → select "MP3 Encoder"
b. open .aac with QuickTime Player → Export As → Audio Only: convert .aac to .m4a
c. open .m4a with iTunes: File → Convert → Create MP3 version and then click the file → Show in Finder
The above steps help you extract audio from video and convert it to mp3.

2. Extract Video Segment

$ ffmpeg -i videoname.mp4 -c:v libx264 -c:a aac -ss 00:00:05 -to 00:10:36 -y segment1.mp4
$ ffmpeg -i videoname.mp4 -c:v libx264 -an -ss 00:00:05 -to 00:10:36 -y segment1.mp4: video only.
-ss: segment start time, -to: end time.

3. Remove Audio from Video

$ ffmpeg -i videoname.mp4 -vcodec copy -an -y nosound.mp4

4. Scale Video

$ ffmpeg -i videoname.mp4: fetch video resolution.
The above command will print something like: Stream #0:0(eng): Video: h264 (High) ..., yuv420p, 240x180
$ ffmpeg -i videoname.mp4 -s 240x180 -c:a copy 240x180.mp4
240x180: the width and height of the scaled output video.

5. Crop Video by Offset

$ ffmpeg -i video.mp4 -filter:v "crop=320:164:0:0" 320x164.mp4
width:height:offx:offy
width: the output width.
height: the output height.
offx: the x offset from top left.
offy: the y offset from top left.

6. Merge Video Segments

$ ffmpeg -f concat -safe 0 -i files.txt -c copy -y combined.mp4
files.txt include the extracted video segments.
file segment1.mp4
file segment2.mp4
...

7. Combine Video with audio

$ ffmpeg -i videoname.mp4 -i song.mp3 -c:v copy -c:a aac videoname-new.mp4

Command line is not monster!

Command line commands is not as terrible as they seems, you can now make a video very easy and comfortable if you mastered above seven commands. More info about manipulating video with ffmpeg, please visit the official ffmpeg website: http://ffmpeg.org.