A Powershell Script for HandBrake


  1. Posts : 5
    Windows 10 Professional
       #1

    A Powershell Script for HandBrake


    Here's the thing. My system is an age-old i3-530 overclocked to 3.5GHz coupled with GTX 1050 2GB. I have around 1.5TB of tutorial videos that I have to encode due to dearth in HDD space. I want to encode the videos while keeping the folder and subfolder structure intact.

    Here's the problem though. Since my system is overclocked, I sometimes get
    Code:
    BSOD
    with IFME. And when I run Handbrake GUI, sometimes it stops working. The difference is that in case of IFME, the incomplete file is in a
    Code:
    TEMP 
    folder, whereas it's pretty darn hard to differentiate between an incomplete and a complete output of HandBrake.

    Here's what I want to do. I want to run a
    Code:
    Powershell
    script (I'm a Windows 10 x64 user), which will do the following -


    For each .mp4 in given folder:


    • Run IFME/Handbrake with proper arguments with output file in a
      Code:
      TEMP
      folder
    • Once the encoding completes successfully (maybe use
      Code:
      ERRORLEVEL
      here?), replace the original file with the encoded one.


    Can this be done?
      My Computer


  2. Posts : 777
    Microsoft Windows 10 Pro 64-bit
       #2

    Why not just set the CPU to where it should be and see if the problem stop's.
      My Computer

  3. Bree's Avatar
    Posts : 19,644
    10 Home x64 (21H1) (10 Pro on 2nd pc)
       #3

    sml156 said:
    Why not just set the CPU to where it should be and see if the problem stop's.
    I agree.


    Mycroft2046 said:
    I have around 1.5TB of tutorial videos that I have to encode due to dearth in HDD space...


    On another note, I have similar space concerns, so I have looked for the most compression I can get away with without noticeable quality loss. It's not the size of the original files that you should be looking at, rather the duration of the videos that's the determining factor.

    I use the free Open Source command line utility FFmpeg for my processing. The settings I use are:
    Codec: X.264 with Constant Rate Factor (CRF) of 28, preset 'veryslow' and tune 'film' (for live action) or 'animation' (if your tutorials are slideshows). This produces about 200MB for an hour of live action video (less if there's little action taking place). These settings are also available in Handbrake, just choose the H.264 codec to access them.

    If you want to script your conversions, FFmpeg (as it's used from a command line) may be easier to set up. a typical command line would be:

    FFMPEG -i input.mp4 -crf 28 -preset veryslow -tune film output.mp4
      My Computers


  4. Posts : 5
    Windows 10 Professional
    Thread Starter
       #4

    sml156 said:
    Why not just set the CPU to where it should be and see if the problem stop's.
    Unfortunately, it doesn't. I've tried to run them in stock settings, but that doesn't work as well. And I only get problems with IFME or Handbrake. I regularly use 7Zip to compress files of size 2GB, or run multithreaded Python scripts that push the CPU to the extreme, but no problem occurs then.
      My Computer


  5. Posts : 5
    Windows 10 Professional
    Thread Starter
       #5

    Bree said:
    I agree.




    On another note, I have similar space concerns, so I have looked for the most compression I can get away with without noticeable quality loss. It's not the size of the original files that you should be looking at, rather the duration of the videos that's the determining factor.

    I use the free Open Source command line utility FFmpeg for my processing. The settings I use are:
    Codec: X.264 with Constant Rate Factor (CRF) of 28, preset 'veryslow' and tune 'film' (for live action) or 'animation' (if your tutorials are slideshows). This produces about 200MB for an hour of live action video (less if there's little action taking place). These settings are also available in Handbrake, just choose the H.264 codec to access them.

    If you want to script your conversions, FFmpeg (as it's used from a command line) may be easier to set up. a typical command line would be:

    FFMPEG -i input.mp4 -crf 28 -preset veryslow -tune film output.mp4
    Since most of my tutorials are screen grabs, I think they are comparable to slideshows. How does animation preset work with slideshows? Is sharpness of the texts affected?
      My Computer

  6. Bree's Avatar
    Posts : 19,644
    10 Home x64 (21H1) (10 Pro on 2nd pc)
       #6

    Mycroft2046 said:
    Since most of my tutorials are screen grabs, I think they are comparable to slideshows. How does animation preset work with slideshows? Is sharpness of the texts affected?
    No. Details are preserved as much as possible, they are the last thing to be affected at higher CRF values. It appears to be large areas of a single colour which 'animation' tuning takes advantage of to reduce the filesize. That, and the fact that an animation will have several consecutive identical frames. For 'film' tuning it appears to be fast motion where the tuning get's its savings.

    Either way, tuning is the (optional) icing on the cake - for a particular type of video tuning can get you a little bit extra compression for a given CRF value, it's by increasing the CRF that the biggest savings are found.

    The preset works by allowing more (or less) time to process each frame. For a given CRF using veryslow gives the best perceived quality and the smallest filesize, while ultrafast makes larger files with noticeable compression artefacts (useful for a quick test of other settings, but not recommended for a video you want to keep).

    You can experiment with different CRF levels. More info on CRF, tuning and preset here...
    ...a subjectively sane range is 18-28...
    ...The range is exponential, so increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value.
    https://trac.ffmpeg.org/wiki/Encode/H.264
    (this FFmpeg documentation is equally applicable to Handbrake, the settings are standard H.264 ones)
    Last edited by Bree; 23 Oct 2017 at 13:36.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 15:16.
Find Us




Windows 10 Forums