Skip to content

Subtitle Behaviours Overhaul #1860

Open

Description

@wellloaded

It would be nice to have Handbrake automate things up when a video source has available external subtitles.

This I guess would mean extend the default behaviour to look (and optionally prefer/not prefer) subtitle files present as an external file in the same folder the the source video lives.

Of course this would mean relay on the filename for the language selection or scan .idx/.sub for additional details but I guess "any" can also be an option as per internal subtitles.

it would help in my opinion

Thanks

Activity

  1. woodstockathbf commented on Jan 31, 2019

    @woodstockathbf

    How do you propose this feature to work, given that SRT (and soon SSA) subtitles do not need to be in the same subdirectory or even have similar names to the video file being encoded? Do you envision it searching all drives, attempting to find the subtitles, so as to determine if it should include them in the menu?

  2. jstebbins commented on Jan 31, 2019

    @jstebbins
    Contributor

    SSA is doable if you make some simplifying assumptions about how things are named. If HandBrake allowed import of other supported subtitle types like vobsub and pgs, these also would be doable. But the file naming rules would have to be pretty strict which would negate much of the utility of such a feature since the user would have to make sure ahead of time that the files are properly named.

    There are players that have a feature like this, and we often get issues raised about HandBrake generating spurious subtitle tracks because the player incorrectly read some text file and showed it as an extra subtitle track. The players often have more lenient rules for determining when to use an external text file as a subtitle track. But this kind of error would potentially ruin someone's encode and waste hours of their time, so it's a more serious issue for HandBrake than it is for these players.

    SRT is not doable because correctly parsing SRT requires that you also know what character code set the SRT file is using. This information is not contained in the SRT and can not be reliably guessed by looking at the characters in the file. We get enough noise in the forums and github issues from incorrect use of the current SRT import functionality. People use random SRT files without any understanding about how code sets work and why the setting is required. If SRT files were automatically read as source subtitle tracks, the selection behaviour rules for automatically adding subtitles to an encode would have to ignore SRT source tracks since the necessary information to process the SRT is not available. So the SRT could appear as a source track and be selectable that way instead of opening the file, but that's kind of a pointless distinction.

    Overall, I don't see this as a high value feature worthy of much of anyone's time. But if a well written patch landed in my lap, I probably wouldn't ignore it.

  3. changed the title [-]Subtitles default behaviour: extend preference to external subtile files[/-] [+]Subtitle Behaviours Overhaul[/+] on Dec 20, 2019
  4. sr55 commented on Dec 20, 2019

    @sr55
    Contributor

    Been contemplating a redesign of the subtitle defaults as per #2129 for Audio.

    Here are my thoughts for the behaviour tab to really make it a lot clearer what's going on.

    Example of a Track Layout Design


    Subtitle Behaviours

    Language Track Choice Is Default (Priority) Passthru (Priority) Forced Only Track Naming
    Foreign Audio N/A No Preferred Yes Automatic
    English All Yes (First) No No Custom: YYYYYY
    German First No Yes, else drop No None
    Imported N/A No Yes, else drop No None

    [ X ] Automatically import SRT/SSA where the filename matches source filename. (If Supported)
    [ X ] Passthru Track name if available.

    Default Track Order: [ComboBox V]

    • By Language (Ordered as above)
    • By Track ID (Same as source)

    • Language (Dropdown)

      • Standard choice of languages.
    • Track Choice (Dropdown)

      • What tracks do we add to the list. Choices include:
        • First Track
        • Second Track
        • First and Second Track
        • All Tracks
    • Is Default (Dropdown)

      • Yes (First)
      • Yes (Last)
      • Passthru from source?
      • No
    • Passthru (Dropdown)

      • Preferred (If possible, passthru, burn-in otherwise)
      • Yes, else Drop
      • No
    • Forced Only (Checkbox)

      • Yes
      • No
    • Track Naming (Combo / Text Field)

      • Automatic
      • None
      • Custom: [ Text Field Entry, maybe with placeholders? ]

    • Where one is selected by a previous track, option is ignored for subsequent tracks.

    • Where "Any" language is selected, No other tracks can be added. We should also make sure the UI's follow the same ordering standard.

    • The existing track selection / management pane would still exist for tweaking.

    • We would potentially want to make this behaviours tab the default view. At which point, we have a sub-tab of some kind to display (and allow adjustment for) "Actual Output". Not sure we have space to show both at the same time.


    This will require changing some preset keys in order for this to work so would need agreement before pushing on.

  5. bradleysepos commented on Dec 20, 2019

    @bradleysepos
    Contributor

    Automatically import SRT/SSA where the filename matches source filename. (If Supported)

    Probably want burn in / other sub options for this.

    We would potentially want to make this behaviours tab the default view. At which point, we have a sub-tab of some kind to display (and allow adjustment for) "Actual Output".

    Yes. This might be the single biggest solution to the current confusion.

  6. jstebbins commented on Dec 22, 2019

    @jstebbins
    Contributor

    Once #2495 is merged I plan to start working on using libav for transcoding subtitles. We currently transcode ssa and srt to tx3g when using the mp4 container. We can use libav for this. With libav we could transcode any supported text source to srt, ssa, webvtt, and tx3g. In theory, we can also transcode bitmap subs to vobsub format.

    Also, I've been thinking it would be nice to be able to write subtitle tracks as separate files (e.g. .srt, .ass, .webvtt and .sub/.idx formats) since some players can automatically import external subtitle files (vlc, mpv, kodi). This would allow for better subtitle support when using the mp4 container. And in the case of webm, the only supported "standard" way of including subtitles is an external webvtt.

    So might want to think about what we want to support and how to represent that in the UI.

  7. sr55 commented on Dec 30, 2019

    @sr55
    Contributor

    Linking #2545 to consider order in the above design too.

  8. jstebbins commented on Mar 30, 2020

    @jstebbins
    Contributor

    So, with the ability to export subtitle files, we have another tier we can add to passthru behavior.
    We have a bit of a matrix of possibilities

    • Passthru (Dropdown)
      • Passthru if possible, else Drop
      • Export if possible, else Drop
      • Passthru if possible, else Burn
      • Export if possible, else Burn
      • Passthru if possible, else Export if possible, else Drop
      • Export if possible, else Passthru if possible, else Drop
      • Passthru if possible, else Export if possible, else Burn
      • Export if possible, else Passthru if possible, else Burn
      • Burn Only

    Hehe, am I missing something? I can't help but think there's got to be a more intuitive way to represent this.

  9. Haravikk commented on Apr 4, 2020

    @Haravikk

    Glad to see this area is being looked at!

    One thing I'd like to see is more of a connection between the subtitle selection and the audio selection, currently it doesn't appear to be possible to change subtitle selection automatically depending upon which audio tracks are available (or if it is then it's not obvious to me)?

    For example, I watch a lot of anime, and sometimes that's only available with Japanese audio and subtitles, other times it's available with dubbing, but the quality of that can vary (I'm not a purist, but sometimes the casting just leaves a lot to be desired). However this results in some complex selection behaviours, as I want to include both English and Japanese audio, but my subtitle selection depends upon which audio tracks are available.

    For example, I might want to set up something like the following:

    Include any of the following audio tracks if present:
        English (default, search for foreign audio subtitled in english and include as default subtitles)
        Japanese (include full English subtitle track if present)
    

    If an Anime only has Japanese audio then it should have a full English subtitle if possible, if it only has English then only a foreign audio search will be performed for English foreign audio/signs subtitles. If both English and Japanese audio are found then both full English subtitles and the result of a foreign audio search should be included, with the latter as default, so if I watch a re-encoded dual audio the default would be English with minimal subtitles, but I can switch to Japanese with full subtitles if I want to.

    This might be a bit complex UI wise, I envision a window with basic options at the top (for specifying formats/passthru) then two columns; on the left will be the list of languages with checkboxes to include them or not. Selecting a language will open up subtitle selection in the right column, where I can choose which subtitles should be included if the selected audio language was found.

    If automatic passthru/burn-in behaviour is set globally, then the only conflict that could occur is that different subtitles may be recommended as defaults for different languages, but since ordering matters I think it's fine to just use the default subtitle for the first audio language found (or the next and so-on, until a default subtitle, if any, is found).

    I realise this is a much more complex setup to present, but I think it's probably the only way to get fully flexible automatic behaviour that can cover as many cases as possible.

  10. jstebbins commented on Apr 5, 2020

    @jstebbins
    Contributor

    it doesn't appear to be possible to change subtitle selection automatically depending upon which audio tracks are available

    There are 2 options related to this on the subtitle "Track Selection" pane

    • Add Foreign Audio Scan Pass
    • Add subtitle track if default audio is not (this text is context sensitive in linux gui)

    The first is sensitive to the language of the first audio track in the source and your "preferred language" setting. Your preferred language is set by adding a language to the "Selected Languages" on the subtitle "Track Selection" pane. If the first audio track matches your preferred language, foreign audio scan will scan all subtitle tracks in your preferred language for events that look like they might be translations for foreign audio. If such events are found, a subtitle track is added to your output tracks that will have only those foreign audio translation events.

    The second is sensitive to the audio track you have set as the default audio track in your output audio tracks. This will be the first output audio track unless you manually change it. If that default audio track is not your preferred language. The first source subtitle track matching your preferred language will be added to your list of output subtitle tracks.

    My personal preference for settings is the following:
    On the audio track selection pane, selected languages are "Any", then "English". "Selection Behavior" is First Matching. For sources that have a first audio track that is not English, that first audio track will be the first track in my output. If the source also has an English track that will be the second track in my output. If the first audio track in the source is English, only an English audio track will be put in my output.

    On the subtitle selection pane, selected language is only "English". This established my "preferred language". "Add Foreign Audio Scan Pass" and "Add English subtitle track if default audio is not English". For sources where the first audio track is not English, this results in an English subtitle track being output. For sources where the first audio track is English, this results in a foreign audio scan pass being performed and subtitle track added (and set as the default subtitle track) if foreign audio translation events are found.

    I never use the MP4 container and never burn in subtitles. But I could see where some more flexibility in how to specify what subtitle gets burned could be useful to some.

  11. Haravikk commented on Apr 18, 2020

    @Haravikk

    Add subtitle track if default audio is not (this text is context sensitive in linux gui)

    Is this perhaps an option that isn't present in the Mac version of the app? I can't seem to find it anywhere? It probably would solve my specific need if I could use it, though I do still wonder if a UI could make it more explicit about how the selection behaviour will work, as it can get a bit confusing trying to reconcile what you want to do vs. what you're telling Handbrake to do.

  12. sr55 commented on Jul 17, 2020

    @sr55
    Contributor

    #3014 -> A request to "prefer" subtitle types. Throws another layer of complexity in there so I'll need to have a think about how this would fit into my proposal.

  13. TrekMaster commented on Dec 15, 2020

    @TrekMaster

    If you're looking into subtitles, it would be great to convert PGS subtitles into text (either Tx3g or PST) using OCR, especially when using an MP4 container. Subler does and it's very fast and efficient.

  14. eusi commented on May 1, 2021

    @eusi

    Hey guys,
    Is there already something in progress or roughly planned (on a roadmap)?

  15. 21 remaining items

  16. sr55 commented on Feb 23, 2024

    @sr55
    Contributor

    @TrekMaster -

    HandBrake 1.7 will strill trigger burn-in if there is a compatibility conflict. I.e PGS in MP4. There is no way to stop this.

    The new panel design solves this with the "Passthru else drop" option

  17. TrekMaster commented on Feb 24, 2024

    @TrekMaster

    Is there perhaps a build I can test?

  18. nevaran commented on Aug 24, 2024

    @nevaran

    Could it not be easily made to "default" the first option that finds a regex "contains" search of the subtitles names? Since pretty much every subtitle ive seen has the language written out somewhere in the entry. In which case having to search the first that has "eng" (uppercase ignored) should be able to grab the first (or last if an additional option is added) subtitles entry and default it. Would save a decent amount of going around manually editing it before adding the media in the queue; its quite the annoyance to the point i didnt bother doing it for 95% of the stuff i got

  19. eusi commented on Aug 26, 2024

    @eusi

    @nevaran If I ve understood you correctly that is exactly what I did in my fork (longer time ago...): https://github.com/eusi/HandBrake (simple example/description in README below)?

  20. daniel22-git commented on Sep 16, 2024

    @daniel22-git

    Isn't there at least a way to just do a 1:1 passthrough of the subtitles that are already present in an mkv and just take the default and forced settings as there are already set in the input file and to tick the checkboxes?

    I don't understand what the issue is with this example scenario. Isn't it basically just -c:s copy in ffmpeg?

  21. sr55 commented on Sep 16, 2024

    @sr55
    Contributor

    @dandud100
    If your referring to the SRT->SSA issue, that's tracking under a different issue and is a limitation of the HandBrake pipeline until someone wants to have a go at fixing it. It's not getting fixed as part of this issue.

    If talking in general, it is not always possible to passthru subtitles. WebM and to a lesser extend, MP4 both have limitations as to what is allowed. Thus, the new behaviours screen will offer better choice on what to do in those circumstances.


    Could it not be easily made to "default" the first option that finds a regex "contains" search of the subtitles names? Since pretty much every subtitle ive seen has the language written out somewhere in the entry.

    Regex isn't something I'm planning to implement. The new design is being driven off Track Language.

    While I've got some ideas about imported files but I've not yet implemented these. Right now they just get "tacked on" but I want to get the rules to handle those too. The current iteration will try to auto-detect language of external subtitles based on filename. (Either ISO639 or Native Name) It won't get 100% of files but should get many files this way.

    When I get some time to get back to this, I'll share more around what I'm going to do with external files.

  22. daniel22-git commented on Sep 17, 2024

    @daniel22-git

    If talking in general, it is not always possible to passthru subtitles.

    I am talking in general, and with an mkv as an input + output and as already suggested why not just use -c:s copy. My problem is, that i can't transcode a whole bunch of mkv to h265 without losing the subtitle settings (setting for default and forced).

  23. jstebbins commented on Sep 17, 2024

    @jstebbins
    Contributor

    why not just use -c:s copy

    HandBrake doesn't use ffmpeg cli. It uses libavcodec, libavformat, and friends directly through their public API. HandBrake has it's own internal pipeline for handling of subtitles that requires enhancements in order to do what you are requesting.

  24. heliosyne commented on Oct 30, 2024

    @heliosyne

    If talking in general, it is not always possible to passthru subtitles.

    I am talking in general, and with an mkv as an input + output and as already suggested why not just use -c:s copy. My problem is, that i can't transcode a whole bunch of mkv to h265 without losing the subtitle settings (setting for default and forced).

    FWIW, using ffmpeg beforehand to dump the subtitle tracks to separate files works very well and avoids the issue entirely. You can use a tool like SubtitleEdit to timeshift the subtitles if you're cutting the video. Output to MKV and it's very easy to reinsert the subtitle file(s) afterward using mkvtoolnix. You can also leave them seperate. External subtitle files are well supported and it also makes it trivial to fix any typos or timing errors you find during playback.

  25. Garfield999 commented on Mar 13, 2025

    @Garfield999

    Is there still no option to passthrough a default subtitle to output? Means: import a video, analyze which subtitle has default flag set (if there is any) and mark it as default in subtitle settings. With current version, default checkbox is unchecked after opening a video with default subtitle set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions