[FFmpeg-devel] [PATCH] dvbsub fix transcoding

anshul anshul.ffmpeg at gmail.com
Fri Jun 20 12:36:51 CEST 2014


On 06/16/2014 12:07 AM, Michael Niedermayer wrote:
> diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
> index e6e746d..c213524 100644
> --- a/libavcodec/dvbsubdec.c
> +++ b/libavcodec/dvbsubdec.c
> @@ -234,6 +234,9 @@ typedef struct DVBSubContext {
>
>       int version;
>       int time_out;
> +    int compute_edt; /**< if 1 end display time calculated using pts
> +                          if 0 (Default) calculated using pts */
> "using pts" in both cases is wrong
>
It was a typo corrected.
>> +    int64_t prev_start;
>>       DVBSubRegion *region_list;
>>       DVBSubCLUT   *clut_list;
>>       DVBSubObject *object_list;
>> @@ -771,7 +774,8 @@ static void save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub)
>>       int i;
>>       int offset_x=0, offset_y=0;
>>
>> -    sub->end_display_time = ctx->time_out * 1000;
>> +    if(ctx->compute_edt == 0)
>> +        sub->end_display_time = ctx->time_out * 1000;
>>
>>       if (display_def) {
>>           offset_x = display_def->x;
>> @@ -786,6 +790,8 @@ static void save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub)
>>       }
>>
>>       if (sub->num_rects > 0) {
>> +        if(ctx->compute_edt == 1 && ctx->prev_start)
>>
> prev_start == 0 is the wrong thing to check for here, 0 shouldnt be
> special, it could be a valid timestamp
>
changed it to AV_NOPTS
>> +            sub->end_display_time = av_rescale_q((sub->pts - ctx->prev_start )/90, AV_TIME_BASE_Q, avctx->time_base) - 1;
> the /90 looks wrong as well
> rescaling happen between 2 timebases, there should not be a 3rd factor
> dividing the input before av_rescale_q()
>
done
>>           sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects);
>>           for(i=0; i<sub->num_rects; i++)
>>               sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
>> @@ -837,6 +843,8 @@ static void save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub)
>>               i++;
>>           }
>>       }
>> +    if(ctx->compute_edt == 1)
>> +        FFSWAP(int64_t,ctx->prev_start,sub->pts);
>>   }
>>
> IIRC there can be "things" like for example differnent languages and
> for example the begin of the english subtitle doesnt signify the end
> of the previous german one
>
> also after this patch the "int *data_size," from the dvbsub_decode()
> function will be wrongly set
>
for different language different dvbcontext are made, because we do not 
support
or have code for different language with same elementry stream id. 
therefor no worry.

*data_size was not set after this patch, but I think it is not set 
correctly now or before
have to look for that.
>   [...]
>
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -1999,7 +1999,15 @@ fail:
>   static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
>   {
>       AVSubtitle subtitle;
> -    int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
> +    AVDictionary *options = NULL;
> +    int i, ret = 0;
> +
> +    if(ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
> +    {
> +        av_dict_set(&options, "compute_edt", "1", 0);
> +        av_opt_set_dict2(ist->dec_ctx->priv_data, &options, AV_OPT_SEARCH_CHILDREN);
> +    }
> +    ret = avcodec_decode_subtitle2(ist->dec_ctx,
>                                             &subtitle, got_output, pkt);
>
> this option should be set when opening the codec not when decoding
> repeatly for each packet
done

New patch attached

Thanks
Anshul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-fix-transcoding-dvbsub-to-dvbsub.patch
Type: text/x-patch
Size: 5153 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140620/4b60570b/attachment.bin>


More information about the ffmpeg-devel mailing list