batch video size reduction in nested folders maintaining their source folders as destination

1

1

I have a folder containing nested folders which hold many video files with different formats. I want to reduce their size with HandBrake and maintain properties of the original videos (such as frame size, audio sampling frequency, audio bitrate, ...) and use HandBrake's default options except 2 of them (speak about them at the end) and I want the destination folder for each converted video to be its source folder with the same file name with the original file deleted after conversion.

Two HandBrake options to be varied:

  • constant quality: 35
  • x264 preset: medium

Is there any way to do it with HandBrake possibly in combination with cmd or something?

living being

Posted 2015-01-14T16:13:00.027

Reputation: 812

RF 35 is going to look quite bad. You sure you want that? – slhck – 2015-01-14T17:54:10.437

it's OK. I converted dozens of videos with this quality. – living being – 2015-01-14T19:33:30.123

Answers

1

Here is a one liner solution (run it in command line).

for /R .\test %F in (*.mov) do HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%~fF" -o "%~pF%~nF_conv.mp4

Feel free to edit the HandBrakeCLI ... piece to suite your needs (see the HandbrakeCLI guide). I have made source and destination in a way that you can play with (e.g. different extension, naming etc.). See the full reference here

Note that if you want to run it in a batch file, you need to change it to double percentage format:

for /R .\test %%F in (*.mov) do HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~pF%%~nF_conv.mp4

Mahdi

Posted 2015-01-14T16:13:00.027

Reputation: 550

OK. I'm waiting. – living being – 2015-01-14T16:45:46.380

Sorry for the formatting. I will post the my batch file later today. – Mahdi – 2015-01-16T18:14:32.533

in "HandBrakeCLI ..." piece of the code, could you modify the code so it can do what I requated in the question? I emphasize I need the same frame size. – living being – 2015-01-19T07:29:57.347

continued: for example I converted this 250-KB video file with the code above and I got different frame size: http://1drv.ms/1xn4RJP

– living being – 2015-01-19T07:45:51.350

-w and -l are perhaps the options you are looking for, I updated the above code for that. Give it a try. – Mahdi – 2015-01-19T18:29:03.477

in this way we set the width and height of the output files fixed at 1280 by 720. But we should set frame size for each file as frame size of its related input file. If you didn't get it, I can write Persian! – living being – 2015-01-19T19:43:00.353

1Sorry, I think I have not carefully read the question. I updated the answer to do what you want. It keeps the frame size, just tunes the encoder (x264) for what you want (preset to medium and quality to 35). – Mahdi – 2015-01-19T20:23:45.590

It doesn't keep the frame size. If you run the code for the video file I uploaded, you can see the input file frame size is 368 by 272, while the output file frame size is 354 by 272. – living being – 2015-01-20T09:20:35.017

1If you look at the converted videos, you do not see any cropping though. Handbrake auto crops to remove dead pixels. Nonetheless, if you need your w and h as is, use --crop, as I have added to the answer. – Mahdi – 2015-01-20T15:58:12.993

Everything in order! Just a little issue: audio sample rate and bit rate varied. How can we keep them untouched? – living being – 2015-01-20T16:46:03.043

1

I think your audio settings are also altered when you set your quality/profile. You can copy audio as is using -E copy:* See https://trac.handbrake.fr/wiki/CLIGuide and find out what you need.

– Mahdi – 2015-01-20T16:50:02.683

@livingbeing if you find a comment useful, please vote it up. – Mahdi – 2015-01-20T17:28:38.860

Don't be so picky compatriot! – living being – 2015-01-20T17:36:11.200