Last active
October 9, 2018 08:38
-
-
Save riverscn/42046c4002bb523508245d813a6931d6 to your computer and use it in GitHub Desktop.
Use FFMPEG to mix video and audio. extend video length to match audio length and add transparent watermark.
This file contains hidden or 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
@ECHO OFF | |
CHCP 65001>nul | |
SETLOCAL EnableDelayedExpansion | |
SET /p iv=Video File: | |
SET iv="%iv%" | |
FOR %%i in (%iv%) DO SET filename=%%~ni-mixed.mp4 | |
ECHO Output:%filename% | |
SET filename="%filename%" | |
SET /p ia=Audio File: | |
SET ia="%ia%" | |
SET ATTR=height | |
SET /a count=0 | |
FOR /F "delims== tokens=1 " %%a IN ( | |
'ffprobe -v quiet -show_streams -select_streams v:0 %iv%') DO ( | |
IF %%a==%ATTR% ( | |
SET /a find=count | |
) | |
SET /a count+=1 | |
) | |
SET /a count=0 | |
SET RESULT=None | |
FOR /F "delims== tokens=2 " %%a IN ( | |
'ffprobe -v quiet -show_streams -select_streams v:0 %iv%') DO ( | |
SET /a count+=1 | |
IF !count! EQU !find! ( | |
SET RESULT=%%a | |
) | |
) | |
ECHO Height: %RESULT% | |
SET bitrate=1000k | |
IF %RESULT% LSS 1080 ( | |
SET bitrate=800k | |
) | |
IF %RESULT% LSS 720 ( | |
SET bitrate=500k | |
) | |
ECHO Bitrate: %bitrate% | |
PAUSE | |
ffmpeg -i watermark.png -y -v quiet -vf scale=-1:%RESULT%*0.2 scaled.png | |
ffmpeg -y -i %iv% -i %ia% -i scaled.png -filter_complex "[0]trim=0:1[hold];[0][hold]concat[extended];[extended][0]overlay[final];[2]lut=a=val*0.5[wm];[final][wm]overlay=x=(main_w-overlay_w)/10:y=(main_h-overlay_h)/10" -c:v libx264 -b:v %bitrate% -pass 1 -an -f mp4 NUL && ^ | |
ffmpeg -y -i %iv% -i %ia% -i scaled.png -map 0:v:0 -map 1:a:0 -filter_complex "[0]trim=0:1[hold];[0][hold]concat[extended];[extended][0]overlay[final];[2]lut=a=val*0.5[wm];[final][wm]overlay=x=(main_w-overlay_w)/10:y=(main_h-overlay_h)/10" -c:v libx264 -b:v %bitrate% -pass 2 -c:a copy %filename% | |
DEL *.log | |
DEL *.mbtree | |
PAUSE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment