[FFmpeg-devel] [PATCH 12/12] tools/dvd2concat: generate VOBSUB extradata
Nicolas George
george at nsup.org
Tue Aug 31 21:07:39 EEST 2021
The extradata contains the frame size of the subtitles images
and the palette.
Signed-off-by: Nicolas George <george at 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.
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}}) {
--
2.33.0
More information about the ffmpeg-devel
mailing list