I want to cut out a specific area of an mp4 format video.
I used python's ffmpeg library.
If you specify the input file path and trimming area, a trimmed file will be generated in the same hierarchy as the input file.
trimming.py
import ffmpeg
def video_trimming(input_file_path, start_x, start_y, w, h):
"""
input_file_path #Absolute path of file
start_x = 850 #X coordinate (px) of the section you want to cut
start_y = 500 #Y coordinate (px) of the section you want to cut
width = 700 #Width of the section you want to cut (px)
height = 580 #Height of the section you want to cut (px)
"""
#Trimming file parameter specification
stream = ffmpeg.input(input_file_path)
stream = ffmpeg.crop(stream, start_x, start_y, w, h)
#Output file name generation
output_file_str = input_file_path.split(".")
output_file_name = output_file_str[0] + "_trimed." + output_file_str[1]
stream = ffmpeg.output(stream, output_file_name)
#Run(Overwrite if there is a file)
ffmpeg.run(stream, overwrite_output=True)
return
Recommended Posts