ffmpeg-python仅仅是对ffmpeg的wrap,它所支持滤镜也是ffmpeg所支持的滤镜,滤镜可以用命令查看:
ffmpeg -filters
Filters:
T.. = Timeline support
.S. = Slice threading
..C = Command support
A = Audio input/output
V = Video input/output
N = Dynamic number and/or type of input/output
| = Source or sink filter
前略...
.TS. fade V->V Fade in/out input video.
T.. fftdnoiz V->V Denoise frames using 3D FFT.
T.. fftfilt V->V Apply arbitrary expressions to pixels in frequency domain.
... field V->V Extract a field from the input video.
... fieldhint V->V Field matching using hints.
... fieldmatch N->V Field matching for inverse telecine.
T.. fieldorder V->V Set the field order.
T.C fillborders V->V Fill borders of the input video.
... find_rect V->V Find a user specified object.
T.. floodfill V->V Fill area with same color with another color.
... format V->V Convert the input video to one of the specified pixel formats.
... fps V->V Force constant framerate.
... framepack VV->V Generate a frame packed stereoscopic video.
.S. framerate V->V Upsamples or downsamples progressive source between specified frame rates.
T.. framestep V->V Select one frame every N frames.
... freezedetect V->V Detects frozen video input.
... freezeframes VV->V Freeze video frames.
T.C frei0r V->V Apply a frei0r effect.
T.. fspp V->V Apply Fast Simple Post-processing filter.
TSC gblur V->V Apply Gaussian Blur filter.
后略.....
比如 fade 就是淡入淡出滤镜,可以查看fade参数:
ffmpeg -h filter=fade
Filter fade
Fade in/out input video.
slice threading supported
Inputs:
#0: default (video)
Outputs:
#0: default (video)
fade AVOptions:
type <int> ..FV....... set the fade direction (from 0 to 1) (default in)
in 0 ..FV....... fade-in
out 1 ..FV....... fade-out
t <int> ..FV....... set the fade direction (from 0 to 1) (default in)
in 0 ..FV....... fade-in
out 1 ..FV....... fade-out
start_frame <int> ..FV....... Number of the first frame to which to apply the effect. (from 0 to INT_MAX) (default 0)
s <int> ..FV....... Number of the first frame to which to apply the effect. (from 0 to INT_MAX) (default 0)
nb_frames <int> ..FV....... Number of frames to which the effect should be applied. (from 1 to INT_MAX) (default 25)
n <int> ..FV....... Number of frames to which the effect should be applied. (from 1 to INT_MAX) (default 25)
alpha <boolean> ..FV....... fade alpha if it is available on the input (default false)
start_time <duration> ..FV....... Number of seconds of the beginning of the effect. (default 0)
st <duration> ..FV....... Number of seconds of the beginning of the effect. (default 0)
duration <duration> ..FV....... Duration of the effect in seconds. (default 0)
d <duration> ..FV....... Duration of the effect in seconds. (default 0)
color <color> ..FV....... set color (default "black")
c <color> ..FV....... set color (default "black")
下例给出使用 gblur,scale, fade滤镜把视频马赛克并淡入淡出
# coding: utf-8
import ffmpeg
VIDEO_FRAMERATE = 30
def image2mp4(fullpath,duration):
# 输入图片地址fullpath,生成视频时长duration,
v_in = ffmpeg.input(fullpath, t=duration, framerate=VIDEO_FRAMERATE, loop=1)
# 高斯模糊滤镜,看起来有镜头不聚焦的效果
v_g = ffmpeg.filter(v_in, filter_name='gblur', sigma=8)
# 缩放滤镜,视频分辨率到427x240
v_s1 = ffmpeg.filter(v_g, filter_name='scale', size='32:18')
# 缩放滤镜,视频分辨率到1280x720
v_s = ffmpeg.filter(v_s1, filter_name='scale', size='1280:720')
# 淡入滤镜,效果时长1秒,白色
v_f = ffmpeg.filter(v_s, filter_name='fade', type=0, duration=1, color='white')
# 淡出滤镜,效果时长1秒,所以start_time等于视频时长减1秒,白色
video = ffmpeg.filter(v_f, filter_name='fade', type=1, start_time=duration-1, duration=1, color='white')
try:
out, err = (ffmpeg
.output(
video,
'new.mp4',
vcodec='libx264',
f='mp4')
.overwrite_output()
.run(cmd=["ffmpeg"])
)
except ffmpeg.Error as error:
print("stderr:",error.stderr)

3412

被折叠的 条评论
为什么被折叠?



