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 | 32 | typedef struct LibWebPAnimContext { |
| 33 | 33 | LibWebPContextCommon cc; |
| 34 | 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 | 36 | int done; // If true, we have assembled the bitstream already |
| 37 | 37 | } LibWebPAnimContext; |
| 38 | 38 | |
| @@ -48,7 +48,7 @@ static av_cold int libwebp_anim_encode_init(AVCodecContext *avctx) · 9 unmodified lines | ||
| 48 | 48 | s->enc = WebPAnimEncoderNew(avctx->width, avctx->height, &enc_options); |
| 49 | 49 | if (!s->enc) |
| 50 | 50 | return AVERROR(EINVAL); |
| 51 | − s->prev_frame_pts = -1; | |
| 51 | + s->first_frame_pts = AV_NOPTS_VALUE; | |
| 52 | 52 | s->done = 0; |
| 53 | 53 | } |
| 54 | 54 | return ret; |
| @@ -73,7 +73,7 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 18 unmodified lines | ||
| 73 | 73 | memcpy(pkt->data, assembled_data.bytes, assembled_data.size); |
| 74 | 74 | s->done = 1; |
| 75 | 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 | 77 | *got_packet = 1; |
| 78 | 78 | return 0; |
| 79 | 79 | } else { |
| @@ -102,7 +102,8 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 22 unmodified lines | ||
| 102 | 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 | 107 | ret = 0; |
| 107 | 108 | *got_packet = 0; |
| 108 | 109 | |