23 ways to use FFMPEG and Linux for your multimedia work or youtube video editing
Did you wonder if you could convert a video to mp3 audio without spending money? Or going to Internet?
Did you ever trim an audio or video file online and wondered if there was a better way?
1. Convert video from avi container to mp4
$ ffmpeg -i in.mp4 out.avi
2. Rotate video 90 degrees clockwise
$ ffmpeg -i in.mp4 -vf “transpose=1” out.mp4
3. Create a Youtube thumbnail at 10 seconds
$ ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg
4. Add life to a muted video or gif animation
$ ffmpeg -i “$no_audio_video” -i “$audio” -shortest -vcodec copy -acodec copy “$output_video”;
5. Make composite video
$ ffmpeg -i “$left_video” -i “$right_video” -filter_complex hstack “$output_video”
6. Extract 5 seconds long video
$ ffmpeg -ss 00:00:03 -t 00:00:08 -i input.mp4 -async 1 cut.mp4
7. Record from your microphone
$ ffmpeg -f pulse -i 2 -ac 2 -acodec libmp3lame -ab 320k out.mp3
8. Scale down a video
$ ffmpeg -i <input> -vf scale=640:480 <output>
9. Extract metadata/id3 tags
$ ffmpeg -i file.mp3 -f ffmetadata metadata.txt
10. Resample audio
$ ffmpeg -i file.aac -acodec mp3 -ar 44100 -ab 128000 output.mp3
11. Create video from images(slideshow)
$ ffmpeg -f image2 -i image%d.jpg video.mp4
12. Remove first X seconds from a video
$ ffmpeg -ss 10 -i input.mp4 -async 1 cut.mp4
13. Boost volume of your song
$ffmpeg -i input.mp3 -filter:a “volume=4.0” output.mp3
14. Speed up a video
$ ffmpeg -i video.mpg -vf “setpts=0.5*PTS” highspeed.mpg
15. Slowdown a video
$ ffmpeg -i video.mpg -vf “setpts=0.5*PTS” highspeed.mpg
16. Add subtitles in SRT format to video[hardcode]
$ ffmpeg -i input.mp4 -vf subtitles=sub.srt out.mp4
17. Cross fade audio effect
$ ffmpeg -i first.flac -i second.flac -filter_complex acrossfade=d=10:c1=exp:c2=exp output.flac
18. Save shoutcast stream to file on disk
$ ffmpeg -i <url> -acodec copy -vcodec copy file.mp4
19. Mute first 90 seconds
$ffmpeg -i in.mp4 -vcodec copy -af “volume=enable=’lte(t,90)’:volume=0” out.mp4
20. Crop video Crop size (width:height:xoffset:yoffset):
$ ffmpeg -i input_video -vf crop=1500:800:200:100 -vcodec libx264 -b:v 1000k -an output_video.mp4
21. Modify video frame rate
$ ffmpeg -i “$video” -filter:v fps=20 “$output_video”
22. Record your screen in Linux
$ ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i pulse -acodec aac screencast.mp4
23. Dump video length and codec details
$ ffmpeg -hide_banner -filter:v idet -frames:v 100 -an -f rawvideo -y /dev/null -i VIDEO.mp4
TL;DR
- convert video to audio
- scale down a video
- record a podcast
- record a screencast
- bump up the volume
- speed up a video
Follow @girish1729 for such tips and tricks.
Take a minute to thank Fabrice Bellard.
You can download a FFMPEG cheatsheet for free from my Gumroad.