# 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:** 1\
**Showing post:** 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

```

---

_[View the full topic](https://forums.plex.tv/t/solution-for-audio-unknown/402270)._
