avcodec/dvbsub: add support for Display Definition Segment to DVB Subtitle encoder

Current version of dvbsub encoder doesn't support HD DVB subtitles. The high
resolution bitmaps are muxed into the stream but without the DDS (display definition
segment) the players asume that the DVB subtitles are in SD (720x576) resolution
which causes them to either render the subtitles too large and misplaced or don't
render them at all. By including the DDS as defined in section 7.7.1 of ETSI EN 300
743 (V1.3.1) this problem is fixed.

7.2.1 Display definition segment The display definition for a subtitle service may
be defined by the display definition segment if present in the stream. Absence of a
DDS implies that the stream is coded in accordance with EN 300 743 (V1.2.1) [5] and
that a display width of 720 pixels and a display height of 576 lines may be assumed.

https://www.etsi.org/deliver/etsi_en/300700_300799/300743/01.03.01_60/en_300743v010301p.pdf

Signed-off-by: Jernej Fijacko <mikrohard@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Jernej Fijacko 2019-07-13 19:33:16 +02:00 committed by Marton Balint
parent a2572e3c67
commit f86f213a6d
1 changed files with 16 additions and 3 deletions

View File

@ -247,9 +247,10 @@ static void dvb_encode_rle8(uint8_t **pq,
*pq = q; *pq = q;
} }
static int encode_dvb_subtitles(DVBSubtitleContext *s, static int encode_dvb_subtitles(AVCodecContext *avctx,
uint8_t *outbuf, const AVSubtitle *h) uint8_t *outbuf, const AVSubtitle *h)
{ {
DVBSubtitleContext *s = avctx->priv_data;
uint8_t *q, *pseg_len; uint8_t *q, *pseg_len;
int page_id, region_id, clut_id, object_id, i, bpp_index, page_state; int page_id, region_id, clut_id, object_id, i, bpp_index, page_state;
@ -261,6 +262,19 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
if (h->num_rects && !h->rects) if (h->num_rects && !h->rects)
return -1; return -1;
if (avctx->width > 0 && avctx->height > 0) {
/* display definition segment */
*q++ = 0x0f; /* sync_byte */
*q++ = 0x14; /* segment_type */
bytestream_put_be16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
*q++ = 0x00; /* dds version number & display window flag */
bytestream_put_be16(&q, avctx->width - 1); /* display width */
bytestream_put_be16(&q, avctx->height - 1); /* display height */
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
}
/* page composition segment */ /* page composition segment */
*q++ = 0x0f; /* sync_byte */ *q++ = 0x0f; /* sync_byte */
@ -446,10 +460,9 @@ static int dvbsub_encode(AVCodecContext *avctx,
unsigned char *buf, int buf_size, unsigned char *buf, int buf_size,
const AVSubtitle *sub) const AVSubtitle *sub)
{ {
DVBSubtitleContext *s = avctx->priv_data;
int ret; int ret;
ret = encode_dvb_subtitles(s, buf, sub); ret = encode_dvb_subtitles(avctx, buf, sub);
return ret; return ret;
} }