| 64 | } |
| 65 | |
| 66 | static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 67 | const AVFrame *frame, int *got_packet) { |
| 68 | LibWebPAnimContext *s = avctx->priv_data; |
| 69 | int ret; |
| 70 | |
| 71 | if (!frame) { |
| 72 | if (s->done) { // Second flush: return empty package to denote finish. |
| 73 | *got_packet = 0; |
| 74 | return 0; |
| 75 | } else { // First flush: assemble bitstream and return it. |
| 76 | WebPData assembled_data = { 0 }; |
| 77 | ret = WebPAnimEncoderAssemble(s->enc, &assembled_data); |
| 78 | if (ret) { |
| 79 | ret = ff_get_encode_buffer(avctx, pkt, assembled_data.size, 0); |
| 80 | if (ret < 0) { |
| 81 | WebPDataClear(&assembled_data); |
| 82 | return ret; |
| 83 | } |
| 84 | memcpy(pkt->data, assembled_data.bytes, assembled_data.size); |
| 85 | WebPDataClear(&assembled_data); |
| 86 | s->done = 1; |
| 87 | pkt->pts = s->first_frame_pts; |
| 88 | |
| 89 | if (pkt->pts != AV_NOPTS_VALUE && s->end_pts > pkt->pts) |
| 90 | pkt->duration = s->end_pts - pkt->pts; |
| 91 | |
| 92 | if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { |
| 93 | pkt->opaque = s->first_frame_opaque; |
| 94 | pkt->opaque_ref = s->first_frame_opaque_ref; |
| 95 | s->first_frame_opaque_ref = NULL; |
| 96 | } |
| 97 | |
| 98 | *got_packet = 1; |
| 99 | return 0; |
| 100 | } else { |
| 101 | WebPDataClear(&assembled_data); |
| 102 | av_log(s, AV_LOG_ERROR, |
| 103 | "WebPAnimEncoderAssemble() failed with error: %d\n", |
| 104 | VP8_ENC_ERROR_OUT_OF_MEMORY); |
| 105 | return AVERROR(ENOMEM); |
| 106 | } |
| 107 | } |
| 108 | } else { |
| 109 | int timestamp_ms; |
| 110 | WebPPicture *pic = NULL; |
| 111 | AVFrame *alt_frame = NULL; |
| 112 | ret = ff_libwebp_get_frame(avctx, &s->cc, frame, &alt_frame, &pic); |
| 113 | if (ret < 0) |
| 114 | goto end; |
| 115 | |
| 116 | timestamp_ms = |
| 117 | avctx->time_base.num * frame->pts * 1000 / avctx->time_base.den; |
| 118 | ret = WebPAnimEncoderAdd(s->enc, pic, timestamp_ms, &s->cc.config); |
| 119 | if (!ret) { |
| 120 | av_log(avctx, AV_LOG_ERROR, |
| 121 | "Encoding WebP frame failed with error: %d\n", |
| 122 | pic->error_code); |
| 123 | ret = ff_libwebp_error_to_averror(pic->error_code); |
nothing calls this directly
no test coverage detected