BrianDMG / conv2mp4

This Powershell script will recursively search through a user-defined file path and convert all videos of user-specified file types to MP4 with H264 video and AAC audio using ffmpeg. The purpose of this script is to reduce transcoding CPU load on a media server like Plex or Emby and increase video compatibility across platforms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Is this lossless?

Aethaeran opened this issue · comments

Haven't seen a straightforward answer to this anywhere. Been trying to parse through your code to see if I can find an answer to this, but it looks like it would take a decent understanding of the ffmpeg and Handbrake CLIs to really figure it out that way. In the hopes that this will get me my answer quicker, I decided to just ask.

Is the ffmpeg conversion lossless? (I assume it is when possible. If not always possible, some information on when it wouldn't be would be helpful.)

What are possible triggers for "conversion failure" that would cause Handbrake to kick in?

Is the Handbrake conversion lossless? (I assume it is not, since my limited experience in Handbrake is that lossless encoding would increase the filesize dramatically.)

Well, I seem to have answered two of my own questions after all. After much further research and a bit more parsing, I found the answers I was looking for in 'files\func\ConvertFile.ps1'. All the arguments passed to FFmpeg and HandbrakeCLI are located there.

FFmpeg passes the following arguments:

  • For video
    libx264 -preset medium -crf 18

  • For audio
    aac

HandbrakeCLI passes the following arguments

  • For video
    -e x264 --encoder-preset slow --encoder-profile high --encoder-level 4.1 -q 18

  • For audio
    -E aac --audio-copy-mask aac

For those of you who don't understand what that's saying, much like I didn't yesterday. The "-crf 18" and "-q 18" arguments in FFmpeg and HandbrakeCLI respectively are essentially the same thing. To get a truly lossless conversion would require these to be set to 0. Although, as stated in my previous post this would likely dramatically change the filesize. A setting of 18 should be visually comparable to the source and will probably be more than fine for most users.

Oh, and aac is a lossy audio codec so it is implied that it will never be a lossless conversion in terms of audio. You would have to use a codec like FLAC instead, which not all players support, which would defeat the purpose of this script in the first place.

Some sources I got this information from:

The file containing the CLI arguments used in this script
Handbrake document explaining that lossless will enlarge files.
FFmpeg h264 documentation
FFmpeg AAC documentation

I'd close this question, but I am still curious about what will cause the trigger of HandbrakeCLI over FFmpeg. Let me know.

commented

Hey! As you've discovered, it's not "lossless" per se, but it's set to keep the quality basically on par with the original. To answer your question about the failover, it's a comparison between the source (original) file size and the target (converted) file size. If the difference exceeds a given threshold (which can be defined in your config file by setting the failover_threshold) it deletes the target file and starts to convert with Handbrake. This helps avoid situations where ffmpeg fails for some reason and leaves either a file that's incredibly small (indicating something went wrong) or ridiculously large (which would indicate the conversion wasn't very efficient). It basically enforces a certain level of consistency in the script's output, while offering some other option than outright failure. Hope that answers your question.