Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: M-Reimer on August 08, 2016, 04:22:42 PM

Title: Any chance to keep subtitles in TS files?
Post by: M-Reimer on August 08, 2016, 04:22:42 PM
Hello,

I want to cut video in TS format. This seems to work well but the subtitle is removed when saving.

Would it be possible to keep the subtitle at least in the case, where the output format is TS, too?
Title: Re: Any chance to keep subtitles in TS files?
Post by: Jan Gruuthuse on August 08, 2016, 04:41:03 PM
Quote from: M-Reimer on August 08, 2016, 04:22:42 PM
Would it be possible to keep the subtitle at least in the case, where the output format is TS, too?

No, not with avidemux:

Quote from: mean on June 10, 2015, 02:51:06 PM
subtitles are discarded at the moment
(any non audio/video track actually)

Only way to keep subtitles is with mkv container.

extract subtitle with mkvtoolnix gui from original .TS
edit original .TS with avidemux, save into MKV (muxer)
edit subtitles with Aegisub Advanced Subtitle Editor to match .TS editing (timing, ...)
merge the edit subtile back into mkv with mkvtoolnix gui

http://www.aegisub.org/
https://mkvtoolnix.download
see previous posting: Soft subtitles in MKV and MP4 container (http://avidemux.org/smif/index.php/topic,16376.0.html)
Title: Re: Any chance to keep subtitles in TS files?
Post by: M-Reimer on August 08, 2016, 04:49:29 PM
I think this is not much fun as soon as I cut parts from within a recording, as this would mean that I have to edit subtitles at multiple places, right?

Is it planned to add this feature (direct cutting the subtitles "stream") to avidemux at some time?
Title: Re: Any chance to keep subtitles in TS files?
Post by: Jan Gruuthuse on August 08, 2016, 05:03:25 PM
you load original subtitle, you can load video into subtitle editor, and adjust timings
it helps keeping timing track on paper where you cut.
Title: Re: Any chance to keep subtitles in TS files?
Post by: M-Reimer on August 08, 2016, 05:18:00 PM
I wasn't even able to extract the subtitle using mkvtoolnix gui. I only have video and audio tracks. If I play the file in VLC, I have subtitles.

I haven't tried it, but I think adding subtitles in the way, you suggested, requires quite some work. So far I did my cutting with VDR which kept the subtitles without any additional work. In theory this shouldn't be that difficult, as all the information is already there.

Maybe I'll have a deeper look at the TS file format to find out where subtitles are saved. Maybe it is possible to auto-align the subtitle information from the source file to the cutted target file, but I think this only works if avidemux doesn't change time stamps.
Title: Re: Any chance to keep subtitles in TS files?
Post by: mean on August 08, 2016, 07:12:08 PM
The tracks are not just copied
They are analyzed, extracted & reconstructed in the target file
Adding subtitles is not easy (i.e. need to extra them in a format agnostic way and resynthetize them later)

Title: Re: Any chance to keep subtitles in TS files?
Post by: M-Reimer on August 08, 2016, 08:13:14 PM
Seems like there are two possible formats for subtitles in TS and my "bitmap based" subtitle format, used in the recording, I want to cut, isn't supported by mkvtoolnix.

Currently I fail with analyzing the TS format. I couldn't find any good documentation. But if the tracks are reconstructed, I guess it wouldn't work to merge the subtitles from the original file anyway.

At least for the recordings, where I want to keep the subtitles, I'll have to find a way to keep cutting with VDR even though I want to replace it with Kodi on my HTPC.
Title: Re: Any chance to keep subtitles in TS files?
Post by: Jan Gruuthuse on August 09, 2016, 05:10:09 AM
bitmapped subtitles (dvd source?)
Title: Re: Any chance to keep subtitles in TS files?
Post by: M-Reimer on August 10, 2016, 09:48:52 AM
Yes, the subtitles are bitmapped. May be similar to DVD, but the source is DVB-S2.
Title: Re: Any chance to keep subtitles in TS files?
Post by: Jan Gruuthuse on August 10, 2016, 01:27:51 PM
perhaps you can do something with: http://nikse.dk/SubtitleEdit/
Title: Re: Any chance to keep subtitles in TS files?
Post by: jjddav on March 17, 2017, 11:57:34 PM
Hello,
sorry to come back on this topic but I can't understand the following.
Quote from: mean on August 08, 2016, 07:12:08 PM
The tracks are not just copied
They are analyzed, extracted & reconstructed in the target file
Adding subtitles is not easy (i.e. need to extra them in a format agnostic way and resynthetize them later)
Actually why is the audio treatment different than the subtitle treatment ?
when openning a TS file, extracting the subtitles operation is to associate the PID packets to a timestamp, using the PTS/DTS or the PCR, like for audio I guess.
No analysis of subtitles is necessary because they are only copied back in the TS file after cut is done.
i am not an expert in demux/remux but once the file part (adds for example) is cut, putting back the subtitles should be same operation than copying the audio and remuxing it with video. No?

The only operation I need to do is cut a part or more parts of the original TS file, then save the result by copying video/audio/subtitles in a new TS file.

If it can help, I have 2 examples of such files I got with subtitles, one from ASTRA 2 satellite (BBC4 HD channel with teletext subtitles):
http://davoult.free.fr/tmp/BBC4HD.TS

I made an analysis and export with TS Reader:

QuoteTransport Stream ID: 2061 (0x080d)

PMT PID 16 (0x0010) - Network

PMT PID 259 (0x0103) - Program 8952

Program Number: 8952
Descriptor: Multiplex Buffer Utilization Descriptor
Bound Valid Flag: 1
LTW Offset Lower: 180 Upper: 180

Stream Type: 0x1b H.264 Video PID 5300 (0x14b4)
Descriptor: Stream Identifier Descriptor
0b .
Descriptor: Private Data Indicator Descriptor
4f 54 56 00 OTV.
Descriptor: User Private Descriptor: 0xfe
48 44 56 00 HDV.

Stream Type: 0x03 MPEG-1 Audio PID 5302 (0x14b6)
Descriptor: Stream Identifier Descriptor
07 .
Descriptor: ISO639 Language Descriptor
Language: NAR
Audio type: undefined
Descriptor: Private Data Indicator Descriptor
4f 54 56 00 OTV.
Descriptor: User Private Descriptor: 0xfe
41 55 44 32 AUD2

Stream Type: 0x06 Teletext/VBI PID 5303 (0x14b7)
Descriptor: Stream Identifier Descriptor
04 .
Descriptor: Teletext Descriptor
Language: eng Type: Teletext subtitle page Magazine: 0x00 Page: 0x88
Language: eng Type: Initial Teletext page Magazine: 0x00 Page: 0x88
Descriptor: Private Data Indicator Descriptor
4f 54 56 00 OTV.
Descriptor: User Private Descriptor: 0xfe
53 55 42 00 SUB.

Stream Type: 0x06 Dolby AC3 Audio PID 5301 (0x14b5)
AC3: Bitrate 192 Kbps Sample Rate 48 KHz
AC3: Mode complete main Coding 2/0 L, R
AC3: Dolby Surround Mode Not Dolby Surround
AC3: LFE Mode Off Dialogue normalization -23 dB
Descriptor: Stream Identifier Descriptor
08 .
Descriptor: ISO639 Language Descriptor
Language: eng
Audio type: undefined
Descriptor: AC3 Audio Descriptor
Flags: AC3 Type: False BSID: False Main ID: False ASVC: False
Descriptor: Private Data Indicator Descriptor
4f 54 56 00 OTV.
Descriptor: User Private Descriptor: 0xfe
41 43 33 00 AC3.


and the second file from french DTT, channel TF1 HD with DVBSUB subtitles:
http://davoult.free.fr/tmp/TF1HD.ts

here is the export after analysis with TSReader of the interrested part:

QuoteTransport Stream ID: 6 (0x0006)

PMT PID 100 (0x0064) - Program 1/1537 TF1

Program Number: 1/1537 TF1

Stream Type: 0x1b H.264 Video PID 120 (0x0078)
H.264 Video: Resolution 1920 x 1080 Interlaced: 1

Stream Type: 0x06 ISO/IEC 13818-1 PES packets containing private data PID 130 (0x0082)
Descriptor: ISO639 Language Descriptor
Language: fra
Audio type: undefined
Descriptor: Enhanced AC-3 Descriptor
80 c2 ..

Stream Type: 0x06 ISO/IEC 13818-1 PES packets containing private data PID 131 (0x0083)
Descriptor: ISO639 Language Descriptor
Language: qaa
Audio type: undefined
Descriptor: Enhanced AC-3 Descriptor
80 c2 ..

Stream Type: 0x06 ISO/IEC 13818-1 PES packets containing private data PID 132 (0x0084)
Descriptor: ISO639 Language Descriptor
Language: qad
Audio type: undefined
Descriptor: User Private Descriptor: 0x7f
06 85 66 72 61 ..fra
Descriptor: Enhanced AC-3 Descriptor
80 c2 ..

Stream Type: 0x06 ISO/IEC 13818-1 PES packets containing private data PID 150 (0x0096)
Descriptor: Subtitling Descriptor

Stream Type: 0x06 ISO/IEC 13818-1 PES packets containing private data PID 151 (0x0097)
Descriptor: Subtitling Descriptor

Stream Type: 0x05 ISO/IEC 13818-1 private_sections PID 170 (0x00aa)
Descriptor: Application Signalling Descriptor
80 10 e0 ...

thanks if someone could check this if possible. Other topics related to that TS subtitles subject:
http://avidemux.org/smif/index.php?topic=12392.0 (http://avidemux.org/smif/index.php?topic=12392.0)
http://www.avidemux.org/smf/index.php/topic,10661.0.html (http://www.avidemux.org/smf/index.php/topic,10661.0.html)
Title: Re: Any chance to keep subtitles in TS files?
Post by: jjddav on April 14, 2017, 10:24:55 AM
up
Title: Re: Any chance to keep subtitles in TS files?
Post by: zakk on April 14, 2017, 11:10:33 AM
Remuxe ton .ts avec mkvtoolnix et utilise l'onglet "cible" pour faire tes coupes avec des index temporels. Sinon tu vas galérer. Je viens d'essayer ça marche il garde les sous-titres.
Title: Re: Any chance to keep subtitles in TS files?
Post by: bernd_b on April 17, 2017, 10:39:35 PM
Well, the only things I can add:

ffmpeg can handle dvb-subtitles (both - the bitmap based dvbsub and the textfiles based broadcast in the teletext-stream). I had success with cutting ts files including the subtitle streams using ffmpeg with the "copy" de/encoder. Because ffmpeg is only commandline based, that is of course a hard way to succeed.

To preserve subtitle streams with avidemux2 while using copy mode would be a vervy welcomed feature from my side too.


Title: Re: Any chance to keep subtitles in TS files?
Post by: jjddav on June 23, 2017, 06:18:24 PM
Quote from: bernd_b on April 17, 2017, 10:39:35 PM
To preserve subtitle streams with avidemux2 while using copy mode would be a vervy welcomed feature from my side too.
Yes, sure, we are not the only ones who are requesting this feature.
And I still don't understand why this is so difficult to implement it, as DVBSUB insert mechanism is quite the same than audio in TS mode.
Title: Re: Any chance to keep subtitles in TS files?
Post by: AQUAR on June 24, 2017, 09:34:14 AM
It would be nice to have such a feature but ultimately it is up to the contributors of this project to make it happen.
I believe the author has given an explanation at response 5 viz "it is not that easy".

Anyone that knows better though can always contribute to this open source project and make it happen.

Title: Re: Any chance to keep subtitles in TS files?
Post by: sbarmen on August 03, 2017, 12:04:54 PM
I would also love this feature as I use this alot with VideoReDo. +1 for this feature! :D

Sadly I have too little knowledge to make this happen myself...

Just on a sidenote VideoReDo does this prefectly, and personally I would be willing to pay some money to get this feature if it would be developed.
Title: Re: Any chance to keep subtitles in TS files?
Post by: alexwilmac on November 09, 2018, 03:10:11 PM
I read this a bit old topic and I'd like to know if anyone is aware of any change in the future version of ADM.
Considered how many devices, especially the ones linux-based, use the .ts format with embedded subs, it would be great to have them preserved, as many other user have said ;)
Title: Re: Any chance to keep subtitles in TS files?
Post by: eumagga0x2a on November 09, 2018, 04:10:28 PM
Whoever is interested in subtitle stream support getting added to all the required components (core libs, MpegTS demuxer, editor, at least the MpegTS and preferably MKV muxers), should contribute code or hire a professional developer to work on the project.
Title: Re: Any chance to keep subtitles in TS files?
Post by: alexwilmac on April 03, 2019, 09:21:33 PM
About the alleged difficulties supposed in post#5, I'm also sceptical for a simple reason: if I cut my ts file by an enigma2 plugin, despite the plugin is not perfect at cutting (it has not keyframe capability, for instance) it perfectly manages the subtitles.
This is (probably) because, as jjddav says in post#10, they are embedded into the ts files.
That's why I can't understand why a simple plugin (that cuts in a few seconds a ts file of a couple of hours) is better at preserving subs than a great software like Avidemux is.
Title: Re: Any chance to keep subtitles in TS files?
Post by: alexwilmac on January 27, 2020, 12:09:36 PM
Old topic but...
Avidemux is great, is really such a powerful software.
I (and many, many user who own a PVR and need to cut ts files preserving subtitles) are hoping an effort to make this software the state of the art.
Each time I download a new release, I hope (and pray) to get a surprise.
Title: Re: Any chance to keep subtitles in TS files?
Post by: JDepp on February 28, 2021, 07:36:47 PM
Sorry for replying to this old thread...
I just wanted to add to the long list of users requesting this much looked for functionality - preserving the subtitles in the edited output files
Thanks
Title: Re: Any chance to keep subtitles in TS files?
Post by: xyzzy on April 20, 2021, 10:57:38 AM
I think it might not be that hard to do this outside avidemux.


Everything is trivial except creating aegisub lua script.  Getting edit times from avidemux project is not hard.  There is a trick to turning avidemux timestamps into real PTS values.

I don't think it would be hard to add this to avidemux either.  One can avoid large problem of demuxing and remuxing subtitles from all the different containers and all the different subtitle formats.  ffmpeg already does this.  It is just one ffmpeg command to extract subtitles to srt/ass file.  So avidemux can read in srt/ass file (subtitle filter in avidemux already does this), perform edits on subtitle times, and then save to srt/ass file.  Everything else is just simple scriptable commands with software that already exists.
Title: Re: Any chance to keep subtitles in TS files?
Post by: xyzzy on April 21, 2021, 12:55:02 AM
I thought of another way to get edited subs and it ended up being pretty easy to do.

Extract the subs in srt format from the source file(s) with ffmpeg
Save your avidemux edit as a project
Run my python script on the project file and it will assemble an edited srt file that can be added to avidemux's encoded output video with mkvmerge.

One can never get away with posting code in this forum and there are no attachments, so I put it on an avidemux2 branch on github, srt-edit-script (https://github.com/xyzzy42/avidemux2/tree/srt-edit-script).

Direct link to files, adm_edit_srt.py (https://github.com/xyzzy42/avidemux2/blob/srt-edit-script/addons/adm_edit_srt.py) and fakeavidemux.py (https://github.com/xyzzy42/avidemux2/blob/srt-edit-script/addons/fakeavidemux.py)
Title: Re: Any chance to keep subtitles in TS files?
Post by: butterw on April 21, 2021, 08:30:48 AM
fakeavidemux class allows to extract the segment info from an Avidemux project with an external python script (much more powerful than TinyPy but requires Python installed).

#!/bin/env python3
import os.path
import sys
from fakeavidemux import Avidemux
'''usage: python external_script.py project.py'''

# Read in Avidemux Project, which will create an adm object that has the file and segment info
proj = open(sys.argv[1]).read()
exec(proj)

# adm.segments (list) is now available
Title: Re: Any chance to keep subtitles in TS files?
Post by: xyzzy on April 21, 2021, 10:55:06 AM
Quote from: xyzzy on April 21, 2021, 12:55:02 AMExtract the subs in srt format from the source file(s) with ffmpeg

I enhanced the script so this isn't necessary anymore.  It will automatically use ffprobe and ffmpeg to extract subtitles or closed captions from the video file(s) if there aren't .srt files already.  One needs ffprobe and ffmpeg installed of course.