static void do_subtitle_out(AVFormatContext *s,
                            OutputStream *ost,
                            InputStream *ist,
                            AVSubtitle *sub)
{
    int subtitle_out_max_size = 1024 * 1024;
    int subtitle_out_size, nb, i;
    AVCodecContext *enc;
    AVPacket pkt;
    int64_t pts;
    if (sub->pts == AV_NOPTS_VALUE) {
        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
        if (exit_on_error)
            exit_program(1);
        return;
    }
    enc = ost->enc_ctx;
    if (!subtitle_out) {
        subtitle_out = av_malloc(subtitle_out_max_size);
    }
    /* Note: DVB subtitle need one packet to draw them and one other
       packet to clear them */
    /* XXX: signal it in the codec context ? */
    if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
        nb = 2;
    else
        nb = 1;
    /* shift timestamp to honor -ss and make check_recording_time() work with -t */
    pts = sub->pts;
    if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE)
        pts -= output_files[ost->file_index]->start_time;
    for (i = 0; i < nb; i++) {
        ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
        if (!check_recording_time(ost))
            return;
        sub->pts = pts;
        // start_display_time is required to be 0
        sub->pts               += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
        sub->end_display_time  -= sub->start_display_time;
        sub->start_display_time = 0;
        if (i == 1)
            sub->num_rects = 0;
        ost->frames_encoded++;
        subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
                                                    subtitle_out_max_size, sub);
        if (i == 1)
            sub->num_rects = save_num_rects;
        if (subtitle_out_size < 0) {
            av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
            exit_program(1);
        }
        av_init_packet(&pkt);
        pkt.data = subtitle_out;
        pkt.size = subtitle_out_size;
        pkt.pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
        pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->st->time_base);
        if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
            /* XXX: the pts correction is handled here. Maybe handling
               it in the codec would be better */
            if (i == 0)
                pkt.pts += 90 * sub->start_display_time;
            else
                pkt.pts += 90 * sub->end_display_time;
        }
        pkt.dts = pkt.pts;
        write_frame(s, &pkt, ost);
    }
}
static void do_subtitle_out(AVFormatContext *s,
                            OutputStream *ost,
                            InputStream *ist,
                            AVSubtitle *sub)
{
    int subtitle_out_max_size = 1024 * 1024;
    int subtitle_out_size, nb, i;
    AVCodecContext *enc;
    AVPacket pkt;
    int64_t pts;
    if (sub->pts == AV_NOPTS_VALUE) {
        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
        if (exit_on_error)
            exit_program(1);
        return;
    }
    enc = ost->enc_ctx;
    if (!subtitle_out) {
        subtitle_out = av_malloc(subtitle_out_max_size);
    }
    

    
    if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
        nb = 2;
    else
        nb = 1;
    
    pts = sub->pts;
    if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE)
        pts -= output_files[ost->file_index]->start_time;
    for (i = 0; i < nb; i++) {
        ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
        if (!check_recording_time(ost))
            return;
        sub->pts = pts;
        
        sub->pts               += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
        sub->end_display_time  -= sub->start_display_time;
        sub->start_display_time = 0;
        if (i == 1)
            sub->num_rects = 0;
        ost->frames_encoded++;
        subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
                                                    subtitle_out_max_size, sub);
        if (i == 1)
            sub->num_rects = save_num_rects;
        if (subtitle_out_size < 0) {
            av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
            exit_program(1);
        }
        av_init_packet(&pkt);
        pkt.data = subtitle_out;
        pkt.size = subtitle_out_size;
        pkt.pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
        pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->st->time_base);
        if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
            

            if (i == 0)
                pkt.pts += 90 * sub->start_display_time;
            else
                pkt.pts += 90 * sub->end_display_time;
        }
        pkt.dts = pkt.pts;
        write_frame(s, &pkt, ost);
    }
}
static void FUNC_0(AVFormatContext *VAR_0,
                            OutputStream *VAR_1,
                            InputStream *VAR_2,
                            AVSubtitle *VAR_3)
{
    int VAR_4 = 1024 * 1024;
    int VAR_5, VAR_6, VAR_7;
    AVCodecContext *enc;
    AVPacket pkt;
    int64_t pts;
    if (VAR_3->pts == AV_NOPTS_VALUE) {
        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
        if (exit_on_error)
            exit_program(1);
        return;
    }
    enc = VAR_1->enc_ctx;
    if (!subtitle_out) {
        subtitle_out = av_malloc(VAR_4);
    }
    

    
    if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
        VAR_6 = 2;
    else
        VAR_6 = 1;
    
    pts = VAR_3->pts;
    if (output_files[VAR_1->file_index]->start_time != AV_NOPTS_VALUE)
        pts -= output_files[VAR_1->file_index]->start_time;
    for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) {
        VAR_1->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
        if (!check_recording_time(VAR_1))
            return;
        VAR_3->pts = pts;
        
        VAR_3->pts               += av_rescale_q(VAR_3->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
        VAR_3->end_display_time  -= VAR_3->start_display_time;
        VAR_3->start_display_time = 0;
        if (VAR_7 == 1)
            VAR_3->num_rects = 0;
        VAR_1->frames_encoded++;
        VAR_5 = avcodec_encode_subtitle(enc, subtitle_out,
                                                    VAR_4, VAR_3);
        if (VAR_7 == 1)
            VAR_3->num_rects = save_num_rects;
        if (VAR_5 < 0) {
            av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
            exit_program(1);
        }
        av_init_packet(&pkt);
        pkt.data = subtitle_out;
        pkt.size = VAR_5;
        pkt.pts  = av_rescale_q(VAR_3->pts, AV_TIME_BASE_Q, VAR_1->st->time_base);
        pkt.duration = av_rescale_q(VAR_3->end_display_time, (AVRational){ 1, 1000 }, VAR_1->st->time_base);
        if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
            

            if (VAR_7 == 0)
                pkt.pts += 90 * VAR_3->start_display_time;
            else
                pkt.pts += 90 * VAR_3->end_display_time;
        }
        pkt.dts = pkt.pts;
        write_frame(VAR_0, &pkt, VAR_1);
    }
}
static void FUNC_0(AVFormatContext *VAR_0,
OutputStream *VAR_1,
InputStream *VAR_2,
AVSubtitle *VAR_3)
{ int VAR_4 = 1024 * 1024; int VAR_5, VAR_6, VAR_7; AVCodecContext *enc; AVPacket pkt; int64_t pts; if (VAR_3->pts == AV_NOPTS_VALUE) { av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); if (exit_on_error)
exit_program(1); return; } enc = VAR_1->enc_ctx; if (!subtitle_out) { subtitle_out = av_malloc(VAR_4); } if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
VAR_6 = 2; else
VAR_6 = 1; pts = VAR_3->pts; if (output_files[VAR_1->file_index]->start_time != AV_NOPTS_VALUE)
pts -= output_files[VAR_1->file_index]->start_time; for (VAR_7 = 0; VAR_7 < VAR_6; VAR_7++) { VAR_1->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base); if (!check_recording_time(VAR_1))
return; VAR_3->pts = pts; VAR_3->pts               += av_rescale_q(VAR_3->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); VAR_3->end_display_time  -= VAR_3->start_display_time; VAR_3->start_display_time = 0; if (VAR_7 == 1)
VAR_3->num_rects = 0; VAR_1->frames_encoded++; VAR_5 = avcodec_encode_subtitle(enc, subtitle_out,
VAR_4, VAR_3); if (VAR_7 == 1)
VAR_3->num_rects = save_num_rects; if (VAR_5 < 0) { av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); exit_program(1); } av_init_packet(&pkt); pkt.data = subtitle_out; pkt.size = VAR_5; pkt.pts  = av_rescale_q(VAR_3->pts, AV_TIME_BASE_Q, VAR_1->st->time_base); pkt.duration = av_rescale_q(VAR_3->end_display_time, (AVRational){ 1, 1000 }, VAR_1->st->time_base); if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { if (VAR_7 == 0)
pkt.pts += 90 * VAR_3->start_display_time; else
pkt.pts += 90 * VAR_3->end_display_time; } pkt.dts = pkt.pts; write_frame(VAR_0, &pkt, VAR_1); } }