lisamelton / more-video-transcoding

More tools to transcode videos.
MIT License
45 stars 1 forks source link

Extra "-x crop=auto" #3

Closed loshlee closed 1 year ago

loshlee commented 1 year ago

I don't get the results I'm looking for when I use -x crop=auto with two-pass-trancode.rb. The auto cropping appears to be ignored. Is there a different way to call it? Thanks.

loshlee commented 1 year ago

Also, defaults don't appear to crop to 2.35:1, although it's closer than using -x crop=auto. Is that by design? Thanks.

lisamelton commented 1 year ago

@loshlee Using -x crop-auto actually prevents automatic cropping. So don't do that. 😀

That's because auto is not a valid argument to HandBrakeCLI's `--crop option.

Cropping with all four scripts is already automatic. It just works. So don't change it unless you want to make a specific crop.

BTW, the scripts do use the "conservative" version of HandBrakeCLI's algorithm. This is what you want. You do not want the default cropping algorithm since it will remove too much content.

loshlee commented 1 year ago

Thanks. I'm hoping to achieve cropping to roughly 2.35:1, which is a cinematic output. When using --crop auto in transcode-video, I get the desired results. When using more-video-transcode's two-pass-trancode.rb, cropping isn't correct (it is correct when I use --crop auto in transcode-video).

lisamelton commented 1 year ago

@loshlee Soooo... what is it if it's not correct? Too much? Too little?

loshlee commented 1 year ago

Too little. Black bars remain.

lisamelton commented 1 year ago

@loshlee In other words, can you give me the dimensions of the good crop and the bad crop.

Also, it would be really nice to know what the hell you're cropping here. 😀

lisamelton commented 1 year ago

@loshlee You can use the default, more aggressive version of HandBrakeCLI's cropping algorithm by adding -x crop-mode=auto to your command line. Notice that's crop-mode there and not just crop.

loshlee commented 1 year ago

Thanks! I will try -x crop-mode=auto and let you know. In the meantime: Correct (transcode-video)

Width                                    : 1 920 pixels
Height                                   : 798 pixels
Display aspect ratio                     : 2.40:1

Incorrect: (two-pass-trancode.rb)

Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9

But this is almost definitely moot. I'm sure -x crop-mode=auto instead of -x crop=auto for two-pass-trancode.rb is what is needed. I'll confirm in just a moment after I've tried it. Thanks again!

loshlee commented 1 year ago

Confirmed! Using -x crop-mode=auto instead of -x crop=auto gave me the correct results. Thanks so much! I really think my transcoding results using two-pass-trancode.rb will be much better while taking up less disk space than using either other_video_transcoding (ffmpeg) or transcode-video (HandBrake).

lisamelton commented 1 year ago

@loshlee Good! But I advise against using -x crop-mode=auto for all titles. It's too aggressive in most cases.

Are we ready to close this now?

loshlee commented 1 year ago

Thanks! Closing now.

loshlee commented 1 year ago

Here's the AppleScript I created that allows me to incorporate the suggestions offered by @donmelton to meet my specific transcoding needs when using two-pass-transcode.rb on my Mac. Most video sources for the content I transcode are generated by an add-on capture device called the Hauppauge HDPVR 2. This device is not compatible with video sources for which copying is prohibited through HDCP.

I find that the highest quality output from the device is normally received in telecine format, so my transcode process requires IVTC, as incorporated into this AppleScript.

For usage and scope information, compare this AppleScript to the one I've already provided for using two-pass-transcode.rb without custom options at Other-Video-Transcoding issues.

This AppleScript also includes an ffmpeg construct for removing and replacing the default .mkv output of two-pass-transcode.rb with .m4v output. This construct can be removed by deleting

";ffmpeg -i" & space & (quoted form of (pos_filepath & the_output_file)) & space & "-c copy" & space & (quoted form of (pos_filepath & endFile)) & ";rm -rf" & space & (quoted form of (pos_filepath & the_output_file)) &

from the AppleScript.

If you prefer output in .mp4 instead of .mkv, leave the previously mentioned construct, but change each occurrence of m4v in the AppleScript to mp4 (there are 3 occurrences).

I eventually hope to add both this and the one provided at Other-Video-Transcoding issues as gists for More-Video-Transcoding.

The Two-Pass-Handbrake-Detelecine-aggressive-crop AppleScript follows:

use AppleScript version "2.5"
use scripting additions

property temppath : "/private/tmp/"
property tmpfile : "/tmp/execme.command"

on open the_items
    my handbrake_transcode(the_items)
end open

on handbrake_transcode(the_items)
    set theshellscript to ""
    repeat with the_item in the_items
        set the_item to the_item as alias
        try
            tell application "Finder"
                set sost to (container of the_item) as string
            end tell
            set pos_filepath to POSIX path of sost

        end try
        set this_filepath to (the_item as text)

        if last character of this_filepath is ":" then
            tell me to set it_is_a_folder to true
        else
            set it_is_a_folder to false
        end if
        set thesourcename to (name of (info for the_item))
        set namepart to (name extension of (info for the_item))
        set the_source_file to POSIX path of this_filepath
        set newname to replace_chars(thesourcename, namepart, "detelecine.m4v")
        set the_output_file to replace_chars(newname, "detelecine.m4v", "mkv")
        set endFile to replace_chars(the_output_file, "mkv", "m4v")

        try
            set theshellscript to the theshellscript & "cd" & space & pos_filepath & ";two-pass-transcode.rb --ac3-surround -x detelecine -x rate=23.976 -x cfr -x crop-mode=auto" & space & (quoted form of the_source_file) & ";ffmpeg -i" & space & (quoted form of (pos_filepath & the_output_file)) & space & "-c copy" & space & (quoted form of (pos_filepath & endFile)) & ";rm -rf" & space & (quoted form of (pos_filepath & the_output_file)) & ";/bin/echo'" & space & "

            ==========================

            " & newname & space & "FINISHED!

            ==========================

            ';"

        on error onerr
            activate
            display dialog onerr
        end try
    end repeat
    set theshellscript to theshellscript & "sleep 2;mv" & space & (quoted form of tmpfile) & space & (quoted form of (POSIX path of (path to trash)))
    do shell script "echo " & quoted form of theshellscript & " > " & tmpfile
    repeat
        do shell script "chmod +x " & tmpfile
        do shell script "open -a Terminal.app" & space & tmpfile
        exit repeat
    end repeat
end handbrake_transcode

on replace_chars(this_text, _bad, _good)
    set AppleScript's text item delimiters to the _bad
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the _good as text
    set this_text to the item_list as text
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

on run
    set the_items to ((choose file) as list)
    handbrake_transcode(the_items)
end run