[FFmpeg-devel] [PATCH 09/11] libzvbi-teletextdec: output ass subtitles instead of plain text

Marton Balint cus at passwd.hu
Sat Nov 9 13:06:38 CET 2013


On Sat, 9 Nov 2013, Clément Bœsch wrote:

> On Thu, Oct 31, 2013 at 09:28:55PM +0100, Marton Balint wrote:
>> Signed-off-by: Marton Balint <cus at passwd.hu>
>> ---
>>  libavcodec/libzvbi-teletextdec.c | 50 +++++++++++++++++++++++++++++++++-------
>>  1 file changed, 42 insertions(+), 8 deletions(-)
>>
>> diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
>> index 6180192..4678d5f 100644
>> --- a/libavcodec/libzvbi-teletextdec.c
>> +++ b/libavcodec/libzvbi-teletextdec.c
>> @@ -19,6 +19,7 @@
>>   */
>>
>>  #include "avcodec.h"
>> +#include "libavcodec/ass.h"
>>  #include "libavutil/opt.h"
>>  #include "libavutil/bprint.h"
>>  #include "libavutil/intreadwrite.h"
>> @@ -49,7 +50,7 @@ typedef struct TeletextContext
>>      char           *pgno;
>>      int             x_offset;
>>      int             y_offset;
>> -    int             format_id; /* 0 = bitmap, 1 = text */
>> +    int             format_id; /* 0 = bitmap, 1 = text/ass */
>>      int             chop_top;
>>      int             sub_duration; /* in msec */
>>      int             transparent_bg;
>> @@ -88,10 +89,41 @@ subtitle_rect_free(AVSubtitleRect **sub_rect)
>>  {
>>      av_freep(&(*sub_rect)->pict.data[0]);
>>      av_freep(&(*sub_rect)->pict.data[1]);
>> -    av_freep(&(*sub_rect)->text);
>> +    av_freep(&(*sub_rect)->ass);
>>      av_freep(sub_rect);
>>  }
>>
>> +static int
>> +create_ass_text(TeletextContext *ctx, const char *text, char **ass)
>
> style nit: static int create_ass_text(...)
>
> (same line)
>
> (yes i know this is done for consistency with rest of the code but that's
> not common style)

I don't like it myself, I will change it in a later coding style patch.

>> +{
>> +    int ret;
>> +    AVBPrint buf, buf2;
>> +    const int ts_start    = av_rescale_q(ctx->pts,          AV_TIME_BASE_Q,        (AVRational){1, 100});
>> +    const int ts_duration = av_rescale_q(ctx->sub_duration, (AVRational){1, 1000}, (AVRational){1, 100});
>> +
>
>> +    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
>> +    ff_ass_bprint_text_event(&buf, text, strlen(text), "", 0);
>> +
>> +    if (!av_bprint_is_complete(&buf)) {
>> +        av_bprint_finalize(&buf, NULL);
>> +        return AVERROR(ENOMEM);
>> +    }
>
> Sorry but what is this buf indirection for?
>

What do you mean? ff_ass_bprint_text_event returns the escaped text in 
buf. Am I missing something?

>> +
>> +    av_bprint_init(&buf2, 0, AV_BPRINT_SIZE_UNLIMITED);
>> +    ff_ass_bprint_dialog(&buf2, buf.str, ts_start, ts_duration, 0);
>> +    av_bprint_finalize(&buf, NULL);
>> +
>> +    if (!av_bprint_is_complete(&buf2)) {
>> +        av_bprint_finalize(&buf2, NULL);
>> +        return AVERROR(ENOMEM);
>> +    }
>> +
>> +    if ((ret = av_bprint_finalize(&buf2, ass)) < 0)
>> +        return ret;
>> +
>> +    return 0;
>> +}
>> +
> [...]
>
> Should be OK otherwise
>
> -- 
> Clément B.
>

Regards,
Marton


More information about the ffmpeg-devel mailing list