
1. Use FFmpeg to cut one giant .mp4 file into a few small ones
Use case
Based on my experience, FAT32 is the best external (USB drive) file format supported on Mac. However, the drawback is also very clear: it only supports 4GB write per time, and also it lacks a journaling system like the one for NTFS.
Sometimes a movie is simply too large, and I will have to divide it into 2-3 pieces, where FFmpeg comes in handy.
Use FFmpeg to cut a video file
For example, if I need the first 1200 second (20 min) of a video, I can use:
ffmpeg -ss 00:00:00 -i input.mp4 -c copy -t 1200 output.mp4
where:
-ss: starting time- N.B.
-sscomes before-i
- N.B.
-i: input file-t: where (when) to cut, e.g.- one can use
-t xx-> cutxxsec of video - also, one can use
-t 01:00:00-> cuthh:mm:sslong of a video. Note that this is not the time stamp in a video, rather a more readable way of-t xx
- one can use
Example
Say we need to separate a video into 3 segments, to be more specific, I need 3 videos from Start~01:17:55, 01:17:55~02:06:50, and 02:06:50~End.
Then we can use:
ffmpeg -ss 00:00:00 -i sample_Input.mp4 -c copy -t 01:17:55 sample_Output-part1.mp4 #Start~01:17:55
ffmpeg -ss 01:17:56 -i sample_Input.mp4 -c copy -t 00:48:57 sample_Output-part2.mp4 #01:17:55~02:06:50
ffmpeg -ss 02:06:55 -i sample_Input.mp4 -c copy -t 01:11:48 sample_Output-part3.mp4 #02:06:50~End
2. Use FFmpeg to concatenate multiple .flv files then extract its audio into a .mp3 file
Use case
Sometimes we saw a video online, it looks like a single file, but actually, when we downloaded it server, it was actually several video files as part of a big file. What if I want the audio of the whole video as a .mp3 file?
This is actually a very common use case scenario, say I only want the audio of an ASMR video so I can listen to in bed.
step 1: piece together first
I recommend renaming the video segments to 1.flv, 2.flv, 3.flv...
Then we can use a shell command to output a list of all the file needed:
for f in *.flv; do echo "file '$f'" >> mylist.txt; done
Sometimes the order of files gets scrambled in mylist.txt like 1.flv, 10.flv-19.flv, 2.flv、20.flv-29.flv...
You can use sort to fix that, e.g.
for f in `ls *.flv | sort -n`; do echo "file '$f'" >> mylist.txt; done
Use FFmpeg concat to piece together all video segments:
mylist.txt above should be like:
file '1.flv'
file '2.flv'
file '3.flv'
then:
ffmpeg -f concat -i mylist.txt -c copy output.flv
When using
FFmpeg concat, when filename contains weird characters, you need to use escape sequence in mylist.txt, another reason why I suggest to rename all segments before.
step 2: extract audio
ffmpeg -i output.flv -f mp3 -vn output.mp3
where:
-i: input file-f: format for output-vn: means 'video not', the output will not be video