'''保存选择的图片和视频''' for item in files: file_path = os.path.join(path,item) if ".mp4" in file_path : copyfile(file_path,"/root/web/source/select_video/"+item) if ".jpg" in file_path: image_name = file_path.replace("/root/web/source/","") copyfile(file_path,"/root/web/source/select_picture/"+item) '''读取选择视频中的第一个视频作为输出视频''' select_video_path = "/root/web/source/select_video/" videos = os.listdir(select_video_path) for video in videos: video_name = os.path.join("select_video/",video) break copyfile("/root/web/source/"+video_name,"/root/web/source/now_video/"+ video) copyfile("/root/web/source/bing1_1.MP4", "/rootweb/source/input_har.mp4") return_state = 200将这段代码改写成读取选择视频中的全部视频并输出到指定路径并实现点选播放
时间: 2023-12-07 20:03:19 浏览: 25
好的,这里有一个示例代码,可以实现读取选择视频中的全部视频并输出到指定路径,并且可以实现点选播放:
```python
import os
from shutil import copyfile
select_video_path = "/root/web/source/select_video/"
output_video_path = "/root/web/source/output_video/"
# 读取选择视频中的全部视频
videos = os.listdir(select_video_path)
for video in videos:
if video.endswith(".mp4"):
# 复制视频文件到输出路径
copyfile(os.path.join(select_video_path, video), os.path.join(output_video_path, video))
# 生成HTML文件
html = "<html><body>"
for video in videos:
if video.endswith(".mp4"):
# 在HTML中添加视频播放链接
html += f'<a href="{os.path.join(output_video_path, video)}">{video}</a><br>'
html += "</body></html>"
# 将HTML文件写入到指定路径
with open("/root/web/source/index.html", "w") as f:
f.write(html)
# 复制一份示例视频文件到输入路径
copyfile("/root/web/source/bing1_1.MP4", "/root/web/source/input_har.mp4")
```
这段代码会将选择视频中的所有 `.mp4` 文件复制到输出路径 `/root/web/source/output_video/` 中,并生成一个 HTML 文件 `/root/web/source/index.html`,其中包含了所有视频文件的播放链接。同时,还会复制一份示例视频文件 `/root/web/source/bing1_1.MP4` 到输入路径 `/root/web/source/input_har.mp4` 中,以供后续使用。