1.

Solve : HandbrakeCLI: use same target file name as source file name?

Answer»

Hi,
I'm using Handbrake to encode video file. To encode with Handbrake I have to tell Handbrake where it finds the source file and what's the name of the encoded file.
e.g. HandbrakeCLI.exe -i f:/RecordedTV/Hangover.TS -o f:/RecordedTV/Hangover.mkv
Hangover.TS is the source file
Hangover.mkv is the encoded file
Next time I probably will encode Hangover2.TS
So I have to use
HandbrakeCLI.exe -i f:/RecordedTV/Hangover2.TS -o f:/RecordedTV/Hangover2.mkv

So how can I read the file name (here it is e.g. "Hangover" or "Hangover2") and use this file name in a variable way?

I hope you all understand what I mean :-)
In a batch file variables have percent signs before and after like this %filename% so you could do something like this

Code: [Select]set filename-Hangover
HandbrakeCLI.exe -i f:/RecordedTV/%filename%.TS -o f:/RecordedTV/%filename%.mkv
You can use the SET command to assign a variable value like above or SET /P to ASK for a filename like this

Code: [Select]set /p filename="Please input the file name? "
Or you could pass the name as a replaceable parameter to the batch from the command line like this

Encode.bat:

Code: [Select]set filename=%~1
HandbrakeCLI.exe -i f:"/RecordedTV/%filename%.TS" -o f:"/RecordedTV/%filename%.mkv"
Command line: Encode.bat Hangover or Encode.bat "Name with spaces"








Quote from: Salmon Trout on September 19, 2015, 12:01:30 PM

In a batch file variables have percent signs before and after like this %filename%
There are some others with exclamation marks but we don't need to go there right now.
Sorry but you didn't understand what I mean (ENGLISH is not my first language).
I use a media center software with infrared remote control. No keyboard. Inside this software I press a button to start handbrake. By pressing this button this commands will be send:
handbrakecli.exe -i f:/videos -o f:/videos/movie.mkv
"-i" means INPUT. "-o" means OUTPUT. So handbrake is searching for a TS file inside the folder "videos" and then encodes to mkv format. THe encoded movie gets the name "movie.mkv". That means: everytime I start an encoding process the mkv movie gets the name "movie.mkv". That's bad.
ALso I can send this

handbrakecli.exe -i f:/videos/hangover.ts -o f:/videos/hangover.mkv
Thats means: handbrake only encodes the movie hangover.ts to hangover.mkv

Now I need an automatically detection of the movie name.

Something like this:
handbrakecli.exe -i f:/videos/%filename%.ts -o f:/videos/%filename%.mkv

But at this point the variable %filename% is empty. So: how can I prior to that store the the movie name in the variable %filename%.

I think I need a batch that looks inside the folder "videos" for a movie in TS format and when there is a movie then the movie name needs to be STORED in the variable %filename%. But how can I acchieve this?

olli14
The FOR command can list all the files in the directory.
Code: [Select]FOR %%G in (*.ts) do echo %%G[code]To expand on Squashman's code:

Code: [Select]@echo off
FOR %%G in ("f:\videos\*.ts") do "handbrakecli.exe" -i "%%~G" -o "%%~nG.mkv"It's working great. Thanks.


Discussion

No Comment Found