Jump to content

mkvmerge script to remux Live TV .ts files to MKV as recording post processing


Recommended Posts

Posted

I know the the convert function in Emby will use ffmpeg to convert files including recording.  However, I don't want to convert and this inbuilt tool has a habit of failing for a variety of reasons.

There is the 'recording post processing' function in the advanced options of recording. 

Does anyone have any code to convert the .ts file created from a live TV recording as is to an MKV file.  All files contain a AVC vile with either DD or AAC file and some subtitles.  I don't have to delete the orginial - happy for the original to remain.

Posted

HI, why don't you want to convert to a more streaming friendly format?

Posted

Hi - what do you mean by more streaming friendly format?  The stream is already in AVC and AAC or DD.  I just want to put it into an mkv container.

Posted
5 hours ago, kaledi said:

Hi - what do you mean by more streaming friendly format?  The stream is already in AVC and AAC or DD.  I just want to put it into an mkv container.

OK then that makes sense. Most live tv is mpeg2.

Posted

Ahh, I see your point. Yes in the UK SD material is mpeg2 generally, while hd material is h2.64

  • Thanks 1
Posted (edited)
On 2/26/2025 at 9:31 AM, kaledi said:

However, I don't want to convert and this inbuilt tool has a habit of failing for a variety of reasons.

This would be the simplest way I can think of:

ffmpeg -hide_banner -nostdin -y -v info -i "<infile>.ts" -map "0:??" -c copy "<outfile>.mkv"

edit: It will simply try to remux all streams in the original to the new container (no transcoding so it should be just/almost as fast as copying the file).

Although you still need to put this command in an appropriate script wrapper (.bat/.sh…) for your OS (you didn’t specify) and use the post processing to suit.

Also the mkv container may not retain some (any?) EIA-xxx text streams (if exists).

You will also need to ensure emby picks up this new file (RTM/rescan?).

Edited by TMCsw
  • Like 1
Posted (edited)

If using MKV the easiest and most flexible way is by using mkvmerge imo (part of the mkvtoolnix download)

mkvmerge.exe -o "%~d1%~p1%~n1.mkv"  "%~d1%~p1%~n1.ts"

This puts the MKV alongside the TS - and copies all tracks available.

Path is got via the path variable (#1) in the batch file containing the command above (and any other logging etc that you may want to add)

image.png.ca83d05567fd62623d872a42a3de67b9.png

Edited by rbjtech
  • Like 1
Posted

Thank you @rbjtech

I've created the file based on the code you posted elsewhere, which I've now found.  It correctly writes the mkv.  Oddly, files from a particular channel have no audio written into the mkv file.  The file in question is an avc file with an aac audio track and the an mkv is correctly created when using the gui i.e. mkvtoolnix. any thoughts? 

Posted

I may have answered my own question. it looks like your code filters only englings tracks, which these onese wouldn't be marked as such.

  • Like 1
rbjtech
Posted (edited)
On 28/02/2025 at 18:44, kaledi said:

I may have answered my own question. it looks like your code filters only englings tracks, which these onese wouldn't be marked as such.

Ah yes, if you have used my other script. :)   Just remove that part and it will copy all language tracks if you haven't done so already.

Edited by rbjtech
Posted

@rbjtechI have this script fully working on my Windows installation of Emby server, so thank you very much for your guide.  Can it work on a Synology NAS installation?  I've installed mkvtoolnix on the Synology NAS, but I'm unsure where the mkvmerge.exe file resides?

Are there any modifications to the script file that are required (other than location of mkvmerge etc)?

rbjtech
Posted
18 hours ago, kaledi said:

@rbjtechI have this script fully working on my Windows installation of Emby server, so thank you very much for your guide.  Can it work on a Synology NAS installation?  I've installed mkvtoolnix on the Synology NAS, but I'm unsure where the mkvmerge.exe file resides?

Are there any modifications to the script file that are required (other than location of mkvmerge etc)?

You'll need to use linux shell file / mounts (forward slash, rather than backslah etc) as I believe Synology uses linux, but other than that - the syntax is exactly the same.   mkvtoolnix will probably be in /etc somewhere but the package install instructions should tell you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...