Here is an example of a Python script that can be used to convert a video file from one format to multiple formats using the FFmpeg library:
import os
import subprocess
def convert_video(input_filename, output_formats):
# Iterate through the output formats
for output_format in output_formats:
# Construct the output file name
output_filename = os.path.splitext(input_filename)[0] + '.' + output_format
# Call the FFmpeg command to convert the video
subprocess.run(['ffmpeg', '-i', input_filename, output_filename])
# Set the input and output formats
input_filename = 'input.mp4'
output_formats = ['mkv', 'webm', 'avi']
# Convert the video
convert_video(input_filename, output_formats)
This script uses the subprocess
module to call the FFmpeg command-line tool to perform the video conversion. The input_filename
and output_formats
variables should be modified to specify the input file and the desired output formats. The script will then iterate through the output formats and convert the input video file to each of the specified formats.
Note that this script requires that FFmpeg is installed on your system and is available on the system path. You can download FFmpeg from the official website (https://ffmpeg.org/) and follow the installation instructions to set it up on your system.