I have a video archive of personal memories organized into lots of folders. The video files have multiple filetypes and the quality to size ratio is terrible (some are even 20mb/s for a 720p video.

I want to convert each video to 720p and replace it with the converted file, but only when conversion is successful.

Here is my Handbrake preset exported to json:

  "PresetList": [
      "AlignAVStart": true,
      "AudioCopyMask": [
      "AudioEncoderFallback": "ac3",
      "AudioLanguageList": [],
      "AudioList": [
          "AudioBitrate": 128,
          "AudioCompressionLevel": 0.0,
          "AudioEncoder": "av_aac",
          "AudioMixdown": "stereo",
          "AudioNormalizeMixLevel": false,
          "AudioSamplerate": "44.1",
          "AudioTrackQualityEnable": false,
          "AudioTrackQuality": -1.0,
          "AudioTrackGainSlider": 0.0,
          "AudioTrackDRCSlider": 0.0
      "AudioSecondaryEncoderMode": true,
      "AudioTrackSelectionBehavior": "first",
      "ChapterMarkers": true,
      "ChildrenArray": [],
      "Default": false,
      "FileFormat": "av_mp4",
      "Folder": false,
      "FolderOpen": false,
      "Mp4HttpOptimize": false,
      "Mp4iPodCompatible": false,
      "PictureAutoCrop": true,
      "PictureBottomCrop": 0,
      "PictureLeftCrop": 0,
      "PictureRightCrop": 0,
      "PictureTopCrop": 0,
      "PictureDARWidth": 240,
      "PictureDeblock": 4,
      "PictureDeinterlaceFilter": "decomb",
      "PictureCombDetectPreset": "default",
      "PictureCombDetectCustom": "",
      "PictureDeinterlacePreset": "default",
      "PictureDenoiseCustom": "",
      "PictureDenoiseFilter": "off",
      "PictureDenoisePreset": "light",
      "PictureDenoiseTune": "none",
      "PictureSharpenCustom": "",
      "PictureSharpenFilter": "off",
      "PictureSharpenPreset": "medium",
      "PictureSharpenTune": "none",
      "PictureDetelecine": "off",
      "PictureDetelecineCustom": "",
      "PictureItuPAR": false,
      "PictureKeepRatio": true,
      "PictureLooseCrop": false,
      "PictureModulus": 2,
      "PicturePAR": "auto",
      "PicturePARWidth": 1,
      "PicturePARHeight": 1,
      "PictureRotate": "0:0",
      "PictureForceHeight": 0,
      "PictureForceWidth": 0,
      "PresetName": "myarchivesd",
      "Type": 1,
      "UsesPictureFilters": false,
      "UsesPictureSettings": 2,
      "SubtitleAddCC": false,
      "SubtitleAddForeignAudioSearch": true,
      "SubtitleAddForeignAudioSubtitle": false,
      "SubtitleBurnBehavior": "foreign",
      "SubtitleBurnBDSub": false,
      "SubtitleBurnDVDSub": false,
      "SubtitleLanguageList": [],
      "SubtitleTrackSelectionBehavior": "none",
      "VideoAvgBitrate": 0,
      "VideoColorMatrixCode": 0,
      "VideoEncoder": "x264",
      "VideoFramerateMode": "vfr",
      "VideoGrayScale": false,
      "VideoHWDecode": false,
      "VideoScaler": "swscale",
      "VideoPreset": "fast",
      "VideoTune": "",
      "VideoProfile": "main",
      "VideoLevel": "4.1",
      "VideoOptionExtra": "",
      "VideoQualityType": 2,
      "VideoQualitySlider": 25.0,
      "VideoQSVDecode": false,
      "VideoQSVAsyncDepth": 4,
      "VideoTwoPass": false,
      "VideoTurboTwoPass": false,
      "x264Option": "level=4.1:vbv-bufsize=62500:vbv-maxrate=50000:rc-lookahead=30:ref=5:bframes=5:b-adapt=2:direct=auto:me=dia:subme=9:merange=15:trellis=0",
      "x264UseAdvancedOptions": true
  "VersionMajor": "11",
  "VersionMicro": "0",
  "VersionMinor": "0"

So far, I've managed to find the right arguments for conversion with HandbrakeCli. Using the preset I finetuned with HandbrakeGui (gives near YIFY quality):

HandBrakeCLI.exe --maxHeight 720 --maxWidth 1280 --preset-import-file "mypreset.json" -Z "mypreset" -i "input.mp4" -o "output.mp4".


This is my current version of batch file.

  1. First you need to put the path to your hanbrakecli.exe and your preset.json file in the batch file below.
  2. Then copy the batch file to the root directory of your video archive an double click it.

Note: be careful of .DAT extension. only copy this batch to a folder where there are only video files, no app data.

Here is the batch file contents:

@echo off &setlocal
for /R %%I in (*.DAT *.mpg *.mpeg *.wmv *.3gp *.mov *.avi *.mkv *.mp4) do (
    set "fpath=%%~dpnI"
    set "fname=%%~nI"
    setlocal enabledelayedexpansion
    if exist "%%~dpnI.unfinished.mp4" (
        echo "Found unfinished conversion of %%~nI. Deleting leftover files ..."
        del /F "%%~dpnI.unfinished.mp4"
    if "!fname!"=="!fname:.converted=!" (
        echo "converting %%I ..."
        "[path to HandbrakeCli.exe]" --maxHeight 720 --maxWidth 1280 --preset-import-file "[path to your preset.json]" ^
        -Z "[your preset name]" -i "%%I" -o "%%~dpnI.unfinished.mp4"
        if exist "%%~dpnI.unfinished.mp4" (
            echo "conversion of %%I succeded. deleting the source file..."
            del /F "%%~dpnxI"
            move /Y "%%~dpnI.unfinished.mp4" "%%~dpnI.converted.mp4"
        )else (
            echo "conversion of %%I was not successful. Keeping the source file!"
            if exist "%%~dpnI.unfinished.mp4" (
                del /F "%%~dpnI.unfinished.mp4"
    )else (
        echo "We already have %%I. No need to convert it again!"

What it does is:

  1. It searches for each file with common movie extentions.
  2. checks whether it has successfully converted it before or not (via a naming pattern).
  3. starts converting and putting the output file in the input file directory (running hanbrakecli command on the file)
  4. checks for successful conversion (by naming pattern)
  5. removes the input file.

My current challenges are: The handbrakecli command output is super verbose and ugly. it would be better if it only outputs the converting progress and remaining time or even no input.

Is it possible to pipe and filter the handbrake output or silence it?

  • I tried |findstr my string to filter out only certain lines. it works in other commands, but not in handbrakecli. why is that? Does handbrake output to CONSOLE instead of Standard Output? – Euphoria Jul 7 '18 at 14:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.