Synthesize video files with mp3 and images using ffmpeg in MacOS

作者: shaneZhang 分类: 互联网技术 发布时间: 2019-08-28 18:07

First step you should install dependence files.

brew install ffmpeg
brew install libmagic
pip install eyed3

Then you can use the terminal to test the ffmpeg command. And you should see the ffmpeg help output in your terminal if you install ffmpeg success.

Use the python file to make your video files.

#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import os
import urllib
import eyed3
import time

musicPath = '/Users/zhangyuqing/Desktop/tianshidechibang.mp3'
picturePath = '/Users/zhangyuqing/Desktop/timeradio2.jpg'
outFileName = 'tianshidechibang'

xx = eyed3.load(str(musicPath))
seconds = xx.info.time_secs  # 获取音乐时长,为渲染一图流视频做准备
print  seconds
os.system('ffmpeg -loop 1 -r 1 -t '+str(seconds)+' -f image2 -i '+ str(picturePath) + ' -vcodec libx264 -pix_fmt yuv420p -crf 24 -y SinglePictureVideo.mp4')     #渲染一图流视频,参数都是我做完试出来的,尤其是-pix_fmt yuv420p这个参数,缺了它视频就是黑屏了
os.system('ffmpeg -i SinglePictureVideo.mp4 -i '+ str(musicPath) +' -c:v copy -c:a aac -y '+ str(outFileName) +'.flv') #合并视频与音频
os.remove('SinglePictureVideo.mp4')

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注