Help! How can I burn in subtitles when converting tom MKV to MP4?

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
peterpayne
New User
Posts: 2
Joined: Sun Feb 19, 2023 1:44 pm

Help! How can I burn in subtitles when converting tom MKV to MP4?

Post by peterpayne »

Description of problem or question:

Hello, I am trying to use HandbrakeCLI to convert MKV to MP4 files, and permanently burn in subtitles, which I need in burned-in form to edit later.


Steps to reproduce the problem (If Applicable):

I have been experimenting with various commands but can't find anything that will burn the subtitles in. Doing this with Handbrake itself works perfectly, but not with HandbrakeCLI.

The example string I am using is

HandbrakeCLI --preset "Apple 1080p30 Surround" -i /Users/pp/bofuri.mkv -o /Users/pp/bofuri_burned.mkv --subtitle=1,2,3 --subtitle-forced=1 --subtitle-burned=1

(I've tried replacing the subtitle=1,2,3 with many values, but nothing seems to get it to add the English subs that are in the file to my MP4 like Handbrake itself can easily do)

HandBrake version (e.g., 1.0.0):

I am using HandbrakeCLI 1.5.1 it looks like.


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

Fully updated Mac OS program on Apple Silicon M1. OS version is 13.2.1 (22D68).



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

Code: Select all

pp@Macbook ~ % HandbrakeCLI --preset "Apple 1080p30 Surround" -i /Users/pp/bofuri.mkv -o /Users/pp/bofuri_burned.mkv --subtitle=1,2,3 --subtitle-forced=1 --subtitle-burned=1
[00:01:34] Compile-time hardening features are enabled
[00:01:34] hb_init: starting libhb thread
[00:01:34] thread 16f997000 started ("libhb")
HandBrake 1.5.1 (2022011000) - Darwin arm64 - https://handbrake.fr
10 CPUs detected
Opening /Users/pp/bofuri.mkv...
[00:01:34] CPU: 
[00:01:34]  - logical processor count: 10
[00:01:34] hb_scan: path=/Users/pp/bofuri.mkv, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:333: failed opening UDF image /Users/pp/bofuri.mkv
disc.c:437: error opening file BDMV/index.bdmv
disc.c:437: error opening file BDMV/BACKUP/index.bdmv
bluray.c:2646: nav_get_title_list(/Users/pp/bofuri.mkv/) failed
[00:01:34] 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
[00:01:34] dvd: not a dvd - trying as a stream/file instead
Input #0, matroska,webm, from '/Users/pp/bofuri.mkv':
  Metadata:
    ENCODER         : Lavf59.16.100
  Duration: 00:23:40.13, start: 0.000000, bitrate: 2164 kb/s
  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      ENCODER         : Lavc59.18.100 libx265
      BPS-eng         : 1995595
      DURATION-eng    : 00:23:40.085708333
      NUMBER_OF_FRAMES-eng: 34048
      NUMBER_OF_BYTES-eng: 354239412
      _STATISTICS_WRITING_APP-eng: mkvpropedit v45.0.0 ('Heaven in Pennies') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2023-02-08 17:21:10
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(jpn): Audio: aac (LC), 44100 Hz, stereo, fltp (default)
    Metadata:
      BPS-eng         : 128002
      DURATION-eng    : 00:23:40.108000000
      NUMBER_OF_FRAMES-eng: 61160
      NUMBER_OF_BYTES-eng: 22722119
      _STATISTICS_WRITING_APP-eng: mkvpropedit v45.0.0 ('Heaven in Pennies') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2023-02-08 17:21:10
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2(eng): Subtitle: ass (default)
    Metadata:
      title           : English subs
      BPS-eng         : 139
      DURATION-eng    : 00:21:53.610000000
      NUMBER_OF_FRAMES-eng: 354
      NUMBER_OF_BYTES-eng: 22831
      _STATISTICS_WRITING_APP-eng: mkvpropedit v45.0.0 ('Heaven in Pennies') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2023-02-08 17:21:10
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:3: Attachment: ttf
    Metadata:
      filename        : Roboto-Medium.ttf
      mimetype        : application/x-truetype-font
  Stream #0:4: Attachment: ttf
    Metadata:
      filename        : Roboto-MediumItalic.ttf
      mimetype        : application/x-truetype-font
  Stream #0:5: Attachment: ttf
    Metadata:
      filename        : arial.ttf
      mimetype        : application/x-truetype-font
  Stream #0:6: Attachment: ttf
    Metadata:
      filename        : arialbd.ttf
      mimetype        : application/x-truetype-font
  Stream #0:7: Attachment: ttf
    Metadata:
      filename        : comic.ttf
      mimetype        : application/x-truetype-font
  Stream #0:8: Attachment: ttf
    Metadata:
      filename        : comicbd.ttf
      mimetype        : application/x-truetype-font
  Stream #0:9: Attachment: ttf
    Metadata:
      filename        : times.ttf
      mimetype        : application/x-truetype-font
  Stream #0:10: Attachment: ttf
    Metadata:
      filename        : timesbd.ttf
      mimetype        : application/x-truetype-font
  Stream #0:11: Attachment: ttf
    Metadata:
      filename        : trebuc.ttf
      mimetype        : application/x-truetype-font
  Stream #0:12: Attachment: ttf
    Metadata:
      filename        : trebucbd.ttf
      mimetype        : application/x-truetype-font
  Stream #0:13: Attachment: ttf
    Metadata:
      filename        : verdana.ttf
      mimetype        : application/x-truetype-font
  Stream #0:14: Attachment: ttf
    Metadata:
      filename        : verdanab.ttf
      mimetype        : application/x-truetype-font
  Stream #0:15: Attachment: ttf
    Metadata:
      filename        : CONSOLA.TTF
      mimetype        : application/x-truetype-font
  Stream #0:16: Attachment: ttf
    Metadata:
      filename        : CONSOLAB.TTF
      mimetype        : application/x-truetype-font
[00:01:34] scan: decoding previews for title 1
[00:01:34] scan: audio 0x1: aac, rate=44100Hz, bitrate=1 日本語 (AAC LC) (2.0 ch)
Scanning title 1 of 1, preview 6, 60.00 %[00:01:35] scan: 10 previews, 1920x1080, 23.976 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
Scanning title 1 of 1, preview 10, 100.00 %[00:01:35] libhb: scan thread found 1 valid title(s)
+ Using preset: Apple 1080p30 Surround
+ title 1:
  + stream: /Users/pp/bofuri.mkv
  + duration: 00:23:40
  + size: 1920x1080, pixel aspect: 1/1, display aspect: 1.78, 23.976 fps
  + autocrop: 0/0/0/0
  + chapters:
    + 1: duration 00:23:40
  + audio tracks:
    + 1, 日本語 (AAC LC) (2.0 ch) (iso639-2: jpn)
  + subtitle tracks:
    + 1, English [SSA]
Warning: Could not find subtitle track 2, skipped
Warning: Could not find subtitle track 3, skipped
[00:01:36] Starting work at: Fri Feb 24 00:01:36 2023

[00:01:36] 1 job(s) to process
[00:01:36] json job:
{
    "Audio": {
        "AudioList": [
            {
                "Bitrate": 160,
                "CompressionLevel": -1.0,
                "DRC": 0.0,
                "DitherMethod": "auto",
                "Encoder": "ca_aac",
                "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": "ac3",
                "Gain": 0.0,
                "Mixdown": "stereo",
                "NormalizeMixLevel": false,
                "PresetEncoder": "copy:ac3",
                "Quality": -3.0,
                "Samplerate": 0,
                "Track": 0
            }
        ],
        "CopyMask": [
            "copy:aac",
            "copy:ac3"
        ],
        "FallbackEncoder": "ca_aac"
    },
    "Destination": {
        "AlignAVStart": false,
        "ChapterList": [
            {
                "Duration": {
                    "Hours": 0,
                    "Minutes": 23,
                    "Seconds": 40,
                    "Ticks": 127811880
                },
                "Name": ""
            }
        ],
        "ChapterMarkers": false,
        "File": "/Users/pp/bofuri_burned.mkv",
        "InlineParameterSets": false,
        "Mp4Options": {
            "IpodAtom": false,
            "Mp4Optimize": false
        },
        "Mux": "mkv"
    },
    "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": 6,
                "Settings": {
                    "mode": 2,
                    "rate": "27000000/900000"
                }
            },
            {
                "ID": 13,
                "Settings": {
                    "crop-bottom": 0,
                    "crop-left": 0,
                    "crop-right": 0,
                    "crop-top": 0,
                    "height": 1080,
                    "width": 1920
                }
            }
        ]
    },
    "Metadata": {},
    "PAR": {
        "Den": 1,
        "Num": 1
    },
    "SequenceID": 0,
    "Source": {
        "Angle": 0,
        "Path": "/Users/pp/bofuri.mkv",
        "Range": {
            "End": 1,
            "Start": 1,
            "Type": "chapter"
        },
        "Title": 1
    },
    "Subtitle": {
        "Search": {
            "Burn": false,
            "Default": true,
            "Enable": true,
            "Forced": true
        },
        "SubtitleList": [
            {
                "Burn": true,
                "Default": false,
                "Forced": true,
                "Track": 0
            }
        ]
    },
    "Video": {
        "ChromaLocation": 1,
        "ColorInputFormat": 0,
        "ColorMatrix": 1,
        "ColorOutputFormat": 0,
        "ColorPrimaries": 1,
        "ColorRange": 1,
        "ColorTransfer": 1,
        "Encoder": "x264",
        "Level": "4.0",
        "Options": "",
        "Preset": "medium",
        "Profile": "high",
        "QSV": {
            "AdapterIndex": 0,
            "AsyncDepth": 0,
            "Decode": false
        },
        "Quality": 22.0,
        "Tune": "",
        "Turbo": false,
        "TwoPass": false
    }
}
[00:01:36] Skipping subtitle scan.  No suitable subtitle tracks.
[00:01:36] Starting Task: Encoding Pass
[00:01:36] Skipping crop/scale filter
[00:01:36] [ass] libass API version: 0x1502000
[00:01:36] [ass] libass source: tarball: 0.15.2
[00:01:36] [ass] Shaper: FriBidi 1.0.11 (SIMPLE) HarfBuzz-ng 3.1.2 (COMPLEX)
[00:01:36] [ass] Using font provider coretext
[00:01:36] job configuration:
[00:01:36]  * source
[00:01:36]    + /Users/pp/bofuri.mkv
[00:01:36]    + title 1, chapter(s) 1 to 1
[00:01:36]    + container: matroska,webm
[00:01:36]    + data rate: 2164 kbps
[00:01:36]  * destination
[00:01:36]    + /Users/pp/bofuri_burned.mkv
[00:01:36]    + container: Matroska (libavformat)
[00:01:36]  * video track
[00:01:36]    + decoder: hevc 8-bit (yuv420p)
[00:01:36]    + filters
[00:01:36]      + 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)
[00:01:36]      + Decomb (mode=39)
[00:01:36]      + Framerate Shaper (mode=2:rate=27000000/900000)
[00:01:36]        + frame rate: 23.976 fps -> peak rate limited to 30.000 fps
[00:01:36]      + Subtitle renderer ()
[00:01:36]    + Output geometry
[00:01:36]      + storage dimensions: 1920 x 1080
[00:01:36]      + pixel aspect ratio: 1 : 1
[00:01:36]      + display dimensions: 1920 x 1080
[00:01:36]    + encoder: H.264 (libx264)
[00:01:36]      + preset:  medium
[00:01:36]      + profile: high
[00:01:36]      + level:   4.0
[00:01:36]      + quality: 22.00 (RF)
[00:01:36]      + color profile: 1-1-1
[00:01:36]      + chroma location: left
[00:01:36]  * subtitle track 1, English [SSA] (track 0, id 0x2, Text) -> Render/Burn-in, Forced Only
[00:01:36]  * audio track 1
[00:01:36]    + decoder: 日本語 (AAC LC) (2.0 ch) (track 1, id 0x1)
[00:01:36]      + samplerate: 44100 Hz
[00:01:36]    + mixdown: Stereo
[00:01:36]    + encoder: AAC (Apple AudioToolbox)
[00:01:36]      + bitrate: 160 kbps, samplerate: 44100 Hz
[00:01:36]  * audio track 2
[00:01:36]    + decoder: 日本語 (AAC LC) (2.0 ch) (track 1, id 0x1)
[00:01:36]      + samplerate: 44100 Hz
[00:01:36]    + mixdown: Stereo
[00:01:36]    + encoder: AC3 (libavcodec)
[00:01:36]      + bitrate: 640 kbps, samplerate: 44100 Hz
[00:01:36] sync: expecting 34049 video frames
[00:01:36] encx264: min-keyint: 24, keyint: 240
[00:01:36] encx264: encoding at constant RF 22.000000
[00:01:36] encx264: unparsed options: level=4.0:vbv-bufsize=31250:vbv-maxrate=25000
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: ARMv8 NEON
x264 [info]: profile High, level 4.0, 4:2:0, 8-bit
Encoding: task 1 of 1, 0.00 %[00:01:36] sync: first pts video is 0
[00:01:36] sync: Chapter 1 at frame 1 time 0
[00:01:36] sync: first pts audio 0x1 is 0
[00:01:36] sync: first pts audio 0x1 is 0
Encoding: task 1 of 1, 99.78 % (66.19 fps, avg 91.55 fps, ETA 00h00m01s)[00:07:47] reader: done. 1 scr changes
Encoding: task 1 of 1, 99.99 % (66.46 fps, avg 91.47 fps, ETA 00h00m00s)[00:07:49] work: average encoding speed for job is 91.471794 fps
[00:07:49] comb detect: heavy 8188 | light 2089 | uncombed 23771 | total 34048
[00:07:49] decomb: deinterlaced 8188 | blended 2089 | unfiltered 23771 | total 34048
[00:07:49] vfr: 34048 frames output, 0 dropped and 0 duped for CFR/PFR
[00:07:49] vfr: lost time: 0 (0 frames)
[00:07:49] vfr: gained time: 0 (0 frames) (0 not accounted for)
Encoding: task 1 of 1, 99.99 % (66.46 fps, avg 91.47 fps, ETA 00h00m00s)[00:07:49] aac-decoder done: 61160 frames, 0 decoder errors
[00:07:49] aac-decoder done: 61160 frames, 0 decoder errors
[00:07:49] hevc-decoder done: 34048 frames, 0 decoder errors
[00:07:49] sync: got 34048 frames, 34049 expected
[00:07:49] sync: framerate min 23.976 fps, max 23.976 fps, avg 23.976 fps
x264 [info]: frame I:811   Avg QP:17.34  size:100105
x264 [info]: frame P:11015 Avg QP:19.06  size: 23193
x264 [info]: frame B:22222 Avg QP:21.45  size:  4857
x264 [info]: consecutive B-frames: 10.1%  6.7%  5.3% 77.8%
x264 [info]: mb I  I16..4: 27.7% 59.7% 12.6%
x264 [info]: mb P  I16..4:  6.4% 13.2%  1.8%  P16..4: 21.7%  4.3%  2.7%  0.0%  0.0%    skip:49.9%
x264 [info]: mb B  I16..4:  0.5%  0.8%  0.2%  B16..8: 15.9%  1.0%  0.2%  direct: 1.3%  skip:80.1%  L0:45.0% L1:52.9% BI: 2.1%
x264 [info]: 8x8 transform intra:60.7% inter:84.9%
x264 [info]: coded y,uvDC,uvAC intra: 40.1% 60.4% 24.9% inter: 4.9% 8.8% 0.7%
x264 [info]: i16 v,h,dc,p: 37% 25%  8% 30%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 19% 29%  5%  5%  5%  5%  6%  5%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 17% 19%  6%  8%  7%  6%  6%  4%
x264 [info]: i8c dc,h,v,p: 54% 21% 18%  7%
x264 [info]: Weighted P-Frames: Y:4.8% UV:3.3%
x264 [info]: ref P L0: 63.0% 10.0% 17.3%  9.4%  0.2%
x264 [info]: ref B L0: 84.5% 12.0%  3.5%
x264 [info]: ref B L1: 93.9%  6.1%
x264 [info]: kb/s:2504.66
[00:07:49] mux: track 0, 34048 frames, 444583707 bytes, 2504.33 kbps, fifo 2048
[00:07:49] mux: track 1, 61163 frames, 29202239 bytes, 164.50 kbps, fifo 4096
[00:07:49] mux: track 2, 40773 frames, 113609666 bytes, 639.96 kbps, fifo 2048
[00:07:49] Finished work at: Fri Feb 24 00:07:49 2023

[00:07:49] libhb: work result = 0

Encode done!

HandBrake has exited.
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Help! How can I burn in subtitles when converting tom MKV to MP4?

Post by mduell »

Either supply a subtitle that is flagged as forced, or don't require the sub be flagged as forced.

Also upgrade to the current release, of course.
Deleted User 11865

Re: Help! How can I burn in subtitles when converting tom MKV to MP4?

Post by Deleted User 11865 »

External SRT/SSA subtitles cannot contain "forced" packets, and you're asking HandBrake to skip any packets *not* flagged as forced:

Code: Select all

--subtitle-forced=1
…effectively telling HandBrake to skip all packets ;-)
peterpayne
New User
Posts: 2
Joined: Sun Feb 19, 2023 1:44 pm

Re: Help! How can I burn in subtitles when converting tom MKV to MP4?

Post by peterpayne »

Thanks for the replies. Removing --subtitle-forced=1 did the trick, awesome!

In case anyone wanders in this thread later, this line did what I needed:

HandbrakeCLI --preset "Apple 1080p30 Surround" -i /Users/pp/bofuri.mkv -o /Users/pp/bofuri_burned.mkv --subtitle=1,2,3 --subtitle-burned=1

I am a happy camper!
Post Reply