首页 > 其他分享 >FFmpeg Filtering

FFmpeg Filtering

时间:2024-11-10 10:41:03浏览次数:1  
标签:Filtering FFmpeg stream filter complex video filtergraph output

When transcoding, audio and video streams can be filtered before encoding, with either a simple or complex filtergraph.

3.3.1 Simple filtergraphs
Simple filtergraphs are those that have exactly one input and output, both of the same type (audio or video). They are configured with the per-stream -filter option (with -vf and -af aliases for -filter:v (video) and -filter:a (audio) respectively). Note that simple filtergraphs are tied to their output stream, so e.g. if you have multiple audio streams, -af will create a separate filtergraph for each one.

Taking the trancoding example from above, adding filtering (and omitting audio, for clarity) makes it look like this:

┌──────────┬───────────────┐
│ demuxer │ │ ┌─────────┐
╞══════════╡ video stream │ packets │ video │ frames
│INPUT.mkv │ ├─────────⮞│ decoder ├─────⮞───╮
│ │ │ └─────────┘ │
└──────────┴───────────────┘ │
╭───────────⮜───────────╯
│ ┌────────────────────────┐
│ │ simple filtergraph │
│ ╞════════════════════════╡
│ │ ┌───────┐ ┌───────┐ │
╰──⮞├─⮞│ yadif ├─⮞│ scale ├─⮞├╮
│ └───────┘ └───────┘ ││
└────────────────────────┘│


┌──────────┬───────────────┐ video ┌─────────┐ │
│ muxer │ │ packets │ video │ │
╞══════════╡ video stream │⮜─────────┤ encoder ├───────⮜───────╯
│OUTPUT.mp4│ │ │ │
│ │ │ └─────────┘
└──────────┴───────────────┘
3.3.2 Complex filtergraphs
Complex filtergraphs are those which cannot be described as simply a linear processing chain applied to one stream. This is the case, for example, when the graph has more than one input and/or output, or when output stream type is different from input. Complex filtergraphs are configured with the -filter_complex option. Note that this option is global, since a complex filtergraph, by its nature, cannot be unambiguously associated with a single stream or file. Each instance of -filter_complex creates a new complex filtergraph, and there can be any number of them.

A trivial example of a complex filtergraph is the overlay filter, which has two video inputs and one video output, containing one video overlaid on top of the other. Its audio counterpart is the amix filter.

3.4 Loopback decoders
While decoders are normally associated with demuxer streams, it is also possible to create "loopback" decoders that decode the output from some encoder and allow it to be fed back to complex filtergraphs. This is done with the -dec directive, which takes as a parameter the index of the output stream that should be decoded. Every such directive creates a new loopback decoder, indexed with successive integers starting at zero. These indices should then be used to refer to loopback decoders in complex filtergraph link labels, as described in the documentation for -filter_complex.

Decoding AVOptions can be passed to loopback decoders by placing them before -dec, analogously to input/output options.

E.g. the following example:

ffmpeg -i INPUT \
-map 0:v:0 -c:v libx264 -crf 45 -f null - \
-threads 3 -dec 0:0 \
-filter_complex '[0:v][dec:0]hstack[stack]' \
-map '[stack]' -c:v ffv1 OUTPUT
reads an input video and

(line 2) encodes it with libx264 at low quality;
(line 3) decodes this encoded stream using 3 threads;
(line 4) places decoded video side by side with the original input video;
(line 5) combined video is then losslessly encoded and written into OUTPUT.
Such a transcoding pipeline can be represented with the following diagram:

┌──────────┬───────────────┐
│ demuxer │ │ ┌─────────┐ ┌─────────┐ ┌────────────────────┐
╞══════════╡ video stream │ │ video │ │ video │ │ null muxer │
│ INPUT │ ├──⮞│ decoder ├──┬────────⮞│ encoder ├─┬─⮞│(discards its input)│
│ │ │ └─────────┘ │ │(libx264)│ │ └────────────────────┘
└──────────┴───────────────┘ │ └─────────┘ │
╭───────⮜──╯ ┌─────────┐ │
│ │loopback │ │
│ ╭─────⮜──────┤ decoder ├────⮜──╯
│ │ └─────────┘
│ │
│ │
│ │ ┌───────────────────┐
│ │ │complex filtergraph│
│ │ ╞═══════════════════╡
│ │ │ ┌─────────────┐ │
╰─╫─⮞├─⮞│ hstack ├─⮞├╮
╰─⮞├─⮞│ │ ││
│ └─────────────┘ ││
└───────────────────┘│

┌──────────┬───────────────┐ ┌─────────┐ │
│ muxer │ │ │ video │ │
╞══════════╡ video stream │⮜─┤ encoder ├───────⮜──────────╯
│ OUTPUT │ │ │ (ffv1) │
│ │ │ └─────────┘
└──────────┴───────────────┘

https://www.octfgroup.com/

标签:Filtering,FFmpeg,stream,filter,complex,video,filtergraph,output
From: https://www.cnblogs.com/sathcal/p/18537708

相关文章

  • FFmpeg Stream selection
    ffmpegprovidesthe-mapoptionformanualcontrolofstreamselectionineachoutputfile.Userscanskip-mapandletffmpegperformautomaticstreamselectionasdescribedbelow.The-vn/-an/-sn/-dnoptionscanbeusedtoskipinclusionofvideo,......
  • ffmpeg Synopsis
    1Synopsisffmpeg[global_options]{[input_file_options]-iinput_url}...{[output_file_options]output_url}...2Descriptionffmpegisauniversalmediaconverter.Itcanreadawidevarietyofinputs-includinglivegrabbing/recordingdevices-filter,......
  • About FFmpeg
    FFmpegistheleadingmultimediaframework,abletodecode,encode,transcode,mux,demux,stream,filterandplayprettymuchanythingthathumansandmachineshavecreated.Itsupportsthemostobscureancientformatsuptothecuttingedge.Nomatteri......
  • FFmpeg Libraries for developers
    libavutilisalibrarycontainingfunctionsforsimplifyingprogramming,includingrandomnumbergenerators,datastructures,mathematicsroutines,coremultimediautilities,andmuchmore.libavcodecisalibrarycontainingdecodersandencodersforaudio......
  • php使用ffmpeg实现向视频中添加文字字幕的方法
    这篇文章主要介绍了PHP使用ffmpeg给视频增加字幕显示的方法,实例分析了php操作ffmpeg给视频增加字母的技巧,具有一定参考借鉴价值,需要的朋友可以参考下。具体如下:$dir='./';if($handle=opendir($dir)){while(false!==($file=readdir($handle))){if(is_file($dir.$......
  • PHP中的FFmpeg安装及使用
    FFmpeg简介FFmpeg是视频处理最常用的开源软件。它功能强大,用途广泛,大量用于视频网站和商业软件(比如Youtube和iTunes),也是许多音频和视频格式的标准编码/解码实现。关于FFMPEG视音频编解码的知识可以参考大神雷霄骅的系列教程https://blog.csdn.net/leixiaohua1020/article/detai......
  • FFmpeg 简单介绍及使用
    1.简介FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开......
  • PHP ffmpeg 视频合并
    随着互联网的发展和视频技术的不断完善,视频在我们的生活中扮演着越来越重要的角色。但是,当前视频处理和编辑的需求也在不断增加,这就需要我们使用到一些专业的工具来帮助我们完成这项工作。其中,ffmpeg是一个非常流行的视频处理工具,它支持多种视频编解码格式,可以对视频进行编辑、剪......
  • php 安装ffmpeg扩展
    在使用PHP的ffmpeg扩展之前,我们首先需要安装它。1.下载ffmpeg源码我们可以在https://www.ffmpeg.org/download.html这个网址上下载最新的ffmpeg源码。2.安装ffmpeg在安装之前,我们需要安装一些必要的依赖库和工具:sudoapt-getupdatesudoapt-getinstallautoconfautomakeb......
  • PHP ffmpeg 剪辑视频
    随着互联网的发展和视频技术的不断完善,视频在我们的生活中扮演着越来越重要的角色。但是,当前视频处理和编辑的需求也在不断增加,这就需要我们使用到一些专业的工具来帮助我们完成这项工作。其中,ffmpeg是一个非常流行的视频处理工具,它支持多种视频编解码格式,可以对视频进行编辑、剪......