Allocate the packet via ffmpeg.

Seems we aren't allowed anymore to handle it ourselves.
This commit is contained in:
stefano
2018-08-08 12:11:53 +02:00
committed by JackBurton79
parent 57893202f1
commit 740114b89c
@@ -709,15 +709,14 @@ AVCodecEncoder::_EncodeVideo(const void* buffer, int64 frameCount,
// avcodec.h says we need to set it. // avcodec.h says we need to set it.
fFrame->pts++; fFrame->pts++;
AVPacket pkt; AVPacket* pkt = av_packet_alloc();
pkt.data = NULL; // TODO: Since av_codec_receive_packet() could return more than one packet for one frame,
pkt.size = 0; // we should run this in a loop, like the ffmpeg example do.
av_init_packet(&pkt); if (avcodec_receive_packet(fCodecContext, pkt) == 0) {
if (avcodec_receive_packet(fCodecContext, &pkt) == 0) {
// Maybe we need to use this PTS to calculate start_time: // Maybe we need to use this PTS to calculate start_time:
if (pkt.pts != AV_NOPTS_VALUE) { if (pkt->pts != AV_NOPTS_VALUE) {
TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n", TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n",
pkt.pts, fCodecContext->time_base.num, pkt->pts, fCodecContext->time_base.num,
fCodecContext->time_base.den); fCodecContext->time_base.den);
} else { } else {
TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n", TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n",
@@ -733,17 +732,20 @@ AVCodecEncoder::_EncodeVideo(const void* buffer, int64 frameCount,
info->flags |= B_MEDIA_KEY_FRAME; info->flags |= B_MEDIA_KEY_FRAME;
// Write the chunk // Write the chunk
ret = WriteChunk(pkt.data, pkt.size, info); ret = WriteChunk(pkt->data, pkt->size, info);
if (ret != B_OK) { if (ret != B_OK) {
TRACE(" error writing chunk: %s\n", strerror(ret)); TRACE(" error writing chunk: %s\n", strerror(ret));
break; break;
} }
av_packet_unref(pkt);
} }
// Skip to the next frame (but usually, there is only one to encode // Skip to the next frame (but usually, there is only one to encode
// for video). // for video).
frameCount--; frameCount--;
fFramesWritten++; fFramesWritten++;
buffer = (const void*)((const uint8*)buffer + bufferSize); buffer = (const void*)((const uint8*)buffer + bufferSize);
av_packet_free(&pkt);
} }
return ret; return ret;
} }