ffmpeg-Build a python environment and split the video

Overview

--Split video using python-ffmpeg --Procedure to run python-ffmpeg --Memorandum


Premise

--Environment - python: v.3.7.7 - python-ffmpeg: v.0.2.0 - ffmpeg: v.4.3


Install ffmpeg

--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

Install python-ffmpeg

--Just pip install

pip install ffmpeg-python

Write a video cutout code

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

ffmpeg-Build a python environment and split the video
Build a Python environment and transfer data to the server
Building a python environment with virtualenv and direnv
Python and Ruby split
[Python] Split the date
Create a Python environment
A discussion of the strengths and weaknesses of Python
Create a Django project and application in a Python virtual environment and start the server
Build a python environment to learn the theory and implementation of deep learning
Python: Creating a virtual environment (venv), starting and stopping
Build a python virtual environment with virtualenv and virtualenvwrapper
Building and enabling a python virtual environment, etc. (venv)
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a decent shell and python environment on Windows
Python environment construction and TensorFlow
Building a Python virtual environment
Build a Python environment offline
Building a Python virtual environment
Building a Python environment on a Mac and using Jupyter lab
[Python] Building a virtual python environment for the pyramid tutorial (summary)
[Python3] "A // B" and "math.floor (A / B)" are not always the same! ??
Building a Python environment on Mac
Python a + = b and a = a + b are different
Environment construction of python and opencv
Difference between Ruby and Python split
The story of Python and the story of NaN
Building a Python environment on Ubuntu
Create a virtual environment with Python!
Building a virtual environment with Python 3
[Python] Make the function a lambda function
Create a python environment on centos
[Python] return A [or / and] B
Checking the NAOqi Python development environment
Build a python3 environment on CentOS7
Building a Docker working environment for R and Python 2: Japanese support
Build and test a CI environment for multiple versions of Python
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
[Introduction to Python] How to split a character string with the split function
Build a Python environment on your Mac with Anaconda and PyCharm
Specify or create a python folder and then save the screenshot.
Solve the Python knapsack problem with a branch and bound method
Prepare a distributed load test environment with the Python load test tool Locust
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
[Mac] Create a Python3 execution environment from the fully initialized state
Create a simple Python development environment with VS Code and Docker
LaTeX and R (a little Python) environment construction with SublimeText3 (Windows)
Building a Python3 environment with Amazon Linux2
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
[AWS] Create a Python Lambda environment with CodeStar and do Hello World
Create a Python development environment locally at the fastest speed (for beginners)
[Introduction to Python] What is the difference between a list and a tuple?
Build Python3 and OpenCV environment on Ubuntu 18.04
Write the test in a python docstring
Build a python environment on MacOS (Catallina)
Create a python environment on your Mac
About the virtual environment of python version 3.7
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
A memo with Python2.7 and Python3 on CentOS
Building a Python 3.6 environment with Windows + PowerShell
Search the maze with the python A * algorithm