Dealing with subtitles and "unknown" audio tracks.

...I'm fine with batch changing a few folders to force language to be English...but how do I do this on Mac... what tools can I use? I have a season of Fullmetal Alchemist that have unknown audio and sub, and I'm sick of playing each individually, and changing the audio to english, as it defaults to chinese, when I want to play them.

Please let me know how this batch flag changing works.

i dunno about doing it via batch and it depends on what kind of files they are but you can use 

mkvtoolnix for mkv's

mp4tools for mp4's

and i think subler ( also for mp4's) to edit them without re-encoding on a Mac

Wow after looking at those tools I'm not sure what to say. How unelegant I suppose wraps it up.

Since the language is marked as "unknown" there isn't a way for me to make one the default, and I can't change the mkv flags...I'll find another way. Thank you.

Wow after looking at those tools I'm not sure what to say. How unelegant I suppose wraps it up.

Since the language is marked as "unknown" there isn't a way for me to make one the default, and I can't change the mkv flags...I'll find another way. Thank you.

MKVtoolnix has a builtin tool called Header Editor. That tool is really fast as it does not need to remux the file after you have made the changes.

Open the Header Editor, choose "Open" from the menu and point to the MKV file you want to change. Go into the subtitles track and the click on language. When you have made the alterations you want, simply save it (takes 1 second) then you are done.

Yeah, but I have hundreds of files, even if they take a second...and just to get MKVtoolnix working I need in stall MacPorts, mess with command line. I'm an IT Manager, I get this stuff, but I get no enjoyment in using it, a shame there's not an application I can point at a folder of video files and say, change language flag. I'm surprised there isn't one actually.

Yeah, but I have hundreds of files, even if they take a second...and just to get MKVtoolnix working I need in stall MacPorts, mess with command line. I'm an IT Manager, I get this stuff, but I get no enjoyment in using it, a shame there's not an application I can point at a folder of video files and say, change language flag. I'm surprised there isn't one actually.

Why do you need Macports? That is not necessary if you are on a Mac.

Yeah, it would take some time to do it, no denying that.

Ah, I see a version that is already compiled for Mac OS X, the first few paragraphs of the Mac section talk about needing Macports to compile it yourself.

If you want to manipulate your database directly you can use the following SQL code in any SQLite Browser (e.g. ):

UPDATE media_streams SET language = "ger" WHERE stream_type_id = 2 and "index" = 1 and language = "";
UPDATE media_streams SET language = "eng" WHERE stream_type_id = 2 and "index" = 2 and language = "";

and so on.

This assumes that all of your movies have as "ger" as primary language stream (index 1) and "eng" as your secondary language stream (index 2) (normally index 0 is the video stream).

To make sure we only alter audio streams we add the stream_type_id as query parameter (1 for video, 2 for audio, 3 for subtitles).

Don't forget the " around index. Else the statement won't work because index is a key word in sql and should not be used as a column name.

1 Like

To get an overview which movies have which audio streams with/without language you can use

SELECT mdi.title, s."index", s.language 
FROM media_streams s, media_items mi, metadata_items mdi 
WHERE s.media_item_id = mi.id 
AND mi.metadata_item_id = mdi.id 
AND mdi.metadata_type = 1 
AND s.stream_type_id = 2;

here we just show the title, index and language fields of all movies (mdi.metadata_type = 1, episodes of shows would be 4) and all audio streams (s.stream_type_id = 2)

Couple years on and this still isn’t fixed.

According to the logic found here: https://support.plex.tv/hc/en-us/articles/204985278-Account-Audio-Subtitle-Language-Settings

Plex plays Unknown audio tracks if they are the only one. Then will find a solitary English subtitle file, fail a match test and show the subtitle when it shouldn’t. This is bad logic and either an oversight, or a dumb assumption on the part of the devs. As far as I can tell it would take half a line of code to change. Or a few lines to implement it as a setting.

To the numpty’s saying “go and fix the language flag on all your files”
 yes I could do that. And it would be easy enough. But that’s not the point. If I wanted to have to prep every video file to make sure it was just right and would play nice with a dumb system, then I would just use iTunes. Plex is supposed to be smarter than that. This needs to be fixed.

1 Like

I have figured out a way to deal with unknown audio tracks:
(Works on mac. The Windows solution should be something similar)

  1. download mkvtoolnix
  2. open terminal, change to the directory where your movies are
  3. if your movies are mkv then skip to 4. else convert them to mkv:
    find . -name '*.avi' | while read filename ; do "/Applications/MKVToolNix-8.2.0.app/Contents/MacOS/mkvmerge" -o "${filename%.avi}.mkv" "$filename"; done
  4. then change the header info of the mkv-s:
    find . -name "*.mkv" -exec "/Applications/MKVToolNix-8.2.0.app/Contents/MacOS/mkvpropedit" {} --edit track:a1 --set language=hun --edit track:a2 --set language=eng \;

All of my movies have Hungarian as first, and English as second audio track. If yours are different than change the command accordingly.

@CCarpo said:
If you want to manipulate your database directly you can use the following SQL code in any SQLite Browser (e.g. ):

UPDATE media_streams SET language = “ger” WHERE stream_type_id = 2 and “index” = 1 and language = “”; UPDATE media_streams SET language = “eng” WHERE stream_type_id = 2 and “index” = 2 and language = “”;

and so on.

This assumes that all of your movies have as “ger” as primary language stream (index 1) and “eng” as your secondary language stream (index 2) (normally index 0 is the video stream).

To make sure we only alter audio streams we add the stream_type_id as query parameter (1 for video, 2 for audio, 3 for subtitles).

Don’t forget the " around index. Else the statement won’t work because index is a key word in sql and should not be used as a column name.

Question about the sql snippet. I need to change the language to english form only one library (e.g. Movies), the library ID is “10”. Can you please help with a modified UPDATE sql code to do that?

id library_id name name_sort section_type language agent scanner user_thumb_url user_art_url user_theme_music_url public created_at updated_at scanned_at display_secondary_level user_fields query_xml query_type uuid changed_at


1 Indian 1 en com.plexapp.agents.imdb Plex Movie Scanner 2014-10-30 17:11:07 2016-05-13 17:52:45 2016-05-30 06:09:01 7cd8a525-8879-48a1-b159-190cc7faaa0b 364026
7 Mini Serie 2 en com.plexapp.agents.thet Plex Series Scanne 2014-10-31 14:13:54 2016-03-26 06:53:19 2016-05-30 06:09:05 4da77994-0eca-4639-80a5-5374a7b79da5 332490
10 Movies 1 en com.plexapp.agents.them Plex Movie Scanner 2015-02-04 08:55:50 2016-05-05 22:19:37 2016-06-07 07:55:48 pr%3Aenable 68619170-5abd-4caf-a2c9-3ef5865f6113 361002
12 TV Shows 2 en com.plexapp.agents.thet Plex Series Scanne 2015-09-24 23:13:13 2016-04-09 13:27:55 2016-05-30 06:09:24 6abe7600-0a37-421b-a909-c29bc3ee4e1e 345140

Bump. Any updates that any of the folks are aware of? Thank you.

FYI, for those looking to update only a specific library. In the below example my library_section_id is 10 (english Movies).

UPDATE media_streams SET language = "eng" 
WHERE id IN (SELECT s.id
		FROM media_streams s, media_items mi, metadata_items mdi 
		WHERE s.media_item_id = mi.id 
		AND mi.metadata_item_id = mdi.id 
		AND mdi.metadata_type = 1 
		AND s.stream_type_id = 2
		AND mdi.library_section_id = 10
		AND s.language = "");

I was recently looking at the best way to deal with the whole unknown audio issue due to subtitles being enabled on iOS devices regardless of language settings, I came to the conclusion that this something that should be “fixed” at the file level, because what’s to stop Plex modifying the the metadata in the sqlite DB after running your own UPDATE query if the media is re-analysed by a process you might not even trigger? Surely any sqlite query is just patching over a problem that requires modifications to the media files themselves for the correct fix. Example, what happens if is your Plex DB gets corrupt (and for whatever reason you don’t have a backup), so you re-scan your media files, but now all the audio language data you set is lost, because its not in the file itself (the true source). Sure you can re-run the sqlite query, but even that requires cmd knowledge or being able to install sqlitebrowser or some form of sqlite GUI.

Windows, macOS/OS X and Unix/Unix-like all support mkvtoolnix (.mkv), mp4box (.mp4) via command line or GUI, the elephant in the room is tagging AVI audio streams, but remuxing that to mkv is pretty easy, via batch or single file command.

Someone correct me if I’ve missed the point. Just my thoughts from researching this myself. Personally I just went through my media library, did an audit to obtain the files and the full file path with missing audio labels, then wrote a shell script to loop through this list of mp4/mkv files with mp4box or mkvpropedit respectively.

@jamesmacwhite said:
I was recently looking at the best way to deal with the whole unknown audio issue due to subtitles being enabled on iOS devices regardless of language settings, I came to the conclusion that this something that should be “fixed” at the file level, because what’s to stop Plex modifying the the metadata in the sqlite DB after running your own UPDATE query if the media is re-analysed by a process you might not even trigger? Surely any sqlite query is just patching over a problem that requires modifications to the media files themselves for the correct fix. Example, what happens if is your Plex DB gets corrupt (and for whatever reason you don’t have a backup), so you re-scan your media files, but now all the audio language data you set is lost, because its not in the file itself (the true source). Sure you can re-run the sqlite query, but even that requires cmd knowledge or being able to install sqlitebrowser or some form of sqlite GUI.

Windows, macOS/OS X and Unix/Unix-like all support mkvtoolnix (.mkv), mp4box (.mp4) via command line or GUI, the elephant in the room is tagging AVI audio streams, but remuxing that to mkv is pretty easy, via batch or single file command.

Someone correct me if I’ve missed the point. Just my thoughts from researching this myself. Personally I just went through my media library, did an audit to obtain the files and the full file path with missing audio labels, then wrote a shell script to loop through this list of mp4/mkv files with mp4box or mkvpropedit respectively.

Would you be able to share any of your shell scripts? This whole process has been annoying me lately and I was looking into setting up some scripts to auto update the SQLite database or auto update the files with the correct audio language and it sounds like you might have already gotten most of the way there.

I’m avoiding touching the SQLite database with any UPDATE query, purely because I firmly believe the issue should be corrected a the file server level, seems the Plex metadata is driven by the file information itself. It makes no sense to me to modify the SQLite DB directly to me anyway.

I’ve wrote a very basic loop to fix the current media file I have, I am evaluating options on the best possible methods to maintain this job going forward. Essentially for MP4 and MKV its quite easy to run mkvpropedit or mp4box in a loop of media files, for example I did this:

MEDIA_LIST="media_files_list.txt"
while IFS= read -r MEDIA
do
  if [[ $MEDIA == *"mp4"* ]]
  then
         /usr/local/bin/mp4box -lang 1=eng "$MEDIA"
  elif [[ $MEDIA == *"mkv"* ]]
  then
        /usr/bin/mkvpropedit "$MEDIA" --edit track:a1 --set language=eng
 else
      echo "$MEDIA is not a MP4 or MKV file"
 fi
done < "$MEDIA_LIST"

This assumes that the first audio track within the files are is English. I generally don’t have many multiple audio tracks.

I only have MP4 or MKV files, any other format I converted (remuxed to mkv) such as avi, mpg, divx etc, prior to doing this, as I could not find any command line tool to modify the audio track of an avi file and others easily, plus avi is OLD, most basic clients support MP4 these days.

The media list was generated by essentially exporting my media library with plex2csv, the reason I used this is because I wanted to understand how the schema of the data is, which is what plex2csv does (exports your media library via the SQLite DB at a specific level), to automate this, a SELECT query would need to be done on the SQLite database to look for blank values on audio language or N/A on the audio track and write this to a file somewhere. Unfortunately, my SQL skills are limited, as you’d need to perhaps perform an INNER JOIN on a couple of tables, like media_part and others to get both the Part File value in the query (language and part file are in different tables), but that’s my next goal. The CSV export was good to understand the fields though.

From there this script could be automated via cron to run at intervals to query the Plex DB, identify the files that need to be tagged with the correct Language ISO code and then use something similar to the loop through the list to correctly tag the audio.

Something like this would need to be perhaps smarter to handle multiple audio tracks in a file and when eng is not the first audio stream etc. Its doable, just finding the time really, or looking at potential pre-existing solutions. Mostly it would be driven by the SQLite DB however, though only SELECT queries would be needed to output the required data and not any modifications directly.

Nice, thanks for the info. I’ll have to look into all of this more and hopefully find a fairly automated solution for all of it going forward.

Indeed. I’m also evaluating the best way forward to keep all audio tagged correctly. If I don’t find anything, I may end up writing some form of shell script or channel myself. Doing batch stuff makes it easier, but its the automation part which is missing and that’s probably where a specific channel/addon comes in, with a GUI and functionality.

@CCarpo said:
To get an overview which movies have which audio streams with/without language you can use

SELECT mdi.title, s.“index”, s.language FROM media_streams s, media_items mi, metadata_items mdi WHERE s.media_item_id = mi.id AND mi.metadata_item_id = mdi.id AND mdi.metadata_type = 1 AND s.stream_type_id = 2;

here we just show the title, index and language fields of all movies (mdi.metadata_type = 1, episodes of shows would be 4) and all audio streams (s.stream_type_id = 2)

I’d be interested if this query could be modified to include the media_parts table so the ‘file’ column can be used?

Edit: A basic example, of what I’m after is below, could be better, but my approach is to get the full part file which doesn’t have an audio language assigned and then get a script to loop through the results, to remux or edit the container to set the audio language accordingly.

SELECT media_parts.file, media_streams.language from media_parts 
INNER JOIN media_streams on media_streams.media_item_id = media_parts.media_item_id
WHERE
media_streams.stream_type_id = 2
AND media_streams.language = '';