Subtitle CLI Command?

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
Barnaby98994
New User
Posts: 3
Joined: Sat Mar 30, 2024 5:02 am

Subtitle CLI Command?

Post by Barnaby98994 »

Description of problem or question:

I am trying to come up with the proper CLI to make an MP4 with 5.1 audio, with only Foreign Audio Search subtitles burned in, and all non-forced English subtitles included as well (but not buried in). So, I don't want PGS, but I want to keep foreign language subtitles that are forced (like alien talk). I think I am close, but not there.


Steps to reproduce the problem (If Applicable):
My CLI command:

HandBrakeCLI --preset "HQ 1080p30 Surround" --audio-lang-list eng --all-audio --subtitle-lang-list eng --all-subtitles --subtitle-default none --format av_mp4 --input "/Users/thisguy/Downloads/complete/tF (1985).mkv" --output "/Volumes/Movies/tF (1985).mp4"

HandBrake version (e.g., 1.0.0):

1.7.3

Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):

Mac, Ventura 13.4


HandBrake Activity Log ***required*** (see How-to get an activity log)

Code: Select all

[17:48:19] Compile-time hardening features are enabled
[17:48:20] hb_init: starting libhb thread
[17:48:20] thread 700002889000 started ("libhb")
HandBrake 1.6.1 (2023012200) - Darwin x86_64 - https://handbrake.fr
12 CPUs detected
Opening /Users/thisguy/Downloads/complete/tF (1985).mkv...
[17:48:20] CPU: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
[17:48:20]  - Intel microarchitecture Kaby Lake
[17:48:20]  - logical processor count: 12
[17:48:20] hb_scan: path=/Users/thisguy/Downloads/complete/tF (1985).mkv, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:333: failed opening UDF image /Users/thisguy/Downloads/complete/tF (1985).mkv
disc.c:437: error opening file BDMV/index.bdmv
disc.c:437: error opening file BDMV/BACKUP/index.bdmv
[17:48:20] bd: not a bd - trying as a stream/file instead
libdvdread: Encrypted DVD support unavailable.
libdvdread: DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: vm: failed to read VIDEO_TS.IFO
[17:48:20] dvd: not a dvd - trying as a stream/file instead
Input #0, matroska,webm, from '/Users/thisguy/Downloads/complete/tF (1985).mkv':
  Metadata:
    title           : 
    encoder         : libebml v1.4.0 + libmatroska v1.6.1
    creation_time   : 2020-10-23T08:24:49.000000Z
  Duration: 01:56:01.66, start: 0.000000, bitrate: 13058 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 254.212292
      Metadata:
        title           : Chapter 01

    [deleting chapter details]

      Metadata:
        title           : Chapter 20
  Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1036 [SAR 1:1 DAR 480:259], 23.98 fps, 23.98 tbr, 1k tbn (default)
    Metadata:
      title           : 
  Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
    Metadata:
      title           : 
  Stream #0:2(eng): Subtitle: subrip (default)
    Metadata:
      title           : 
  Stream #0:3(eng): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : English-PGS
  Stream #0:4(ger): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : German-PGS
  Stream #0:5(ita): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : Italian-PGS
  Stream #0:6(spa): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : Spanish-PGS
  Stream #0:7(por): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : Portuguese-PGS
  Stream #0:8(tur): Subtitle: hdmv_pgs_subtitle
    Metadata:
      title           : Turkish-PGS
  Stream #0:9: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 213x120, 90k tbr, 90k tbn (attached pic)
    Metadata:
      filename        : small_cover_land.jpg
      mimetype        : image/jpeg
  Stream #0:10: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 600x882, 90k tbr, 90k tbn (attached pic)
    Metadata:
      filename        : cover.jpg
      mimetype        : image/jpeg
  Stream #0:11: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 1067x600, 90k tbr, 90k tbn (attached pic)
    Metadata:
      filename        : cover_land.jpg
      mimetype        : image/jpeg
  Stream #0:12: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 120x176, 90k tbr, 90k tbn (attached pic)
    Metadata:
      filename        : small_cover.jpg
      mimetype        : image/jpeg
[17:48:20] scan: decoding previews for title 1
[17:48:20] scan: audio 0x1: dca, rate=48000Hz, bitrate=1536000 English (DTS) (5.1 ch) (1536 kbps)
Scanning title 1 of 1, preview 6, 60.00 %[17:48:20] scan: 10 previews, 1920x1036, 23.976 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[17:48:20] libhb: scan thread found 1 valid title(s)
+ Using preset: HQ 1080p30 Surround
+ title 1:
  + stream: /Users/thisguy/Downloads/complete/tF (1985).mkv
  + duration: 01:56:01
  + size: 1920x1036, pixel aspect: 1/1, display aspect: 1.85, 23.976 fps
  + autocrop: 0/0/0/0
  + chapters:
    + 1: duration 00:04:14
    [deleted chapter info]
    + 20: duration 00:04:36
  + audio tracks:
    + 1, English (DTS) (5.1 ch) (1536 kbps) (iso639-2: eng), 48000Hz, 1536000bps
  + subtitle tracks:
    + 1, English [UTF-8]
    + 2, English [PGS]
    + 3, Deutsch [PGS]
    + 4, italiano [PGS]
    + 5, español [PGS]
    + 6, Portugues [PGS]
    + 7, Türkçe [PGS]
[17:48:20] Starting work at: Sat Mar 30 17:48:20 2024

[17:48:20] 1 job(s) to process
[17:48:20] json job:
{
    "Audio": {
        "AudioList": [
            {
                "Bitrate": 160,
                "CompressionLevel": -1.0,
                "DRC": 0.0,
                "DitherMethod": "auto",
                "Encoder": 16384,
                "Gain": 0.0,
                "Mixdown": "stereo",
                "NormalizeMixLevel": false,
                "PresetEncoder": "ca_aac",
                "Quality": -3.0,
                "Samplerate": 0,
                "Track": 0
            },
            {
                "Bitrate": 640,
                "CompressionLevel": -1.0,
                "DRC": 0.0,
                "DitherMethod": "auto",
                "Encoder": 16384,
                "Gain": 0.0,
                "Mixdown": "5point1",
                "NormalizeMixLevel": false,
                "PresetEncoder": "copy:ac3",
                "Quality": -3.0,
                "Samplerate": 0,
                "Track": 0
            }
        ],
        "CopyMask": [
            "copy:aac",
            "copy:ac3"
        ],
        "FallbackEncoder": "ca_aac"
    },
    "Destination": {
        "AlignAVStart": true,
        "ChapterList": [
            {
                "Duration": {
                    "Hours": 0,
                    "Minutes": 4,
                    "Seconds": 14,
                    "Ticks": 22879106
                },
                "Name": "Chapter 1"
            },
            [deleted chapter info],
            {
                "Duration": {
                    "Hours": 0,
                    "Minutes": 4,
                    "Seconds": 36,
                    "Ticks": 24883695
                },
                "Name": "Chapter 20"
            }
        ],
        "ChapterMarkers": true,
        "File": "/Volumes/Movies/tF (1985).mp4",
        "InlineParameterSets": false,
        "Mp4Options": {
            "IpodAtom": false,
            "Mp4Optimize": false
        },
        "Mux": "m4v"
    },
    "Filters": {
        "FilterList": [
            {
                "ID": 3,
                "Settings": {
                    "block-height": "16",
                    "block-thresh": "40",
                    "block-width": "16",
                    "filter-mode": "2",
                    "mode": "3",
                    "motion-thresh": "1",
                    "spatial-metric": "2",
                    "spatial-thresh": "1"
                }
            },
            {
                "ID": 4,
                "Settings": {
                    "mode": "7"
                }
            },
            {
                "ID": 7,
                "Settings": {
                    "mode": 2,
                    "rate": "27000000/900000"
                }
            },
            {
                "ID": 14,
                "Settings": {
                    "crop-bottom": 0,
                    "crop-left": 0,
                    "crop-right": 0,
                    "crop-top": 0,
                    "height": 1036,
                    "width": 1920
                }
            }
        ]
    },
    "Metadata": {
        "Name": ""
    },
    "PAR": {
        "Den": 1,
        "Num": 1
    },
    "SequenceID": 0,
    "Source": {
        "Angle": 0,
        "Path": "/Users/thisguy/Downloads/complete/tF (1985).mkv",
        "Range": {
            "End": 20,
            "Start": 1,
            "Type": "chapter"
        },
        "Title": 1
    },
    "Subtitle": {
        "Search": {
            "Burn": true,
            "Default": false,
            "Enable": true,
            "Forced": true
        },
        "SubtitleList": [
            {
                "Burn": false,
                "Default": true,
                "Forced": false,
                "Track": 0
            },
            {
                "Burn": true,
                "Default": false,
                "Forced": false,
                "Name": "English-PGS",
                "Track": 1
            }
        ]
    },
    "Video": {
        "ChromaLocation": 1,
        "ColorInputFormat": 0,
        "ColorMatrix": 1,
        "ColorOutputFormat": 0,
        "ColorPrimaries": 1,
        "ColorRange": 0,
        "ColorTransfer": 1,
        "Encoder": "x264",
        "HardwareDecode": 0,
        "Level": "4.0",
        "Options": "",
        "Preset": "slow",
        "Profile": "high",
        "QSV": {
            "AdapterIndex": 0,
            "AsyncDepth": 0,
            "Decode": false
        },
        "Quality": 20.0,
        "Tune": "",
        "Turbo": false,
        "TwoPass": false
    }
}
[17:48:20] Starting Task: Subtitle Scan
[17:48:20] Skipping crop/scale filter
[17:48:20] job configuration:
[17:48:20]  * source
[17:48:20]    + /Users/thisguy/Downloads/complete/tF (1985).mkv
[17:48:20]    + title 1, chapter(s) 1 to 20
[17:48:20]    + container: matroska,webm
[17:48:20]    + data rate: 13058 kbps
[17:48:20]  * destination
[17:48:20]    + /Volumes/Movies/tF (1985).mp4
[17:48:20]    + container: MPEG-4 (libavformat)
[17:48:20]      + align initial A/V stream timestamps
[17:48:20]      + chapter markers
[17:48:20]  * video track
[17:48:20]    + decoder: h264 8-bit (yuv420p)
[17:48:20]    + filters
[17:48:20]      + Comb Detect (mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16)
[17:48:20]      + Decomb (mode=39)
[17:48:20]      + Framerate Shaper (mode=2:rate=27000000/900000)
[17:48:20]        + frame rate: 23.976 fps -> peak rate limited to 30.000 fps
[17:48:20]    + Output geometry
[17:48:20]      + storage dimensions: 1920 x 1036
[17:48:20]      + pixel aspect ratio: 1 : 1
[17:48:20]      + display dimensions: 1920 x 1036
[17:48:20]  * Foreign Audio Search: Render/Burn-in, Forced Only
[17:48:20]    + subtitle, English [PGS] (track 1, id 0x3, Picture)
[17:48:20] sync: expecting 166913 video frames
Encoding: task 1 of 2, 94.11 % (0.00 fps, avg 0.00 fps, ETA 00h00m00s)[17:48:25] reader: done. 1 scr changes
[17:48:25] work: average encoding speed for job is 0.000000 fps
[17:48:25] comb detect: heavy 0 | light 0 | uncombed 0 | total 0
[17:48:25] vfr: 0 frames output, 0 dropped and 0 duped for CFR/PFR
[17:48:25] vfr: lost time: 0 (0 frames)
[17:48:25] vfr: gained time: 0 (0 frames) (0 not accounted for)
Encoding: task 1 of 2, 100.00 % (0.00 fps, avg 0.00 fps, ETA 00h00m00s)[17:48:25] h264-decoder done: 0 frames, 0 decoder errors
[17:48:25] sync: got 0 frames, 166913 expected
[17:48:25] Subtitle track 1 (id 0x3) 'English [PGS]': 1525 hits (0 forced)
[17:48:25] No candidate detected during subtitle scan
[17:48:25] Starting Task: Encoding Pass
[17:48:25] Skipping crop/scale filter
[17:48:25] job configuration:
[17:48:25]  * source
[17:48:25]    + /Users/thisguy/Downloads/complete/tF (1985).mkv
[17:48:25]    + title 1, chapter(s) 1 to 20
[17:48:25]    + container: matroska,webm
[17:48:25]    + data rate: 13058 kbps
[17:48:25]  * destination
[17:48:25]    + /Volumes/Movies/tF (1985).mp4
[17:48:25]    + container: MPEG-4 (libavformat)
[17:48:25]      + align initial A/V stream timestamps
[17:48:25]      + chapter markers
[17:48:25]  * video track
[17:48:25]    + decoder: h264 8-bit (yuv420p)
[17:48:25]    + filters
[17:48:25]      + Comb Detect (mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16)
[17:48:25]      + Decomb (mode=39)
[17:48:25]      + Framerate Shaper (mode=2:rate=27000000/900000)
[17:48:25]        + frame rate: 23.976 fps -> peak rate limited to 30.000 fps
[17:48:25]      + Subtitle renderer ()
[17:48:25]    + Output geometry
[17:48:25]      + storage dimensions: 1920 x 1036
[17:48:25]      + pixel aspect ratio: 1 : 1
[17:48:25]      + display dimensions: 1920 x 1036
[17:48:25]    + encoder: H.264 (libx264)
[17:48:25]      + preset:  slow
[17:48:25]      + profile: high
[17:48:25]      + level:   4.0
[17:48:25]      + quality: 20.00 (RF)
[17:48:25]      + color profile: 1-1-1
[17:48:25]      + chroma location: left
[17:48:25]  * subtitle track 1, English [UTF-8] (track 0, id 0x2, Text) -> Passthrough, Default
[17:48:25]  * subtitle track 2, English [PGS] (track 1, id 0x3, Picture) -> Render/Burn-in
[17:48:25]    + name: English-PGS
[17:48:25]  * audio track 1
[17:48:25]    + decoder: English (DTS) (5.1 ch) (1536 kbps) (track 1, id 0x1)
[17:48:25]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[17:48:25]    + mixdown: Stereo
[17:48:25]    + encoder: AAC (Apple AudioToolbox)
[17:48:25]      + bitrate: 160 kbps, samplerate: 48000 Hz
[17:48:25]  * audio track 2
[17:48:25]    + decoder: English (DTS) (5.1 ch) (1536 kbps) (track 1, id 0x1)
[17:48:25]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[17:48:25]    + mixdown: 5.1 Channels
[17:48:25]    + encoder: AAC (Apple AudioToolbox)
[17:48:25]      + bitrate: 640 kbps, samplerate: 48000 Hz
[17:48:25] sync: expecting 166913 video frames
[17:48:25] encx264: min-keyint: 24, keyint: 240
[17:48:25] encx264: encoding at constant RF 20.000000
[17:48:25] encx264: unparsed options: level=4.0:ref=4:direct=auto:subme=8:trellis=2:vbv-bufsize=31250:vbv-maxrate=25000:rc-lookahead=50
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 UnalignedStack
x264 [info]: profile High, level 4.0, 4:2:0, 8-bit
Encoding: task 2 of 2, 0.00 %[17:48:26] sync: first pts video is 0
Woodstock
Veteran User
Posts: 4621
Joined: Tue Aug 27, 2013 6:39 am

Re: Subtitle CLI Command?

Post by Woodstock »

Stream #0:3(eng): Subtitle: hdmv_pgs_subtitle
Any subtitle marked thus can ONLY be burned in on an MP4; PGS is not compatible with MP4. Handbrake will only burn in one subtitle.

You could do it to an MKV file, but that won't work if your player does not understand them.
Barnaby98994
New User
Posts: 3
Joined: Sat Mar 30, 2024 5:02 am

Re: Subtitle CLI Command?

Post by Barnaby98994 »

Thank you, Woodstock.

I am getting closer... Can you tell me is there anyway to determine if Foreign Audio Search subtitles exist? If they do, I can --set-default 1. Otherwise, I would --set-default 0.

My updated CLI currently looks like this:

HandBrakeCLI --preset "HQ 1080p30 Surround" --audio-lang-list eng --all-audio --subtitle-lang-list eng --all-subtitles --subtitle-default 1 --format av_mp4 --input [mkv filename] --output [mp4 filename]
Barnaby98994
New User
Posts: 3
Joined: Sat Mar 30, 2024 5:02 am

Re: Subtitle CLI Command?

Post by Barnaby98994 »

Apologies, I should have been more clear... I would set-default to 1 if Foreign Audio Search is there and it is 'Track 1'. I am assuming if it is there, it would always be track 1. I would set default to 0 if Foreign Audio Search is not there because I don't want the full subtitles to get burned in... At least, that is my thought process.
Woodstock
Veteran User
Posts: 4621
Joined: Tue Aug 27, 2013 6:39 am

Re: Subtitle CLI Command?

Post by Woodstock »

The log shows:

Code: Select all

[17:48:20]  * Foreign Audio Search: Render/Burn-in, Forced Only
[17:48:20]    + subtitle, English [PGS] (track 1, id 0x3, Picture)
This means that subtitle 1 had 10% or fewer subtitles than the other English subtitle track. (FAS looks for that 10% figure)

The "--all-subtitles" is overridden by the MP4 file type, unfortunately. If you didn't have one of them being burned in, you'd get zero subtitles from a BD source. Setting "--subtitle-default = 1" just means that the lowest-numbered subtitle track is what will be burned in.

Taking subtitles from MKV files to put in MP4s is a pain, because MKV doesn't place as many restrictions on type. I used to go through this all the time... until I decided to upgrade my players to being able to handle MKV files. I used to make special encodes for MP4-only players, but got rid of those as my frustrations grew.

Then, I needed to rearrange some of the flags to make what I used to have to burn in become just "default" (different players use different flags).
Post Reply