Bug#1032972: handbrake: debian version of handbrake does not handle subtitles correctly

2024-01-29 Thread michael spreng

Hi Moritz

On 29/01/2024 22:48, Moritz Mühlenhoff wrote:

Can you please send/propose this upstream, they are in a much better position
to assess this approach.

Either by making a pull requesthttps://github.com/HandBrake/HandBrake  or
by opening an issue there.


It has been reported here: 
https://github.com/HandBrake/HandBrake/issues/4029


In short: HandBrake developers insist that handbrake is buildt with 
their heavily patched version of ffmpeg (they prefer ffmpeg handling the 
pts). The Debian package gets branded as unsupported. FFmpeg on the 
other hand does not accept that "convenience" patch (reasoning "That 
makes no sense": https://trac.ffmpeg.org/ticket/10681). And Debian seems 
to be caught in the middle of the hardened positions between those two 
projects.


So sorry, someone has already tried that, and unfortunately for human 
reasons that has failed. Debian has may sympathy, being the anonymous 
bystander caught in the proverbial crossfire.


Thank you for your efforts to resolve this,

Michael


Bug#1032972: handbrake: debian version of handbrake does not handle subtitles correctly

2024-01-29 Thread Moritz Mühlenhoff
Hi Michael,
thanks for looking into this!

michael spreng wrote:
> The above mentioned patch to ffmpeg changes ffmpeg to remember the pts. But
> handbrake can remember the pts just as well. So see the attached patch which
> does exactly that: if the subtitle is incomplete, it saves the pts to the
> handbrake subtitle context, and retrieves it if there is no pts on a
> completed subtitle ready for output.
> 
> I am unsure how to proceed from here. Is that fix acceptable? Where would I
> submit it?

Can you please send/propose this upstream, they are in a much better position
to assess this approach.

Either by making a pull request https://github.com/HandBrake/HandBrake or
by opening an issue there.

Cheers,
Moritz



Bug#1032972: handbrake: debian version of handbrake does not handle subtitles correctly

2024-01-27 Thread cybaer42
On Wed, 22 Nov 2023 16:04:21 +0100 michael spreng  
wrote:
I stumbled on this issue as well. It looks to me like this patch: 
https://github.com/HandBrake/HandBrake/blob/master/contrib/ffmpeg/A07-dvdsubdec-use-pts-of-initial-packet.patch

is particularly important for how handbrake handles dvd sub titles.

My understanding is: dvd subtitles are large (being images) and will 
usually exceed a packet in the stream. ffmpeg only returns the pts with 
the first invocation (packet), where no complete subtitle results. The 
second invocation (packet), which usually completes the subtitle and 
results in a complete subtitle returned, does not contain the pts anymore.


The above mentioned patch to ffmpeg changes ffmpeg to remember the pts. 
But handbrake can remember the pts just as well. So see the attached 
patch which does exactly that: if the subtitle is incomplete, it saves 
the pts to the handbrake subtitle context, and retrieves it if there is 
no pts on a completed subtitle ready for output.


I am unsure how to proceed from here. Is that fix acceptable? Where 
would I submit it?

I tried this patch out and it works. Subtitles are with right timings.



Bug#1032972: handbrake: debian version of handbrake does not handle subtitles correctly

2023-11-22 Thread michael spreng
I stumbled on this issue as well. It looks to me like this patch: 
https://github.com/HandBrake/HandBrake/blob/master/contrib/ffmpeg/A07-dvdsubdec-use-pts-of-initial-packet.patch

is particularly important for how handbrake handles dvd sub titles.

My understanding is: dvd subtitles are large (being images) and will 
usually exceed a packet in the stream. ffmpeg only returns the pts with 
the first invocation (packet), where no complete subtitle results. The 
second invocation (packet), which usually completes the subtitle and 
results in a complete subtitle returned, does not contain the pts anymore.


The above mentioned patch to ffmpeg changes ffmpeg to remember the pts. 
But handbrake can remember the pts just as well. So see the attached 
patch which does exactly that: if the subtitle is incomplete, it saves 
the pts to the handbrake subtitle context, and retrieves it if there is 
no pts on a completed subtitle ready for output.


I am unsure how to proceed from here. Is that fix acceptable? Where 
would I submit it?From: michael spreng 
Date: Wed, 22 Nov 2023 15:36:17 +0100
Subject: [PATCH] Save pts of incomplete subtitle

Referring to bug "debian version of handbrake does NOT handle subtitles
correctly"
handbrake patches ffmpeg to save the pts of multi-packet subtitles
https://github.com/HandBrake/HandBrake/blob/master/contrib/ffmpeg/A07-dvdsubdec-use-pts-of-initial-packet.patch
As debian uses the system libraries, this patch implements the saving of
the pts in handbrake to fix subtitles for debian
---
 libhb/decavsub.c | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libhb/decavsub.c b/libhb/decavsub.c
index aad32beb2..5738b1976 100644
--- a/libhb/decavsub.c
+++ b/libhb/decavsub.c
@@ -28,6 +28,12 @@ struct hb_avsub_context_s
 //  while this should really get fixed elsewhere,
 //  dropping subtitles should be avoided as much as possible
 int64_t last_pts;
+// large subtitles (dvd sub, image based for example) can be split
+// across several packets. avcodec_decode_subtitle2 can return the
+// pts in a non complete packet (got_sub_ptr == 0). In that case
+// save the pts and reuse it once all packets were processed and
+// the subtitle is complete
+int64_t unused_pts;
 // For PGS subs, we need to pass 'empty' subtitles through (they clear the
 // display) - when doing forced-only extraction, only pass empty subtitles
 // through if we've seen a forced sub since the last empty sub
@@ -49,6 +55,7 @@ hb_avsub_context_t * decavsubInit( hb_work_object_t * w, hb_job_t * job )
 }
 ctx->seen_forced_sub   = 0;
 ctx->last_pts  = AV_NOPTS_VALUE;
+ctx->unused_pts= AV_NOPTS_VALUE;
 ctx->job   = job;
 ctx->subtitle  = w->subtitle;
 
@@ -360,6 +367,11 @@ int decavsubWork( hb_avsub_context_t * ctx,
 
 if (!has_subtitle)
 {
+if (subtitle.pts != AV_NOPTS_VALUE)
+{
+ctx->unused_pts = av_rescale(subtitle.pts, 9, AV_TIME_BASE) +
+  av_rescale(subtitle.start_display_time, 9, 1000);
+}
 continue;
 }
 
@@ -436,7 +448,11 @@ int decavsubWork( hb_avsub_context_t * ctx,
 }
 else
 {
-if (in_s.start >= 0)
+if (ctx->unused_pts != AV_NOPTS_VALUE)
+{
+pts = ctx->unused_pts;
+}
+else if (in_s.start >= 0)
 {
 pts = in_s.start;
 }
@@ -475,6 +491,7 @@ int decavsubWork( hb_avsub_context_t * ctx,
 pts = ctx->last_pts + 1 * 9LL;
 }
 ctx->last_pts = pts;
+ctx->unused_pts = AV_NOPTS_VALUE;
 
 if (ctx->subtitle->format == TEXTSUB)
 {
-- 
2.39.2



Bug#1032972: handbrake: debian version of handbrake does NOT handle subtitles correctly

2023-06-18 Thread Alain Ducharme
Package: handbrake-cli
Version: 1.6.1+ds1-1

Ouch, yes, to confirm, upgraded to bookworm and now subtitles are broken
when using HandBrake to convert DVD to .mkv
(worked in bullseye handbrake-cli 1.3.1+ds1-2 and previous versions)

The problem occurs with all DVD subs I tried, both types: VOBSUB and CC608

# Example command:
HandBrakeCLI -i /dev/sr0 -o "7r0N.mkv" -t 1 -s 1 # Title 1, subtitle track 1

Produces lots of decavsub warnings (I'm guessing for every subtitle frame):
[warning] decavsub: track 1, invalid PTS

Result: video ok, but subtitles do not appear and/or not at the correct times.

upstream: https://github.com/HandBrake/HandBrake/issues/4029
...Handbrake depends on custom ffmpeg patches, hmmm...?


Bug#1032972: handbrake: debian version of handbrake does NOT handle subtitles correctly

2023-03-17 Thread js jb
This is the exact version of handbrake I used from fr.handbrake.ghb that fixed 
the subtitles issue (which seems caused because the character encoding of the 
subtitles is not always recognized):
 =>  flatpak info fr.handbrake.ghb
HandBrake - Video Transcoder

  ID: fr.handbrake.ghb
 Ref: app/fr.handbrake.ghb/x86_64/stable
    Arch: x86_64
  Branch: stable
 Version: 1.6.1
 License: GPL-2.0+
  Origin: ghb-origin
  Collection: 
Installation: user
   Installed: 123.3 MB
 Runtime: org.gnome.Platform/x86_64/43
 Sdk: org.gnome.Sdk/x86_64/43

  Commit: 227d2a8398a850cd93a6662116c0bc64be187eeb4f2e5a2ae1e490838cd03248
 Subject: Export fr.handbrake.ghb
    Date: 2023-01-23 18:08:28 +




Bug#1032972: handbrake: debian version of handbrake does NOT handle subtitles correctly

2023-03-15 Thread js jb
I've installed the snapshot version of handbrake from handbrake.fr directly 
(via flatpak)and verified that on the same DVDs, it generates the subtitles 
perfectly.
I also built the debian version of handbrake from source and that one still has 
the same problems.One can also see the subtitles overlaying each other so that 
in rapid dialog multiple subtitles appearone on top of each other, making them 
all illegible.  This does not happen in the handbrake snaphshot.
thanks,--jack


Bug#1032972: handbrake: debian version of handbrake does NOT handle subtitles correctly

2023-03-14 Thread js
Package: handbrake
Version: 1.6.1+ds1-1
Severity: important

Dear Maintainer,

===

   * What led up to the situation?

Tried to convert 2 different DVDs, both NTSC, into m4v (or mp4)
including subtitles.

In both cases, using many different options for handbrake (H264,
H265, different audio encoders, etc), was easily able add subtitles
(as well as burn-in). HOWEVER: the subtitles NEVER worked correctly:
- there are places where characters speak and no subtitles appear at
  all
- also places where characters speak at length and a subtitle pops
  up for only a second
- parts where there is lenghty narration, but no character speaks, and no
  subtitle appears ever

NOTE: in both DVDs, playing the DVD directly results in subtitles
working perfectly. The DVDs have subtitles working but the debian
package of handbrake does not work.

   * What exactly did you do (or not do) that was effective (or ineffective)?

 I contacted handbrake.fr and they recommended using their nightly
 snapshot as they claim debian is using a version of ffmpeg that
 breaks subtitles.

 Entire thread is at: 
https://forum.handbrake.fr/viewtopic.php?p=202972#p202972

 Using the nightly snapshot from handbrake.fr worked perfectly and
 produced an m4v file with subtitles that match exactly the
 characters.

   * What outcome did you expect instead?

   I expected the debian packaged handbrake to work exactly as the one
   from the upstream source but it does not. Failure to generate all
   subtitles and insert them at the correct spot in the video is a major
   failure that makes this packaged version of handbrake unusable for
   videos with subtitles.

   I recommend adding a test case of ripping a DVD with subtitles AND
   verifying that the subtitles really match the speech.

===


-- System Information:
Debian Release: bookworm/sid
  APT prefers testing-security

  APT policy: (500, 'testing-security'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-1-amd64 (SMP w/6 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, 
TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to C.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages handbrake depends on:
ii  libass91:0.17.0-2
ii  libavcodec-extra59 [libavcodec59]  7:5.1.2-3
ii  libavfilter-extra8 [libavfilter8]  7:5.1.2-3
ii  libavformat59  7:5.1.2-3
ii  libavutil577:5.1.2-3
ii  libbluray2 1:1.3.4-1
ii  libc6  2.36-8
ii  libcairo2  1.16.0-7
ii  libdvdnav4 6.1.1-1
ii  libdvdread86.1.3-1
ii  libgdk-pixbuf-2.0-02.42.10+dfsg-1+b1
ii  libglib2.0-0   2.74.5-1
ii  libgstreamer-plugins-base1.0-0 1.22.0-3
ii  libgstreamer1.0-0  1.22.0-2
ii  libgtk-3-0 3.24.36-4
ii  libgudev-1.0-0 237-2
ii  libjansson42.14-2
ii  libpango-1.0-0 1.50.12+ds-1
ii  libswresample4 7:5.1.2-3
ii  libswscale67:5.1.2-3
ii  libtheora0 1.1.1+dfsg.1-16.1
ii  libturbojpeg0  1:2.1.5-2
ii  libva-drm2 2.17.0-1
ii  libva2 2.17.0-1
ii  libvorbis0a1.3.7-1
ii  libvorbisenc2  1.3.7-1
ii  libvpl22023.1.1-1
ii  libx264-1642:0.164.3095+gitbaee400-2+b1
ii  libx265-1993.5-2+b1
ii  libxml22.9.14+dfsg-1.1+b3

Versions of packages handbrake recommends:
ii  gstreamer1.0-alsa1.22.0-3
ii  gstreamer1.0-libav   1.22.0-2
ii  gstreamer1.0-pulseaudio  1.22.0-4
ii  gstreamer1.0-x   1.22.0-3

handbrake suggests no packages.

-- no debconf information