<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:·s²Ó©úÅé
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>I had checked the values about time_base's in AVStream's, and in AVPackets of source and target. Furthermore, the pts, dts in the first two AVPackets, read and write, are both 0 and duration, 999; but I got "00:00:00,000 --> 00:00:00,999" in  source packet and "00:02:11,072 --> 00:02:12,071" in target one.<br> <BR><div>> Date: Sat, 5 Jul 2014 17:40:38 +0200<br>> From: nfxjfg@googlemail.com<br>> To: libav-user@ffmpeg.org<br>> Subject: Re: [Libav-user] Add subtitles to MKV file<br>> <br>> On Sat, 5 Jul 2014 16:15:44 +0800<br>> "ingmar" <ingmar@kingsoftware.com.tw> wrote:<br>> <br>> > Hello Everyone!<br>> > <br>> >  <br>> > <br>> > I am trying to add some text, being a stream, into an MKV file which has<br>> > encoded video and audio data already. Because of some reasons, storing the<br>> > text to an isolated file is not acceptable.<br>> > <br>> >  <br>> > <br>> > The problem I encountered was the times of subtitles were incorrect like<br>> > below.<br>> > <br>> >  <br>> > <br>> > [Original]<br>> > <br>> > 1<br>> > <br>> > 00:00:00,000 --> 00:00:00,999<br>> > <br>> > 2014-07-01 11:59:28<br>> > <br>> >  <br>> > <br>> > 2<br>> > <br>> > 00:00:01,000 --> 00:00:01,999<br>> > <br>> > 2014-07-01 11:59:29<br>> > <br>> >  <br>> > <br>> > [Encoded]<br>> > <br>> > 1<br>> > <br>> > 00:02:11,072 --> 00:02:12,071<br>> > <br>> > 2014-07-01 11:59:28<br>> > <br>> >  <br>> > <br>> > 2<br>> > <br>> > 00:02:12,072 --> 00:02:13,071<br>> > <br>> > 2014-07-01 11:59:29<br>> > <br>> >  <br>> > <br>> > My approach is following.<br>> > <br>> > 1. Create 3 streams: video, audio and subtitle with code AV_CODEC_ID_SUBRIP<br>> > and add to the target MKV file.<br>> > <br>> > 2. Encode all video and audio data.<br>> > <br>> > 3. Create a temporary SRT file and store all text in it.<br>> > <br>> > 4. Read a packet from SRT file (av_read_frame) -> decode<br>> > (avcodec_decode_subtitle2) -> encode (avcodec_encode_subtitle) -> write to<br>> > MKV file (av_interleaved_write_frame).<br>> > <br>> >  <br>> > <br>> > I have been sure the time_base fields of the input and output streams were<br>> > the same; and also for the pts, dts and duration ones of the input and<br>> > output packets.<br>> > <br>> >  <br>> > <br>> > Any advice would be greatly appreciated.<br>> > <br>> <br>> Maybe wrong timebase in timestamp calculations? Just guessing.<br>> _______________________________________________<br>> Libav-user mailing list<br>> Libav-user@ffmpeg.org<br>> http://ffmpeg.org/mailman/listinfo/libav-user<br></div>                                    </div></body>
</html>