Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
13th March 2019, 05:58 | #1 | Link |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
VERY simple batch x264 script for all files in folder...
Okay, I promise I've been searching and trying to find a simple script just to take a bunch of tele episodes that I want to reduce in size and re-encode them all. It's been about 2 hrs and I keep coming upon stuff that is WAY more complex than I need.
Here is the simple script I want to use for all the MKV files in a folder that are roughly about 500 megs each and I wish to reduce them to anywhere around 50-150 megs, which this script has been generating for the individual files: F:\EXECUTABLES\BD-RBV05023\BD_Rebuilder\Tools\x264L.exe "C:\x\00000.mkv" --preset veryfast --crf 24 --output "C:\x\Encode.mkv" I'm just using the x264.exe that JDobbs has in his BDRB folder. Now, the closest I got was some guy gave a script similar to this to 'automate' it so that it would encode all the files in a folder and place the resulting files in another folder. I tried running it, but since I do not understand all the commands, of course I got errors. here is what he posted, or something like this: FOR /R "C:\input-folder" %%i IN ("*.*") DO "C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "C:\input-folder\%%~ni.avi" -t 1 -c 1 -o "D:\output-folder\%%~ni.mkv" -f mkv --strict-anamorphic -e x264 -S 160 -2 -a 1 -E lame -6 stereo -R Auto -B 112 -D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1 Now, he is using Handbrake, which I don't need, so I substituted my 264.exe file instead. I also did not need all those encoding parameters, so I TRIED to take what I THOUGHT was unneeded out (clearly I didn't do it right ) I sort of ended up with this: FOR /R "D:\x" %% IN ("*.*") DO "F:\EXECUTABLES\BD-RBV05023\BD_Rebuilder\Tools\x264L.exe" "D:\x\%%~ni.mkv" --output "D:\output-folder\%%~ni.mkv" --preset veryfast --crf 24 -v 1 But, of course it didn't work. The first error listed in the CMD line was it didn't recognize %%. And, then it couldn't open the input MKVs as listed. And, I have NO bloody idea what that command is and I do NOT know what the 'v 1' at the end it either, but I left it in because it was after the encode parameters he was using. So, all I really need is a VERY VERY simple way to take the extremely simple re-encode script that I am using above and be able to re-encode all the MKV files in one folder and output the re-encoded MKV files to another folder. That's it! There HAS to be a LOT easier way than this Now, if there is an EASY way for the existing audio to be remuxed with the re-encoded file as it processes, well, that would be nice. Otherwise I will simply manually remux the audio of each file when the video re-encodes are done using MKVMerge. But, IF that can easily be automated too, then great! As long as it doesn't get too complicated for me... I very much appreciate the help! A batch file would be fine that I could simple click on after dumping whatever MKV files into the input folder that I want to re-encode. Thanks kindly! |
13th March 2019, 10:07 | #2 | Link | ||
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Code:
FOR /R "D:\x" %% Quote:
Code:
for %%a in (*.mkv) do ffmpeg -i "%%~a" -map 0 -c:v libx264 -preset veryfast -crf 24 -c:a copy -c:s copy "output_folder\%%~a" Quote:
Code:
for %%a in (*.mkv) do ( x264 "%%~a" --preset veryfast --crf 24 -o "temp_folder\%%~a" mkvmerge -o "output_folder\%%~a" "temp_folder\%%~a" --no-video "%%~a" ) Last edited by sneaker_ger; 13th March 2019 at 10:15. |
||
13th March 2019, 12:45 | #3 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Also, if you have a general EXE folder for your tools, put it in the PATH environment variable, is lots easier than giving ultra long paths in command lines.
EDIT: Separate items in the PATH with Semi Colon ';', eg "C:\BIN;D:\BIN"
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
13th March 2019, 13:07 | #4 | Link | |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
|
|
13th March 2019, 13:39 | #5 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Cheers Sneaky, did not know that, but then I dont run Avs or similar on either of my two Win10 10" mini tablet/laptops (browse internet and nowt else really).
I'll set em up one day but not today, again cheers.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
13th March 2019, 20:40 | #6 | Link | |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
Quote:
So, if I copy your code above verbatim, substituting the name of the input and output folders only, I can run it as is to re-encode a folder of MKV files and it will keep and mux the existing audio? If I save the code above as a .bat file, can I then execute it that way by clicking on it? Thanks! |
|
13th March 2019, 20:42 | #7 | Link | |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
Quote:
Thank you kindly! |
|
13th March 2019, 20:49 | #8 | Link |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
Oh, with the 2nd code above, wouldn't I also have to substitute the path of my x264.exe?
So, also substituting the path to my x264.exe, my existing input / output folders then, would the resulting code be this: for %%a in (*.mkv) do ( F:\EXECUTABLES\BD-RBV05023\BD_Rebuilder\Tools\x264L.exe "%%~a" --preset veryfast --crf 24 -o "D:\x\%%~a" mkvmerge -o "D:\x\output_folder\%%~a" "D:\x\%%~a" --no-video "%%~a" ) Would that re-encode the MKV files AND mux the existing audio back into the output MKV files too? |
13th March 2019, 21:20 | #10 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
In the cmd window you must use single "%" instead of "%%". "%%" is for batch files.
For the paths: You have several options. You can set files and folders using their relative paths (relative to the working directory, in your sceenshot it's c:\windows\system32\) or their absolute paths. If you use relative paths for the executables it's easiest to put things into %PATH% like StainlessS said so you can call them from anywhere. It's not strictly necessary, just for convenience. Personally, I usually open the cmd in the directory where the files I want to work on are. Usually I go into the folder using the Explorer, hold shift and right-click on an empty stop and select "open command prompt here" (with Windows 10 it's difficult). Then working directory will be that folder instead of c:\windows\system32\. I have ffmpeg, x264, mkvmerge and other vital tools in %PATH%. Then I can just use the simple commands like my ffmpeg example without writing the long, absolute paths. Last edited by sneaker_ger; 13th March 2019 at 21:29. |
13th March 2019, 21:48 | #11 | Link | |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
Quote:
Thank you! |
|
13th March 2019, 22:35 | #12 | Link |
Registered User
Join Date: Aug 2005
Posts: 1,100
|
Hmmm... weird. I didn't seem to get any lengthy errors, but it didn't do anything. Here is the code I used in the CMD window:
for %a in (*.mkv) do ( F:\EXECUTABLES\BD-RBV05023\BD_Rebuilder\Tools\x264L.exe "%~a" --preset veryfast --crf 24 -o "D:\x\%~a" mkvmerge -o "D:\x\output_folder\%~a" "D:\x\%~a" --no-video "%~a" ) And, here is the result: C:\Windows\system32>for %a in (*.mkv) do ( More? F:\EXECUTABLES\BD-RBV05023\BD_Rebuilder\Tools\x264L.exe "%~a" --preset ver yfast --crf 24 -o "D:\x\%~a" More? mkvmerge -o "D:\x\output_folder\%~a" "D:\x\%~a" --no-video "%~a" More? ) C:\Windows\system32> |
|
|