Last active
January 21, 2024 22:55
-
-
Save jonathanduke/41cc9d782f71d091318da591652d5a63 to your computer and use it in GitHub Desktop.
ffmpeg commands that I need to remember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is for converting a ripped movie to a 480p size so my kids can watch it on their tablets in the car. | |
# I'm cropping off 276 pixels from the top and bottom, which means it's a 3840x2160 image with a 2.39:1 letterboxed video. | |
# The width can vary based on the aspect ratio, but the height should always be 480px. | |
# I'm hard-coding it to use H.264 and yuv420p and to downmix surround sound to regular stereo channels. | |
# On some movies, I had to use -map 0:2 to get the 5.1 audio stream if the 7.1 was truehd and ffmpeg didn't like that. | |
ffmpeg -i "4k.mkv" -vf "crop=iw:ih-552:0:276,scale=1146:480" -c:v libx264 -c:a copy -ac 2 -sn -pix_fmt yuv420p -map 0:0 -map 0:2 -crf 18 -map_chapters -1 "480p.mp4" | |
# After getting the resolution right, follow this process to reduce the size of the video: https://trac.ffmpeg.org/wiki/Encode/H.264#twopass | |
ffmpeg -y -i original.mp4 -c:v libx264 -b:v 1000k -pass 1 -an -f null NULL && ffmpeg -i original.mp4 -c:v libx264 -b:v 1000k -pass 2 -c:a aac -b:a 128k shrink.mp4 | |
# I have to do this all of the time to clip a portion of a video clip from our live stream on social media. | |
ffmpeg -i "live.mp4" -ss 00:01:23 -to 00:04:56 -c copy "clip.mp4" | |
# Occasionally I may have to splice several clips together. This requires a text file, such as concat.txt: | |
file 'clip1.mp4' | |
file 'clip2.mp4' | |
file 'clip3.mp4' | |
# Then, it is a simple operation to create a single video file: | |
ffmpeg -safe 0 -f concat -i concat.txt -c copy full.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment