Jump to content

Post Processing - (Emby crash concat files/extract Closed Captions/remux mkv)


Fratopolis

Recommended Posts

Fratopolis

Well I had this in the general section when it pertained to a different issue but it expanded to this so I figured I'd repost for those who may be interested. Most of this is being added to the actual emby application out of the box except when recordings are split into two files due to server restart or crash. anyway here is the batch script for my windows post processing for anyone interested.

 

echo OFF
embydel=
embyloc=

REM 	(Set ffmepg location)
for /r %APPDATA%\Emby-Server\ffmpeg\ %%a in (*) do if "%%~nxa"=="ffmpeg.exe" set ffmpeg=%%~dpnxa

REM 	(Change Directory to that where the recordings are located)
%~d1
CD "%~dp1"

REM 	(This will concat two recording files that were supposed to be one file but split because of EMBY restart
REM 		and remove files no longer needed once complete if all is successful)
for /r %%F in (*.ts) do (
	if exist "%%~dpnF - 1.ts" (
	%ffmpeg% -i "concat:%%~nxF|%%~nF - 1.ts" -c copy output.ts
	if not errorlevel 1 if exist "output.ts" del /q "%%~nF - 1"* "%%~nxF"
	ren output.ts "%%~nxF"
	)
)

REM 	(Will extract Closed Captions as srt, and remux into mkv container for better direct stream support)
REM 	(CC extraction must happen before converting to mkv or timestamps will not be correct)
REM 	(Also, for some reason I cannot get CC extraction to happen if the filename contains an apostrophe in it
REM 		possibly due to how the ffmpeg filter lavfi processes arguments if you figure this out post the fix)
for /r %%F in (*.ts) do (
	%ffmpeg% -f lavfi -i "movie='%%~nxF'[out0+subcc]" -map s "%%~nF.eng.srt"
	%ffmpeg% -i "%%F" -c:v copy -c:a copy "%%~nF.mkv"
	if not errorlevel 1 if exist "%%~dpnF.mkv" set embydel=yes
	set embyloc="%%F"
)
REM 	(Check if .ts file is in use and if so keep checking until free. Once the file is no longer in use delete
REM 		the file only if the remux to mkv was successful)
:locked
for /r %%F in (*.ts) do (
	set locked=
	move /y "%%~dpnxF" "%%~dpnxF" >nul 2>nul && (set locked=0) || (set locked=1)
	timeout 3
)
if "%locked%"=="1" (GOTO :locked)
if %embydel%==yes del /q %embyloc%

Edited by Fratopolis
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...