diff options
author | anbr <vdr07@deltab.de> | 2017-03-27 21:47:32 +0200 |
---|---|---|
committer | anbr <vdr07@deltab.de> | 2017-03-27 21:47:32 +0200 |
commit | e108a3362b06181a7a859bfa2cf9c2efaac873ea (patch) | |
tree | 90f956304588942096f6611e313e3ac566106135 | |
parent | 79b08415264a806342e06d8138f51fd2ba8d84de (diff) | |
download | vdr-plugin-image-e108a3362b06181a7a859bfa2cf9c2efaac873ea.tar.gz vdr-plugin-image-e108a3362b06181a7a859bfa2cf9c2efaac873ea.tar.bz2 |
-rw-r--r-- | liboutput/encode.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/liboutput/encode.c b/liboutput/encode.c index c1c358b..5b65389 100644 --- a/liboutput/encode.c +++ b/liboutput/encode.c @@ -212,7 +212,6 @@ bool cEncode::ConvertImageToFrame(AVFrame *frame) bool cEncode::EncodeFrames(AVCodecContext *context, AVFrame *frame) { AVPacket outpkt; - int got_output; if(!m_pFrameSizes) { esyslog("imageplugin: Failed to add MPEG sequence, insufficient memory."); @@ -227,18 +226,47 @@ bool cEncode::EncodeFrames(AVCodecContext *context, AVFrame *frame) for(i=0; (i < m_nNumberOfFramesToEncode) && (m_nMPEGSize < m_nMaxMPEGSize); ++i) { + + int err = avcodec_send_frame(context, frame); + if(err < 0) { + esyslog("imageplugin: failed send encoding frame %d at %d %d/%d\n", + i, + frame ? (int) frame->pts : -1, + context->time_base.num, + context->time_base.den); + av_packet_unref(&outpkt); + return false; + } + outpkt.data = ( m_pMPEG + m_nMPEGSize); outpkt.size = m_nMaxMPEGSize - m_nMPEGSize; - int err = avcodec_encode_video2(context, &outpkt,frame, &got_output); - if(err < 0) - { - esyslog("imageplugin: Failed to add frame %d, insufficient memory.", - i); - return false; + + err = avcodec_receive_packet(context, &outpkt); + if (err == AVERROR(EAGAIN)) { // No more packets for now. + if (frame == NULL) { + esyslog("imageplugin: sent flush frame %d, got EAGAIN.", i); + } + break; + } + if (err == AVERROR_EOF) { // No more packets, ever. + if (frame != NULL) { + esyslog("imageplugin: sent image frame %d, got EOF.", i); + } + break; + } + if(err < 0) { + esyslog("imageplugin: failed receive encoded frame %d at %d %d/%d\n", + i, + frame ? (int) frame->pts : -1, + context->time_base.num, + context->time_base.den); + break; } + m_nMPEGSize += outpkt.size; *(m_pFrameSizes + i) = outpkt.size; } + av_packet_unref(&outpkt); // Add four bytes MPEG end sequence if ((m_nMaxMPEGSize - m_nMPEGSize) >= 4) |