The only packet produced by this encoder contains the entire animated stream, so set its pts to the first frame encoded.
Unified · Split
| @@ -32,7 +32,7 @@ · 31 unmodified lines | |||
| 32 | typedef struct LibWebPAnimContext { | 32 | typedef struct LibWebPAnimContext { |
| 33 | LibWebPContextCommon cc; | 33 | LibWebPContextCommon cc; |
| 34 | WebPAnimEncoder *enc; // the main AnimEncoder object | 34 | WebPAnimEncoder *enc; // the main AnimEncoder object |
| 35 | int64_t prev_frame_pts; // pts of the previously encoded frame. | 35 | int64_t first_frame_pts; // pts of the first encoded frame. |
| 36 | int done; // If true, we have assembled the bitstream already | 36 | int done; // If true, we have assembled the bitstream already |
| 37 | } LibWebPAnimContext; | 37 | } LibWebPAnimContext; |
| 38 | 38 | ||
| @@ -48,7 +48,7 @@ static av_cold int libwebp_anim_encode_init(AVCodecContext *avctx) · 9 unmodified lines | |||
| 48 | s->enc = WebPAnimEncoderNew(avctx->width, avctx->height, &enc_options); | 48 | s->enc = WebPAnimEncoderNew(avctx->width, avctx->height, &enc_options); |
| 49 | if (!s->enc) | 49 | if (!s->enc) |
| 50 | return AVERROR(EINVAL); | 50 | return AVERROR(EINVAL); |
| 51 | s->prev_frame_pts = -1; | 51 | s->first_frame_pts = AV_NOPTS_VALUE; |
| 52 | s->done = 0; | 52 | s->done = 0; |
| 53 | } | 53 | } |
| 54 | return ret; | 54 | return ret; |
| @@ -73,7 +73,7 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 18 unmodified lines | |||
| 73 | memcpy(pkt->data, assembled_data.bytes, assembled_data.size); | 73 | memcpy(pkt->data, assembled_data.bytes, assembled_data.size); |
| 74 | s->done = 1; | 74 | s->done = 1; |
| 75 | pkt->flags |= AV_PKT_FLAG_KEY; | 75 | pkt->flags |= AV_PKT_FLAG_KEY; |
| 76 | pkt->pts = pkt->dts = s->prev_frame_pts + 1; | 76 | pkt->pts = pkt->dts = s->first_frame_pts; |
| 77 | *got_packet = 1; | 77 | *got_packet = 1; |
| 78 | return 0; | 78 | return 0; |
| 79 | } else { | 79 | } else { |
| @@ -102,7 +102,8 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 22 unmodified lines | |||
| 102 | goto end; | 102 | goto end; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | s->prev_frame_pts = frame->pts; // Save for next frame. | 105 | if (!avctx->frame_number) |
| 106 | s->first_frame_pts = frame->pts; | ||
| 106 | ret = 0; | 107 | ret = 0; |
| 107 | *got_packet = 0; | 108 | *got_packet = 0; |
| 108 | 109 | ||