Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save eladkarako/6efe04bfdf9fc1b3d25313f08e610960 to your computer and use it in GitHub Desktop.

Select an option

Save eladkarako/6efe04bfdf9fc1b3d25313f08e610960 to your computer and use it in GitHub Desktop.
ffmpeg encode to h264 aac and embed a .srt subtitle SDH file with same name. yet another encoder. support one after the other encoding. intel hardware encoding.
::@echo off
chcp 65001 1>nul 2>nul
goto LOOP
::###########################################################################################
::# - drag and drop any amount of files. they will be processed one after the other. #
::# - for each media file (foo.mkv) the script assumes there is '.srt' file with same name. #
::# - result will be placed under 'output' folder. #
::# #
::###########################################################################################
::-----------------------------------------------------------------
:PROCEDURE_FILE
setlocal
set "ARGS="
set ARGS=%ARGS% -threads 2
set ARGS=%ARGS% -hide_banner
set ARGS=%ARGS% -strict experimental
set ARGS=%ARGS% -err_detect ignore_err
set ARGS=%ARGS% -nostdin
set ARGS=%ARGS% -y
set ARGS=%ARGS% -probesize 1200M
set ARGS=%ARGS% -analyzeduration 1200M
set ARGS=%ARGS% -thread_queue_size 16384
set ARGS=%ARGS% -i "file:%~nx1"
set ARGS=%ARGS% -i "file:%~n1.srt"
set ARGS=%ARGS% -threads 2
set ARGS=%ARGS% -map "0:v:0"
set ARGS=%ARGS% -map "0:a:0"
set ARGS=%ARGS% -map "1:s:0"
set ARGS=%ARGS% -map_chapters "-1"
set ARGS=%ARGS% -map_metadata "-1"
set ARGS=%ARGS% -flags "+cgop+loop-unaligned-output_corrupt"
set ARGS=%ARGS% -fflags "+genpts+autobsf+discardcorrupt+igndts+ignidx"
set ARGS=%ARGS% -avoid_negative_ts make_zero
set ARGS=%ARGS% -use_wallclock_as_timestamps 1
set ARGS=%ARGS% -max_muxing_queue_size 9999
set ARGS=%ARGS% -bufsize 8M
set ARGS=%ARGS% "-c:v" h264_qsv
::set ARGS=%ARGS% -vf "format=pix_fmts=yuv420p"
set ARGS=%ARGS% -global_quality 20
set ARGS=%ARGS% -look_ahead 1
set ARGS=%ARGS% -look_ahead_depth 40
set ARGS=%ARGS% -preset veryslow
::set ARGS=%ARGS% "-profile:v" baseline -level "3.0"
::set ARGS=%ARGS% "-profile:v" high -level "4.1"
::set ARGS=%ARGS% "-bf:v" 0
set ARGS=%ARGS% "-bf:v" 4
::set ARGS=%ARGS% -refs 2
set ARGS=%ARGS% -refs 4
set ARGS=%ARGS% "-c:a" aac "-b:a" 192k -ac 2 -ar 48000
set ARGS=%ARGS% "-metadata:s:a:0" language=eng
::set ARGS=%ARGS% "-metadata:s:a:0" title="English"
set ARGS=%ARGS% "-metadata:s:a:0" handler_name="English"
::set ARGS=%ARGS% "-c:s" mov_text
set ARGS=%ARGS% "-c:s" srt
set ARGS=%ARGS% "-metadata:s:s:0" language=eng
set ARGS=%ARGS% "-metadata:s:s:0" title="English (SDH)"
set ARGS=%ARGS% "-metadata:s:s:0" handler_name="English"
set ARGS=%ARGS% "-disposition:s:0" hearing_impaired
set ARGS=%ARGS% -metadata language=eng
set ARGS=%ARGS% -metadata handler_name="English"
set ARGS=%ARGS% -movflags "+faststart"
::set ARGS=%ARGS% -to "00:00:05.000"
::set ARGS=%ARGS% "file:./output/%~n1.mp4"
set ARGS=%ARGS% "file:./output/%~n1.mkv"
title %~n1
pushd "%~dp1"
mkdir "%CD%\output" 1>nul 2>nul
start "" /MAX /ABOVENORMAL /WAIT /B "ffmpeg.exe" %ARGS%
popd
endlocal
goto :eof
::-----------------------------------------------------------------
::-----------------------------------------------------------------
:LOOP
if ["%~1"] equ [""] ( goto END )
call :PROCEDURE_FILE "%~1"
shift
goto LOOP
::-----------------------------------------------------------------
::-----------------------------------------------------------------
:END
pause
exit /b 0
::-----------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment