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:
Assert(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?
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?