Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac应该怎么运行这个项目 #4

Open
yuxwd opened this issue Aug 28, 2024 · 1 comment
Open

mac应该怎么运行这个项目 #4

yuxwd opened this issue Aug 28, 2024 · 1 comment

Comments

@yuxwd
Copy link

yuxwd commented Aug 28, 2024

这个cmd命令如何运行

# yuxiang.j @ yuxiangjideMacBook-Pro in ~/Desktop/Code/未命名文件夹 2 [14:12:45] 
$ .\ffmpeg -r 60 -i .\frames\%4d.png -i audio.flac -c:v libx264 -shortest -af apad -crf 0 -pix_fmt yuv420p output.mp4 -y
zsh: command not found: .ffmpeg

# yuxiang.j @ yuxiangjideMacBook-Pro in ~/Desktop/Code/未命名文件夹 2 [14:12:48] C:127
$ .\ffmpeg -r 60 -i
zsh: command not found: .ffmpeg

`
macos 14.5 (23F79)

@github-staff github-staff deleted a comment from ViniciusSCG Oct 1, 2024
@yuxwd
Copy link
Author

yuxwd commented Oct 20, 2024

我针对这个情况写了一个合成视频的代码示例

首先

你需要安装python,opencv-python 库,moviepy 库;分别进行运行,合成视频,合成音频

pip install moviepy
pip install opencv-python # 在终端中运行

合成视频的代码

import os  
from moviepy.editor import ImageSequenceClip, AudioFileClip  

# 图像文件夹路径  
image_folder = 'path/to/your/image_folder/'  
# 输出视频文件名  
output_video = 'output_video.mp4'  
# 音频文件路径  
audio_file = 'path/to/your/audio_file.mp3'  # 或 .wav 文件  
# 设置限制的视频时长(单位:秒)  
max_duration = 10  # 限制视频时长为10秒  

# 获取所有图像文件  
images = [img for img in os.listdir(image_folder) if img.endswith(".jpg") or img.endswith(".png")]  
# 对图像进行排序  
images.sort()  

# 创建视频剪辑  
clip = ImageSequenceClip([os.path.join(image_folder, img) for img in images], fps=30)  # 设置帧率为30  

# 添加音频  
audio = AudioFileClip(audio_file)  
video = clip.set_audio(audio)  

# 限制视频时长  
if video.duration > max_duration:  
    video = video.subclip(0, max_duration)  

# 输出视频文件  
video.write_videofile(output_video, codec='libx264')  

print("视频与音频已成功合成,视频时长限制为{}秒!".format(max_duration))

#最后
在文件中记得修改;图像文件夹路径;音频文件路径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@yuxwd and others