question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow use of original subtitle track title as a fallback if the resulting output title is empty

See original GitHub issue

I import a number of files where the original subtitle track title contains some important information that I’d like to preserve. The most common example I have is “Signs and Songs” subtitles intended for use when watching dubbed anime.

“Signs and Songs” subtitle tracks are solely identified by their title, meaning they do not have a unique ffmpeg disposition that could be used to distinguish them. Additionally, there isn’t really a consistent naming scheme (most encoders title the track Signs and Songs, but I’ve seen Signs, S/S, Signs / Songs, etc).

I know the keep-titles option exists, but I’d like to maintain clean title generation for audio tracks and for subtitle tracks that have a distinguishing ffmpeg disposition (such as commetary/forced).

There’s probably a couple ways to address this, but I think the easiest would be to include a config option under the Subtitle category that allows the output track title to fallback to its old value if the new one would be an empty string. I suppose this option could also be placed under Metadata, but I don’t believe I’ve ever seen an audio track outputted without a title, only subtitles.

default is an interesting edge case, because while it doesn’t trigger a change in the output title like commentary/forced do, it also (for this use case) shouldn’t trigger a fallback to the input track title. Meaning that if the default english subtitle track is titled “English Subtitles”, the better outcome is to result in a blank output title instead of falling back, as “English Subtitles” doesn’t provide any important information unlike “Signs and Songs”. Best approach is probably to have a track marked as default always write an empty title and ignore the what the config says about falling back to the input title (unless keep-titles = true, ofc)

Quick mock up of how this would work with this new option called allow-title-fallback:

keep-titles = false allow-title-fallback = false

input subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "English Subtitles"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "Signs and Songs"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced Foreign Language"
  }

output subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": null
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": null
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced / Forced"
  }

keep-titles = true allow-title-fallback = false

input subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "English Subtitles"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "Signs and Songs"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced Foreign Language"
  }

output subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "English Subtitles"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "Signs and Songs"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced Foreign Language"
  }

(behavior I’m proposing) keep-titles = false allow-title-fallback = true

input subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "English Subtitles"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "Signs and Songs"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced Foreign Language"
  }

output subtitles:
  {
      "language": "eng",
      "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": null
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",
      "title": "Signs and Songs"
  },
  {
      "language": "eng",
      "disposition": "-default-dub-original-comment-lyrics-karaoke+forced-hearing_impaired-visual_impaired-captions",
      "title": "Forced / Forced"
  }

The one edge case that can’t really be handled is where we have a titled subtitle track that probably should be marked as default, but isn’t. In this case we’d end up preserving a title where if allow-title-fallback was false, would have been wiped. (i.e. if the “English Subtitles” track in the above examples wasn’t marked as default, its title would be preserved). However that’s probably the best outcome, as the goal of this configuration option is to provide a fallback when we don’t have any useful metadata to work with, so if subtitle tracks aren’t marked properly the best the script could do is use the old track title.

I know this is a bit of an edge case, but I think it would help a lot of people who use this script for libraries that include Anime or other foreign media that include Signs and Songs.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mdhigginscommented, Aug 19, 2022

Actually this is probably what you meant

60f2b42c0baf069385c203703c5d60e6e685ecdb

DISPO_STRING dict there for you

You can also just return None to use the build in title function instead of recreating it

0reactions
sdfg2commented, Aug 20, 2022

I’m feeding mine to Jellyfin which does the same preferences, except when it tries to talk DLNA. Sometimes it’ll just pick whatever track it wants to do, no matter what I tell it - but I think that’s a problem with the dispositions (you’ll see below). I’m the sole user for my stuff, so I’m trying to strip everything I don’t need, and burn in subtitles where I do need them - then no matter what the playback device it’s a single file exactly how I want it.

The problem I have is the dispositions of the streams in the media I have:

    "audio": [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            "index": 1,                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            "codec": "flac",                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
            "bitrate": 719310,                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
            "channels": 2,                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
            "samplerate": 48000,                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            "language": "jpn",                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
            "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions"                                                                                                                                                                                                                                                                                                                                                                     
        },                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            "index": 2,                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            "codec": "flac",                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
            "bitrate": 1262843,                                                                                                                                                                                                                                                                                                                                                                                                                                                                
            "channels": 6,                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
            "samplerate": 44100,                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            "language": "eng",                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
            "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions"                                                                                                                                                                                                                                                                                                                                                                     
        },                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            "index": 3,                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            "codec": "ac3",                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
            "bitrate": 640000,                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
            "channels": 2,                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
            "samplerate": 48000,                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            "language": "jpn",                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
            "disposition": "+default-dub-original+comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions"                                                                                                                                                                                                                                                                                                                                                                     
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
    ],                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    "subtitle": [                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            "index": 4,                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            "codec": "ass",                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
            "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",                                                                                                                                                                                                                                                                                                                                                                    
            "language": "eng"                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
        },                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
            "index": 5,                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            "codec": "ass",                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
            "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",                                                                                                                    
            "language": "eng"            
        },                        
        {                              
            "index": 6,           
            "codec": "ass",              
            "disposition": "+default-dub-original-comment-lyrics-karaoke-forced-hearing_impaired-visual_impaired-captions",                                                                                                                    
            "language": "eng"                                                                                                                                                                                                                  
        }                         
    ],

As you can see, everything is default, so I’ve got no chance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hardcoding Subs with ffmpeg? - Super User
With this command, you set the source of the subtitles filter to the file containing the subtitles. If you want to burn the...
Read more >
Keyboard Control - mpv.io
Show the list of audio and subtitle streams (useful only if a UI window is used, broken on the terminal). i and I:...
Read more >
mpv(1) - Arch manual pages
mpv is a media player based on MPlayer and mplayer2. It supports a wide variety of video file formats, audio and video codecs,...
Read more >
Universal Subtitle Format (.usf) - EZTitles
Allows Outline effect to be applied for all subtitles in the output file. Selecting the None option will discard the Outline currently applied...
Read more >
title - HTML: HyperText Markup Language - MDN Web Docs
Output. Use the title attribute on an iframe to clearly identify the content of the iframe to screen readers. Open main menu.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found