Dealing with subtitles and "unknown" audio tracks.

Having used plex (and other tools) for a number of years, I also agree that ‘this should be fixed at the file level’.
Since all library tools and media players read the file’s metadata, the most widely successful place to save the languages is in the file itself.

Imagine if a city library was filled with books with blank covers, and it was the policy that you just ask the librarian for the book you want since they have all the info in the system; it would be easy to change the cover design or correct spelling mistakes on the title, and it’s much easier to print these books, but I think you’d agree that something is lost compared to making sure each book can be picked up on it’s own.

Yes, if the person who created the original file wants to cut corners, it’s less work to skip adding language info, and yes it’s extra work to add it afterwards, but if you do it at the file level you only have to do it once for all future uses.

@jackandjohn said:
Having used plex (and other tools) for a number of years, I also agree that ‘this should be fixed at the file level’.
Since all library tools and media players read the file’s metadata, the most widely successful place to save the languages is in the file itself.

Imagine if a city library was filled with books with blank covers, and it was the policy that you just ask the librarian for the book you want since they have all the info in the system; it would be easy to change the cover design or correct spelling mistakes on the title, and it’s much easier to print these books, but I think you’d agree that something is lost compared to making sure each book can be picked up on it’s own.

Yes, if the person who created the original file wants to cut corners, it’s less work to skip adding language info, and yes it’s extra work to add it afterwards, but if you do it at the file level you only have to do it once for all future uses.

It just doesn’t make sense for people with large, rapidly-changing libraries.

There’s really no reason to not have a “treat Unknown audio as X” setting. Automatic subtitle selection is 100% useless on my server.

The automatic subtitle selection feature created this problem without providing a solution. I already had the knowledge all my media files were in english unless otherwise specified.

@honkdazzle said:

@jackandjohn said:
Having used plex (and other tools) for a number of years, I also agree that ‘this should be fixed at the file level’.
Since all library tools and media players read the file’s metadata, the most widely successful place to save the languages is in the file itself.

Imagine if a city library was filled with books with blank covers, and it was the policy that you just ask the librarian for the book you want since they have all the info in the system; it would be easy to change the cover design or correct spelling mistakes on the title, and it’s much easier to print these books, but I think you’d agree that something is lost compared to making sure each book can be picked up on it’s own.

Yes, if the person who created the original file wants to cut corners, it’s less work to skip adding language info, and yes it’s extra work to add it afterwards, but if you do it at the file level you only have to do it once for all future uses.

It just doesn’t make sense for people with large, rapidly-changing libraries.

There’s really no reason to not have a “treat Unknown audio as X” setting. Automatic subtitle selection is 100% useless on my server.

The automatic subtitle selection feature created this problem without providing a solution. I already had the knowledge all my media files were in english unless otherwise specified.

I don’t believe rewriting the metadata is the answer either though. That’s why I was quite vocal and actively discouraging it.

If you could set a default language value for any unknown audio tracks in media files that would be fine too I guess.

I’ve been struggling with this problem for a while as well. I have a lot of old AVIs that are incorrectly labelled as Unknown audio. Yes it would be best to fix this problem at its source (the file) but that would take a long time and it feels like Plex could add a very basic option on the Subtitles settings page that asks how to treat Unknown audio (ie, as Unknown [default] or as a specific language).

If I could set that option to English I could keep the “Show subtitles on foreign audio” selected and it would mean all the foreign language would have subtitles by default, and the English (and Unknown) audio wouldn’t.

Is there a Feature Request that deals specifically with this issue? This one (https://forums.plex.tv/discussion/52254/default-language-setting-per-section/p1) seems to mention it in one of the comments but the request itself is about something larger.

I’m sure putting in an option like this wouldn’t be too much development work.

The AVI container was a problem for me as well, I ended up converting all AVI files to MKV, though I can appreciate not everyone would want to do this.

As far as I know AVI does apparently support labelling audio tracks but I could never get it to work with files that were Unknown Audio, I also couldn’t find a command line tool capable of doing it on a batch basis, so that’s why I opted for MKV.

I would certainly +1 a feature request for setting a default language when an audio track is unknown, it would prevent subtitles being shown on English audio tracks that are just identified as Unknown to Plex.

My resolution has been to write a shell script that will query the SQLite DB, pull the full media part file path of any file that has unknown audio, scan the extension for .mp4, .mkv etc and run the appropriate action based on this. Its crude but works and runs once every 12 hours, shell isn’t the solution however, if anything it probably could be its own plugin with proper management and functionality, but it works, the main reason I wanted to fix it, is because of subtitles.

A default language setting for unknown audio would save a lot of other people from the hassle though.

Same problem here, lots and lots of shows with unknown audio, really need a setting.

+1 on this one.

+1 - a setting to classify unknown audio as english would be very helpful

This has been an issue for me for a long time and I never quite knew why. I can’t imagine how many others have this issue and either don’t speak up or just assume it’s something they’re doing wrong, when it’s actually not something they’re doing wrong.

In my case a lot of my media is ‘unknown’ language (100% always English, though) and I thought that I just had bad settings or buggy apps on different platforms. Worse yet it turns out that the settings I was adjusting are actually per-user so I was wasting my time trying to fix this for friends and family and had only really ‘fixed’ it for myself (by making subtitles completely manual).

+1 to a ‘Treat unknown language as [English]’ option. I would pay for this, now that I understand the actual issue!

1 Like

In the mean time, if anyone knows of a decent post-processing script that I could use to automatically modify new downloads (via nzbget, etc) that would be awesome. I might try and write my own but I am unfamiliar with the tools.

EDIT: Found something from this post which I modified and potentially fixed (the script was using 0-based indexes but mkvpropedit takes 1-based indexes). Too bad I already ran it against all my media before noticing that. Ah well.

Disclaimer: If it messes up your library, don’t blame me.

Script:

#!/bin/bash
FILE="$1"
numStreams=$(ffprobe -loglevel quiet -show_streams -probesize 10000000 -analyzeduration 10000000 "$FILE" | grep -o '\[STREAM\]' | wc -l | awk '{print $1}')
numStreamsFromIndex=$(expr $numStreams - 1)

for i in $(seq 0 "$numStreamsFromIndex"); do
    mkvpropeditIndex=$((i+1))
    codec_type=$(ffprobe -v error -show_entries stream=codec_type -of default=noprint_wrappers=1:nokey=1 -select_streams $i "$FILE")
    codec_name=$(ffprobe -v error -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -select_streams $i "$FILE")
    language=$(ffprobe -v error -show_entries stream_tags=language -of default=noprint_wrappers=1:nokey=1 -select_streams $i "$FILE")

    if [ -z "$language" ]; then
        language="und"
    fi

    echo "[$FILE] Stream Index: $i, Language: $language, Codec type: $codec_type, Codec name: $codec_name"

    if [[ $codec_type = 'video' ]] && [[ $codec_name != 'mjpeg' ]] && [[ $language != 'eng' ]] && [[ $language = 'und' ]]; then
        echo mkvpropedit "$FILE" --edit track:v$mkvpropeditIndex --set language=eng
    fi

    if [[ $codec_type = 'audio' ]] && [[ $language != 'eng' ]] && [[ $language = 'und' ]]; then
        echo mkvpropedit "$FILE" --edit track:a$mkvpropeditIndex --set language=eng
    fi
done

How to run it against a folder:

find Movies/ -name '*.mkv' -exec ./unknown-to-eng.sh {} \;

I have a similar problem. I have recently converted all my TV show collection into .mp4 format. Unfortunately I forget to set the language flag in Handbrake and all my files show as unknown audio language when all of them are English.

All the files are in a predefined folder tree e.g -> TV shows -> Title of TV show -> Season -> Episode.mp4

I have about 14,000 files to fix and really do not want to copy these files into a new folder in order to fix them and then have to copy them back into their original folder tree one season at a time. This would be very manual and take forever.

It there a way of getting mp4box to scan the contents of the entire folder tree and make the language change to the files while not actually changing the location of the files (can it overwrite the files in the same location or create a fixed .temp file in the same location , deleted the original file and rename the .temp file to .mp4)

Can mp4box do this? or is there any tool that can? I shiver at the fact that I may have to do this manually.

rewen scrpit seems to be only for .mkv files.

It looks like jamesmacwhite shell script may do this by getting the file location from the Plex DB. Can it be shared and can it work in Windows?

@user1842 said:
I have a similar problem. I have recently converted all my TV show collection into .mp4 format. Unfortunately I forget to set the language flag in Handbrake and all my files show as unknown audio language when all of them are English.

All the files are in a predefined folder tree e.g → TV shows → Title of TV show → Season → Episode.mp4

I have about 14,000 files to fix and really do not want to copy these files into a new folder in order to fix them and then have to copy them back into their original folder tree one season at a time. This would be very manual and take forever.

It there a way of getting mp4box to scan the contents of the entire folder tree and make the language change to the files while not actually changing the location of the files (can it overwrite the files in the same location or create a fixed .temp file in the same location , deleted the original file and rename the .temp file to .mp4)

Can mp4box do this? or is there any tool that can? I shiver at the fact that I may have to do this manually.

rewen scrpit seems to be only for .mkv files.

It looks like jamesmacwhite shell script may do this by getting the file location from the Plex DB. Can it be shared and can it work in Windows?

mp4box can be run via command line on Windows as well. So you could replicate a for loop with either batch (.bat) or PowerShell script to do the same thing.

You can indeed use mp4box to set the lang value on audio tracks. Something very basic like this would potentially work on WIndows, this will recursively go through all files within folders from the directory it is run from.

for /R %f in (*.mp4) do MP4Box.exe -lang 1=eng "%f"
  • %f being the variable for each file

This assumes that you only want to change the first audio track in each MP4 this targets. Likewise you’ll need to have the MP4Box.exe in your PATH or alternatively specific the full path to the exe.

Also, I strongly advise you potentially query your Plex DB prior to performing anything to understand what items are marked with unknown. If you don’t have command line experience with sqlite, you can use an excellent plugin called plex2csv, where you can export your entire library contents with different levels of detail to see all the information Plex is storing against each file, this include languages, but also if an MP4 has multiple audio tracks as well.

Finally, make sure to test any batch operation on a small subset of files before going all out and YOLO on your files. Make sure you’ve got backups!

Good luck!

@jamesmacwhite said:

You can indeed use mp4box to set the lang value on audio tracks. Something very basic like this would potentially work on WIndows, this will recursively go through all files within folders from the directory it is run from.

for /R %f in (*.mp4) do MP4Box.exe -lang 1=eng "%f"
  • %f being the variable for each file

This assumes that you only want to change the first audio track in each MP4 this targets. Likewise you’ll need to have the MP4Box.exe in your PATH or alternatively specific the full path to the exe.

Also, I strongly advise you potentially query your Plex DB prior to performing anything to understand what items are marked with unknown. If you don’t have command line experience with sqlite, you can use an excellent plugin called plex2csv, where you can export your entire library contents with different levels of detail to see all the information Plex is storing against each file, this include languages, but also if an MP4 has multiple audio tracks as well.

Finally, make sure to test any batch operation on a small subset of files before going all out and YOLO on your files. Make sure you’ve got backups!

Good luck!

Thank you very much. I will do some tests when I get home.

Just tried the command and its works perfectly, thank you very much jamesmacwhite. I just changed “1=eng” to "2=eng as the audio track is in ID: 2 for all my .mp4 files.

for /R %f in (*.mp4) do MP4Box.exe -lang 2=eng "%f"

There was also no need to put MP4Box.exe in my PATH once i installed it.

Thanks again.

One last question would the same command work in a Linux terminal? my parents use openmediavault and I would like to run a command directly on their PC to do the same.

@user1842 said:
Just tried the command and its works perfectly, thank you very much jamesmacwhite. I just changed “1=eng” to "2=eng as the audio track is in ID: 2 for all my .mp4 files.

for /R %f in (*.mp4) do MP4Box.exe -lang 2=eng "%f"

There was also no need to put MP4Box.exe in my PATH once i installed it.

Thanks again.

One last question would the same command work in a Linux terminal? my parents use openmediavault and I would like to run a command directly on their PC to do the same.

Ah, good to know. I didn’t realise MP4Box gets added to PATH automatically. Glad it worked for you.

I’m not familiar with OpenMediaVault, are you able to get Shell access to it? Looks like its based on Debian, so if you can install deb packages, there should be a package for a MP4box that might be compatible with it, but I can’t be sure.

If not, you could always use a Windows machine that has read/write permissions to the share(s) and then run the same command as you’ve done but against the share path, it will probably take longer due to network speed rather than just plain disk access though.

@jamesmacwhite said:
Ah, good to know. I didn’t realise MP4Box gets added to PATH automatically. Glad it worked for you.

I’m not familiar with OpenMediaVault, are you able to get Shell access to it? Looks like its based on Debian, so if you can install deb packages, there should be a package for a MP4box that might be compatible with it, but I can’t be sure.

If not, you could always use a Windows machine that has read/write permissions to the share(s) and then run the same command as you’ve done but against the share path, it will probably take longer due to network speed rather than just plain disk access though.

I should be able to get Shell access on OpenMediaVault. I will try to install the Debain MP4box package. I really do not want to use a networked Windows machine here. They only have a 100mbps network connection so I think it would take forever. Would the same script run in the Linux Shell or would it need to be majorly modified for Linux?

Thanks again

@user1842 said:

@jamesmacwhite said:
Ah, good to know. I didn’t realise MP4Box gets added to PATH automatically. Glad it worked for you.

I’m not familiar with OpenMediaVault, are you able to get Shell access to it? Looks like its based on Debian, so if you can install deb packages, there should be a package for a MP4box that might be compatible with it, but I can’t be sure.

If not, you could always use a Windows machine that has read/write permissions to the share(s) and then run the same command as you’ve done but against the share path, it will probably take longer due to network speed rather than just plain disk access though.

I should be able to get Shell access on OpenMediaVault. I will try to install the Debain MP4box package. I really do not want to use a networked Windows machine here. They only have a 100mbps network connection so I think it would take forever. Would the same script run in the Linux Shell or would it need to be majorly modified for Linux?

Thanks again

By network, you’d only be limited by LAN speed, unless you wanted to do this remotely (I wouldn’t recommend it) not the actual downlink speed on the WAN side. In terms of running this script on Linux, you’d have to slightly adapt it for being compatible with shell/bash. You can do something like this:

find /media/root/path -iname '*.mp4' -execdir MP4Box -lang eng {} \;

Might want to adapt it a bit given the audio track integer value change you made and always test a small subset of files before going all out on the root media directory, and once again verify you’ve got backups before doing any batch operation.

I have this issue too, I’m mass converting my avi/mp4 to mkv.

But I still have many many files with unknown audio.

I only have automatic subtitles turned on for forced subtitles since that’s the only way. This is really a stupid problem. You should have an option for either treat unknown as selected language or forced subtitles only for automatic.

On an OSX system, this can be done with MKVToolNix

Set your defaults so it will automatically set the language for an unknown video. Also, set a default directory that the files will be created in. The default is to add a “(1)” to the end of the file and place it in the same directory, but its a pain to delete-rename files. This way you can just paste them back and overwrite the old ones.

As an added bonus, it will also automatically add some lossless compression to subtitle tracks. Its not much, but its something.

This program is not capable of re-encoding files. It simply manipulates the “container”. In this case mkv.

You can also remove, or add audio tracks and subtitles. You can also rename them. I like placing what type of audio it is like 5.1. Chapters can also be edited and created (although ive never done it before)

If you’re just specifying a language for the default files, it should take you 5 minutes to do several thousand movies.

Easy Peasy. All GUI

A little elaboration of the above. Since it does not re-encode the files there is NEVER any loss of video or audio quality. In addition, it’s also very fast to save them.

I did find that it does not pre-copy the original file your working on, so you cant “save” the file. You need to create a new file and then overwrite it. Also, note that it only saves mkv, so if it was a mov, avi, flv (etc) before it will rename it with the mkv extension, but that is not re-encoding, its still manipulating the “container”.