[PATCH] Add support for parsing the Display Definition Segment in dvbsubdec.c
The attached patch parses the Display Definition Segment in DVB subtitle packets (see EN 300 743 V1.3.1). The Display Definition Segment explicitly indicates to the decoder the display size for which the subtitles were generated, allowing standard definition subtitles to be displayed on high definition streams. This extends AVSubtitleRect to hold the new display information and, if a Display Definition Segment is not seen, defaults to 720x576 (per the standard). regards Mark
On 23 April 2010 05:05, Mark Kendall <mark.kendall at gmail.com> wrote:
The attached patch parses the Display Definition Segment in DVB subtitle packets (see EN 300 743 V1.3.1).
The Display Definition Segment explicitly indicates to the decoder the display size for which the subtitles were generated, allowing standard definition subtitles to be displayed on high definition streams.
This extends AVSubtitleRect to hold the new display information and, if a Display Definition Segment is not seen, defaults to 720x576 (per the standard).
Would it be more appropriate to fill in the width and height fields of AVCodecContext? Ian
On Fri, Apr 23, 2010 at 09:05:03AM +0100, Ian Caulfield wrote:
On 23 April 2010 05:05, Mark Kendall <mark.kendall at gmail.com> wrote:
The attached patch parses the Display Definition Segment in DVB subtitle packets (see EN 300 743 V1.3.1).
The Display Definition Segment explicitly indicates to the decoder the display size for which the subtitles were generated, allowing standard definition subtitles to be displayed on high definition streams.
This extends AVSubtitleRect to hold the new display information and, if a Display Definition Segment is not seen, defaults to 720x576 (per the standard).
Would it be more appropriate to fill in the width and height fields of AVCodecContext?
agree, with documentation added to width/height and where the x/y position is documented [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I know you won't believe me, but the highest form of Human Excellence is to question oneself and others. -- Socrates
On Fri, Apr 23, 2010 at 03:41:09PM +0200, Michael Niedermayer wrote:
On Fri, Apr 23, 2010 at 09:05:03AM +0100, Ian Caulfield wrote:
On 23 April 2010 05:05, Mark Kendall <mark.kendall at gmail.com> wrote:
The attached patch parses the Display Definition Segment in DVB subtitle packets (see EN 300 743 V1.3.1).
The Display Definition Segment explicitly indicates to the decoder the display size for which the subtitles were generated, allowing standard definition subtitles to be displayed on high definition streams.
This extends AVSubtitleRect to hold the new display information and, if a Display Definition Segment is not seen, defaults to 720x576 (per the standard).
Would it be more appropriate to fill in the width and height fields of AVCodecContext?
agree, with documentation added to width/height and where the x/y position is documented
modified patch attached. Also moved display_x/y to AVSubtitle since it's at least in the case of dvb subtitles for all rects identical. If we expect it to change per rect we can't store the size in AVCodecContext. Also bumped minor version, removed whitespace only changes and fixed off-by-one errors in the width/height calculation. Janne
On Thu, May 06, 2010 at 01:11:58AM +0200, Janne Grunau wrote:
On Fri, Apr 23, 2010 at 03:41:09PM +0200, Michael Niedermayer wrote:
On Fri, Apr 23, 2010 at 09:05:03AM +0100, Ian Caulfield wrote:
On 23 April 2010 05:05, Mark Kendall <mark.kendall at gmail.com> wrote:
The attached patch parses the Display Definition Segment in DVB subtitle packets (see EN 300 743 V1.3.1).
The Display Definition Segment explicitly indicates to the decoder the display size for which the subtitles were generated, allowing standard definition subtitles to be displayed on high definition streams.
This extends AVSubtitleRect to hold the new display information and, if a Display Definition Segment is not seen, defaults to 720x576 (per the standard).
Would it be more appropriate to fill in the width and height fields of AVCodecContext?
agree, with documentation added to width/height and where the x/y position is documented
modified patch attached. Also moved display_x/y to AVSubtitle since it's at least in the case of dvb subtitles for all rects identical. If we expect it to change per rect we can't store the size in AVCodecContext. Also bumped minor version, removed whitespace only changes and fixed off-by-one errors in the width/height calculation.
Janne
avcodec.h | 10 ++++++++- dvbsubdec.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) dcde49dfda3c601c37db785edef94505562ea1f2 hd_dvb_subtitles2.diff diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b643747..0abd53f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 66 +#define LIBAVCODEC_VERSION_MINOR 67 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -1097,6 +1097,9 @@ typedef struct AVCodecContext { * picture width / height. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. + * If set for subtitles width / height of the display region. The top + * left corner of the display region is specified in AVSubtitle as + * display_x, display_y. * Note: For compatibility it is possible to set this instead of * coded_width/height before decoding. */
@@ -2863,6 +2866,11 @@ typedef struct AVSubtitle { unsigned num_rects; AVSubtitleRect **rects; int64_t pts; ///< Same as packet pts, in AV_TIME_BASE + /** + * top left corner of region into which rects are displayed. + * display width and height are in AVCodecContext + */ + int display_x, display_y;
the rectangles already contain x/y variables this is unneeded and confusing [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The educated differ from the uneducated as much as the living from the dead. -- Aristotle
On Fri, May 07, 2010 at 12:50:05AM +0200, Michael Niedermayer wrote:
On Thu, May 06, 2010 at 01:11:58AM +0200, Janne Grunau wrote:
On Fri, Apr 23, 2010 at 03:41:09PM +0200, Michael Niedermayer wrote:
agree, with documentation added to width/height and where the x/y position is documented
modified patch attached. Also moved display_x/y to AVSubtitle since it's at least in the case of dvb subtitles for all rects identical. If we expect it to change per rect we can't store the size in AVCodecContext. Also bumped minor version, removed whitespace only changes and fixed off-by-one errors in the width/height calculation.
avcodec.h | 10 ++++++++- dvbsubdec.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) dcde49dfda3c601c37db785edef94505562ea1f2 hd_dvb_subtitles2.diff diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b643747..0abd53f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 66 +#define LIBAVCODEC_VERSION_MINOR 67 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -1097,6 +1097,9 @@ typedef struct AVCodecContext { * picture width / height. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. + * If set for subtitles width / height of the display region. The top + * left corner of the display region is specified in AVSubtitle as + * display_x, display_y. * Note: For compatibility it is possible to set this instead of * coded_width/height before decoding. */
@@ -2863,6 +2866,11 @@ typedef struct AVSubtitle { unsigned num_rects; AVSubtitleRect **rects; int64_t pts; ///< Same as packet pts, in AV_TIME_BASE + /** + * top left corner of region into which rects are displayed. + * display width and height are in AVCodecContext + */ + int display_x, display_y;
the rectangles already contain x/y variables this is unneeded and confusing
unfortunately the specs are confusing and overly complicated. see Section 7.2.1 and Annex B of http://www.etsi.org/deliver/etsi_en/300700_300799/300743/01.03.01_60/en_3007... Especially point b) of Annex B doesn't make much sense. We could add the x/y from the display window to the values in the rects but it would make scaling the subtitles much harder. Janne
On Mon, May 10, 2010 at 10:16:20PM +0200, Janne Grunau wrote:
On Fri, May 07, 2010 at 12:50:05AM +0200, Michael Niedermayer wrote:
On Thu, May 06, 2010 at 01:11:58AM +0200, Janne Grunau wrote:
On Fri, Apr 23, 2010 at 03:41:09PM +0200, Michael Niedermayer wrote:
agree, with documentation added to width/height and where the x/y position is documented
modified patch attached. Also moved display_x/y to AVSubtitle since it's at least in the case of dvb subtitles for all rects identical. If we expect it to change per rect we can't store the size in AVCodecContext. Also bumped minor version, removed whitespace only changes and fixed off-by-one errors in the width/height calculation.
avcodec.h | 10 ++++++++- dvbsubdec.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) dcde49dfda3c601c37db785edef94505562ea1f2 hd_dvb_subtitles2.diff diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b643747..0abd53f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 66 +#define LIBAVCODEC_VERSION_MINOR 67 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -1097,6 +1097,9 @@ typedef struct AVCodecContext { * picture width / height. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. + * If set for subtitles width / height of the display region. The top + * left corner of the display region is specified in AVSubtitle as + * display_x, display_y. * Note: For compatibility it is possible to set this instead of * coded_width/height before decoding. */
@@ -2863,6 +2866,11 @@ typedef struct AVSubtitle { unsigned num_rects; AVSubtitleRect **rects; int64_t pts; ///< Same as packet pts, in AV_TIME_BASE + /** + * top left corner of region into which rects are displayed. + * display width and height are in AVCodecContext + */ + int display_x, display_y;
the rectangles already contain x/y variables this is unneeded and confusing
unfortunately the specs are confusing and overly complicated. see Section 7.2.1 and Annex B of http://www.etsi.org/deliver/etsi_en/300700_300799/300743/01.03.01_60/en_3007...
Especially point b) of Annex B doesn't make much sense.
We could add the x/y from the display window to the values in the rects but it would make scaling the subtitles much harder.
i dont understand the issue before the subtitle decoder we have some binary stream after the subtitle decoder we have rectangles that contain bitmaps or text possibly with formating possibly with effects. the positions of the rectangles can be specified in pixels or relative to a 0.0-1.0 screen i see no case in which a hierachical system with an additional rectangle that contanins the other rectangles would make sense. thats besides that whatever is done the API must be unambigously and clearly be described. that is the interaction/relation of all the values and their scale must be documented. anyway, please elaborate on what problem you see [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On Thu, May 20, 2010 at 10:20:22PM +0200, Michael Niedermayer wrote:
i see no case in which a hierachical system with an additional rectangle that contanins the other rectangles would make sense. thats besides that whatever is done the API must be unambigously and clearly be described. that is the interaction/relation of all the values and their scale must be documented. anyway, please elaborate on what problem you see
The only (minor) problem I see is that recalculating the subtitle rect's x/y position makes scaling them up to the full display size harder. As far as I understand the only purpose of this part of the DVB subtitle standard is to center SD subtitles reused for HD streams. So it's valid concern but probably not important enough to clutter the API. Attached patch doesn't change API and changes only x/y values. Janne
On Fri, May 21, 2010 at 01:50:15AM +0200, Janne Grunau wrote:
On Thu, May 20, 2010 at 10:20:22PM +0200, Michael Niedermayer wrote:
i see no case in which a hierachical system with an additional rectangle that contanins the other rectangles would make sense. thats besides that whatever is done the API must be unambigously and clearly be described. that is the interaction/relation of all the values and their scale must be documented. anyway, please elaborate on what problem you see
The only (minor) problem I see is that recalculating the subtitle rect's x/y position makes scaling them up to the full display size harder. As far as I understand the only purpose of this part of the DVB subtitle standard is to center SD subtitles reused for HD streams. So it's valid concern but probably not important enough to clutter the API.
Attached patch doesn't change API and changes only x/y values.
Janne
[...]
@@ -334,6 +346,9 @@ static void delete_state(DVBSubContext *ctx) av_free(clut); }
+ if (ctx->display_definition) + av_free(ctx->display_definition);
the if() is superflous and av_freep is maybe safer
+ /* Should already be null */ if (ctx->object_list) av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
@@ -1254,10 +1269,49 @@ static void save_display_set(DVBSubContext *ctx) } #endif
+static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx, + const uint8_t *buf, + int buf_size) +{ + DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
unneeded cast
+ DVBSubDisplayDefinition *display_def = ctx->display_definition; + int dds_version, info_byte; + + if (buf_size < 5) + return; + + info_byte = bytestream_get_byte(&buf); + dds_version = (info_byte >> 4) & 0xF;
have you ever seen a byte that had its upper 4 bits > 0xf ? ;)
+ if (display_def && (display_def->version == dds_version)) + return; // already have this display definition version + + if (!display_def) { + ctx->display_definition = av_mallocz(sizeof(DVBSubDisplayDefinition)); + display_def = ctx->display_definition; + } + + display_def->version = dds_version; + display_def->x = 0; + display_def->y = 0; + display_def->width = bytestream_get_be16(&buf) + 1; + display_def->height = bytestream_get_be16(&buf) + 1; + + if (buf_size < 13) + return; + + if ((info_byte >> 3) & 1) { // display_window_flag
i would write & (1<<3) but i guess gcc can optimize that itself [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are too smart to engage in politics are punished by being governed by those who are dumber. -- Plato
On Mon, May 24, 2010 at 10:44:01PM +0200, Michael Niedermayer wrote:
On Fri, May 21, 2010 at 01:50:15AM +0200, Janne Grunau wrote:
The only (minor) problem I see is that recalculating the subtitle rect's x/y position makes scaling them up to the full display size harder. As far as I understand the only purpose of this part of the DVB subtitle standard is to center SD subtitles reused for HD streams. So it's valid concern but probably not important enough to clutter the API.
Attached patch doesn't change API and changes only x/y values.
@@ -334,6 +346,9 @@ static void delete_state(DVBSubContext *ctx) av_free(clut); }
+ if (ctx->display_definition) + av_free(ctx->display_definition);
the if() is superflous and av_freep is maybe safer
changed to av_freep
+ /* Should already be null */ if (ctx->object_list) av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
@@ -1254,10 +1269,49 @@ static void save_display_set(DVBSubContext *ctx) } #endif
+static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx, + const uint8_t *buf, + int buf_size) +{ + DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
unneeded cast
removed
+ DVBSubDisplayDefinition *display_def = ctx->display_definition; + int dds_version, info_byte; + + if (buf_size < 5) + return; + + info_byte = bytestream_get_byte(&buf); + dds_version = (info_byte >> 4) & 0xF;
have you ever seen a byte that had its upper 4 bits > 0xf ? ;)
no, fixed :)
+ if (display_def && (display_def->version == dds_version)) + return; // already have this display definition version + + if (!display_def) { + ctx->display_definition = av_mallocz(sizeof(DVBSubDisplayDefinition)); + display_def = ctx->display_definition; + } + + display_def->version = dds_version; + display_def->x = 0; + display_def->y = 0; + display_def->width = bytestream_get_be16(&buf) + 1; + display_def->height = bytestream_get_be16(&buf) + 1; + + if (buf_size < 13) + return; + + if ((info_byte >> 3) & 1) { // display_window_flag
i would write & (1<<3) but i guess gcc can optimize that itself
changed, I think it is easier to read. also removed a couple of superfluous parentheses and checks av_mallocz return values. Janne
On Mon, May 24, 2010 at 11:51:20PM +0200, Janne Grunau wrote:
On Mon, May 24, 2010 at 10:44:01PM +0200, Michael Niedermayer wrote:
On Fri, May 21, 2010 at 01:50:15AM +0200, Janne Grunau wrote:
The only (minor) problem I see is that recalculating the subtitle rect's x/y position makes scaling them up to the full display size harder. As far as I understand the only purpose of this part of the DVB subtitle standard is to center SD subtitles reused for HD streams. So it's valid concern but probably not important enough to clutter the API.
Attached patch doesn't change API and changes only x/y values.
@@ -334,6 +346,9 @@ static void delete_state(DVBSubContext *ctx) av_free(clut); }
+ if (ctx->display_definition) + av_free(ctx->display_definition);
the if() is superflous and av_freep is maybe safer
changed to av_freep
+ /* Should already be null */ if (ctx->object_list) av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
@@ -1254,10 +1269,49 @@ static void save_display_set(DVBSubContext *ctx) } #endif
+static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx, + const uint8_t *buf, + int buf_size) +{ + DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
unneeded cast
removed
+ DVBSubDisplayDefinition *display_def = ctx->display_definition; + int dds_version, info_byte; + + if (buf_size < 5) + return; + + info_byte = bytestream_get_byte(&buf); + dds_version = (info_byte >> 4) & 0xF;
have you ever seen a byte that had its upper 4 bits > 0xf ? ;)
no, fixed :)
+ if (display_def && (display_def->version == dds_version)) + return; // already have this display definition version + + if (!display_def) { + ctx->display_definition = av_mallocz(sizeof(DVBSubDisplayDefinition)); + display_def = ctx->display_definition; + } + + display_def->version = dds_version; + display_def->x = 0; + display_def->y = 0; + display_def->width = bytestream_get_be16(&buf) + 1; + display_def->height = bytestream_get_be16(&buf) + 1; + + if (buf_size < 13) + return; + + if ((info_byte >> 3) & 1) { // display_window_flag
i would write & (1<<3) but i guess gcc can optimize that itself
changed, I think it is easier to read.
also removed a couple of superfluous parentheses and checks av_mallocz return values.
Janne
dvbsubdec.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) 36866d448453076c6c9d93a0d216adb438b0a77b dvbsub_display_def_seg2.diff commit cb6c7ba08b84a7f571f1db3c144be04aecadedde
should be ok if tested [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt.
On Tue, May 25, 2010 at 04:59:35AM +0200, Michael Niedermayer wrote:
On Mon, May 24, 2010 at 11:51:20PM +0200, Janne Grunau wrote:
dvbsubdec.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) 36866d448453076c6c9d93a0d216adb438b0a77b dvbsub_display_def_seg2.diff commit cb6c7ba08b84a7f571f1db3c144be04aecadedde
should be ok if tested
applied I still think it's desirable to export size and top left position of the subtitle rect to allow scaling to full screen for SD subtitles in HD videos. Janne
participants (4)
-
ian.caulfield@gmail.com -
janne-ffmpeg@jannau.net -
mark.kendall@gmail.com -
michaelni@gmx.at