Chen-tao / webm

Automatically exported from code.google.com/p/webm
0 stars 0 forks source link

Duration in the webm file. #579

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I'd like to create a webm video from custom frames.
I created a Segment (m_Segment) with one videotrack. I set the videotrack's 
framerate to 25.

Than I encoded the frame:

#define TIMESCALE_DEFAULT (1000000UL)

vpx_codec_encode(m_Encoder, m_Image, 0, 2000, VPX_EFLAG_FORCE_KF, 
VPX_DL_REALTIME);

const vpx_codec_cx_pkt_t* packet;
vpx_codec_iter_t iter = NULL;

while ((packet = vpx_codec_get_cx_data(m_Encoder, &iter)))
{
    switch (packet->kind)
    {
    case VPX_CODEC_CX_FRAME_PKT:
        {
            BYTE* encodedFrame = (BYTE*)packet->data.frame.buf;
            size_t encodedSize = packet->data.frame.sz;
            bool keyFrame = (packet->data.frame.flags & VPX_FRAME_IS_KEY) != 0;

            // Write into the webm
            // 1 track per webm (track_number 1)
            if (!m_Segment->AddFrame(encodedFrame, encodedSize, 1, 0 * TIMESCALE_DEFAULT, keyFrame))
                Log("Cannot add frame to webm.");
        }            
        break;

    default:
        LMIAssert(false); // Should not happen
        break;
    }
}

m_Segment->Finalize();

The webm is not 2 sec long but 0. And if I add a new frame to the video 
(pts:2000 duration:2000) the video will be 2 sec long (but should be 4 sec).

Can you help how can I solve this problem?

Original issue reported on code.google.com by Peter.Ko...@gmail.com on 15 May 2013 at 3:47

GoogleCodeExporter commented 8 years ago
If I add a last dummy frame to the video (for example the first frame's 
duration is 2 sec, the last dummy frame's pts is 2000 and its duration is 1) 
the video seems to be ok in chrome and firefox but in vlc I can't play it 
correctly (just one window resize for a moment and after that the video is 
over).

By the way, is this last dummy frame method correct?

Original comment by Peter.Ko...@gmail.com on 16 May 2013 at 10:34

GoogleCodeExporter commented 8 years ago

Original comment by tnakam...@google.com on 23 May 2013 at 10:09

GoogleCodeExporter commented 8 years ago
I've tried AddMetaData instead of AddFrame:
if (!m_Segment->AddMetadata(encodedFrame, encodedSize, 1, pts * 
TIMESCALE_DEFAULT, packet->data.frame.duration * TIMESCALE_DEFAULT))
                    Log("Cannot add frame to webm.");

VLC is the same :(
And I can't seek in the video in firefox and chrome :(

Original comment by Peter.Ko...@gmail.com on 30 May 2013 at 12:25

GoogleCodeExporter commented 8 years ago
I'm also running into this issue, where I'm creating a video from frames (using 
custom code and the ffmpeg and vpx libraries), and the duration is only that of 
a single frame and won't play properly in vlc.

Original comment by mant...@gmail.com on 24 Sep 2014 at 12:52

GoogleCodeExporter commented 8 years ago
Update:  I was able to fix my duration problem by manually setting the 
AVFrame->pts to the frame number.

Original comment by mant...@gmail.com on 24 Sep 2014 at 8:11