Log in

View Full Version : How to multiplex MKV with DVB subs to TS?


LigH
28th January 2019, 10:18
A user of the German doom9/Gleitz board reports that ffmpeg is able to remultiplex an MKV with H.264 video, MP2 audio, and DVB subtitles to TS, but the result does not play smoothly for him, and Avidemux complains about B-frames and PTS monotony.

Remultiplexing with tsMuxeR is not possible because it does not support the subtitle format.

Can you recommend any other TS multiplexer?

More details in German + DropBox link to a sample (https://gleitz.info/forum/index.php?thread/48093-nur-mkv-zu-ts-umverpackt-ergebnis-ruckelt/)

Ghitulescu
1st February 2019, 08:11
I never had a problem with DVB subtitles and tsmuxer.
I'll see at home what kind of "DVD Subs" he has...
I did and still do regularly conversions from SAT recordings to BDs.

Anyway, I'd first demux each source into their corresponding streams, then reassemble the needed ones with tsmuxergui.

mkver
1st February 2019, 18:20
1. This has nothing to do with the audio or subtitles; it also has nothing to do with the target format. Remuxing to Matroska would be similarly affected. But it has something to do with the source format.
2. The file is 50i H.264, coded as separated field, not via MBAFF. The file has b-frames, so that dts!=pts in general. Given that Matroska does not explicitly store dts, but only pts, ffmpeg has to make timestamps up (it needs to do this to remux it into ts (because dts is coded explicitly for (video) streams with b frames), but it does this all the time, also if your source format is Matroska), so it either reads the number of reordered frames from the VUI section of the SPS or (if the SPS does not contain said information) it guesses the number of reordered frames by looking at the first few frames. Your sample uses two reordered frames (the pair of paired fields counts as one frame!):

I frame, track 1, timestamp 00:00:00.000000000, size 47227, adler 0x1c06c0ca
P frame, track 1, timestamp 00:00:00.020000000, size 7938, adler 0xd35e4c6f
P frame, track 1, timestamp 00:00:00.160000000, size 7132, adler 0x0015d277
P frame, track 1, timestamp 00:00:00.180000000, size 6912, adler 0x37e4713f
P frame, track 1, timestamp 00:00:00.080000000, size 1273, adler 0xc7ae83f9
P frame, track 1, timestamp 00:00:00.100000000, size 1397, adler 0xf76eb655
B frame, track 1, timestamp 00:00:00.040000000, size 377, adler 0x9222ba53
B frame, track 1, timestamp 00:00:00.060000000, size 368, adler 0x886daf17
B frame, track 1, timestamp 00:00:00.120000000, size 169, adler 0x482e48d1
B frame, track 1, timestamp 00:00:00.140000000, size 241, adler 0xbdb07799
P frame, track 1, timestamp 00:00:00.320000000, size 7313, adler 0x80415a27
P frame, track 1, timestamp 00:00:00.340000000, size 7141, adler 0x3c7ff229
P frame, track 1, timestamp 00:00:00.240000000, size 693, adler 0x3df74801
P frame, track 1, timestamp 00:00:00.260000000, size 1466, adler 0x6736dfb3
B frame, track 1, timestamp 00:00:00.200000000, size 99, adler 0xb5f826b4
B frame, track 1, timestamp 00:00:00.220000000, size 95, adler 0x3de82b52
B frame, track 1, timestamp 00:00:00.280000000, size 99, adler 0xb0b228c6
B frame, track 1, timestamp 00:00:00.300000000, size 77, adler 0x2c721ff0
P frame, track 1, timestamp 00:00:00.480000000, size 7309, adler 0xff8d3b2f
P frame, track 1, timestamp 00:00:00.500000000, size 8233, adler 0xb9caefe6
P frame, track 1, timestamp 00:00:00.400000000, size 835, adler 0x402196b7
P frame, track 1, timestamp 00:00:00.420000000, size 1203, adler 0x037759ac
B frame, track 1, timestamp 00:00:00.360000000, size 62, adler 0x6db617d0
...

(You see that there are two frames/field pairs that follow the field pair with timestamps 40ms and 60ms in display order, but precede it in decoding order (namely (160ms, 180ms) and (80ms, 100ms)).)

And now there is a problem: The generic dts guessing code does not know that these blocks contain only fields and therefore count only half as much as frames (i.e. counted in blocks, the number of reordered blocks is four); it thinks in blocks/AVPackets. This is essentially ffmpeg trac ticket 6810 (https://trac.ffmpeg.org/ticket/6810#comment:13).

3. There is a workaround: Use -strict 1 as an input option. This has the consequence that ffmpeg assumes the worst delay (namely the maximum number of reference frames compatible with the level of your sample) if the SPS doesn't contain a number of reordered frames (like in your sample). In your case this means five which is of course more than four, so that muxing works now without errors.
(But this is still suboptimal: The difference of pts to dts in the output file will be bigger than it needs to be; this also affects interleavement. But I don't think that one needs to worry about this.)

Matt Kirby
1st February 2019, 22:21
Hi, I'm the (german) person with the problem.

At first. Thank you for your answers.
Well:
Let's forget about the original videostream. I coded it to 1280*720p50 to Blu-Ray standard and the audio to ac3 2.0.

I muxed the new video.avc and new audio.ac3 to new.mkv
then I muxed the original.mkv into that new.mkv but only the dvb-(sat)-subs.
so I've got a newwithsubs.mkv with 3 streams inside V+A+S.

When I remux it with ffmpeg to TS
ffmpeg -i "newwithsubs.mkv" -vcodec copy -acodec copy -scodec copy -f mpegts output-file.ts

the result is played in VLC and MPC-HC and it's smooth.
But my Blu-Ray authoring program "TMPGenc Auhtoring Works 6" can't read it. It's freezing.

Tsmuxer don't want that newwithsubs.mkv because of the dvb-subs.
When I try new.mkv (without subs) it works.

Please tell me Ghitulescu how do you handle with dvbsub-streams.
I can only extract it from mkv mit cmd-line: mkvextract --raw....
Every mkvextractgui tells me that it is a unsupported/unknown stream.

Hier a new testfile with 3 streams inside

https://www.dropbox.com/sh/pg0bnz7pq6otogn/AADVt2TT_w3F4l41hvuv1hRta?dl=0

Who can mux it to TS so that TMPGenc Authoring Works reads it?

nevcairiel
1st February 2019, 22:33
DVB subs cannot be put on Blu-rays, maybe explaining your final goal might help to clarify.

Matt Kirby
1st February 2019, 22:42
My final goal is a BluRay with subs in the same colors the dvb-subs had.

I know that dvbsubs can't direct go to BD. But Tmpeg Auth. Works (TAW) can read them when they are in a ts-stream and can convert them into pgs-subs.
But I only have a MKV so I need a TS that can be read by TAW.

mkver
1st February 2019, 23:54
Have you tried simply muxing only the subs to ts (with ffmpeg) and loading this into TAW?

Matt Kirby
2nd February 2019, 09:18
As far as I know that doesn't work with TAW. You can only add wohle clips to a project. You can import srt-Textfiles and thats it.

mkver
2nd February 2019, 10:31
I guess TAW freezes because the subtitles are for 720*576 video and you now use a 1280*720 video. Have you tried to use other tools to convert the subtitles to the Bluray PGS format (like SubtitleEdit)?

And they don't allow you to import more than one ts file? Wow, that sucks.

[Edit]: For future files: Check whether your files have teletext subtitles in addition to the DVB subtitles; these teletext subtitles can then be extracted with e.g. ccextractor while preserving the color.

Matt Kirby
2nd February 2019, 11:29
Have you tried to use other tools to convert the subtitles to the Bluray PGS format (like SubtitleEdit)?

With Subtitle Edit I can import the dvb-subs but then I have to run them trough OCR and then I can export them to PGS. That's not what I want.
Are there any other tools?



Check whether your files have teletext subtitles

No, there is no teletext on this channel.

mkver
2nd February 2019, 12:33
You are wrong. SubtitleEdit can export image-based formats: When the OCR image opens up, don't OCR the subs; instead, right-click on a subtitle entry and use the export functionality.
(But testing this, the subtitle color changes slightly (in MPC-HC and MPC-BE with internal subtitle renderer; maybe it has something to do with limited/full range? I don't know.)

Matt Kirby
2nd February 2019, 16:09
Oh, thank you. This function I didn't know yet.

Ghitulescu
4th February 2019, 11:26
DVB subs cannot be put on Blu-rays, maybe explaining your final goal might help to clarify.
That's false of course.
It is possible and it works without magic transformations, they only need to be extracted by an aware tool and have to fit the video (they can't be larger, only smaller).

Ghitulescu
4th February 2019, 11:29
Please tell me Ghitulescu how do you handle with dvbsub-streams.

Essentially, I demux the DVB subs via the very latest ProjectX version. PjX also knows how to demux the Teletext/Videotext subtitles into SRT if existing.

Remuxing back I do with TSMuxerGUI.

SeeMoreDigital
4th February 2019, 17:59
Essentially, I demux the DVB subs via the very latest ProjectX version. PjX also knows how to demux the Teletext/Videotext subtitles into SRT if existing.Which version exactly? Much like TSmuxerGUI, ProjectX has not been developed for years!

Ghitulescu
4th February 2019, 20:40
Which version exactly? Much like TSmuxerGUI, ProjectX has not been developed for years!

That xtremely old version.... it only has to be the last one. AFAIK it's the only PjX that can demux HD subs.

Ghitulescu
4th February 2019, 20:41
Which version exactly? Much like TSmuxerGUI, ProjectX has not been developed for years!

I also use several versions of tsmuxer and GUI for sometimes the old 1.10 is better than the last one.