Excerpt |
---|
ffmepg is a integrated tool for video encoding/decoding processing as open source project - http://ffmpeg.org |
...
You can easily convert video file to mp4 like below simple command on your linux device.
Code Block |
---|
ffmpeg –i source_video.mov –vcodec h264 –acodec mp2 my-video.mp4 |
If you want to use audio codec by aac in the video, it will be super simple like:
Code Block |
---|
ffmpeg –i source_video.mov –vcodec h264 –acodec aac my-video.mp4 |
Typical syntax of ffmpeg command is like below:
Code Block |
---|
ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ... |
1. Get Video Information
Code Block |
---|
$ ffmpeg -i video.mp4 |
2. Get Video Information without bannder
Code Block |
---|
$ ffmpeg -i video.mp4 -hide_banner |
3. Converting video to mp4
Code Block |
---|
$ ffmpeg -i video.avi video.mp4 |
4. Converting video to mkv
Code Block |
---|
$ ffmpeg -i video.avi video.mkv |
5. Converting video to mp4 without any quality loss
Code Block |
---|
$ ffmpeg -i input.webm -qscale 0 output.mp4 |
6. Displaying the supported formats by ffmpeg
Code Block |
---|
$ ffmpeg -formats |
7. Converting video files to audio files
Code Block |
---|
$ ffmpeg -i input.mp4 -vn -ab 320 output.mp3 |
8. Change resolution of video files
Code Block |
---|
$ ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4 |
or
Code Block |
---|
$ ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4 |
9. Compressing video files
Code Block |
---|
$ ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4 |
Note crf value 24 is too aggressive, you'd better lower its value,
10. Compressing audio files
Code Block |
---|
$ ffmpeg -i input.mp3 -ab 128 output.mp3 |
11. Extracting images from video
Code Block |
---|
$ ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png |
- -r – Set the frame rate. I.e the number of frames to be extracted into images per second. The default value is 25.
- -f – Indicates the output format i.e image format in our case.
- image-%2d.png – Indicates how we want to name the extracted images. In this case, the names should start like image-01.png, image-02.png, image-03.png and so on. If you use %3d, then the name of images will start like image-001.png, image-002.png and so on.
12. Split video files into multiple parts
Code Block |
---|
$ ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4 |
Below is an advanced version of splitting video files showing the way to implement one command instead of multiple command even though that does not reduce efforts to type the necessary options.
Code Block |
---|
echo "Two commands"
time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 -sn test1.mkv
time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:30:00 -t 01:00:00 -sn test2.mkv
echo "One command"
time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 \
-sn test3.mkv -vcodec copy -acodec copy -ss 00:30:00 -t 01:00:00 -sn test4.mkv |
13. Joining multiple video parts into one
Code Block |
---|
$ ffmpeg -f concat -i join.txt -c copy output.mp4 |
For your information, join.txt contains following video files
Code Block |
---|
C:\Users\LifePlanet\Downloads\part1.mp4
C:\Users\LifePlanet\Downloads\part2.mp4
C:\Users\LifePlanet\Downloads\part3.mp4
C:\Users\LifePlanet\Downloads\part4.mp4 |
14. Adding subtitles to a video file
Code Block |
---|
$ fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4 |
15. Adding multi subtitles to a video file
Code Block |
---|
$ ffmpeg -i $movie.mov -i $sub_en.srt -i $sub_de.srt -map 0:v -map 0:a -map 1 -map 2 \
-c:v copy -c:a copy -c:s srt \
-metadata:s:s:0 language=eng -metadata:s:s:1 language=ger \
$output.mkv |
Children Display | ||
---|---|---|
|
...