Created
May 14, 2025 07:55
-
-
Save manzil-infinity180/9a626fba0d9950b99f3fd81fb4e47114 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ffmpeg | |
# Basic Usage (Convert Video Format) | |
""" | |
( | |
ffmpeg.input("src/rahulxf.mov") | |
.output("output.mp4") | |
.run() | |
) | |
""" | |
# Convert to mp3 | |
# It will convert the video to MP3 automatically using the default audio codec (libmp3lame): | |
# You can also use a custom audio codec by specifying it in the acodec parameter of the output() function: | |
""" | |
( | |
ffmpeg.input("src/filter_complex3.mp4") | |
.output("src/audio.mp3", acodec="libshine") | |
.run() | |
) | |
""" | |
# Trim Video | |
""" | |
start_time = '00:00:01' # Start time for trimming (HH:MM:SS) | |
end_time = '00:00:09' # End time for trimming (HH:MM:SS) | |
( | |
ffmpeg.input("src/output.mp4", ss=start_time, to=end_time) | |
.output("src/output_trim.mp4") | |
.run() | |
) | |
""" | |
# Extract Frames from Videos | |
""" | |
( | |
ffmpeg.input("src/output.mp4") | |
.output("src/frames/frame_%d.png", vframes=20) | |
.run() | |
) | |
""" | |
""" | |
( | |
ffmpeg.input("src/output.mp4") | |
.output("src/frames/frame_%d.png", vf='fps=1') # every seconds -> https://ffmpeg.org/ffmpeg-filters.html#fps-1 | |
.run() | |
) | |
""" | |
# Create Video Thumbnails | |
""" | |
( | |
ffmpeg.input("src/output.mp4", ss="00:00:12") | |
.output("src/thumbnail.png", vframes=1) | |
.run() | |
) | |
""" | |
""" | |
Besides using the ss parameter to select a particular frame from the video, you can also use a filter. | |
The “Thumbnail” filter selects the most representative frame in a given sequence of consecutive frames | |
automatically from the video and saves it as the thumbnail image. | |
You can use the “Thumbnail” filter by specifying the filter name in the filter() function following input(): | |
""" | |
( | |
ffmpeg.input("src/output.mp4") | |
.filter('thumbnail') | |
.output("src/thumbnail_filter.png") | |
.run() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment