# Solution for Audio: Unknown

**URL:** <https://forums.plex.tv/t/solution-for-audio-unknown/402270>\
**Category:** Tips, Tricks & How-Tos\
**Tags:** server-linux, tipstricks\
**Created:** [April 20, 2019, 6:28am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270 "2019-04-20T06:28:14Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![syluccy](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@syluccy](https://forums.plex.tv/u/syluccy)\
**Post date:** [April 20, 2019, 6:28am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/1 "2019-04-20T06:28:14Z")

</div>

So it really annoyed me to have lots of tvshows with ‘Unknown’ audio stream in my library, and I found out, Plex has serious problem with the .avi container. Since some of the really old tvshows only available in SD with XviD codec, I had to figure out a solution. The basic idea was to convert them into a compatible container. My choice was the .mkv. Found a script made by @ntrevena - thx a lot for them - and modified it a bit, since I didn’t want to reencode those files, only wanted to remux them, change the encoder, and name the audio streams. Had to tweak it a bit, because it handled filenames containing “.” pretty bad - Family.Guy.S06E01.HUN.ENG-m493.avi → Family.mkv -, but now it works like a charm.

- Looks for .avi or .mp4 files
- It works recursively in all subfolders
- Deletes the original .avi or .mp4 file
- Names the primary audio stream to English
- Deletes the .sh file to clean out the mess 🙂

Save the quote into a .sh file (debian/ubuntu script)  
Run the following commands:

sudo chmod +x filename.sh  
sudo chmod 777 filename.sh  
./filename.sh

enjoy! 🙂

```auto
#!/bin/bash
# A simple script to convert all files in a given folder to a playable MKV format

####################################################
# Workarounds for known issues
####################################################
#
# If it fails with a "No Interpreter" error, try running: sed -i -e 's/\r$//' convert2mkv.sh
#
####################################################
# Edit these variables as required (do not work yet)
####################################################

container="mkv" # Choose output container (mkv; mp4 only)
tempdir="/tmp" # Temporary directory for transcodes (required)

####################################################
# You can set filetypes to parse here (remember to not use the same types as your container above)
####################################################

filetypes=(" **/*.mp4" "** /*.avi")

####################################################
# Don't change anything beyond this point!
####################################################

# Disable case sensativity

shopt -s nocaseglob
shopt -s globstar

# Search file type

  for i in ${filetypes[*]}; do
  path=$(readlink -m "$i")
  filename="${path##*/}"
  dirpath=${path%/*}
  echo "Currently Testing File: " "$filename"

# Run transcode

ffmpeg -fflags +genpts -i "$i" -map 0 -c: copy -metadata:s:a:0 language=eng $tempdir/"${filename%.*}".$container && \

mv $tempdir/"${filename%.*}".$container "$dirpath"/"${filename%.*}".$container
rm -f "$dirpath""/""$filename"
rm -f "remux.sh"
echo "Completed"

  done
shopt -u nocaseglob

```

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 20, 2019, 6:46am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/2 "2019-04-20T06:46:50Z")

</div>

> [@syluccy](#):
>
> .mp4 files

This format already supports tagging of languages.

> [@syluccy](#):
>
> ffmpeg -fflags +genpts -i “$i” -c:v copy -c:a copy -map 0:? tempdir/“{filename%.\*}”.$container && \

This will destroy any subtitles a MP4 file might have when muxing to MKV.  
I would use `-map 0 -c: copy` to copy all tracks.

> [@syluccy](#):
>
> # Name primary audio stream
> 
> mkvpropedit “${i%.\*}”.$container --edit track:a1 --set language=eng

ffmpeg can also set the lang of tracks at the time of muxing/remuxing.  
`-metadata:s:a:0 language=eng`  
This will set the first audio track(0-based index) to english.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 20, 2019, 7:19am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/3 "2019-04-20T07:19:43Z")

</div>

Additionally, mkvmerge will read mp4 and write mkv natively, no ffmpeg required.

This is the excerpt from my maintenance script

Merge this the above in a **find** loop and substituting would seem a perfect solution?

```auto
  echo `date` Cleaning: $Episode >> ${Logfile}
  rm -f temp.mkv
  ${Bin}/mkvmerge -o temp.mkv -M -S --no-global-tags --disable-track-statistics-tags "$Episode"
  if [$? -ne 0]; then
    echo `date` Bad file: Error \($?\) "$Episode" >> ${Logfile}
    rm -f temp.mkv
  else
    echo `date` "Keeping: " "$Episode" >> ${Logfile}
   ${Bin}/mkvpropedit -s title= temp.mkv
   ${Bin}/mkvpropedit --edit track:a1 --set language=eng --edit track:v1 --set language=eng temp.mkv
   mv -f temp.mkv "$Episode"
   rm -f temp.mkv
  fi

```

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 20, 2019, 7:26am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/4 "2019-04-20T07:26:02Z")

</div>

> [@ChuckPa](#):
>
> –no-global-tags --disable-track-statistics-tags

No kidding. What a pain!

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 20, 2019, 7:45am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/5 "2019-04-20T07:45:16Z")

</div>

Actually, besides tidying up. The new PMS update kinda fixes the unknown audio issue. At least with certain aspects of automatic subtitle selection.

> [@Plex Media Server](https://forums.plex.tv/t/plex-media-server/30447/256):
>
> Plex Media Server 1.15.4.919 is now available to Plex Pass users in the Beta update channel NEW: (DVR) Ability to give Home Users DVR access. (#8794) (Playback) Assume unknown audio to be foreign if the preferred audio language is not english (#6126) (Streaming Brain) Preference to allow automatically terminating playbacks which have been paused for an hour (#9700) (Subtitles) Auto select forced subtitles when not listening to foreign audio (#6126) When transcoding for supported clients, auto…

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [April 20, 2019, 10:41am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/6 "2019-04-20T10:41:29Z")

</div>

> [@ChuckPa](#):
>
> Additionally, mkvmerge will read mp4 and write mkv natively,

It also reads AVI  
Here is my primitive batch file for Windows, which is probably very easy to convert to bash script

```auto
for %%f in (*.avi) do (
        echo %%~nf
         "C:\Program Files\MKVToolNix\mkvmerge" -o "%%~nf.mkv" --language 0:ger --language 1:jpn "%%~nf.avi"

)

```

It tags the video stream `0` with a language as well (I use this for anime to indicate the language of “hard” subs. This won’t appear in Plex though, except in the mediainfo.)

---

<div class="post-metadata">

**Author:** ![ntrevena](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ntrevena/32/20931_2.png) [@ntrevena](https://forums.plex.tv/u/ntrevena)\
**Post date:** [April 20, 2019, 5:22pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/7 "2019-04-20T17:22:02Z")

</div>

@syluccy - Good on you for tweaking the script, and fixing it up for your own purposes. I’m glad to see there are people who still find it useful.

I’ve messaged/replied to you on the [original thread](https://forums.plex.tv/t/convert2mkv-new-options-new-hardware-logic-wip-updated-27-01-19/159028/95). I apologize for not replying sooner. Work has been pretty heavy. 👍

---

<div class="post-metadata">

**Author:** ![syluccy](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@syluccy](https://forums.plex.tv/u/syluccy)\
**Post date:** [April 21, 2019, 3:37pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/8 "2019-04-21T15:37:32Z")

</div>

let me try it!  
could you edit the full line, you are referring to?

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 23, 2019, 7:21am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/9 "2019-04-23T07:21:23Z")

</div>

Sorry for late reply. Power supply went on a long vacation…

I’m assuming both of my examples?

This is for Windows. I don’t know the syntax for linux but sure Chuck will.

This will copy ALL(everything possible including all tracks, set languages, track descriptions, chapters, etc)

```auto
ffmpeg.exe -i "SourceFile.mp4" -map 0 -c: copy "DestFile.mp4"

```

Will mux(copy all in the process) and set the video to undetermined and audio track 1 (0-Based Index) to English.

```auto
ffmpeg.exe -i "SourceFile.mp4" -map 0 -c: copy -metadata:s:v language=und -metadata:s:a:0 language=eng "DestFile.mp4"

```

Again, Windows script only.

---

<div class="post-metadata">

**Author:** ![syluccy](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@syluccy](https://forums.plex.tv/u/syluccy)\
**Post date:** [April 26, 2019, 8:14pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/10 "2019-04-26T20:14:01Z")

</div>

thx man! I’ve updated the script. now it’s more efficient. 😉

Correction. I’ve been testing it around, and it still has a problem with mp4, embedded subtitle.

```auto
[matroska @ 0x55c286bfd800] Subtitle codec 94213 is not supported.
av_interleaved_write_frame(): Function not implemented
    Last message repeated 1 times
Error writing trailer of /tmp/XXXXX.XXXXX.S04E11.WEBRip.x264-TURBO.mkv: Function not implemented

```

---

<div class="post-metadata">

**Author:** ![syluccy](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@syluccy](https://forums.plex.tv/u/syluccy)\
**Post date:** [April 27, 2019, 6:34am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/11 "2019-04-27T06:34:23Z")

</div>

okay, I’ve decided to let go of remuxing mp4 files. 🙂  
the basic idea was I can’t name language tracks on mp4 files.  
at least I had no luck with mkvproedit. but you guys made it clear, I don’t need mkvproedit. will try to split this script to two different parts.

---

<div class="post-metadata">

**Author:** ![blim5001](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@blim5001](https://forums.plex.tv/u/blim5001)\
**Post date:** [April 27, 2019, 8:03am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/12 "2019-04-27T08:03:22Z")

</div>

For mp4 files you might want to look at MP4Box ([https://gpac.wp.imt.fr/mp4box/](https://gpac.wp.imt.fr/mp4box/))

I use this one liner which removes metadata (MP4Box seems to do this by default) and sets lang to en.

It reads all mp4 files in directories in your current working directory, processes the files, outputs them to new dir and deletes the originals

`find "$PWD/" -name '*.mp4' -print0 | while IFS= read -r -d '' file; do if [-s "$file"]; then echo $(basename "$file" ); /path/to/MP4Box -add "$file" -lang 2=en /path/to/output/$(basename "$file" ) -new; rm "$file"; fi done`

---

<div class="post-metadata">

**Author:** ![syluccy](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@syluccy](https://forums.plex.tv/u/syluccy)\
**Post date:** [April 27, 2019, 8:08am UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/13 "2019-04-27T08:08:47Z")

</div>

okay, so I found a solution to get audio language for mp4 files.

`mediainfo --Inform="Audio;%Language%" filename.mp4`

won’t work with AVI files, but that’s okay, since I would remux them anyway.  
so I need branches. first to get the extension. if it’s avi, the existing script should run.  
if it’s an mp4, mediainfo should check if language is unknown.  
if it is, I can make the language rename branch.  
if it is eng already, it should skip that mp4 file.

Could anyone help me with this? I’m not an expert of coding 😕

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 27, 2019, 6:14pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/14 "2019-04-27T18:14:09Z")

</div>

> [@syluccy](#):
>
> Could anyone help me with this?

I would look at @blim5001 example. While I’m not familiar with the syntax used, the actual command looks like my MP4Box batch file.

```auto
for %%f in (*.mp4) do MP4Box.exe -lang 2=eng "%%f"
pause

```

There are many topics on this subject that might help you.  
Here is one.

> [@Set Audio Language tag MP4/MKV](https://forums.plex.tv/t/set-audio-language-tag-mp4-mkv/114491):
>
> Hi this is a little tutorial about how set lenguage tags on mp4 and mkv files. If you don’t like to see AUDIO tag as “UNKNOWN” on your videos and go from this [image] to this [image] or this [image] to this [image] you just have to: Get [MKVToolNix](https://www.bunkus.org/videotools/mkvtoolnix/downloads.html "MKVToolNix") and [GPAC](https://gpac.wp.mines-telecom.fr/downloads/ "GPAC") both open source free an multiplataform. On Ubuntu: $ sudo echo “deb [http://www.bunkus.org/ubuntu/$](http://www.bunkus.org/ubuntu/%24)(lsb\_release -sc)/ ./” | sudo tee /etc/apt/sources.list.d/mkvtoolnix.list $ wget -q -O - [https://www.bunkus.org/gpg-pub-moritzbunk…](https://www.bunkus.org/gpg-pub-moritzbunkus.txt)

---

<div class="post-metadata">

**Author:** ![NewPlaza](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/newplaza/32/128634_2.png) [@NewPlaza](https://forums.plex.tv/u/NewPlaza)\
**Post date:** [April 27, 2019, 10:59pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/15 "2019-04-27T22:59:26Z")

</div>

> [@syluccy](#):
>
> and it still has a problem with mp4, embedded subtitle.

And you will.  
There is no need to convert/mux MP4 files to MKV if all you want to do is set language for audio track(s).

```auto
"%~DP0%FFmpeg.exe%" -i "%~1" -map 0 -c: copy -metadata:s:v language=und -metadata:s:a language=eng -metadata:s:s language=eng "%~dpn1.mp4.mp4"

```

Note the `"%~dpn1.mp4.mp4"` at the end. The extra “.mp4” is because ffmpeg will not edit existing files in-place.  
Though, you could always save to a different folder like say `"%~dp1CONVERTED\%~n1.mp4"`.  
That way you can keep it’s original name.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [July 26, 2019, 10:59pm UTC](https://forums.plex.tv/t/solution-for-audio-unknown/402270/16 "2019-07-26T22:59:29Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
