Skip to content

Instantly share code, notes, and snippets.

@emcodem
Created February 21, 2025 16:33
Show Gist options
  • Save emcodem/0329344dc09f9fa35a6b4428e0f291b8 to your computer and use it in GitHub Desktop.
Save emcodem/0329344dc09f9fa35a6b4428e0f291b8 to your computer and use it in GitHub Desktop.
transcodeeverythingv2.bat
@echo off
setlocal enabledelayedexpansion
SET FFMAPS=
SET FPSFILTER=
:: Check if the file has a video stream
ffmpeg -v error -i "%1" -vframes 1 -map 0:v -f null - >nul 2>&1
if %ERRORLEVEL%==0 (
SET FFMAPS=!FFMAPS! -map 0:v
echo Video stream detected. FFMAPS: !FFMAPS!
::TODO: SET FPS FILTER ONLY FOR VFR MATERIAL? Basically we want to avoid issues with vfr at the transcoder
SET FPSFILTER=-vf fps=50
) else (
echo Video found
)
:: Check for up to 16 audio streams (0:a:0 to 0:a:15)
:: This checks if the stream can be actually decoded, ffmpeg can easily fail with map 0:a or similar, initiator for this was iphone 16 spatial apac audio
for /L %%i in (0,1,15) do (
ffmpeg -loglevel quiet -i "%1" -t 0.1 -map 0:a:%%i -f null - 2>&1 > nul
if !ERRORLEVEL!==0 (
SET FFMAPS=!FFMAPS! -map 0:a:%%i
echo Audio %%i stream detected. FFMAPS: !FFMAPS!
) else (
echo Audio %%i stream not found.
goto :transcode
)
)
:transcode
echo Proceeding with transcoding...
if "!FFMAPS!"=="" (
echo No audio or video streams detected.
goto endwitherror
)
SET FFCMD=ffmpeg -y -i %1 -vcodec mjpeg -pix_fmt yuvj422p -vb 200M -vsync cfr -g 1 -acodec pcm_s24le !FFMAPS! !FPSFILTER! -aspect 16:9 %1.avi
echo !FFCMD!
!FFCMD!
goto endsuccess
:endsuccess
echo "All Finished with success"
exit /b 0
:endwidtherror
pause
exit /b 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment