diff options
-rw-r--r-- | render.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -15,8 +15,6 @@ */ #include "api.h" -#include "libavutil/channel_layout.h" -#include "libavutil/mathematics.h" #include "log.h" #include "hook.h" #include "render.h" @@ -26,6 +24,8 @@ #include <libavformat/avformat.h> #include <libavcodec/avcodec.h> #include <libavcodec/codec_id.h> +#include <libavutil/channel_layout.h> +#include <libavutil/mathematics.h> #include <libavutil/error.h> #include <libavutil/opt.h> #include <libavutil/log.h> @@ -69,7 +69,6 @@ struct renderctx { AVFrame *aframe; AVFrame *aframe_tmp; struct SwrContext *swr; - u64 nextpts; }; static struct renderctx ctx = { 0 }; @@ -102,7 +101,10 @@ bool encode(AVCodecContext *codec, AVFrame *frame, AVStream *stream) { } bool do_frame(struct videomode *this, struct movieinfo *info) { + (void)(info); // unused param is_rendering = true; + + static int nextpts = 0; static struct { u8 bgr[3]; } *pixels = 0; if (!pixels) pixels = malloc(args.width * args.height * sizeof(*pixels)); @@ -118,7 +120,7 @@ bool do_frame(struct videomode *this, struct movieinfo *info) { sws_scale(ctx.sws, (const u8 **)&pixels, &stride, 0, args.height, ctx.yuv_frame->data, ctx.yuv_frame->linesize); - ctx.yuv_frame->pts = info->curframe; + ctx.yuv_frame->pts = nextpts++; ctx.yuv_frame->time_base = ctx.vcodec_ctx->time_base; ctx.yuv_frame->duration = 1; @@ -135,7 +137,7 @@ void VIRTUAL hook_write_movie_frame(struct videomode *this, bool do_audio_frame(void) { if (!is_rendering) return true; - + static u64 nextpts = 0; static int frame_idx = 0; #define CLIP16(n) (i16)(n < -32768 ? -32768 : (n > 32767 ? 32767 : n)) @@ -151,8 +153,8 @@ bool do_audio_frame(void) { ctx.aframe_tmp->nb_samples) < 0) bail("failed to resample audio frame"); - ctx.aframe->pts = ctx.nextpts; - ctx.nextpts += ctx.aframe->nb_samples; + ctx.aframe->pts = nextpts; + nextpts += ctx.aframe->nb_samples; encode(ctx.acodec_ctx, ctx.aframe, ctx.astream); frame_idx = 0; } @@ -316,8 +318,6 @@ bool render_init(void) { if (swr_init(ctx.swr) < 0) bail("failed to init resampler"); - ctx.nextpts = 0; - // audio frame ctx.aframe = av_frame_alloc(); if (!ctx.aframe) bail("failed to alloc audio frame"); |