Last active
April 26, 2024 06:14
-
-
Save ggarnier/4590893a26380e24d9e0643d57a64df5 to your computer and use it in GitHub Desktop.
ffmpeg commands
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
# Adding blurred boxes | |
# - build a layer called b0, a blurred box with size 100x50 and offset 600x50, between 23s and 31s | |
# - build a layer called b1, a blurred box with size 300x80 and offset 190x270, between 37s and 49s | |
# - merge the original video and b0 on ovr0 | |
# - merge ovr0 and b1 to build output | |
ffmpeg -i input.mp4 -filter_complex \ | |
"[0:v]crop=100:50:600:150,boxblur=10:enable='between(t,23,31)'[b0]; \ | |
[0:v]crop=300:80:190:270,boxblur=10:enable='between(t,37,49)'[b1]; \ | |
[0:v][b0]overlay=600:150[ovr0]; \ | |
[ovr0][b1]overlay=190:270[output]" \ | |
-map "[output]" -map 0:a -c:v libx264 -c:a copy -movflags +faststart output.mp4 | |
# Slicing a part of a video | |
# https://stackoverflow.com/questions/30444768/ffmpeg-cut-first-5-seconds | |
# https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg | |
# - builds a video starting at 0:10:00.123, with duration 00:00:45.466 | |
ffmpeg -ss 0:10:00.123 -i input.mp4 -t 00:00:45.466 -c copy output.mp4 | |
# - builds a video starting at 0:01:00 and ending at 00:02:00 | |
ffmpeg -ss 0:00:01 -to 00:02:00 -i input.mp4 -c copy output.mp4 | |
# Extracting an image from a specific timeframe | |
ffmpeg -i input.mp4 -ss 00:00:07.000 -vframes 1 output.jpg | |
# References | |
# http://shelleyness.com/questions/814/ffmpeg-aplique-desfoque-no-rosto | |
# https://medium.com/abraia/basic-video-editing-for-social-media-with-ffmpeg-commands-1e873801659 | |
# http://ffmpeg.org/ffmpeg-filters.html#boxblur | |
# https://www.bugcodemaster.com/article/extract-images-frame-frame-video-file-using-ffmpeg | |
# https://gist.github.com/eyecatchup/51ebf27478889a42e07c2baeedebb76b | |
# Audio filtering | |
# afftdn filter - https://ffmpeg.org/ffmpeg-filters.html#afftdn | |
# https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg | |
ffmpeg -i original.mp4 -af "afftdn=nf=-25:nr=97:tn=1" output.mp4 | |
# highpass && lowpass | |
ffplay original.mp4 -af lowpass=2000,highpass=200 | |
ffmpeg -i original.mp4 -af lowpass=2000,highpass=200 output.mp4 | |
# Extract audio from video | |
# https://stackoverflow.com/a/36324719/823533 | |
ffmpeg -i sample.avi -ss 00:03:05 -t 00:00:45.0 -q:a 0 -map a sample.mp3 | |
# Join audio slices | |
# https://superuser.com/a/1631198 | |
ffmpeg -i "concat:p1.mp3|p2.mp3|p3.mp3" -acodec copy output.mp3 | |
# Concat video files | |
# https://stackoverflow.com/a/11175851/823533 | |
cat mylist.txt | |
file '/path/to/file1' | |
file '/path/to/file2' | |
file '/path/to/file3' | |
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4 | |
# concat reencoding | |
# http://www.ffmpeg.org/faq.html#Concatenating-using-the-concat-demuxer | |
ffmpeg -i input1.avi -qscale:v 1 intermediate1.mpg | |
ffmpeg -i input2.avi -qscale:v 1 intermediate2.mpg | |
ffmpeg -i concat:"intermediate1.mpg|intermediate2.mpg" -c copy intermediate_all.mpg | |
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.avi | |
# other solution | |
# https://stackoverflow.com/a/67840993/823533 | |
ffmpeg -i jpn_op.m4a -i eng_nop.m4a -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" final.mp4 | |
# Flip video | |
ffmpeg \ | |
-i input_file \ | |
-filter:v "hflip, vflip" \ | |
-c:a copy \ | |
output_file | |
# Add 5s delay to audio track | |
# https://gist.github.com/adrienjoly/e5b2db9c9a61f454ed08f56c32999f17 | |
ffmpeg -i input.mp4 -itsoffset 5 -i input.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy delayed.mp4 | |
# Scale | |
# https://ottverse.com/change-resolution-resize-scale-video-using-ffmpeg/ | |
# https://www.bannerbear.com/blog/how-to-crop-resize-a-video-using-ffmpeg/ | |
# https://trac.ffmpeg.org/wiki/Scaling | |
# Resize video, adding black boxes around | |
# https://stackoverflow.com/questions/46671252/how-to-add-black-borders-to-video | |
ffmpeg -i input.mp4 -filter_complex "[0]pad=w=1920:h=ih:x=96:y=0:color=black" output.mp4 | |
ffmpeg -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" | |
# Generic command for scaling - https://superuser.com/a/991412/462292 | |
ffmpeg -i input -vf "scale=w=1280:h=720:force_original_aspect_ratio=1,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output | |
# Build video with 15 seconds from image | |
# https://stackoverflow.com/questions/25891342/creating-a-video-from-a-single-image-for-a-specific-duration-in-ffmpeg | |
ffmpeg -loop 1 -i image.png -c:v libx264 -t 15 -pix_fmt yuv420p -vf scale=320:240 out.mp4 | |
# Build video from single image and audio | |
# https://superuser.com/questions/1041816/combine-one-image-one-audio-file-to-make-one-video-using-ffmpeg | |
ffmpeg -loop 1 -i ima.jpg -i audio.wav -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4 | |
# https://stackoverflow.com/questions/68153115/ffmpeg-create-mp4-from-mp3-and-jpg | |
ffmpeg -y -loop 1 -i test.png -i music.mp3 -shortest -c:v libx264 -pix_fmt yuv420p -b:v 5M -preset slow video.mp4 | |
# Add fade | |
# https://askubuntu.com/questions/1128754/how-do-i-add-a-1-second-fade-out-effect-to-the-end-of-a-video-with-ffmpeg | |
ffmpeg -i input.mp4 -vf "fade=type=in:duration=1,fade=type=out:duration=1:start_time=9" -c:a copy output.mp4 | |
# Change volume | |
# https://trac.ffmpeg.org/wiki/AudioVolume | |
ffmpeg -i input.mp3 -filter:a "volume=0.5" output.mp3 | |
# Reduce noise | |
# https://onelinerhub.com/ffmpeg/how-to-reduce-background-audio-noise-using-afftdn | |
# https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment