Skip to content

Instantly share code, notes, and snippets.

@DonRichards
Last active December 5, 2021 17:31
Show Gist options
  • Save DonRichards/b69c8c54d9a6868017851a13c1a2524d to your computer and use it in GitHub Desktop.
Save DonRichards/b69c8c54d9a6868017851a13c1a2524d to your computer and use it in GitHub Desktop.
Convert Videos for Plex Playback

Convert videos for Plex / Playstation playback

  • SRC="/home/don/Downloads/Convert" This is the location of the video files to convert

  • DEST="/home/don/Videos" This is where you want them to end up

  • PRESET="/home/don/Desktop/mp4_out.json" This is the presets. Lengthy and a bit complicated. If you want a new set of presets try opening the Handbrake app > using the UI make the configurations you want and Presets > Export to create a new json file.

  • DEST_EXT=mp4 This is the extension you want it to be.

#!/bin/bash
SRC=$(pwd)
DEST="~/Videos"
PRESET="mp4_out.json"
DEST_EXT=mkv
HANDBRAKE_CLI=HandBrakeCLI
rm -f errors.log
for FILE in "$SRC"/*
do
filename=$(basename "$FILE")
extension=${filename##*.}
filename=${filename%.*}
$HANDBRAKE_CLI --preset-import-gui --preset-import-file "$PRESET" -i "$FILE" -o "$DEST"/"$filename".$DEST_EXT
ffmpeg -nostdin error -i "${filename%.*}.mkv" -f null - 2>errors.log
done
{
"PresetList": [
{
"AudioCopyMask": [
"copy:aac"
],
"AudioEncoderFallback": "av_aac",
"AudioLanguageList": [],
"AudioList": [
{
"AudioBitrate": 160,
"AudioCompressionLevel": -1.0,
"AudioDitherMethod": "auto",
"AudioEncoder": "av_aac",
"AudioMixdown": "dpl2",
"AudioNormalizeMixLevel": false,
"AudioSamplerate": "auto",
"AudioTrackDRCSlider": 0.0,
"AudioTrackGainSlider": 0.0,
"AudioTrackQuality": -1.0,
"AudioTrackQualityEnable": false
}
],
"AudioSecondaryEncoderMode": true,
"AudioTrackSelectionBehavior": "first",
"ChapterMarkers": true,
"ChildrenArray": [],
"Default": true,
"FileFormat": "av_mkv",
"Folder": false,
"FolderOpen": false,
"Mp4HttpOptimize": false,
"Mp4iPodCompatible": false,
"PictureAutoCrop": true,
"PictureBottomCrop": 0,
"PictureCombDetectCustom": "",
"PictureCombDetectPreset": "default",
"PictureDARWidth": 0,
"PictureDeblock": 0,
"PictureDeblockCustom": "qp=0:mode=2",
"PictureDeinterlaceCustom": "",
"PictureDeinterlaceFilter": "decomb",
"PictureDeinterlacePreset": "default",
"PictureDenoiseCustom": "",
"PictureDenoiseFilter": "off",
"PictureDenoisePreset": "light",
"PictureDenoiseTune": "none",
"PictureDetelecine": "off",
"PictureDetelecineCustom": "",
"PictureForceHeight": 0,
"PictureForceWidth": 0,
"PictureHeight": 720,
"PictureItuPAR": false,
"PictureKeepRatio": true,
"PictureLeftCrop": 0,
"PictureLooseCrop": false,
"PictureModulus": 2,
"PicturePAR": "auto",
"PicturePARHeight": 720,
"PicturePARWidth": 853,
"PictureRightCrop": 0,
"PictureRotate": "angle=0:hflip=0",
"PictureTopCrop": 0,
"PictureWidth": 1280,
"PresetDescription": "H.264 video (up to 720p30) and AAC stereo audio, in an MKV container.",
"PresetName": "H.264 MKV 720p30",
"SubtitleAddCC": false,
"SubtitleAddForeignAudioSearch": true,
"SubtitleAddForeignAudioSubtitle": false,
"SubtitleBurnBDSub": true,
"SubtitleBurnBehavior": "foreign",
"SubtitleBurnDVDSub": true,
"SubtitleLanguageList": [],
"SubtitleTrackSelectionBehavior": "none",
"Type": 0,
"UsesPictureFilters": true,
"UsesPictureSettings": 1,
"VideoAvgBitrate": 3000,
"VideoColorMatrixCode": 0,
"VideoEncoder": "x264",
"VideoFramerate": "30",
"VideoFramerateMode": "pfr",
"VideoGrayScale": false,
"VideoLevel": "3.1",
"VideoOptionExtra": "",
"VideoPreset": "medium",
"VideoProfile": "main",
"VideoQSVAsyncDepth": 4,
"VideoQSVDecode": false,
"VideoQualitySlider": 21.0,
"VideoQualityType": 2,
"VideoScaler": "swscale",
"VideoTune": "",
"VideoTurboTwoPass": false,
"VideoTwoPass": true,
"x264Option": "",
"x264UseAdvancedOptions": false
}
],
"VersionMajor": 23,
"VersionMicro": 0,
"VersionMinor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment