Ticket #862: SRT-in-MKV-support.patch

File SRT-in-MKV-support.patch, 1.7 KB (added by Vladimír Matěna, 15 years ago)

Add timecodes to srt subtitles exported from matroska.

  • libavformat/matroskadec.c

    a b  
    10581058    return -1;
    10591059}
    10601060
     1061static void matroska_fix_srt_packet(MatroskaDemuxContext *matroska,
     1062                                    AVPacket *pkt, uint64_t display_duration)
     1063{
     1064   char *text = pkt->data, *subtitle;
     1065   int len = pkt->size + 36 + FF_INPUT_BUFFER_PADDING_SIZE;
     1066
     1067   int64_t end_pts = pkt->pts + display_duration;
     1068   int sc = matroska->time_scale * pkt->pts / 1000000;
     1069   int ec = matroska->time_scale * end_pts  / 1000000;
     1070   int sh, sm, ss, eh, em, es;
     1071   sh = sc/3600000;  sc -= 3600000*sh;
     1072   sm = sc/  60000;  sc -=   60000*sm;
     1073   ss = sc/   1000;  sc -=    1000*ss;
     1074   eh = ec/3600000;  ec -= 3600000*eh;
     1075   em = ec/  60000;  ec -=   60000*em;
     1076   es = ec/   1000;  ec -=    1000*es;
     1077
     1078   subtitle = av_malloc(len);
     1079
     1080   snprintf(subtitle, len, "0\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n%s\r\n",
     1081            sh, sm, ss, sc, eh, em, es, ec, text);
     1082
     1083   av_free(pkt->data);
     1084   pkt->data = subtitle;
     1085   pkt->size = strlen(subtitle);
     1086}
     1087
    10611088static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
    10621089                                    AVPacket *pkt, uint64_t display_duration)
    10631090{
    … …  
    19481975                else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE)
    19491976                    pkt->duration = duration;
    19501977
     1978                if (st->codec->codec_id == CODEC_ID_SRT)
     1979                    matroska_fix_srt_packet(matroska, pkt, duration);
     1980
    19511981                if (st->codec->codec_id == CODEC_ID_SSA)
    19521982                    matroska_fix_ass_packet(matroska, pkt, duration);
    19531983