summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNicolas George <george@nsup.org>2021-08-31 19:37:09 +0200
committerNicolas George <george@nsup.org>2021-09-16 10:17:59 +0200
commit8f92a1862a5894eec72114f3c097a6ba346908cd (patch)
tree719e90102e67ae7a2db8fe5a7c8340cff51f58f1 /tools
parent94aa7e8a764b2136cafe43f296a6e41a6b0a14ed (diff)
tools/dvd2concat: generate VOBSUB extradata
The extradata contains the frame size of the subtitles images and the palette.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/dvd2concat22
1 files changed, 22 insertions, 0 deletions
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}}) {