I am using the ffmpeg-python wrapper.
I want to use the crop filter to extract a cropped section of the video file; I want the section's size to be half the dimensions of the input.
According to ffmpeg's documentation, I can use the input parameters in_w
and in_h
like so:
crop=1/2*in_w:1/2*in_h
(or crop=w=1/2*in_w:h=1/2*in_h
with named parameters)
However, I struggle to find how to use them in ffmpeg-python. I figured I could pass them as standard arguments like so: filter_('crop', '1/2*in_w:1/2*in_h')
but I seem to misunderstand how direct arguments work here because this does not work.
Obviously, I can't use keyword arguments either like so:
filter_('crop', w=1/2*in_w, h=1/2*in_h)
because they're interpreted as undefined names.
I was actually very close. While testing more possibilities, I found out that all I needed to do was to send the keywords as strings:
(ffmpeg
.input("input.mp4")
.filter_('crop', w='1/2*in_w', h='1/2*in_h')
.output("output.mp4")
.run()
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.