speed
authoryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 13:53:11 +0000 (21:53 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 13:53:11 +0000 (21:53 +0800)
simp.h
simp_filter.c

diff --git a/simp.h b/simp.h
index 3ced822a4b08cb3ae796051e7cd8d40e72f8f110..0f44cf8772b597073de89e424e7f5c5ae0466fce 100644 (file)
--- a/simp.h
+++ b/simp.h
@@ -38,6 +38,7 @@ struct  simp_avio_s
        scf_list_t           aout;
 
        int64_t              start_time;
+       AVRational           speed;
 
        int                  x;
        int                  y;
@@ -81,6 +82,8 @@ struct  simp_filter_s
        AVFrame*             vframe;
        AVFrame*             aframe;
 
+       AVRational           speed;
+
        int                  error;
        int                  exit;
        int                  flush;
index f857ddea491c51b795bc14a9dc80034fe5994bc6..4e3c1694e094c49d392d7698ed6fae5cb778aa93 100644 (file)
@@ -259,7 +259,7 @@ int simp_filter_close(simp_filter_t*  f, int flush)
        return 0;
 }
 
-static int  _filter_add_video(simp_avio_t* io)
+static int  _filter_add_video(simp_avio_t* io, AVRational speed)
 {
        simp_frame_t*  vf;
        scf_list_t*    vl;
@@ -273,6 +273,12 @@ static int  _filter_add_video(simp_avio_t* io)
                int64_t time  = gettime() - io->start_time;
                int64_t vtime = vf->frame->pts * av_q2d(io->frame_rate) * 1000000LL;
 
+               if (speed.num > 0 && speed.den > 0)
+                       time *= av_q2d(speed);
+
+               else if (io->speed.num > 0 && io->speed.num > 0)
+                       time *= av_q2d(io->speed);
+
                if (vtime < time) {
                        scf_list_del(&vf->list);
                        io->nb_vframes--;
@@ -300,7 +306,7 @@ static int  _filter_add_video(simp_avio_t* io)
        return 0;
 }
 
-static int  _filter_add_audio(simp_avio_t* io)
+static int  _filter_add_audio(simp_avio_t* io, AVRational speed)
 {
        simp_frame_t*  af;
        scf_list_t*    al;
@@ -357,7 +363,7 @@ static void* __filter_run(void* arg)
 
        while (!f->exit) {
 
-               usleep(500 * 1000);
+               usleep(1000);
 
                for (l = scf_list_head(&f->inputs); l != scf_list_sentinel(&f->inputs); l = scf_list_next(l)) {
                        io = scf_list_data(l, simp_avio_t, list);
@@ -369,7 +375,7 @@ static void* __filter_run(void* arg)
                                simp_avio_stop(io);
 
                        if (io->vopen) {
-                               f->error = _filter_add_video(io);
+                               f->error = _filter_add_video(io, f->speed);
                                if (f->error < 0)
                                        goto error;
 
@@ -384,7 +390,7 @@ static void* __filter_run(void* arg)
                        }
 
                        if (io->aopen) {
-                               f->error = _filter_add_audio(io);
+                               f->error = _filter_add_audio(io, f->speed);
                                if (f->error < 0)
                                        goto error;