--Split video using python-ffmpeg --Procedure to run python-ffmpeg --Memorandum
--Environment - python: v.3.7.7 - python-ffmpeg: v.0.2.0 - ffmpeg: v.4.3
--Use a pre-built image
--Easy if you use the pre-built files from https://www.johnvansickle.com/ffmpeg/
--After decompressing the downloaded file, copy it under / usr / local / bin
and it's OK.
--If you don't copy ffprobe
, when you run ffmpeg.probe
`[Errno 2] No such file or directory:'ffprobe':'ffprobe'`
, so be careful
wget http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz
tar xvf ffmpeg-release-arm64-static.tar.xz
sudo cp ./ffmpeg-4.3-arm64-static/ffmpeg /usr/local/bin
sudo cp ./ffmpeg-4.3-arm64-static/ffprobe /usr/local/bin
--Just pip install
pip install ffmpeg-python
import ffmpeg
srcfile_path = 'hoge.mp4' #Video storage path
split_num = 5 #Number of video divisions
# ffmpeg.Execute probe to get video metadata
video_info = ffmpeg.probe(srcfile_path)
#Full length of the video(Seconds)Get
duration = float(video_info['streams'][0]['duration'])
stride = duration/split_num
#Divide the video into N pieces
for i in range(split_num):
start = int(i * stride)
stream = ffmpeg.input(srcfile_path, ss=start, t=stride)
#c option is ffmpeg-with vcodec-Specify acodec collectively
# c="copy"By specifying it, you can save time and effort for re-conversion.
stream = ffmpeg.output(stream, 'output_{}'.format(i), c="copy")
ffmpeg.run(stream)
There is also a method using OpenCV, but ffmpeg is easy and convenient if you only edit the video ~
Recommended Posts