Background:
I heavily post-process all my downloaded content. First by re-encoding to HEVC at a high quality level into MKV containers, then by converting the ASS subtitles to SRT (for Plex compatibility).
Note: While Plex nominally support ASS subtitles, it appears to seek to them by scanning the media file data from the beginning of the file to locate them. When you are distant from the server, even on a 100Mb connection this is suboptimal and usually times out. This problem might no longer exist, but I have not seen any release notes indicating it has been fixed.
You can test this by starting a movie file with ASS subs present but not enabled, then skip in 30 minutes and enable an ASS sub track. Resume playback. It should resume instantly if the issue is fixed. If not, playback will probably timeout before all the data to that point can be read over a slow connection to find the next sub.
Update: A new version of the script is now available. This script has a new name 'subs.sh', some optimizations and new functionality though using it is very similar to the original version.
The updated version will convert the subs in both .mkv and, now, .mp4 files but it always produces a .mkv output file.
Functionally, the handling of .mkv files is the same.
In the case of .mp4 files, it depends on whether the file contains text based subs. If so, they are extracted and converted to SRT form and reinserted into the output .mkv file. If no text subs are found in the .mp4, it is simply remuxed into the output .mkv file with no conversion.
In either case any .mp4 files below or in the current directory will be converted. This may not be desirable, in which case you may want to use the original mkvsrt.sh command, instead.
I have been using the newer subs.sh version for about 6 months and it has served me well. I continue to re-encode the AVC output of AP and NF, but now directly convert the HEVC output of HM.
This post is about the process of converting those subtitles and the script I use to do it.
As part of the second stage, I set the forced flag on anything that has the word 'forced' in the name of the subtitle. If you have multiple 'forced' subtitles in your video file, the result is undefined and you probably won't like it. The default flag is carried to the converted subtitle that had the default flag before conversion.
All the subtitle processing is done in a Cygwin/bash script that recursively processes directories of video MKV files. Thus, it can (to the extent you trust it) process an entire Plex library directory with a single invocation (though it may take quite a long time).
This has been thoroughly tested on a single Windows 10 system. This is another way of saying that a large number of really obvious problems would probably appear immediately if anyone were to run it on a different Windows or Linux system.
It does backup the video it changes (so you need an equal amount of space to any files with ASS subs that are processed). It removes the ASS subs after it adds the SRT equivalents, so nothing is processed two or more times. Each file is sanity checked before the backup/replace operation occurs. All tools used are free (primarily mkvtoolnix and ffmpeg). It works equally well on TV episodes and movies. It puts out too much console information for anybody but me.
Installation:
Two packages are required to be installed to use the script:
mkvtoolnix
ffmpeg
For standalone linux, use the usual distribution package manager to install them.
For Cygwin, which does not offer a package manager other that the setup program, you can use that setup as described here:
https://blueskyworkshop.com/blog/2015/09/10-cygwin-packages.html
Or add the third party package manager apt-cyg as described here:
https://techdirectarchive.com/2020/...packages-from-the-command-line-using-apt-cyg/
Unfortunately, that approach requires wget or lynx which may not be installed, forcing you back to the setup method to get them. Probably best to use setup and be done with the operation.
The attached script is called 'mkvsrt.sh'. It should be placed in a location on the default path of your CygWin setup (Windows) or bash shell (linux). Under CygWin, '/usr/local/bin/' appears to be such a place. Once placed there, make it executable by running the command (assuming that you put it in /usr/local/bin/):
chmod +x /usr/local/bin/mkvsrt.sh
If you are using the newer subs.sh version, the command would be:
chmod +x /usr/local/bin/subs.sh
Before you begin:
Your video files may be in MKV (.mkv) containers or in the MP4 (.mp4) containers typically produced by AS
If you have MP4 containers (.mp4 files) you must use the new version of the script: subs.sh.
If you have MKV containers, you can use either script. The newer, subs.sh will perform somewhat better when more than one ASS sub is embedded because it will only make one pass over the file to extract all subtitles, instead of one pass each.
Usage:
open a shell (either Cygwin from windows or bash from linux).
cd to the directory at the top of the file collection you want to process. Initially, pick a directory with one or a few files at or below the directory you choose. If the script causes your computer to catch fire, this will limit the damage.
To convert both MP4 (.mp4) and MKV (,mkv) files, execute the new script by typing its name:
subs.sh
To covert only MKV (.mkv) files, execute the original script by typing its name:
mkvsrt.sh
Once you press return, it will begin searching for mp4 and mkv files. It will check each one for ASS subtitles and, if present, begin processing the file. Files without ASS subtitles will be ignored. This allows you to restart the process without much loss if it stops or you stop it for some reason (running out of disk space, for example).
As each file is inspected, and potentially processed, quite a bit of text will be output to the shell window. If something goes wrong, this is the text you will need to capture to report an issue.
Last thing the script does is to save the original video file in a subdirectory with a name like this: SubConvBackup 2021-05-30 00.39.14
Inside that directory, the script places a .plexignore file which makes the backup (old) files invisble to Plex. Without this each movie processed would appear as a duplicate. The date and time in the backup directory name are set each time you launch the script. This will prevent one backup from overwriting another.
When and if you are satisfied that the video has be faithfully converted, delete any backup directories to recover the space.
Good luck. Proceed cautiously.
I heavily post-process all my downloaded content. First by re-encoding to HEVC at a high quality level into MKV containers, then by converting the ASS subtitles to SRT (for Plex compatibility).
Note: While Plex nominally support ASS subtitles, it appears to seek to them by scanning the media file data from the beginning of the file to locate them. When you are distant from the server, even on a 100Mb connection this is suboptimal and usually times out. This problem might no longer exist, but I have not seen any release notes indicating it has been fixed.
You can test this by starting a movie file with ASS subs present but not enabled, then skip in 30 minutes and enable an ASS sub track. Resume playback. It should resume instantly if the issue is fixed. If not, playback will probably timeout before all the data to that point can be read over a slow connection to find the next sub.
Update: A new version of the script is now available. This script has a new name 'subs.sh', some optimizations and new functionality though using it is very similar to the original version.
The updated version will convert the subs in both .mkv and, now, .mp4 files but it always produces a .mkv output file.
Functionally, the handling of .mkv files is the same.
In the case of .mp4 files, it depends on whether the file contains text based subs. If so, they are extracted and converted to SRT form and reinserted into the output .mkv file. If no text subs are found in the .mp4, it is simply remuxed into the output .mkv file with no conversion.
In either case any .mp4 files below or in the current directory will be converted. This may not be desirable, in which case you may want to use the original mkvsrt.sh command, instead.
I have been using the newer subs.sh version for about 6 months and it has served me well. I continue to re-encode the AVC output of AP and NF, but now directly convert the HEVC output of HM.
This post is about the process of converting those subtitles and the script I use to do it.
As part of the second stage, I set the forced flag on anything that has the word 'forced' in the name of the subtitle. If you have multiple 'forced' subtitles in your video file, the result is undefined and you probably won't like it. The default flag is carried to the converted subtitle that had the default flag before conversion.
All the subtitle processing is done in a Cygwin/bash script that recursively processes directories of video MKV files. Thus, it can (to the extent you trust it) process an entire Plex library directory with a single invocation (though it may take quite a long time).
This has been thoroughly tested on a single Windows 10 system. This is another way of saying that a large number of really obvious problems would probably appear immediately if anyone were to run it on a different Windows or Linux system.
It does backup the video it changes (so you need an equal amount of space to any files with ASS subs that are processed). It removes the ASS subs after it adds the SRT equivalents, so nothing is processed two or more times. Each file is sanity checked before the backup/replace operation occurs. All tools used are free (primarily mkvtoolnix and ffmpeg). It works equally well on TV episodes and movies. It puts out too much console information for anybody but me.
Installation:
Two packages are required to be installed to use the script:
mkvtoolnix
ffmpeg
For standalone linux, use the usual distribution package manager to install them.
For Cygwin, which does not offer a package manager other that the setup program, you can use that setup as described here:
https://blueskyworkshop.com/blog/2015/09/10-cygwin-packages.html
Or add the third party package manager apt-cyg as described here:
https://techdirectarchive.com/2020/...packages-from-the-command-line-using-apt-cyg/
Unfortunately, that approach requires wget or lynx which may not be installed, forcing you back to the setup method to get them. Probably best to use setup and be done with the operation.
The attached script is called 'mkvsrt.sh'. It should be placed in a location on the default path of your CygWin setup (Windows) or bash shell (linux). Under CygWin, '/usr/local/bin/' appears to be such a place. Once placed there, make it executable by running the command (assuming that you put it in /usr/local/bin/):
chmod +x /usr/local/bin/mkvsrt.sh
If you are using the newer subs.sh version, the command would be:
chmod +x /usr/local/bin/subs.sh
Before you begin:
Your video files may be in MKV (.mkv) containers or in the MP4 (.mp4) containers typically produced by AS
If you have MP4 containers (.mp4 files) you must use the new version of the script: subs.sh.
If you have MKV containers, you can use either script. The newer, subs.sh will perform somewhat better when more than one ASS sub is embedded because it will only make one pass over the file to extract all subtitles, instead of one pass each.
Usage:
open a shell (either Cygwin from windows or bash from linux).
cd to the directory at the top of the file collection you want to process. Initially, pick a directory with one or a few files at or below the directory you choose. If the script causes your computer to catch fire, this will limit the damage.
To convert both MP4 (.mp4) and MKV (,mkv) files, execute the new script by typing its name:
subs.sh
To covert only MKV (.mkv) files, execute the original script by typing its name:
mkvsrt.sh
Once you press return, it will begin searching for mp4 and mkv files. It will check each one for ASS subtitles and, if present, begin processing the file. Files without ASS subtitles will be ignored. This allows you to restart the process without much loss if it stops or you stop it for some reason (running out of disk space, for example).
As each file is inspected, and potentially processed, quite a bit of text will be output to the shell window. If something goes wrong, this is the text you will need to capture to report an issue.
Last thing the script does is to save the original video file in a subdirectory with a name like this: SubConvBackup 2021-05-30 00.39.14
Inside that directory, the script places a .plexignore file which makes the backup (old) files invisble to Plex. Without this each movie processed would appear as a duplicate. The date and time in the backup directory name are set each time you launch the script. This will prevent one backup from overwriting another.
When and if you are satisfied that the video has be faithfully converted, delete any backup directories to recover the space.
Good luck. Proceed cautiously.
Attachments
Last edited: