import ffmpeg
# Create a new input stream
ffmpeg.input('input.mp4')
Adding Input Options¶
To specify additional options for the input stream, such as start time and duration, you can include them directly in the ffmpeg.input
function.
import ffmpeg
# Create a new input stream with specific options
ffmpeg.input('input.mp4', ss=10, t=20) # Start at 10 seconds and last for 20 seconds
Note
The ss
option specifies the start time (in seconds), and the t
option specifies the duration (in seconds) of the input stream. For more details, refer to the FFmpeg documentation.
Output¶
Creating a New Output Stream¶
To create a new output stream, use the ffmpeg.output
function. This function is used to configure the output settings of the stream.
import ffmpeg
# Create a new output stream
ffmpeg.input("input.mp4").output(filename="output.mp4")
Specifying Output Options¶
You can specify various output options directly in the ffmpeg.output
function, such as the start time and duration for the output file.
import ffmpeg
# Create and configure a new output stream
ffmpeg.input("input.mp4").output(filename="output.mp4", ss=10, t=20) # Output starting at 10 seconds with a duration of 20 seconds
You can also map multiple streams to a single output file.
import ffmpeg
# Define input streams
input1 = ffmpeg.input('input1.mp4')
input2 = ffmpeg.input('input2.mp3')
# Map multiple inputs to a single output
ffmpeg.output(input1, input2, filename="output.mp4")
Alternatively:
import ffmpeg
# Chain input and output operations
(
ffmpeg.input('input1.mp4')
.output(ffmpeg.input("input2.mp3"), filename="output.mp4")
)
Merging Outputs¶
FFmpeg allows processing multiple output files simultaneously. The Python FFmpeg wrapper supports this feature through the merge_outputs
method.
import ffmpeg
# Define input streams
input1 = ffmpeg.input('input1.mp4')
input2 = ffmpeg.input('input2.mp4')
# Define output streams
output1 = input1.output(filename="output1.mp4")
output2 = input2.output(filename="output2.mp4")
# Merge the outputs into a single operation
ffmpeg.merge_outputs(output1, output2)