Would anyone be willing to help me create a simple script? Remux Plex TS file to MKV.

I have zero knowledge on how to do this but my need is quite simple. I was hoping someone might have a few minutes to help me with a post processing script that meets my setup needs?

Plex DVR lives on a Mac mini saving shows to a directly connected Drobo 5D. Tuner is a HD Homerun Prime. I already have Homebrew, Handbrake CLI and FFMPEG installed if that is important.

All I need is a post processing script to remux the saved .ts file to either a .mkv or a .mp4 and have it overwrite the existing .ts file. I don’t want any transcoding to take place, just change the container.

Any help would be greatly appreciated. Would be happy to “buy you a beer” as well if you could help.

Thanks

Why dont you have it set to transcode to mkv automatically?

@dirtycajunrice said:
Why dont you have it set to transcode to mkv automatically?

I don’t think thats an option anymore?

I have the “transcode” drop down enable but even if its doing any sort of transcoding it is still saving it as a TS file. I think at one point it saved as MKV but the Plex team changed that.

I need a MKV file as my playback device (Kodi running the PlexKodiConnect plugin) does a lot better with MKV files. There is a noticeable lag in fast forward and rewind when the file is saved as a TS.

Check out this thread, I’m using it as the basis for my script on Ubuntu

Thanks a lot for the pointer. What do I save the script as if I may ask? A text file?

There also looks like there are file paths that need to change (@appstore? What the heck is that) but I’m not sure what to point to on a Mac?

I really feel I can get this going easy enough but I just don’t understand the meaning of the lines in this simple script having never worked with this sort of thing before.

library paths are so it knows where the files are, simplest script is to name this as postprocessing.sh and enter the path to it in your DVR settings
#!/bin/bash
outfile=${1//.ts/.mkv}
ffmpeg -hide_banner -i "$1" -vcodec copy -acodec copy -y "$outfile"
rm "$1"

Test it in terminal on a test ts file copy you’re not afraid to lose (testfile.ts in example), you can put a # in front of the rm “$1” while testing to prevent it from deleting the original file

./postprocessing.sh testfile.ts and it should run ffmpeg and delete the ts file leaving you with an mkv

@ImCoKeMaN said:
library paths are so it knows where the files are, simplest script is to name this as postprocessing.sh and enter the path to it in your DVR settings
#!/bin/bash
outfile=${1//.ts/.mkv}
ffmpeg -hide_banner -i "$1" -vcodec copy -acodec copy -y "$outfile"
rm "$1"

Test it in terminal on a test ts file copy you’re not afraid to lose (testfile.ts in example), you can put a # in front of the rm “$1” while testing to prevent it from deleting the original file

./postprocessing.sh testfile.ts and it should run ffmpeg and delete the ts file leaving you with an mkv

Thanks a lot. I will try this out in the morning…

Thanks again @ImCoKeMaN . That worked in terminal but when I plugged it into Plex it would fail with a message in the logs indicating that the file was deleted.

Another member here send me one that does work in both Terminal and when plugged into Plex. Its pasted here just in case anyone else is reading this thread wanting the same results. This one is based off of the link posted earlier in this thread.

#!/bin/bash

hints to get working

https://forums.plex.tv/discussion/254085/transcode-not-working/p1

outfile=${1//.ts/.mkv}
#outfile=${1//.ts/.mp4}

ffmpeg="/usr/local/bin/ffmpeg"
copy=“true”
#encode_time="-t 30"

if [ “$copy” = “true” ] ; then
“$ffmpeg” -hide_banner -i “$1” -vcodec copy -acodec copy $encode_time -y “$outfile”
else
crf=17
#https://support.plex.tv/hc/en-us/articles/200250347-Transcoder
preset=veryfast
#Prefer higher speed encoding:
encode_opts="-x264opts subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none"
#Prefer higher quality encoding:
#encode_opts="-x264opts subme=0:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none"
#Make my CPU hurt:
#encode_opts="-x264opts subme=2:me_range=4:rc_lookahead=10:me=hex:8x8dct=1"
“$ffmpeg” -hide_banner -i “$1” -vcodec libx264 -preset $preset -crf $crf $encode_opts -maxrate 5000k -bufsize 10000k -acodec copy $encode_time -y “$outfile”
fi

rm “$1”