Skip to content

Instantly share code, notes, and snippets.

@jamietre
Last active September 16, 2023 01:14
Show Gist options
  • Save jamietre/9776ec821ee2d410989ff89bddd6571b to your computer and use it in GitHub Desktop.
Save jamietre/9776ec821ee2d410989ff89bddd6571b to your computer and use it in GitHub Desktop.
Batch file for transcoding MVC 3D streams in an MKV container
@ECHO OFF
rem usage: transcodemvc input output [-r] [-s]
rem -r will re-use a previously extracted elementary stream from the temp file location
rem -s will swap eyes
set TEMP_DIR=c:\temp\recodemvc
set TEMP_FILE=%TEMP_DIR%\temp_mvc.264
set PROFILE=high
set SWAP=false
rem 1 = slowest/best, 7 = fastest/worst
set USAGE=3
set MIN_BITRATE=20000
set MAX_BITRATE=35000
rem parse args
set INFILE=%1
set OUTFILE=%2
SHIFT & SHIFT
SET REUSE=
:loop
IF "%1" neq "" (
IF "%1" == "-r" (
SET REUSE=1
SHIFT
GOTO :loop
) ELSE IF "%1" == "-s" (
SET SWAP=1
SHIFT
GOTO :loop
) ELSE (
SHIFT
GOTO :loop
)
)
if not exist %INFILE% (
echo "input file doesn't exist"
goto :finished
)
if exist %OUTFILE% (
echo "output file already exists; delete it first"
goto :finished
)
echo profile=%PROFILE%; USAGE=%USAGE%; MIN_BITRATE=%MIN_BITRATE%; MAX_BITRATE=%MAX_BITRATE%
if "%REUSE%" == "1" (
echo reusing cached elementary stream
goto :reuse
)
set TEMP_LEFT=%TEMP_FILE%.left.264
set TEMP_RIGHT=%TEMP_FILE%.right.264
if not exist %TEMP_DIR% mkdir "%TEMP_DIR%"
if exist %TEMP_FILE% del "%TEMP_FILE%" >nul 2>&1
if exist %TEMP_LEFT% del "%TEMP_LEFT%" >nul 2>&1
if exist %TEMP_RIGHT% del "%TEMP_RIGHT%" >nul 2>&1
if exist %TEMP_FILE%.created del "%TEMP_FILE%.created" >nul 2>&1
echo -- Extract elementary stream from mkvextract
echo.
mkvextract -f tracks %INFILE% 0:"%TEMP_FILE%" --fullraw || goto :error
echo . >%TEMP_FILE%.created
echo Temporary file created; you can use "-r" option to start from this point.
:reuse
if not exist %TEMP_FILE% (
echo There's no temporary file "%TEMP_FILE%"... did you use -R argument erroneously?
goto :finished
)
set ADDL_OPTS=
if "%SWAP%" == "1" (
set ADDL_OPTS=-swaplr
)
echo -- Begin transcoding
FRIMDecode64 -i:mvc "%TEMP_FILE%" -tab -o - | FRIMEncode64 -tab 2 -i - -o:mvc "%TEMP_FILE%.recoded" -w 1920 -h 1080 -sw -profile %PROFILE% -level 4.1 -vbr %MIN_BITRATE% %MAX_BITRATE% -cpbsize 3372 -l 6 -gop 24 4 0 O -maxdpb 4 -u %USAGE% %ADDL_OPTS%
if %errorlevel% neq 0 exit /b %errorlevel%
rem Original implementation: can't swap eyes, as far as I know
rem FrimTranscode64 -i:mvc "%TEMP_FILE%" -o:mvc "%TEMP_FILE%.recoded" -sw -profile %PROFILE% -level 4.1 -vbr 20000 35000 -cpbsize 3372 -l 6 -gop 24 4 0 O -maxdpb 4 -u %USAGE%
mkvmerge -o %OUTFILE% "%TEMP_FILE%.recoded" --no-video %INFILE% || goto :error
goto :finished
:error
echo Failed with error %errorlevel%
exit /b %errorlevel%
:finished
echo Success! Created "%OUTFILE%"
@kadrim
Copy link

kadrim commented Mar 13, 2021

BTW: using this on a very old Samsung UE6100 (2012) in combination with a equally old Bluray 3D player from samsung. just have to remux the files to m2ts with

  1. h264
  2. mvc
  3. audio or whatever

the order for the streams seems to be important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment