From c85dd27c9e06bf4dff8d51ab79d9570003018471 Mon Sep 17 00:00:00 2001 From: JackBurton79 Date: Tue, 7 Aug 2018 17:46:39 +0200 Subject: [PATCH] AVCodecEncoder: Use new API Change-Id: I5b985cebf241e67f901e93a5a4bb61a67a659cdf --- .../media/plugins/ffmpeg/AVCodecEncoder.cpp | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp index f7f7aa7de2..c6d64b8665 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp @@ -700,31 +700,30 @@ AVCodecEncoder::_EncodeVideo(const void* buffer, int64 frameCount, fDstFrame.linesize); // Encode one video chunk/frame. - int gotPacket; + int result = avcodec_send_frame(fCodecContext, fFrame); + if (result != 0) { + TRACE(" avcodec_send_frame() failed: %d\n", result); + return B_ERROR; + } + + // avcodec.h says we need to set it. + fFrame->pts++; + AVPacket pkt; pkt.data = NULL; pkt.size = 0; av_init_packet(&pkt); - int usedBytes = avcodec_encode_video2(fCodecContext, &pkt, fFrame, &gotPacket); - // avcodec.h says we need to set it. - fFrame->pts++; + if (avcodec_receive_packet(fCodecContext, &pkt) == 0) { + // Maybe we need to use this PTS to calculate start_time: + if (pkt.pts != AV_NOPTS_VALUE) { + TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n", + pkt.pts, fCodecContext->time_base.num, + fCodecContext->time_base.den); + } else { + TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n", + fCodecContext->time_base.num, fCodecContext->time_base.den); + } - if (usedBytes < 0) { - TRACE(" avcodec_encode_video() failed: %d\n", usedBytes); - return B_ERROR; - } - - // Maybe we need to use this PTS to calculate start_time: - if (pkt.pts != AV_NOPTS_VALUE) { - TRACE(" codec frame PTS: %lld (codec time_base: %d/%d)\n", - pkt.pts, fCodecContext->time_base.num, - fCodecContext->time_base.den); - } else { - TRACE(" codec frame PTS: N/A (codec time_base: %d/%d)\n", - fCodecContext->time_base.num, fCodecContext->time_base.den); - } - - if (gotPacket == 1) { // Setup media_encode_info, most important is the time stamp. info->start_time = (bigtime_t)(fFramesWritten * 1000000LL / fInputFormat.u.raw_video.field_rate);