Convert .ts files to .mkv after recording

I’d like to see an option to automatically convert the .ts files into a .mkv format after recording (just change the container with ffmpeg, no transcoding). This will be useful because the .mkv file maintains a timecode index that allows quick seeking in the file.

Currently, when seeking forward or backwards in a .ts file, it takes an extremely long time. This has a negative impact on the usability of the DVR feature.

To go even further, there would also be an option to define a set of re-encoding profiles and you could set a default for the DVR or choose per-recording. E.g., transcode mpeg2 into h.265 with a certain quality setting.

This option does exist in the form of the post-processing script option in the DVR settings. However, there has been a bug with this feature since the beginning of the year (see thread) . For changing the container, a very simple bash script would work

#! /bin/bash
fdir=$(dirname $1)
fname=$(basename $1 .ts)
ffmpeg -i $1 -codec copy $fdir/$fname.mkv

1 Like

Yeah, I’m doing this right now but I need to beef up the script to include things like error handling, logging, disk space checking, verification of output files, management of source files (retention for troubleshooting).

I’m going to attack this in Python eventually. Anyone want to collaborate?

I have fairly robust code base going on my github for converting video files. Started it when I was using MakeMKV and have been adding for plex. I have actually been working on a watchdog (to be run as a Linux service) to convet the .ts files after they are moved to their final location because I’m sick of waiting for them to fix the post-processing bug.

I have a good deal of logging implemented, no disk space checking or file verification, besides checking return codes from ffmpeg.

I do have code for Metadata tagging in mp4 files, with data grabbed from IMDb, the tv database, and the movie database. There is also capability to download subtitles from opensubtitles and/or convert vobsob or OTA subtitles to srt; this requires some external libraries.

Yeah it’s probably more ideal to remux to MP4 than MKV, also better for metadata/tags, embedded subs (DVB subs to MPEG-4 Part 17 subs) etc.

Can you tell me more about why it’s better to remux to MP4? I had some errors in ffmpeg when going to MP4, so I chose MKV instead.

@kwodz, What’s the post-processing bug?

FYI, this is my script right now:

#!/bin/bash
outfile=${1//.ts/.mkv}
ffmpeg -hide_banner -i "$1" -map 0 -c copy -y "$outfile"
mv "$1" /mnt/plexdvr/processed

find /mnt/plexdvr/processed -name "*.ts" -type f -mtime +7 -delete

MPEG-4 video in an MPEG-4 container with MPEG-4 audio and MPEG-4 timed text subs is probably more likely to work?

I had started to add mkv support, but didn’t get too far as I was more interested in getting dvr processing working. Also, didn’t find a python based editor for mkv metadata; currently using Mutagen for mp4 tagging.

@c.megalodon, the DVR post bug appears when there is more than one file in the .grab directory when DVRd shows are recorded. When Plex goes to move files to their final location, all but one disappears. A more detailed discussion is in this thread .

Also, what were the ffmpeg errors when going to mp4?

@certuna It’s actually mpeg2 video with ac3 audio and EIA-608 subs.

Is there a specific issue you found with .mkv vs .mp4, or is it more of a personal feeling?

1 Like

Are you sure it is MPEG-2 video? Most HD channels have H.264 streams.

Where do you live?
I’ve never seen an HD broadcast that’s NOT in MPEG-2.
Now that I think about it…
I’ve never seen a broadcast NOT in MPEG-2.

In Australia channel nine HD

A’ight…

NE USA - not always in WV, but it’s a total MPEG-2 fest in these parts. Will probably change very shortly - major Nationwide upgrades/overhaul underway.

BTW: I’ve been doing exactly what this thread is about for more than 10 years with MCEBuddy, so it’s not like something that pushes the envelope of common sense, or some wild idea never thought of before… seems pretty standard actually.

…for what that’s worth…

UK, German, French, Turkish, Polish, Swedish, Belgian, Swiss and Dutch channels, pretty much all SD channels are MPEG-2, HD in H.264.

So apologies for assuming it’s a general thing :slight_smile:

For you guys it seems general. For us that’s crazy talk…lol

Early 2021 clean-up: implemented (option to have post-processing scripts for DVR)