• 正文
  • 相关推荐
申请入驻 产业图谱

音视频开发ffmpeg应用:使用滤镜对视频进行处理

9小时前
231
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

一、前言

在现代的多媒体处理中,视频和音频滤镜起着至关重要的作用。可以帮助开发者对视频和音频进行各种处理,如色彩校正、尺寸调整、去噪、特效添加等。而FFmpeg作为一个功能强大的开源多媒体框架,提供了丰富的滤镜库,使我们能够轻松地对多媒体文件进行处理和转换。

本文将介绍FFmpeg滤镜的使用,帮助大家了解如何利用这些滤镜来实现各种多媒体处理任务。将探索不同类型的滤镜,包括视频滤镜和音频滤镜,并深入了解它们的功能和用法。

二、查询支持的滤镜

FFmpeg支持许多滤镜,用于视频和音频处理。可以使用以下命令来查看FFmpeg所支持的滤镜列表:

ffmpeg -filters

运行上述命令后,将输出FFmpeg支持的所有滤镜的列表,包括视频滤镜、音频滤镜和多媒体滤镜。每个滤镜都有一个唯一的名称,可以在代码中使用这些名称来调用相应的滤镜。

也可以使用以下命令来查看特定滤镜的详细信息,包括滤镜的选项和用法:

ffmpeg -h filter=<filter_name>

<filter_name>替换为要查询的滤镜名称。运行上述命令后,将输出有关该滤镜的详细信息,包括滤镜的选项、语法和示例用法。

C:Users11266>ffmpeg -filters
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
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
 ... abench            A->A       Benchmark part of a filtergraph.
 ... acompressor       A->A       Audio compressor.
 ... acontrast         A->A       Simple audio dynamic range compression/expansion filter.
 ... acopy             A->A       Copy the input audio unchanged to the output.
 ... acue              A->A       Delay filtering to match a cue.
 ... acrossfade        AA->A      Cross fade two input audio streams.
 ... acrossover        A->N       Split audio into per-bands streams.
 ... acrusher          A->A       Reduce audio bit resolution.
 .S. adeclick          A->A       Remove impulsive noise from input audio.
 .S. adeclip           A->A       Remove clipping from input audio.
 T.. adelay            A->A       Delay one or more audio channels.
 ... aderivative       A->A       Compute derivative of input audio.
 ... aecho             A->A       Add echoing to the audio.
 ... aemphasis         A->A       Audio emphasis.
 ... aeval             A->A       Filter audio signal according to a specified expression.
 T.. afade             A->A       Fade in/out input audio.
 TSC afftdn            A->A       Denoise audio samples using FFT.
 ... afftfilt          A->A       Apply arbitrary expressions to samples in frequency domain.
 .S. afir              AA->N      Apply Finite Impulse Response filter with supplied coefficients in 2nd stream.
 ... aformat           A->A       Convert the input audio to one of the specified formats.
 ... agate             A->A       Audio gate.
 .S. aiir              A->N       Apply Infinite Impulse Response filter with supplied coefficients.
 ... aintegral         A->A       Compute integral of input audio.
 ... ainterleave       N->A       Temporally interleave audio inputs.
 ... alimiter          A->A       Audio lookahead limiter.
 TSC allpass           A->A       Apply a two-pole all-pass filter.
 ... aloop             A->A       Loop audio samples.
 ... amerge            N->A       Merge two or more audio streams into a single multi-channel stream.
 T.. ametadata         A->A       Manipulate audio frame metadata.
 ... amix              N->A       Audio mixing.
 ... amultiply         AA->A      Multiply two audio streams.
 ..C anequalizer       A->N       Apply high-order audio parametric multi band equalizer.
 TSC anlmdn            A->A       Reduce broadband noise from stream using Non-Local Means.
 ... anull             A->A       Pass the source unchanged to the output.
 T.. apad              A->A       Pad audio with silence.
 ... aperms            A->A       Set permissions for the output audio frame.
 ... aphaser           A->A       Add a phasing effect to the audio.
 ... apulsator         A->A       Audio pulsator.
 ... arealtime         A->A       Slow down filtering to match realtime.
 ... aresample         A->A       Resample audio data.
 ... areverse          A->A       Reverse an audio clip.
 ... aselect           A->N       Select audio frames to pass in output.
 ... asendcmd          A->A       Send commands to filters.
 ... asetnsamples      A->A       Set the number of samples for each output audio frames.
 ... asetpts           A->A       Set PTS for the output audio frame.
 ... asetrate          A->A       Change the sample rate without altering the data.
 ... asettb            A->A       Set timebase for the audio output link.
 ... ashowinfo         A->A       Show textual information for each audio frame.
 T.. asidedata         A->A       Manipulate audio frame side data.
 T.. asoftclip         A->A       Audio Soft Clipper.
 ... asplit            A->N       Pass on the audio input to N audio outputs.
 ... astats            A->A       Show time domain statistics about audio frames.
 ..C astreamselect     N->N       Select audio streams
 ..C atempo            A->A       Adjust audio tempo.
 ... atrim             A->A       Pick one continuous section from the input, drop the rest.
 TSC bandpass          A->A       Apply a two-pole Butterworth band-pass filter.
 TSC bandreject        A->A       Apply a two-pole Butterworth band-reject filter.
 TSC bass              A->A       Boost or cut lower frequencies.
 TSC biquad            A->A       Apply a biquad IIR filter with the given coefficients.
 ... channelmap        A->A       Remap audio channels.
 ... channelsplit      A->N       Split audio into per-channel streams.
 ... chorus            A->A       Add a chorus effect to the audio.
 ... compand           A->A       Compress or expand audio dynamic range.
 ... compensationdelay A->A       Audio Compensation Delay Line.
 T.. crossfeed         A->A       Apply headphone crossfeed filter.
 ... crystalizer       A->A       Simple expand audio dynamic range filter.
 T.. dcshift           A->A       Apply a DC shift to the audio.
 T.. deesser           A->A       Apply de-essing to the audio.
 ... drmeter           A->A       Measure audio dynamic range.
 T.. dynaudnorm        A->A       Dynamic Audio Normalizer.
 ... earwax            A->A       Widen the stereo image.
 ... ebur128           A->N       EBU R128 scanner.
 TSC equalizer         A->A       Apply two-pole peaking equalization (EQ) filter.
 T.. extrastereo       A->A       Increase difference between stereo audio channels.
 ..C firequalizer      A->A       Finite Impulse Response Equalizer.
 ... flanger           A->A       Apply a flanging effect to the audio.
 ... haas              A->A       Apply Haas Stereo Enhancer.
 ... hdcd              A->A       Apply High Definition Compatible Digital (HDCD) decoding.
 .S. headphone         N->A       Apply headphone binaural spatialization with HRTFs in additional streams.
 TSC highpass          A->A       Apply a high-pass filter with 3dB point frequency.
 TSC highshelf         A->A       Apply a high shelf filter.
 ... join              N->A       Join multiple audio streams into multi-channel output.
 ... loudnorm          A->A       EBU R128 loudness normalization
 TSC lowpass           A->A       Apply a low-pass filter with 3dB point frequency.
 TSC lowshelf          A->A       Apply a low shelf filter.
 ... mcompand          A->A       Multiband Compress or expand audio dynamic range.
 ... pan               A->A       Remix channels with coefficients (panning).
 ... replaygain        A->A       ReplayGain scanner.
 ... sidechaincompress AA->A      Sidechain compressor.
 ... sidechaingate     AA->A      Audio sidechain gate.
 ... silencedetect     A->A       Detect silence.
 ... silenceremove     A->A       Remove silence.
 .S. sofalizer         A->A       SOFAlizer (Spatially Oriented Format for Acoustics).
 ... stereotools       A->A       Apply various stereo tools.
 T.. stereowiden       A->A       Apply stereo widening effect.
 ... superequalizer    A->A       Apply 18 band equalization filter.
 .S. surround          A->A       Apply audio surround upmix filter.
 TSC treble            A->A       Boost or cut upper frequencies.
 ... tremolo           A->A       Apply tremolo effect.
 ... vibrato           A->A       Apply vibrato effect.
 T.C volume            A->A       Change input volume.
 ... volumedetect      A->A       Detect audio volume.
 ... aevalsrc          |->A       Generate an audio signal generated by an expression.
 ... anoisesrc         |->A       Generate a noise audio signal.
 ... anullsrc          |->A       Null audio source, return empty audio frames.
 ... hilbert           |->A       Generate a Hilbert transform FIR coefficients.
 ... sinc              |->A       Generate a sinc kaiser-windowed low-pass, high-pass, band-pass, or band-reject FIR coefficients.
 ... sine              |->A       Generate sine wave audio signal.
 ... anullsink         A->|       Do absolutely nothing with the input audio.
 ... alphaextract      V->N       Extract an alpha channel as a grayscale image component.
 ... alphamerge        VV->V      Copy the luma value of the second input into the alpha channel of the first input.
 .S. amplify           V->V       Amplify changes between successive video frames.
 ... ass               V->V       Render ASS subtitles onto input video using the libass library.
 TS. atadenoise        V->V       Apply an Adaptive Temporal Averaging Denoiser.
 TS. avgblur           V->V       Apply Average Blur filter.
 T.. bbox              V->V       Compute bounding box for each frame.
 ... bench             V->V       Benchmark part of a filtergraph.
 T.. bitplanenoise     V->V       Measure bit plane noise.
 ... blackdetect       V->V       Detect video intervals that are (almost) black.
 ... blackframe        V->V       Detect frames that are (almost) black.
 TS. blend             VV->V      Blend two video frames into each other.
 TS. bm3d              N->V       Block-Matching 3D denoiser.
 T.. boxblur           V->V       Blur the input.
 TS. bwdif             V->V       Deinterlace the input image.
 TS. chromahold        V->V       Turns a certain color range into gray.
 TS. chromakey         V->V       Turns a certain color into transparency. Operates on YUV colors.
 TS. chromashift       V->V       Shift chroma.
 ... ciescope          V->V       Video CIE scope.
 T.. codecview         V->V       Visualize information about some codecs.
 TS. colorbalance      V->V       Adjust the color balance.
 TS. colorchannelmixer V->V       Adjust colors by mixing color channels.
 TS. colorkey          V->V       Turns a certain color into transparency. Operates on RGB colors.
 TS. colorhold         V->V       Turns a certain color range into gray. Operates on RGB colors.
 TS. colorlevels       V->V       Adjust the color levels.
 TS. colormatrix       V->V       Convert color matrix.
 TS. colorspace        V->V       Convert between colorspaces.
 TS. convolution       V->V       Apply convolution filter.
 TS. convolve          VV->V      Convolve first video stream with second video stream.
 ... copy              V->V       Copy the input video unchanged to the output.
 ... cover_rect        V->V       Find and cover a user specified object.
 ..C crop              V->V       Crop the input video.
 T.. cropdetect        V->V       Auto-detect crop size.
 ... cue               V->V       Delay filtering to match a cue.
 TS. curves            V->V       Adjust components curves.
 .S. datascope         V->V       Video data analysis.
 TS. dctdnoiz          V->V       Denoise frames using 2D DCT.
 TS. deband            V->V       Debands video.
 T.. deblock           V->V       Deblock video.
 ... decimate          N->V       Decimate frames (post field matching filter).
 TS. deconvolve        VV->V      Deconvolve first video stream with second video stream.
 TS. dedot             V->V       Reduce cross-luminance and cross-color.
 TS. deflate           V->V       Apply deflate effect.
 ... deflicker         V->V       Remove temporal frame luminance variations.
 ... deinterlace_qsv   V->V       QuickSync video deinterlacing
 ... dejudder          V->V       Remove judder produced by pullup.
 T.. delogo            V->V       Remove logo from input video.
 T.. derain            V->V       Apply derain filter to the input.
 ... deshake           V->V       Stabilize shaky video.
 TS. despill           V->V       Despill video.
 ... detelecine        V->V       Apply an inverse telecine pattern.
 TS. dilation          V->V       Apply dilation effect.
 T.. displace          VVV->V     Displace pixels.
 ... doubleweave       V->V       Weave input video fields into double number of frames.
 T.. drawbox           V->V       Draw a colored box on the input video.
 ... drawgraph         V->V       Draw a graph using input video metadata.
 T.. drawgrid          V->V       Draw a colored grid on the input video.
 T.C drawtext          V->V       Draw text on top of video frames using libfreetype library.
 T.. edgedetect        V->V       Detect and draw edge.
 ... elbg              V->V       Apply posterize effect, using the ELBG algorithm.
 T.. entropy           V->V       Measure video frames entropy.
 T.C eq                V->V       Adjust brightness, contrast, gamma, and saturation.
 TS. erosion           V->V       Apply erosion effect.
 ... extractplanes     V->N       Extract planes as grayscale frames.
 .S. 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.. 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.
 T.. fspp              V->V       Apply Fast Simple Post-processing filter.
 TS. gblur             V->V       Apply Gaussian Blur filter.
 TS. geq               V->V       Apply generic equation to each pixel.
 T.. gradfun           V->V       Debands video quickly using gradients.
 ... graphmonitor      V->V       Show various filtergraph stats.
 TS. greyedge          V->V       Estimates scene illumination by grey edge assumption.
 TS. haldclut          VV->V      Adjust colors using a Hald CLUT.
 TS. hflip             V->V       Horizontally flip the input video.
 T.. histeq            V->V       Apply global color histogram equalization.
 ... histogram         V->V       Compute and draw a histogram.
 T.. hqdn3d            V->V       Apply a High Quality 3D Denoiser.
 .S. hqx               V->V       Scale the input by 2, 3 or 4 using the hq*x magnification algorithm.
 ... hstack            N->V       Stack video inputs horizontally.
 T.C hue               V->V       Adjust the hue and saturation of the input video.
 ... hwdownload        V->V       Download a hardware frame to a normal frame
 ... hwmap             V->V       Map hardware frames
 ... hwupload          V->V       Upload a normal frame to a hardware frame
 ... hwupload_cuda     V->V       Upload a system memory frame to a CUDA device.
 T.. hysteresis        VV->V      Grow first stream into second stream by connecting components.
 ... idet              V->V       Interlace detect Filter.
 T.. il                V->V       Deinterleave or interleave fields.
 TS. inflate           V->V       Apply inflate effect.
 ... interlace         V->V       Convert progressive video into interlaced.
 ... interleave        N->V       Temporally interleave video inputs.
 ... kerndeint         V->V       Apply kernel deinterlacing to the input.
 .S. lagfun            V->V       Slowly update darker pixels.
 .S. lenscorrection    V->V       Rectify the image by correcting for lens distortion.
 TS. limiter           V->V       Limit pixels components to the specified range.
 ... loop              V->V       Loop video frames.
 TS. lumakey           V->V       Turns a certain luma into transparency.
 TS. lut               V->V       Compute and apply a lookup table to the RGB/YUV input video.
 TS. lut1d             V->V       Adjust colors using a 1D LUT.
 TS. lut2              VV->V      Compute and apply a lookup table from two video inputs.
 TS. lut3d             V->V       Adjust colors using a 3D LUT.
 TS. lutrgb            V->V       Compute and apply a lookup table to the RGB input video.
 TS. lutyuv            V->V       Compute and apply a lookup table to the YUV input video.
 TS. maskedclamp       VVV->V     Clamp first stream with second stream and third stream.
 TS. maskedmerge       VVV->V     Merge first stream with second stream using third stream as mask.
 TS. maskfun           V->V       Create Mask.
 ... mcdeint           V->V       Apply motion compensating deinterlacing.
 ... mergeplanes       N->V       Merge planes.
 ... mestimate         V->V       Generate motion vectors.
 T.. metadata          V->V       Manipulate video frame metadata.
 T.. midequalizer      VV->V      Apply Midway Equalization.
 ... minterpolate      V->V       Frame rate conversion using Motion Interpolation.
 .S. mix               N->V       Mix video inputs.
 ... mpdecimate        V->V       Remove near-duplicate frames.
 TS. negate            V->V       Negate input video.
 TS. nlmeans           V->V       Non-local means denoiser.
 T.. nnedi             V->V       Apply neural network edge directed interpolation intra-only deinterlacer.
 ... noformat          V->V       Force libavfilter not to use any of the specified pixel formats for the input to the next filter.
 TS. noise             V->V       Add noise.
 T.. normalize         V->V       Normalize RGB video.
 ... null              V->V       Pass the source unchanged to the output.
 T.. oscilloscope      V->V       2D Video Oscilloscope.
 TSC overlay           VV->V      Overlay a video source on top of the input.
 ... overlay_qsv       VV->V      Quick Sync Video overlay.
 T.. owdenoise         V->V       Denoise using wavelets.
 ... pad               V->V       Pad the input video.
 ... palettegen        V->V       Find the optimal palette for a given stream.
 ... paletteuse        VV->V      Use a palette to downsample an input video stream.
 ... perms             V->V       Set permissions for the output video frame.
 TS. perspective       V->V       Correct the perspective of video.
 T.. phase             V->V       Phase shift fields.
 ... pixdesctest       V->V       Test pixel format definitions.
 T.. pixscope          V->V       Pixel data analysis.
 T.C pp                V->V       Filter video using libpostproc.
 T.. pp7               V->V       Apply Postprocessing 7 filter.
 TS. premultiply       N->V       PreMultiply first stream with first plane of second stream.
 TS. prewitt           V->V       Apply prewitt operator.
 T.. pseudocolor       V->V       Make pseudocolored video frames.
 ... psnr              VV->V      Calculate the PSNR between two video streams.
 ... pullup            V->V       Pullup from field sequence to frames.
 T.. qp                V->V       Change video quantization parameters.
 ... random            V->V       Return random frames.
 T.. readeia608        V->V       Read EIA-608 Closed Caption codes from input video and write them to frame metadata.
 ... readvitc          V->V       Read vertical interval timecode and write it to frame metadata.
 ... realtime          V->V       Slow down filtering to match realtime.
 TS. remap             VVV->V     Remap pixels.
 TS. removegrain       V->V       Remove grain.
 T.. removelogo        V->V       Remove a TV logo based on a mask image.
 ... repeatfields      V->V       Hard repeat fields based on MPEG repeat field flag.
 ... reverse           V->V       Reverse a clip.
 TS. rgbashift         V->V       Shift RGBA.
 TS. roberts           V->V       Apply roberts cross operator.
 TSC rotate            V->V       Rotate the input image.
 T.. sab               V->V       Apply shape adaptive blur.
 ..C scale             V->V       Scale the input video size and/or convert the image format.
 ... scale_qsv         V->V       QuickSync video scaling and format conversion
 ..C scale2ref         VV->VV     Scale the input video size and/or convert the image format to the given reference.
 ... select            V->N       Select video frames to pass in output.
 TS. selectivecolor    V->V       Apply CMYK adjustments to specific color ranges.
 ... sendcmd           V->V       Send commands to filters.
 ... separatefields    V->V       Split input video frames into fields.
 ... setdar            V->V       Set the frame display aspect ratio.
 ... setfield          V->V       Force field for the output video frame.
 ... setparams         V->V       Force field, or color property for the output video frame.
 ... setpts            V->V       Set PTS for the output video frame.
 ... setrange          V->V       Force color range for the output video frame.
 ... setsar            V->V       Set the pixel sample aspect ratio.
 ... settb             V->V       Set timebase for the video output link.
 ... showinfo          V->V       Show textual information for each video frame.
 T.. showpalette       V->V       Display frame palette.
 T.. shuffleframes     V->V       Shuffle video frames.
 T.. shuffleplanes     V->V       Shuffle video planes.
 T.. sidedata          V->V       Manipulate video frame side data.
 .S. signalstats       V->V       Generate statistics from video analysis.
 ... signature         N->V       Calculate the MPEG-7 video signature
 T.. smartblur         V->V       Blur the input video without impacting the outlines.
 TS. sobel             V->V       Apply sobel operator.
 ... split             V->N       Pass on the input to N video outputs.
 T.C spp               V->V       Apply a simple post processing filter.
 T.. sr                V->V       Apply DNN-based image super resolution to the input.
 ... ssim              VV->V      Calculate the SSIM between two video streams.
 .S. stereo3d          V->V       Convert video stereoscopic 3D view.
 ..C streamselect      N->N       Select video streams
 ... subtitles         V->V       Render text subtitles onto input video using the libass library.
 ... super2xsai        V->V       Scale the input by 2x using the Super2xSaI pixel art algorithm.
 T.. swaprect          V->V       Swap 2 rectangular objects in video.
 T.. swapuv            V->V       Swap U and V components.
 TS. tblend            V->V       Blend successive frames.
 ... telecine          V->V       Apply a telecine pattern.
 TS. threshold         VVVV->V    Threshold first video stream using other video streams.
 ... thumbnail         V->V       Select the most representative frame in a given sequence of consecutive frames.
 ... tile              V->V       Tile several successive frames together.
 ... tinterlace        V->V       Perform temporal field interlacing.
 TS. tlut2             V->V       Compute and apply a lookup table from two successive frames.
 TS. tmix              V->V       Mix successive video frames.
 .S. tonemap           V->V       Conversion to/from different dynamic ranges.
 ... tpad              V->V       Temporarily pad video frames.
 .S. transpose         V->V       Transpose input video.
 ... trim              V->V       Pick one continuous section from the input, drop the rest.
 TS. unpremultiply     N->V       UnPreMultiply first stream with first plane of second stream.
 TS. unsharp           V->V       Sharpen or blur the input video.
 T.. uspp              V->V       Apply Ultra Simple / Slow Post-processing filter.
 T.. vaguedenoiser     V->V       Apply a Wavelet based Denoiser.
 ... vectorscope       V->V       Video vectorscope.
 T.. vflip             V->V       Flip the input video vertically.
 ... vfrdet            V->V       Variable frame rate detect filter.
 TS. vibrance          V->V       Boost or alter saturation.
 ... vidstabdetect     V->V       Extract relative transformations, pass 1 of 2 for stabilization (see vidstabtransform for pass 2).
 ... vidstabtransform  V->V       Transform the frames, pass 2 of 2 for stabilization (see vidstabdetect for pass 1).
 T.. vignette          V->V       Make or reverse a vignette effect.
 ... vmafmotion        V->V       Calculate the VMAF Motion score.
 ... vpp_qsv           V->V       Quick Sync Video VPP.
 ... vstack            N->V       Stack video inputs vertically.
 TS. w3fdif            V->V       Apply Martin Weston three field deinterlace.
 .S. waveform          V->V       Video waveform monitor.
 ... weave             V->V       Weave input video fields into frames.
 .S. xbr               V->V       Scale the input using xBR algorithm.
 .S. xmedian           N->V       Pick median pixels from several video inputs.
 ... xstack            N->V       Stack video inputs into custom layout.
 TS. yadif             V->V       Deinterlace the input image.
 ... zoompan           V->V       Apply Zoom & Pan effect.
 ..C zscale            V->V       Apply resizing, colorspace and bit depth conversion.
 ... allrgb            |->V       Generate all RGB colors.
 ... allyuv            |->V       Generate all yuv colors.
 ... cellauto          |->V       Create pattern generated by an elementary cellular automaton.
 ..C color             |->V       Provide an uniformly colored input.
 ... haldclutsrc       |->V       Provide an identity Hald CLUT.
 ... life              |->V       Create life.
 ... mandelbrot        |->V       Render a Mandelbrot fractal.
 ... mptestsrc         |->V       Generate various test pattern.
 ... nullsrc           |->V       Null video source, return unprocessed video frames.
 ... pal75bars         |->V       Generate PAL 75% color bars.
 ... pal100bars        |->V       Generate PAL 100% color bars.
 ... rgbtestsrc        |->V       Generate RGB test pattern.
 ... smptebars         |->V       Generate SMPTE color bars.
 ... smptehdbars       |->V       Generate SMPTE HD color bars.
 ... testsrc           |->V       Generate test pattern.
 ... testsrc2          |->V       Generate another test pattern.
 ... yuvtestsrc        |->V       Generate YUV test pattern.
 ... nullsink          V->|       Do absolutely nothing with the input video.
 ... abitscope         A->V       Convert input audio to audio bit scope video output.
 ... adrawgraph        A->V       Draw a graph using input audio metadata.
 ... agraphmonitor     A->V       Show various filtergraph stats.
 ... ahistogram        A->V       Convert input audio to histogram video output.
 ... aphasemeter       A->N       Convert input audio to phase meter video output.
 ... avectorscope      A->V       Convert input audio to vectorscope video output.
 ..C concat            N->N       Concatenate audio and video streams.
 ... showcqt           A->V       Convert input audio to a CQT (Constant/Clamped Q Transform) spectrum video output.
 ... showfreqs         A->V       Convert input audio to a frequencies video output.
 .S. showspatial       A->V       Convert input audio to a spatial video output.
 .S. showspectrum      A->V       Convert input audio to a spectrum video output.
 .S. showspectrumpic   A->V       Convert input audio to a spectrum video output single picture.
 ... showvolume        A->V       Convert input audio volume to video output.
 ... showwaves         A->V       Convert input audio to a video output.
 ... showwavespic      A->V       Convert input audio to a video output single picture.
 ... spectrumsynth     VV->A      Convert input spectrum videos to audio output.
 ..C amovie            |->N       Read audio from a movie source.
 ..C movie             |->N       Read from a movie source.
 ... afifo             A->A       Buffer input frames and send them when they are requested.
 ... fifo              V->V       Buffer input images and send them when they are requested.
 ... abuffer           |->A       Buffer audio frames, and make them accessible to the filterchain.
 ... buffer            |->V       Buffer video frames, and make them accessible to the filterchain.
 ... abuffersink       A->|       Buffer audio frames, and make them available to the end of the filter graph.
 ... buffersink        V->|       Buffer video frames, and make them available to the end of the filter graph.

三、滤镜的官方介绍文档

文档地址:https://ffmpeg.org/ffmpeg-all.html#Video-Filters

四、ffmpeg使用滤镜(代码调用API实现)

下面代码演示如何使用FFmpeg的API进行视频界面渲染并应用滤镜:

#include <stdio.h>
#include <libavutil/opt.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>

int main() {
    // 注册所有的FFmpeg组件
    av_register_all();
    avfilter_register_all();

    // 打开输入文件
    AVFormatContext* formatContext = NULL;
    if (avformat_open_input(&formatContext, "input.mp4", NULL, NULL) != 0) {
        printf("无法打开输入文件n");
        return -1;
    }

    // 获取视频流信息
    if (avformat_find_stream_info(formatContext, NULL) < 0) {
        printf("无法获取流信息n");
        return -1;
    }

    // 寻找视频流索引
    int videoStreamIndex = -1;
    for (int i = 0; i < formatContext->nb_streams; i++) {
        if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
            videoStreamIndex = i;
            break;
        }
    }

    if (videoStreamIndex == -1) {
        printf("找不到视频流n");
        return -1;
    }

    // 获取视频流解码器参数
    AVCodecParameters* codecParameters = formatContext->streams[videoStreamIndex]->codecpar;

    // 打开视频解码器
    AVCodec* codec = avcodec_find_decoder(codecParameters->codec_id);
    if (codec == NULL) {
        printf("无法找到解码器n");
        return -1;
    }

    AVCodecContext* codecContext = avcodec_alloc_context3(codec);
    if (avcodec_parameters_to_context(codecContext, codecParameters) != 0) {
        printf("无法初始化解码器上下文n");
        return -1;
    }

    if (avcodec_open2(codecContext, codec, NULL) < 0) {
        printf("无法打开解码器n");
        return -1;
    }

    // 创建滤镜图表
    AVFilterGraph* filterGraph = avfilter_graph_alloc();
    AVFilterContext* buffersrcContext = NULL;
    AVFilterContext* buffersinkContext = NULL;

    // 创建输入滤镜
    AVFilter* buffersrc = avfilter_get_by_name("buffer");
    AVFilterInOut* inputs = avfilter_inout_alloc();
    AVBufferSinkParams* buffersinkParams = av_buffersink_params_alloc();

    avfilter_graph_create_filter(&buffersrcContext, buffersrc, "in", NULL, NULL, filterGraph);
    av_opt_set_bin(buffersrcContext, "video_size", codecParameters->extradata, codecParameters->extradata_size, AV_OPT_SEARCH_CHILDREN);
    av_opt_set_bin(buffersrcContext, "pix_fmt", (uint8_t*)&codecParameters->format, sizeof(codecParameters->format), AV_OPT_SEARCH_CHILDREN);

    // 创建输出滤镜
    AVFilter* buffersink = avfilter_get_by_name("buffersink");
    avfilter_graph_create_filter(&buffersinkContext, buffersink, "out", NULL, NULL, filterGraph);
    av_opt_set_bin(buffersinkContext, "pix_fmts", (uint8_t*)&codecParameters->format, sizeof(codecParameters->format), AV_OPT_SEARCH_CHILDREN);

    // 链接滤镜
    inputs->name = av_strdup("out");
    inputs->filter_ctx = buffersrcContext;
    inputs->pad_idx = 0;
    inputs->next = NULL;

    AVFilterInOut* outputs = avfilter_inout_alloc();
    outputs->name = av_strdup("in");
    outputs->filter_ctx = buffersinkContext;
    outputs->pad_idx = 0;
    outputs->next = NULL;

    if (avfilter_graph_parse_ptr(filterGraph, "null", &inputs, &outputs, NULL) < 0) {
        printf("无法解析滤镜图表n");
        return -1;
    }

    if (avfilter_graph_config(filterGraph, NULL) < 0) {
        printf("无法配置滤镜图表n");
        return -1;
    }

    // 解码并处理视频帧
    AVPacket packet;
    AVFrame* frame = av_frame_alloc();

    while (av_read_frame(formatContext, &packet) >= 0) {
        if (packet.stream_index == videoStreamIndex) {
            if (avcodec_send_packet(codecContext, &packet) < 0) {
                printf("无法发送解码数据n");
                break;
            }

            while (avcodec_receive_frame(codecContext, frame) == 0) {
                // 应用滤镜
                if (av_buffersrc_add_frame_flags(buffersrcContext, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
                    printf("无法添加帧到输入滤镜n");
                    break;
                }

                while (av_buffersink_get_frame(buffersinkContext, frame) >= 0) {
                    // 处理滤镜输出的帧数据
                    // 在这里可以进行渲染或其他处理操作
                }
            }
        }

        av_packet_unref(&packet);
    }

    // 清理资源
    av_frame_free(&frame);
    avcodec_free_context(&codecContext);
    avformat_close_input(&formatContext);
    avfilter_graph_free(&filterGraph);
    avfilter_inout_free(&inputs);
    avfilter_inout_free(&outputs);

    return 0;
}

五、下载最新ffmpeg

官网:https://ffmpeg.org/download.html#build-windows

可以直接下载源码。

如果要下载构建好的库文件和可执行文件直接使用,可以点击这里。(我这里以Windows系统为例)

下载地址:https://github.com/BtbN/FFmpeg-Builds/releases

一个是静态文件(适合直接使用ffmpeg的3个工具),一个动态库+可执行文件(比较适合二次开发,包含了头文件、库文件)。

六、ffplay.exe使用滤镜

6.1 使用滤镜的语法

要在使用ffplay.exe播放视频时添加滤镜参数,可以使用以下命令行格式:

ffplay -vf <filter_name> <input_file>

<filter_name>替换为要使用的滤镜名称,将<input_file>替换为要播放的视频文件路径。

例如,如果要使用黑白滤镜(hue=s=0)播放名为input.mp4的视频文件,可以运行以下命令:

ffplay -vf "hue=s=0" input.mp4

这将在ffplay中应用黑白滤镜并播放视频。

注意:滤镜参数需要放在双引号内,以便正确解析滤镜选项。

6.2 黑白滤镜

【1】未使用滤镜的效果

【2】使用滤镜之后的效果

6.3 九宮格滤镜

在ffplay中,为了达到九宫格效果,可以使用crop滤镜和tile滤镜的组合。

ffplay -vf "crop=iw/3:ih/3:0:0, tile=3x3" D:/123.mp4

这个命令使用crop滤镜将视频分割成3行3列的九个部分。crop滤镜的参数iw/3:ih/3表示每个部分的宽度和高度是原始视频宽度和高度的1/3。然后使用tile滤镜将九个部分拼接成九宫格效果。

6.4 矩形框绘制滤镜

要在视频中间绘制一个200x200的红色矩形,可以使用 drawbox 滤镜。

ffplay.exe -i input.mp4 -vf "drawbox=x=(iw-200)/2:y=(ih-200)/2:w=200:h=200:color=red"

参数解释:

• x=(iw-200)/2:矩形框的 x 坐标。

iw 表示输入视频的宽度。

(iw-200)/2 表示将矩形框的左上角横坐标设置为视频宽度减去 200 的一半,即将其居中显示。•

y=(ih-200)/2:矩形框的 y 坐标。

ih 表示输入视频的高度。

(ih-200)/2 表示将矩形框的左上角纵坐标设置为视频高度减去 200 的一半,即将其居中显示。•

w=200:矩形框的宽度,这里设置为 200。•

h=200:矩形框的高度,这里设置为 200。•

color=red:矩形框的颜色,这里设置为红色。

通过设置这些参数,drawbox 滤镜将在视频的中心位置绘制一个红色的 200x200 矩形框。

6.5 旋转角度滤镜

ffplay.exe -i D:/123.mp4 -vf "rotate=180"

相关推荐