• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Off Topic Self-hosting & Homelabs Powershell Script to transcode MP4 & MKV files to HEVC/AAC

     
    • 0 Vote(s) - 0 Average

    Powershell Script to transcode MP4 & MKV files to HEVC/AAC

    Maximus1
    Offline

    Junior Member

    Posts: 2
    Threads: 1
    Joined: 2023 Nov
    Reputation: 1
    Country:Germany
    #1
    2023-11-07, 07:22 PM (This post was last modified: 2023-11-07, 07:27 PM by Maximus1.)
    Hello folks, 

    I needed space on the disks and have written one (two) script(s) in PowerShell to convert my MP4 and MKV files into HEVC/AAC.
    I decided to use Handbrake for Video and Audio Transcoding and FFmpeg for Audio Transcoding only because Handbrake has a better resulting quality at a lower file size. FFmpeg works better with multiple instances simultaneously. So FFmpeg was better for Audio transcoding.
    I would like to share the result with you.

    You need to install a PowerShell module called Get-MediaInfo
    Instructions on powershellgallery


    Warning!!
     
    I Transcoded hundreds of files with no error, but this doesn't mean it will do the same at your PC. 
    Please take a look at the code and change it to your needs.
     
     
    What does the 1st script do:
    • Read the folder you choose, recursive into an Array.
    • Checking for Codecs used in the Files.
    • Deciding how to convert.
    • Runs 1 instance of Handbrake and up to 5 FFmpeg instances at the same time.
    • Runs on CPU only to get the best visual results.
    • Setting different parameters for Movies and Series (Series are scaled to 720P if resolution >720P (-w 720 --keep-display-aspect)).
    • Generating a ".ignore" file so Emby ignores the actual folder.
    • Converting into same Directory, but not deleting old file.
    • Checking if file was converted.
    • The path of the currently converting file is written to a .txt file.
    • Writing every step into the console.
    • This Script removes all Audio tracks except the first one
    • This Script removes all Subtitles


    How the script decides to convert:

    Checking for Codecs used in the Files
    • If Audio not AAC and Video not HEVC → convert Video and Video (Handbrake)
    • If Audio not AAC and Video is HEVC → convert Audio copy Video (FFmpeg)
    • If Audio is AAC and Video not HEVC → convert Video copy Audio (Handbrake)
    • If Audio is AAC and Video is HEVC → do nothing 


    Audio Transcoding (FFmpeg) :

    The script differentiates between Mono/Stereo and Surround

    Mono/Stereo :
    • $aacbitrate = '128k'  (lower is possible, but not recommended)
    • $aachz = '44100'
    Surround : 
    • $aacbitrate = '256k'
    • $aachz = '48000'


    Video Transcoding (Handbrake): 

    Handbrake Series :
    •  -e x265 --encoder-preset medium -w 720 --keep-display-aspect --vfr --quality "$videoquality" -E "$handbrakeaudiocodec" -B "$handbrakeaudiobitrate" --normalize-mix "$handbrakenormalize" -i "$oldfile" -o "$newfile""
    Handbrake Movie : 
    • -e x265 --encoder-preset medium --vfr --quality "$videoquality" -E "$handbrakeaudiocodec" -B "$handbrakeaudiobitrate" --normalize-mix "$handbrakenormalize" -i "$oldfile" -o "$newfile""



    Here is my 2nd Script.

    This Script cleans up after the 1st script has done his job.

    What does the 2nd script do:
    • Read the folder you choose, recursive into an Array.
    • Comparing old file and new file → duration and file size
    • deleting old file if checks are OK
    • Renaming new file to old file
    • Checks for files maybe generated by Emby while transcoding 
    • Deleting these files if found.
    • Deleting ".ignore" file if found
    • Counting Videos "cleaned/renamed"
    • Counting Errors for file size and duration
    • Writing every step into the console.

    Files to search for:

       '.neu' + $file.Extension
       '.nfo'
       '.neu' + '.nfo'
       '.neu-clearlogo.png'
       '.neu-fanart.jpg'
        '.neu-poster.jpg'
        '.neu-discart.png'
        '.neu-thumb.jpg'
        '.neu-landscape.jpg'
        '.neu-banner.jpg'
        '.neu-clearart.png'

    Proof will come, I have to make something to clean :-)


    Attached Files
    .zip   Video Transcoder.zip (Size: 2.81 KB / Downloads: 128)
    .zip   Video Transcode cleanup.zip (Size: 1.79 KB / Downloads: 105)
    1
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode