将音频添加到剪辑
Adding audio to the clip
我有以下代码并且在视频输出中没有收到声音。我正在使用 MoviePy 包。
from moviepy.editor import *
picture = VideoFileClip("/Users/name/Desktop/trial.jpg", audio=False).set_duration(50)
txt_clip = TextClip("Hey",fontsize = 150, color='white')
txt_clip = txt_clip.set_pos('center').set_duration(10)
audio = AudioFileClip("/Users/name/Desktop/music.mp3").subclip(0,50)
video_with_new_audio = picture.set_audio(audio)
final_video = CompositeVideoClip([video_with_new_audio,txt_clip])
final_video.write_videofile("trial.mp4")
可能是什么问题?:c
会不会是缺少 MP3 编解码器、“LAME”等?您的代码适用于 Windows:
from moviepy.editor import *
picture = VideoFileClip("img.jpg", audio=False).set_duration(20)
txt_clip = TextClip("Hey",fontsize = 150, color='white')
txt_clip = txt_clip.set_pos('center').set_duration(10)
audio = AudioFileClip(r"C:\Users\Public\Music\Sample Music\Kalimba.mp3").subclip(0,20)
video_with_new_audio = picture.set_audio(audio)
final_video = CompositeVideoClip([video_with_new_audio,txt_clip])
final_video.write_videofile("trial.mp4")
这是输出:trial.mp4
你能 运行 ffprobe trial.mp4
或 ffmpeg -i trial.mp4
并显示输出吗?
这是我视频中 ffprobe 的输出:
ffprobe z:\trial.mp4
(...)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'z:\trial.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:20.04, start: 0.000000, bitrate: 236 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 822x556,
100 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 12
7 kb/s (default)
Metadata:
handler_name : SoundHandler
这可能与ffmpeg设置和moviepy版本有关:
我有以下代码并且在视频输出中没有收到声音。我正在使用 MoviePy 包。
from moviepy.editor import *
picture = VideoFileClip("/Users/name/Desktop/trial.jpg", audio=False).set_duration(50)
txt_clip = TextClip("Hey",fontsize = 150, color='white')
txt_clip = txt_clip.set_pos('center').set_duration(10)
audio = AudioFileClip("/Users/name/Desktop/music.mp3").subclip(0,50)
video_with_new_audio = picture.set_audio(audio)
final_video = CompositeVideoClip([video_with_new_audio,txt_clip])
final_video.write_videofile("trial.mp4")
可能是什么问题?:c
会不会是缺少 MP3 编解码器、“LAME”等?您的代码适用于 Windows:
from moviepy.editor import *
picture = VideoFileClip("img.jpg", audio=False).set_duration(20)
txt_clip = TextClip("Hey",fontsize = 150, color='white')
txt_clip = txt_clip.set_pos('center').set_duration(10)
audio = AudioFileClip(r"C:\Users\Public\Music\Sample Music\Kalimba.mp3").subclip(0,20)
video_with_new_audio = picture.set_audio(audio)
final_video = CompositeVideoClip([video_with_new_audio,txt_clip])
final_video.write_videofile("trial.mp4")
这是输出:trial.mp4
你能 运行 ffprobe trial.mp4
或 ffmpeg -i trial.mp4
并显示输出吗?
这是我视频中 ffprobe 的输出:
ffprobe z:\trial.mp4
(...)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'z:\trial.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:20.04, start: 0.000000, bitrate: 236 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 822x556,
100 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 12
7 kb/s (default)
Metadata:
handler_name : SoundHandler
这可能与ffmpeg设置和moviepy版本有关: