Code ghép sub, logo (filter) vào Video:
ffmpeg -i input.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=10:10:enable='between(t\,1\,900)' [tmp], [tmp][1:v]overlay=20:20:enable='between(t\,1800\,3200)',subtitles=sub.srt" -map "[a4]" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1150k -profile:v main -level 3.1 -acodec libmp3lame -b:a 96k -ar 48000 -preset superfast output_sub_logo.mp4
Code ghép 1 ảnh 1 mp3:
ffmpeg -loop 1 -i image.png -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output_1_image_1_mp3.mp4
Code ghép 1 ảnh 1 mp3 (hàng loạt file mp3):
@ECHO OFF Setlocal EnableDelayedExpansion set INPUT=E:\in set OUTPUT=E:\out for %%i in ("%INPUT%\*.mp3") DO ffmpeg -loop 1 -i image.png -i "%%i" -c:v libx264 -c:a aac -b:v 1400k -b:a 128k -shortest -preset superfast "%OUTPUT%/%%~ni.mp4" pause
Code ghép 1 ảnh nhiều mp3:
dir /b "E:\in\*.mp3" > list.txt ffmpeg -loop 1 -framerate 5 -i image.png -f concat -i list.txt -c:v libx264 -pix_fmt yuv420p -c:a copy -shortest -preset superfast output_1_image_multi_mp3
Code ghép nhiều ảnh 1 mp3:
ffmpeg -y -framerate 1/10 -start_number 1 -i E:/in_image/photo3-%04d.png -i E:/in_music/musichehe.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p -c:a aac -strict experimental -shortest output_multi_image_1_mp3.mp4
Code nhiều ảnh nhiều mp3:
(for %i in ("E:\in\*.mp3") do @echo file '%i') > mylist.txt ffmpeg -y -framerate 1/10 -i E:/img/image-%03d.jpg -f concat -safe 0 -i mylist.txt -c:v libx264 -r 30 -pix_fmt yuv420p -c:a aac -strict experimental multi_all.mp4
Code Add Logo/Watermark vào Video:
ffmpeg –i video.mp4 -i logo.png -filter_complex "overlay=10:10" -preset ultrafast top_left.mp4 ffmpeg –i video.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-10:10" -preset ultrafast top_right.mp4 ffmpeg –i video.mp4 -i logo.png -filter_complex "overlay=10:main_h-overlay_h-10" -preset ultrafast bottom_left.mp4 ffmpeg –i video.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-10/2:main_h-overlay_h-10/2" -preset ultrafast bottom_right.mp4 ffmpeg -i video.mp4 -i logo.png -filter_complex "overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2" -preset ultrafast center.mp4
Code cắt video thành nhiều đoạn bằng nhau:
ffmpeg -i "{input}.*" -c copy -map 0 -segment_time 00:10 -f segment "{output}_%2d.mp4"
Code thủ nhỏ 1 lớn vieo làm 4 video nhỏ:
ffmpeg -i "input.mp4" -filter_complex " nullsrc=size=1280x720 [base]; [0:v] setpts=PTS-STARTPTS, scale=640x360 [upperleft]; [0:v] setpts=PTS-STARTPTS, scale=640x360 [upperright]; [0:v] setpts=PTS-STARTPTS, scale=640x360 [lowerleft]; [0:v] setpts=PTS-STARTPTS, scale=640x360 [lowerright]; [base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][upperright] overlay=shortest=1:x=640 [tmp2]; [tmp2][lowerleft] overlay=shortest=1:y=360 [tmp3]; [tmp3][lowerright] overlay=shortest=1:x=640:y=360, setdar=16:9" "output_4video.mp4"
Code cắt toàn bộ Video thành 2 hoặc 3 đoạn:
@echo off for %%i in (*.mp4) do ( ffmpeg -i "%%~i" -vcodec copy -acodec copy -ss 00:00:00 -t 00:00:05 "D:\out\%%~ni_1.mp4" ffmpeg -i "%%~i" -vcodec copy -acodec copy -ss 00:00:05 -t 00:00:10 "D:\out\%%~ni_2.mp4" ffmpeg -i "%%~i" -vcodec copy -acodec copy -ss 00:00:10 "D:\out\%%~ni_3.mp4" ) pause
Code xoay Video:
ffmpeg -i in.mp4 -vf "transpose=1" out.mp4 ///////////////////////////////////////// 1 = 90Clockwise (theo chiều kim đồng hồ) 2 = 90CounterClockwise (ngược chiều kim đồng hồ)
Code làm xiên Video:
ffmpeg -y -i "input.mp4" -loop 1 -i "nen.jpg" -filter_complex "[0:a]atempo=1.0,aecho=0.4:0.66:2:0.2, chorus=0.5:0.9:50|80:0.4|0.42:0.25|0.4:2|1.4, firequalizer=gain_entry='entry(90,0); entry(400, -4); entry(1000, -6); entry(2000, 0)',pan=stereo|c0<c0+0*c1|c1<c0+0*c1,aeval=val(0)|val(1),volume=2; [0:v]setpts=PTS/1.0,scale=395:333,pad="iw+4:ih+4:2:2:0x00000000",perspective=00:-130:440:00:00:445:440:360 [v1]; [1:v][v1]overlay=shortest=1:x=438:y=128,setdar=16/9" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1400k -profile:v main -level 3.1 -acodec libmp3lame -b:a 128k -ar 44100 -metadata title="" -metadata artist="" -metadata album_artist="" -metadata album="" -metadata date="" -metadata track="" -metadata genre="" -metadata publisher="" -metadata encoded_by="" -metadata copyright="" -metadata composer="" -metadata performer="" -metadata TIT1="" -metadata TIT3="" -metadata disc="" -metadata TKEY="" -metadata TBPM="" -metadata language="eng" -metadata encoder="" -threads 0 -preset superfast "output_xien.mp4"
Code ghép âm thanh vào video bằng FFMpeg:
ffmpeg -i video_input.mp4 -i audio_input.mp3 -c copy -map 0:v -map 1:a output.mp4
Code xóa âm thanh trong Video:
//Tách nhạc ra khỏi Video: ffmpeg -i input.mp4 -vn -acodec copy output44.aac //Chuyển nhạc thành mp3: ffmpeg -i output44.aac -acodec libmp3lame -ab 128k output.mp3 //Xóa nhạc trong video: ffmpeg -i input.mp4 -vcodec copy -an output.mp4 //Ghép nhạcc với video: ffmpeg -i output.mp4 -i output.mp3 -c:v copy -c:a aac -strict experimental output.mp4
Và nhiều code ffmpeg choYoutube nữa mình sẽ tiếp tục cập nhật…