VideoHelp Forum




+ Reply to Thread
Results 1 to 15 of 15
  1. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    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!
    Quote Quote  
  2. 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...
      )
    But ffmpeg has the ability to scale videos. You could just use that:

    Code:
    md New
    for %%F in (*.mkv) do ( ffmpeg -i "%%~nxF" -vf scale=640:-4 -c:v libx264 -c:a copy "New\%%~nxF" )
    The new files are created in a sub-folder called New.
    Last edited by jagabo; 21st May 2021 at 09:38.
    Quote Quote  
  3. I'm a Super Moderator johns0's Avatar
    Join Date
    Jun 2002
    Location
    canada
    Search Comp PM
    With vidcoder you can batch encode lots of videos at a lower resolution of your choice.
    I think,therefore i am a hamster.
    Quote Quote  
  4. 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
    Quote Quote  
  5. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by johns0 View Post
    With vidcoder you can batch encode lots of videos at a lower resolution of your choice.
    Thank you!
    Quote Quote  
  6. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by jagabo View Post
    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...
    Quote Quote  
  7. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by Lathe View Post
    Originally Posted by johns0 View Post
    With vidcoder you can batch encode lots of videos at a lower resolution of your choice.
    Thank you!
    I'm trying Vidcoder now. It certainly LOOKS super easy. I dropped the files to reencode into the program and simply chose Veryfast 720, so I will see how they come out. Nice & Easy, thanks!
    Quote Quote  
  8. I'm a Super Moderator johns0's Avatar
    Join Date
    Jun 2002
    Location
    canada
    Search Comp PM
    Also vidcoder is based on the handbrake engine,you can also tweak all the settings so you get better results.
    I think,therefore i am a hamster.
    Quote Quote  
  9. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by johns0 View Post
    Also vidcoder is based on the handbrake engine,you can also tweak all the settings so you get better results.
    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 customizer it 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!
    Quote Quote  
  10. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    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!
    Quote Quote  
  11. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    And yes, I did find the additional settings rather cryptically under the Windows tab
    Quote Quote  
  12. 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
    Quote Quote  
  13. Originally Posted by Lathe View Post
    Originally Posted by jagabo View Post
    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!
    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"
    Originally Posted by Lathe View Post
    ***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.
    That code was meant to show you how to build the AviScript. You need to replace the line "REM encoding line goes here..." with your encoding command. You appeared to have a command line encoder you were happy with in your first post:
    Code:
    F:\EXECUTABLES\BD-RBV06122\BD_Rebuilder\Tools\x264L.exe "C:\x\test.avs" --preset veryfast --crf 22 --output "C:\x\Encode.mkv"
    You just need to change the input and output names:
    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"
      )
    I also added "mkdir New" at the start of the script to create the New subfolder where the new files will be created.
    Quote Quote  
  14. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by Pressa View Post
    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
    Hey, that is an excellent one too, thanks mate!
    Quote Quote  
  15. Member Lathe's Avatar
    Join Date
    Nov 2007
    Location
    Sunny Southern California
    Search Comp PM
    Originally Posted by jagabo View Post
    Originally Posted by Lathe View Post
    Originally Posted by jagabo View Post
    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!
    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"
    Originally Posted by Lathe View Post
    ***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.
    That code was meant to show you how to build the AviScript. You need to replace the line "REM encoding line goes here..." with your encoding command. You appeared to have a command line encoder you were happy with in your first post:
    Code:
    F:\EXECUTABLES\BD-RBV06122\BD_Rebuilder\Tools\x264L.exe "C:\x\test.avs" --preset veryfast --crf 22 --output "C:\x\Encode.mkv"
    You just need to change the input and output names:
    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"
      )
    I also added "mkdir New" at the start of the script to create the New subfolder where the new files will be created.
    Excellent, thank you!
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!