I've always wanted to be able to write a CMD line script where I could reencode a bunch of episodes at once using the same script. No matter how many times I tried it, it never worked.
I just stumbled upon a very short, simple video which shown how to import a folder of MKV files into Handbrake and set them to reencode. Super easy! BUT... I don't see any way to resize the videos (AVS) which is a bugger because a lot of these episodes are like full HD 1920x1080 and I don't need that. We're talk'n about 25 minute comedy episodes and the file sizes are like from 1.5 - 4 Gigs! Ridiculous! So, using Handbrake, I can very easily reencode them all using the built in .x264. But, I don't see any resizing options. I don't suppose that Handbrake can somehow incorporate some AVS script, by any chance...? I mean the CMD line I would use is super simple, something like this:
F:\EXECUTABLES\BD-RBV06122\BD_Rebuilder\Tools\x264L.exe "C:\x\test.avs" --preset veryfast --crf 22 --output "C:\x\Encode.mkv" Where test.avs is:
DirectshowSource("C:\x\00000.mkv")
Spline36Resize(640, 360)
ConvertToYV12()
So, I can do them one at a time using this script, but it would REALLY be nice if there was a way to batch encode them all at once. The Handbrake does the x264 part just fine, but I need to bring those sizes down about 2/3.
Any suggestions without getting TOO complicated?
Thanks kindly!
+ Reply to Thread
Results 1 to 15 of 15
-
-
You could just use a batch file that builds an AviSynth script for each file in the folder and encodes it?
Code:for %%F in (*.mkv) do ( echo a = LWlibavAudioSource^(^"%%F^", cache=false^) >script.avs echo v = LWlibavVideoSource^(^"%%F^", cache=false^) >>script.avs echo AudioDub^(v,a^) >>script.avs echo Spline36Resize^(640, 360^) >>script.avs echo ConvertToYV12^(^) >>script.avs REM encoding line goes here... )
Code:md New for %%F in (*.mkv) do ( ffmpeg -i "%%~nxF" -vf scale=640:-4 -c:v libx264 -c:a copy "New\%%~nxF" )
Last edited by jagabo; 21st May 2021 at 09:38.
-
If you only want to process some file in a folder here's an ffmpeg batch file onto which you can drag/drop one or more video files. Again, the new files will be in a sub-folder called New.
Code:PUSHD %~dp0 if [%1]==[] goto :eof :loop mkdir "%~dp1New" ffmpeg -i "%~dpnx1" -vf scale=640:-4 -c:v libx264 -c:a copy "%~dp1New\%~nx1" shift if not [%1]==[] goto loop
-
Thank you kindly jagabo for both replies and the scripts. I will try it because I would love to run script that would work, but I've always gotten errors in the past no matter how carefully I copy suggested scripts. But, I will give it a go. Also, I found a simple freeware program that is basically a GUI for ffmpeg called WinFF that has drag and drop and does resizing. I haven't checked it out thoroughly yet, but on the flipside of Handbrake, if it also allows me to customize the encode as well as resize, then that should do it.
Otherwise though, I really would like to try the scripts you gave me, thanks!
***EDIT
Also, this script:
Code:
for %%F in (*.mkv) do (
echo a = LWlibavAudioSource^(^"%%F^", cache=false^) >script.avs
echo v = LWlibavVideoSource^(^"%%F^", cache=false^) >>script.avs
echo AudioDub^(v,a^) >>script.avs
echo Spline36Resize^(640, 360^) >>script.avs
echo ConvertToYV12^(^) >>script.avs
REM encoding line goes here...
)
Does it also allow me to control the reencoding parameters like 'veryfast' and 'CRF' or does it just resize. It would be nice to be able to do both, thus my initial interest in the batch encoding of Handbrake. That way I can reduce the resolution and maybe lighten up the encoding since I would have to reencode using AVS anyway.Last edited by Lathe; 22nd May 2021 at 00:19. Reason: More Stuff...
-
-
I think it will do pretty well. I've done one 1080 file > 720, and I believe the preset is Veryfast CRF 22, which is about right. The resulting file came out to less than half the size, from 973 Megs to 384, which is pretty good. I'm doing another 1.23 Gig file now. Really I don't need the resolution to be that high (720) I believe that there is another preset at 576p25 I'm guessing the 25 is the framerate. The 720p30 I suppose would be 30. Don't really know why except IIRC some television encodes are at a framerate of 30, and I believe is it European or PAL encoding is at 25, I don't really remember. I don't suppose that it really makes any difference if I am simply going to play these back on my computer, right? They have a separate section for 'Mastroyka' (don't know why the separate section since the ones I'm trying now are simply MP4) But under the MKV section I could even try the 576 hevc. I'm guessing it would yield a smaller file size. But, IDK if the processing time would take any longer.
So, these presets I THINK will be sufficient, but of course ALWAYS being the customizerit does get my curiosity when you say that I can 'Tweak the Settings' I don't see how I can do anything else CMD line or otherwise other than choose the presets given.
This program should be great, thanks again mate! -
Yep, Vidcoder works perfectly! Thank you jagabo though for the script. If I do more demanding stuff later on, I will definitely keep that on file!
Again, these are just episodes of a comedy / game show (Whose Line Is It Anyway) so, not super critical. But, I just ran a 1.23 Gig file through using the 480p30 and WOW, the resulting file was 132 Megs and looks great! Done and Done, thanks gentlemen! -
And yes, I did find the additional settings rather cryptically under the Windows tab
-
Hi Lathe,
I had the same problem and here's how I solved it.
I opened one of the files to edit with the HandBrake graphical interface, after which I calibrated the various settings. Then I saved the Preset, naming it, for example "My_preset"; so I exported this preset as a .json file (saving it in the HandBrake installation folder).
After that I compiled a simple batch file:
md "Folder"
for % x in (*.mkv) do C:\HandBrake\HandBrakeCLI -i "% x" -o "Folder\% x" --preset-import-file C:\HandBrake\My_preset.json
and I ran it in the folder where I had the files to edit (in my case, the new files will have the same name as the original files and will go into the "Folder" subfolder; I could have changed the names using the "% X" variable, thus avoiding having to create a subfolder)
Easier to do than to say -
If you want to customize the x264 settings you can add the settings to the ffmpeg line:
Code:ffmpeg -i "%~dpnx1" -vf scale=640:-4 -c:v libx264 -preset veryfast -crf 22 -c:a copy "%~dp1New\%~nx1"
Code:F:\EXECUTABLES\BD-RBV06122\BD_Rebuilder\Tools\x264L.exe "C:\x\test.avs" --preset veryfast --crf 22 --output "C:\x\Encode.mkv"
Code:mkdir New for %%F in (*.mkv) do ( echo a = LWlibavAudioSource^(^"%%F^", cache=false^) >script.avs echo v = LWlibavVideoSource^(^"%%F^", cache=false^) >>script.avs echo AudioDub^(v,a^) >>script.avs echo Spline36Resize^(640, 360^) >>script.avs echo ConvertToYV12^(^) >>script.avs F:\EXECUTABLES\BD-RBV06122\BD_Rebuilder\Tools\x264L.exe "Script.avs" --preset veryfast --crf 22 --output "%~dpFNew\%~nxF" )
-
Similar Threads
-
Batch remove subtitles from mkv files
By rumblylwc in forum SubtitleReplies: 19Last Post: 26th Feb 2024, 07:15 -
Batch convert mkv files to different frame rate
By Nico Darko in forum Video ConversionReplies: 22Last Post: 18th Nov 2020, 10:04 -
Cropping Batch Files in Handbrake
By buddyboy101 in forum Newbie / General discussionsReplies: 1Last Post: 9th Mar 2019, 19:54 -
Batch Adding Chapters to Multiple MKV Files
By Shady in forum Newbie / General discussionsReplies: 15Last Post: 2nd Jun 2018, 09:34 -
Batch Remove Cover From Multiple MKV Files
By MohamedYousri in forum Newbie / General discussionsReplies: 4Last Post: 5th Oct 2017, 13:27