From 4b107b60e7fec799755a487f7d07452717a83949 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 1 Mar 2024 21:00:33 +1100 Subject: [PATCH] dvbsubenc: Fix bottom field size calculation Don't accidentally include the stuffing byte (if present) into the bottom field size. It should only be included in the total segment length. Fixes problems with FFmpeg not rendering the subtitles with a stuffing byte, giving a "Invalid object location!" error. Part-of: --- .../gst/dvbsubenc/gstdvbsubenc-util.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/dvbsubenc/gstdvbsubenc-util.c b/subprojects/gst-plugins-bad/gst/dvbsubenc/gstdvbsubenc-util.c index e1e8d046ee..cb39b41ee0 100644 --- a/subprojects/gst-plugins-bad/gst/dvbsubenc/gstdvbsubenc-util.c +++ b/subprojects/gst-plugins-bad/gst/dvbsubenc/gstdvbsubenc-util.c @@ -551,7 +551,7 @@ static gboolean dvbenc_write_object_data (GstByteWriter * b, int object_version, int page_id, int object_id, SubpictureRect * s) { - guint seg_size_pos, end_pos; + guint seg_size_pos, end_pos, bottom_end_pos; guint pixel_fields_size_pos, top_start_pos, bottom_start_pos; EncodeRLEFunc encode_rle_func; const gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&s->frame->info, 0); @@ -588,13 +588,15 @@ dvbenc_write_object_data (GstByteWriter * b, int object_version, int page_id, if (h > 1) encode_rle_func (b, pixels + stride, stride * 2, w, h >> 1); - end_pos = gst_byte_writer_get_pos (b); + bottom_end_pos = gst_byte_writer_get_pos (b); /* If the encoded size of the top+bottom field data blocks is even, * add a stuffing byte */ - if (((end_pos - top_start_pos) & 1) == 0) { + if (((bottom_end_pos - top_start_pos) & 1) == 0) { gst_byte_writer_put_uint8 (b, 0); end_pos = gst_byte_writer_get_pos (b); + } else { + end_pos = bottom_end_pos; } /* Re-write the size fields */ @@ -605,12 +607,12 @@ dvbenc_write_object_data (GstByteWriter * b, int object_version, int page_id, if (bottom_start_pos - top_start_pos > G_MAXUINT16) return FALSE; /* Data too big */ - if (end_pos - bottom_start_pos > G_MAXUINT16) + if (bottom_end_pos - bottom_start_pos > G_MAXUINT16) return FALSE; /* Data too big */ gst_byte_writer_set_pos (b, pixel_fields_size_pos); gst_byte_writer_put_uint16_be (b, bottom_start_pos - top_start_pos); - gst_byte_writer_put_uint16_be (b, end_pos - bottom_start_pos); + gst_byte_writer_put_uint16_be (b, bottom_end_pos - bottom_start_pos); gst_byte_writer_set_pos (b, end_pos); GST_LOG ("Object seg size %u top_size %u bottom_size %u",