From 6d01aa63895473799fdc119371d63a90c823bb12 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 18 Oct 2025 12:36:46 +0800 Subject: [PATCH] =?UTF-8?q?loadMP4File=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=94=AF=E6=8C=81seek=5Fms=E4=B8=8Espeed=E5=8F=82=E6=95=B0=20(?= =?UTF-8?q?#4261)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postman/ZLMediaKit.postman_collection.json | 12 ++++++++++++ server/WebApi.cpp | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/postman/ZLMediaKit.postman_collection.json b/postman/ZLMediaKit.postman_collection.json index 953c81b4..0d5e9837 100644 --- a/postman/ZLMediaKit.postman_collection.json +++ b/postman/ZLMediaKit.postman_collection.json @@ -2612,6 +2612,18 @@ "description": "是否循环点播mp4文件,如果配置文件已经开启循环点播,此参数无效", "disabled": true }, + { + "key": "seek_ms", + "value": "0", + "description": "点播seek到特定位置,单位毫秒", + "disabled": true + }, + { + "key": "speed", + "value": "1.0", + "description": "播放速度, float类型", + "disabled": true + }, { "key": "enable_hls", "value": "", diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 7d0dda9a..2c1ade7f 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -2251,6 +2251,19 @@ void installWebApi() { // sample_ms设置为0,从配置文件加载;file_repeat可以指定,如果配置文件也指定循环解复用,那么强制开启 [AUTO-TRANSLATED:23e826b4] // sample_ms is set to 0, loaded from the configuration file; file_repeat can be specified, if the configuration file also specifies loop demultiplexing, then force it to be enabled reader->startReadMP4(0, true, allArgs["file_repeat"]); + auto seek_ms = allArgs["seek_ms"].as(); + auto speed = allArgs["speed"].as(); + if (seek_ms || speed) { + auto p = static_pointer_cast(reader); + p->getOwnerPoller(MediaSource::NullMediaSource())->async([seek_ms, speed, p]() { + if (seek_ms) { + p->seekTo(MediaSource::NullMediaSource(), seek_ms); + } + if (speed && speed != 1.0) { + p->speed(MediaSource::NullMediaSource(), speed); + } + }); + } val["data"]["duration_ms"] = (Json::UInt64)reader->getDemuxer()->getDurationMS(); }); #endif