I am using Python to make a script with ffmpeg where the script exports the middle frame into a jpg file and then stitches it back into beginning of the video. This is my script
video_filename = "test_video.webm"
import ffmpeg
# Open the input video file
input_video = ffmpeg.input(video_filename)
# Get the video stream from the input video
video_stream = next(s for s in input_video.streams if s.type == 'video')
# Get the total number of frames in the stream
num_frames = video_stream.frame_count
# Calculate the middle frame number
middle_frame = num_frames // 2
# Extract the middle frame from the input video
middle_frame_extract = input_video.trim(start_frame=middle_frame, end_frame=middle_frame+1).setpts('PTS-STARTPTS')
# Save the extracted frame to an image file
ffmpeg.output(middle_frame_extract, 'middle_frame.jpg').run()
# Open the image file
middle_frame_image = ffmpeg.input('middle_frame.jpg')
# Concatenate the image file with the rest of the video
output_video = ffmpeg.concat(middle_frame_image, input_video, v=1, a=0).setpts('PTS+STARTPTS')
# Save the output video to a file
ffmpeg.output(output_video, 'output.mp4').run()
I get this error though
AttributeError Traceback (most recent call last)
<ipython-input-8-7bfc1bdca9c8> in <module>
6
7 # Get the video stream from the input video
----> 8 video_stream = next(s for s in input_video.streams if s.type == 'video')
9
10 # Get the total number of frames in the stream
AttributeError: 'FilterableStream' object has no attribute 'streams'
The issue is that there is little documentation to do this and I only found this snippet of code online. How do I modify it to make it work for my use case?