Message ID | 20210831180739.873390-12-george@nsup.org |
---|---|
State | Accepted |
Commit | 8f92a1862a5894eec72114f3c097a6ba346908cd |
Headers | show |
Series | [FFmpeg-devel,01/12] lavf/concat: refactor parsing | expand |
Context | Check | Description |
---|---|---|
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
andriy/make_ppc | success | Make finished |
andriy/make_fate_ppc | success | Make fate finished |
Nicolas George (12021-08-31): > For muxing the subtitles, some more work to be done, probably: mencoder > is still needed. With Matroska output: With -c:s dvd_subtitle it works, and the subtitles packets are much smaller. But I am not 100% confident in our encoder, it tries to guess which parts are the body of the letters and which parts are the outline. With -c:s copy, the resulting file has no duration on the subtitles, which IIRC is not valid, but mkvalidator does not complain. mkvmerge can fix the file. Not 100% satisfactory, but still very good, if I say so myself. Regards,
Nicolas George: > Nicolas George (12021-08-31): >> For muxing the subtitles, some more work to be done, probably: mencoder >> is still needed. > > With Matroska output: > > With -c:s dvd_subtitle it works, and the subtitles packets are much > smaller. But I am not 100% confident in our encoder, it tries to guess > which parts are the body of the letters and which parts are the outline. > > With -c:s copy, the resulting file has no duration on the subtitles, > which IIRC is not valid, but mkvalidator does not complain. mkvmerge can > fix the file. > Our VobSub demuxer does not set the duration (it is encoded as part of the payload). So our muxer uses SimpleBlocks (because duration == 0 actually says "play this until the next packet arrives", which coincides with the semantics for SimpleBlocks). mkvmerge reads the duration from the payload. Is there a proper spec for the VobSub format somewhere? - Andreas
Andreas Rheinhardt (12021-08-31): > Our VobSub demuxer does not set the duration (it is encoded as part of > the payload). So our muxer uses SimpleBlocks (because duration == 0 > actually says "play this until the next packet arrives", which coincides > with the semantics for SimpleBlocks). > mkvmerge reads the duration from the payload. > Is there a proper spec for the VobSub format somewhere? As far as I know, the best there is would be: https://www.matroska.org/technical/subtitles.html https://www.matroska.org/technical/codec_specs.html I vaguely remember that muxing Matroska from VobSub in FFmpeg failed because it did not set durations on the subtitles packets, but I do not remember what tool exactly refused to use the result. Now, it seems to work, which is the most we can ask for with a fringe format like that. Regards,
diff --git a/tools/dvd2concat b/tools/dvd2concat index ccc021c4cc..24809fbdf5 100755 --- a/tools/dvd2concat +++ b/tools/dvd2concat @@ -94,6 +94,28 @@ for my $subp (@{$track->{subp}}) { $concat .= "\nstream\nexact_stream_id " . $subp->{streamid} . "\n"; $concat .= "stream_codec dvd_subtitle\n"; $concat .= "stream_meta language " . $subp->{langcode} . "\n" if $subp->{langcode}; + my $extradata = ""; + if ($track->{width} && $track->{height}) { + $extradata .= "size: " . $track->{width} . "x" . $track->{height} . "\n"; + } + if (my $pal = $track->{palette}) { + my @pal; + for my $c (@$pal) { + # Adapted from mplayer/sub/vobsub.c + my $y = ((hex($c) >> 16) & 0xFF); + my $u = ((hex($c) >> 8) & 0xFF) - 128; + my $v = ((hex($c) >> 0) & 0xFF) - 128; + my ($r, $g, $b) = map { int($_ < 0 ? 0 : $_ > 255 ? 255 : $_) } + $y + 1.4022 * $u, + $y - 0.3456 * $u - 0.7145 * $v, + $y + 1.7710 * $v; + push @pal, sprintf "%06x", ($r << 16) | ($g << 8) | $b; + } + $extradata .= "palette: " . join(", ", @pal) . "\n"; + } + if ($extradata ne "") { + $concat .= "stream_extradata " . unpack("H*", $extradata); + } } my $chap_time = 0; for my $chap (@{$track->{chapter}}) {
The extradata contains the frame size of the subtitles images and the palette. Signed-off-by: Nicolas George <george@nsup.org> --- tools/dvd2concat | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) And with this, we can encode DVDs correctly, and even have the hardcoded subtitles the right color. For muxing the subtitles, some more work to be done, probably: mencoder is still needed. If somebody wants, taking the code from lsdvd and creating a special demuxer that will create a ConcatContext internally would allow us to read DVDs directly.