speed
authoryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 14:20:42 +0000 (22:20 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 14:20:42 +0000 (22:20 +0800)
main.c
simp_filter.c

diff --git a/main.c b/main.c
index a7d1d8e3dc9a9ac7794d04633c78b575c1cc395e..19288d0c4722c4ef9141eedc5ae0ad6515cf4631 100644 (file)
--- a/main.c
+++ b/main.c
@@ -34,6 +34,9 @@ int main(int argc, char* argv[])
        simp_filter_add_input (f, in);
        simp_filter_add_output(f, out);
 
+       f->speed.num = 200;
+       f->speed.den = 1;
+
        if (simp_filter_run(f) < 0) {
                scf_loge("\n");
                return -1;
index 4e3c1694e094c49d392d7698ed6fae5cb778aa93..da8c69e9e6812e51812b25d33bfb51c081da98cb 100644 (file)
@@ -284,7 +284,15 @@ static int  _filter_add_video(simp_avio_t* io, AVRational speed)
                        io->nb_vframes--;
                        pthread_mutex_unlock(&io->mutex);
 
-                       scf_logd("vf->pts: %ld, vtime: %ld, time: %ld, nb_vframes: %d\n", vf->frame->pts, vtime, time, io->nb_vframes);
+                       int64_t usec = vtime % 1000000;
+                       int64_t sec  = vtime / 1000000;
+                       int64_t hour = sec   / 3600;
+                       sec %= 3600;
+                       int64_t min  = sec   / 60;
+                       sec %= 60;
+
+                       scf_logi("vf->pts: %ld, vtime: %ld, time: %ld, nb_vframes: %d, %ld:%ld:%ld.%ld\n",
+                                       vf->frame->pts, vtime, time, io->nb_vframes, hour, min, sec, usec);
 
                        int ret = av_buffersrc_add_frame_flags(io->vbuffersrc_ctx, vf->frame, AV_BUFFERSRC_FLAG_KEEP_REF);
 
@@ -320,6 +328,12 @@ static int  _filter_add_audio(simp_avio_t* io, AVRational speed)
                int64_t time  = gettime() - io->start_time;
                int64_t atime = af->frame->pts * av_q2d(io->sample_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 (atime < time) {
                        scf_list_del(&af->list);
                        pthread_mutex_unlock(&io->mutex);
@@ -363,7 +377,7 @@ static void* __filter_run(void* arg)
 
        while (!f->exit) {
 
-               usleep(1000);
+               usleep(100);
 
                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);