I am trying to setup a simple batch file to use handbrake to compress videos. I had Handbrake installed and saw that I needed to install HandbrakeCLI separately. I downloaded HandBrakeCLI.exe
and placed it on C:\
. I then made a preset and set it as the default using the GUI
. I then call handbrake
like so:
@echo off
for %%f in (*.mpg) do (
C:\HandBrakeCLI -i 'C:\Users\rv\Desktop\Newfolder\%%f' -o 'C:\encode\%%f.mp4'
)
pause
I get the following error telling me the file type is unrecognized:
[10:19:30] dvd: not a dvd - trying as a stream/file instead
[10:19:30] hb_stream_open: open 'C:\Users\rv\Desktop\Newfolder\126_812-714A_812-713_111914_san.mpg'
failed
[10:19:30] scan: unrecognized file type
[10:19:30] libhb: scan thread found 0 valid title(s)
No title found.
Any thoughts on why the command line version is suddenly unable to open the file? The same file is able to be opened in the GUI
and be converted.
I tried reinstalling everything and deleting the preset folder, even though that doesn't seem like the issue.
Update: Here is the final code that works for me.
@echo off
set /A count_complete = 0
set /A count_total = 0
pushd %~dp0
for /R %%f in (*.mp2, *.mpg, *.vob, *.avi, *.wmv, *.mov, *.m4v, *.mpeg, *.mp4) do (
set /A count_total+=1
)
for /R %%f in (*.mp4) do (
echo Count is currently %count% of %count_total%
C:\HandBrakeCLI --preset-import-gui C:\Users\xxx\Desktop\customencode.json -Z "CustomCompress" -i "%%f" -o "%%~dpf%%~nf_conv.mp4"
if exist "%%~dpf%%~nf_conv.mp4" (
del "%%f"
ren "%%~dpf%%~nf_conv.mp4" "%%~nf.mp4"
set /A count_complete+=1
)
)
for /R %%f in (*.mp2, *.mpg, *.vob, *.avi, *.wmv, *.mov, *.m4v, *.mpeg) do (
echo Count is currently %count% of %count_total%
C:\HandBrakeCLI --preset-import-gui C:\Users\xxxxx\Desktop\customencode.json -Z "CustomCompress" -i "%%f" -o "%%~dpf%%~nf_conv.mp4"
if exist "%%~dpf%%~nf_conv.mp4" (
del "%%f"
ren "%%~dpf%%~nf_conv.mp4" "%%~nf.mp4"
set /A count_complete+=1
)
)
popd
echo Count is: %count% out of %count_try% attempted.
pause
I needed to use double quotes instead of single. Like this: