Skip to content

Instantly share code, notes, and snippets.

@mjc
Created March 29, 2022 22:04
Show Gist options
  • Save mjc/37996785f47f565eb431dca19b56cf84 to your computer and use it in GitHub Desktop.
Save mjc/37996785f47f565eb431dca19b56cf84 to your computer and use it in GitHub Desktop.
M1 macs: Preserving HDR, convert all mkv in a folder to 1080P using HandBrakeCLI. Uses VideoToolbox for hardware encoding.
#!/usr/bin/env bash
read -r -d '' profile <<'EOF'
{
"PresetList" : [
{
"AlignAVStart" : true,
"AudioCopyMask" : [
"copy:aac",
"copy:ac3",
"copy:eac3",
"copy:dtshd",
"copy:dts",
"copy:truehd"
],
"AudioEncoderFallback" : "ca_aac",
"AudioLanguageList" : [
"any"
],
"AudioList" : [
{
"AudioBitrate" : 960,
"AudioCompressionLevel" : -1,
"AudioDitherMethod" : "auto",
"AudioEncoder" : "copy",
"AudioMixdown" : "7point1",
"AudioNormalizeMixLevel" : false,
"AudioSamplerate" : "auto",
"AudioTrackDRCSlider" : 0,
"AudioTrackGainSlider" : 0,
"AudioTrackQuality" : -1,
"AudioTrackQualityEnable" : false
}
],
"AudioSecondaryEncoderMode" : true,
"AudioTrackSelectionBehavior" : "all",
"ChapterMarkers" : true,
"ChildrenArray" : [
],
"Default" : true,
"FileFormat" : "av_mkv",
"Folder" : false,
"FolderOpen" : false,
"InlineParameterSets" : false,
"MetadataPassthrough" : true,
"Mp4HttpOptimize" : false,
"Mp4iPodCompatible" : false,
"PictureAllowUpscaling" : false,
"PictureAutoCrop" : true,
"PictureBottomCrop" : 0,
"PictureChromaSmoothCustom" : "",
"PictureChromaSmoothPreset" : "off",
"PictureChromaSmoothTune" : "none",
"PictureColorspaceCustom" : "",
"PictureColorspacePreset" : "bt2020",
"PictureCombDetectCustom" : "",
"PictureCombDetectPreset" : "default",
"PictureDARWidth" : 1920,
"PictureDeblockCustom" : "strength=strong:thresh=20:blocksize=8",
"PictureDeblockPreset" : "off",
"PictureDeblockTune" : "medium",
"PictureDeinterlaceCustom" : "",
"PictureDeinterlaceFilter" : "decomb",
"PictureDeinterlacePreset" : "default",
"PictureDenoiseCustom" : "",
"PictureDenoiseFilter" : "off",
"PictureDenoisePreset" : "light",
"PictureDenoiseTune" : "none",
"PictureDetelecine" : "off",
"PictureDetelecineCustom" : "",
"PictureForceHeight" : 0,
"PictureForceWidth" : 0,
"PictureHeight" : 1080,
"PictureItuPAR" : false,
"PictureKeepRatio" : false,
"PictureLeftCrop" : 0,
"PictureLooseCrop" : false,
"PictureModulus" : 2,
"PicturePadBottom" : 0,
"PicturePadColor" : "black",
"PicturePadLeft" : 0,
"PicturePadMode" : "none",
"PicturePadRight" : 0,
"PicturePadTop" : 0,
"PicturePAR" : "auto",
"PicturePARHeight" : 1,
"PicturePARWidth" : 1,
"PictureRightCrop" : 0,
"PictureRotate" : "angle=0:hflip=0",
"PictureSharpenCustom" : "",
"PictureSharpenFilter" : "off",
"PictureSharpenPreset" : "medium",
"PictureSharpenTune" : "none",
"PictureTopCrop" : 0,
"PictureUseMaximumSize" : true,
"PictureWidth" : 1920,
"PresetDescription" : "",
"PresetDisabled" : false,
"PresetName" : "test hdr",
"SubtitleAddCC" : true,
"SubtitleAddForeignAudioSearch" : true,
"SubtitleAddForeignAudioSubtitle" : false,
"SubtitleBurnBDSub" : false,
"SubtitleBurnBehavior" : "none",
"SubtitleBurnDVDSub" : false,
"SubtitleLanguageList" : [
"any"
],
"SubtitleTrackSelectionBehavior" : "all",
"Type" : 1,
"UsesPictureFilters" : true,
"VideoAvgBitrate" : 6000,
"VideoColorMatrixCodeOverride" : 0,
"VideoEncoder" : "vt_h265_10bit",
"VideoFramerate" : "auto",
"VideoFramerateMode" : "vfr",
"VideoGrayScale" : false,
"VideoLevel" : "auto",
"VideoOptionExtra" : "",
"VideoPreset" : "quality",
"VideoProfile" : "auto",
"VideoQSVDecode" : false,
"VideoQualitySlider" : 28,
"VideoQualityType" : 2,
"VideoScaler" : "swscale",
"VideoTune" : "",
"VideoTurboTwoPass" : false,
"VideoTwoPass" : false,
"x264Option" : "",
"x264UseAdvancedOptions" : false
}
],
"VersionMajor" : 47,
"VersionMicro" : 0,
"VersionMinor" : 0
}
EOF
echo "$profile" > /tmp/hdr.json
fd '.*hdr.*mkv' -j 1 -x HandBrakeCLI -Z test\ hdr --preset-import-file /tmp/hdr.json -e vt_h265_10bit -i {} -o {}.1080p.mkv
@mjc
Copy link
Author

mjc commented Mar 29, 2022

Preserves most audio and subtitles. Does not delete the original files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment