Process MKV Files with ASS Subs for Usage With Plex

Discussion in 'AnyStream' started by jbrisbin, Jun 2, 2021.

  1. jbrisbin

    jbrisbin Well-Known Member

    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).

    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.

    Two packages are required to be installed to use the script:
    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:
    Or add the third party package manager apt-cyg as described here:
    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 ''. 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/

    Before you begin:
    Your video files need to be in MKV containers, not the .mp4 typically produced by AS.
    If you transcode after download, just use .mkv output from HandBrake or similar. If not, use MKVToolnix (GUI) or command line to convert from the mp4 container to mkv.

    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.

    execute the script by typeing its name:

    Once you press return, it will begin searching for 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 will check-in later this evening.

    Attached Files:

    whatever_gong82 likes this.
  2. cartman0208

    cartman0208 Well-Known Member

    I'm sure your work will be appreciated, but according to Plex ASS subtitles are supported anyway
  3. jbrisbin

    jbrisbin Well-Known Member

    If the ones generated by AS worked under Roku, Amazon Fire, or Shield TV Plex clients, I would be more impressed.
  4. Scott Tedder

    Scott Tedder Active Member

    I have a fire cube and Nvidia shield. I definitely can verify that .ASS subtitles work in Plex and have for quite a while.
  5. Scott Tedder

    Scott Tedder Active Member

    I used to convert all of the amzn 1080p webdl to HEVC for a smaller size. Until I upgraded from a 51" 1080p plasma TV to a 65 inch 4K TV. It did not take very long for me to start wanting to replace all of those converted files with untouched webdl. All of my compressed content actually looked bad whereas it did not with the 1080p TV. Now I won't watch anything unless I can get it in the highest untouched quality.
  6. sycor

    sycor Well-Known Member

    As I said in another post. I download the srt file and then use mkvtoolnix to combine the SRT and the mp4 to a mkv with no remux, just a container change. No change in quality. Works fine with plex using my nVidia shield.
  7. Scott Tedder

    Scott Tedder Active Member

    REMUX means changing the container. But I know what you mean because I use MKVTOOLNIX to merge the SRT subtitle and the MP4 into MKV.
  8. cartman0208

    cartman0208 Well-Known Member

    I mentioned this in some other threads...
    The subtitles generated by AnyStream are not ASS , because ASS (or SSA) is not supported in MP4 files while TTXT (or tx3g) is, you can check this with MediaInfo
  9. Vzxy

    Vzxy Well-Known Member

    I've never seen ASS subs in AS files.
  10. jbrisbin

    jbrisbin Well-Known Member

    You are correct. The mux to MKV, which I find necessary to avoid glitches and hangs in remote video playback, deals with that major issue, but requires additional processing to include tx3g subs.
    My apologies, I was writing from memory about things I investigated some time back.
    The real issue is with the output of Handbrake which performs an implicit (non-negotiable with developers) conversion from tx3g to ASS. MKVToolnix just ignores the subs and does not copy them at all if tx3g. This is also non-negotiable with the developer.
    Since I have made the informed decision to transcode to HEVC (you may differ, but it doesn't matter to me), Handbrake is almost the only choice. Except for the ASS subs that perform poorly, if at all with Plex.
    The issue with plex is that if you turn on ASS subs after starting, it appears to scan up to the current point in the film to find the sub, if you are patient enough, it will display one subtitle, then continue on.
    If you are remote, 'patient enough' results in a timeout. If you enable the sub before starting play back, it works until you skip, then they are gone or you are hung (and not well).
    These may be purely Handbrake/Plex artifacts, but I can't be sure.

    These considerations make the script I have published of far less general interest than I had thought.

    I will update it so that it can handle .mp4 input.

    The result should be that the output will avoid the problems with hangs and stalls during simple non-sub playback (because of remux to mkv), support automatic forced subs where present (adding forced flag where appropriate), and predictable and consistent behavior locally and remotely (because if Plex supports ASS, it supports SRT much better). tx3g is academic with an mkv container.

    Hopefully, it won't take long.
  11. sycor

    sycor Well-Known Member

    I guess I'm confused as to why use ASS when SRT works fine? Like I said, remux (thanks for the correction, was typing too fast previously) to MVK with the mp4 and external SRT using mkvtoolnix. Then you can encode to x265 if you want using Handbrake and it should work perfectly. I've done the x265 conversion myself but personally didn't think the time it took was worth it to compress a compressed stream download. But it did work.
    RedFox 1 likes this.
  12. cartman0208

    cartman0208 Well-Known Member

    I would strongly recommend StaxRip here ...
    It's not as easy to use as Handbrake, but it can convert almost anything to anything.
    Once you set your output template, you can feed whole folders to the program and all output is the same.
    For me its audio conversion to 640kb AC3 for compatibility, subtitles to SRT (no issues at all with Plex) and if needed recoding to HEVC with NVENC (got my Turing graphics card the mining mania let the prices go through the roof) else I just remux the videostream