ffmpeg - 颜色分级视频 material 并将原始源显示为画中画,使用 -filter_complex

ffmpeg - color-grading video material AND display original source as picture-in-picture, using -filter_complex

这是我第一次 post 在这个论坛上,所以请保持温柔以防我不小心绊倒了我还不知道的任何论坛规则:)。

我想对水下 GoPro 镜头应用一些颜色分级。为了更快地衡量我的颜色设置的效果(到目前为止,反复试验),我想将原始输入视频流视为画中画(例如,缩小到 50% 甚至 30%),在底部-转换后的输出影片的右上角。

我有一部要进行颜色分级的输入影片。 PIP 应该使用原件作为输入,只是它的缩小版本。

我想使用 ffmpeg 的“-filter_complex”选项来执行画中画,但我在“-filter_complex”上找到的所有示例都将使用两部已经存在的电影。相反,我想让颜色校正后的流成为“-filter_complex”的即时输入,然后呈现 PIP。

这是否可行,一次完成?

下面的两个片段都工作正常,我现在想将它们结合起来并跳过中间颜色分级 TMP 输出的创建,然后在最终的 PIP 创建过程中与原始输出结合。 非常感谢您帮助将这两个单独的步骤合并为一个“-filter_complex”操作!

提前致谢, 掠夺。

[existing code snippets (M$ batch files)]

::declarations/defines::
set "INPUT=<path-to-movie>"
set "TMP=<path-to-intermediate-output-movie>"
set "OUTPUT=<path-to-movie>"
set "FFMPG=<path-to-executable>"
set "QU=9" :: quality settings

set "CONV='"0 -1 0 -1 5 -1 0 -1 0:0 -1 0 -1 5 -1 0 -1 0:0 -1 0 -1 5 -1 
0 -1 0:0 -1 0 -1 5 -1 0 -1 0'"" :: sharpening convolution filter

::color-grading part::
%FFMPG% -i %INPUT% -vf convolution=%CONV%,colorbalance=rs=%rs%:gs=%gs%:bs=%bs%:rm=%rm%:gm=%gm%:bm=%bm%:rh=%rh%:gh=%gh%:bh=%bh% -q:v %QU% -codec:v mpeg4 %TMP%

::PIP part::
%FFMPG% -i %TMP% -i %INPUT% -filter_complex "[1]scale=iw/3:ih/3 
[pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10" -q:v 
%QU% -codec:v mpeg4 %OUTPUT%

[/existing code]
ffmpeg -i input -filter_complex "[0]scale=iw/3:-1[pip];[0]convolution,colorbalance[bg];[bg][pip]overlay=main_w-overlay_w-10:main_h-overlay_h-10[v]" -map "[v]" -map 0:a -c:a copy output

这是一个简化的命令。您需要输入卷积和色彩平衡值并将其集成到批处理文件中。

描述:

  1. [0] 指的是第一个(且仅在本例中)输入文件,是比例过滤器的输入。 scale 的输出被任意命名为 [pip]。你可以给它起任何你喜欢的名字。有关详细信息,请参阅 Filtering Introduction, Filtergraph description, and Filtergraph syntax
  2. [0]也作为卷积的输入。卷积的输出直接馈送到色彩平衡。过滤器的线性链通过逗号连接(见上文 link)。 colorbalance 的输出名为 [bg].
  3. overlay 需要两个输入,即 [bg][pip][pip] 叠加在 [bg] 上。 overlay 的输出命名为 [v].
  4. -map option is used to manually select the streams to put into the output. It is generally a good idea to get into the habit to use -map unless you fully understand the default stream selection 行为。
  5. 我假设输入音频是 AAC,因此您可以流式复制音频而不是重新编码。如果没有,那么您可以删除 -c:a copy,系统将根据您的输出文件格式选择默认编码器,或者您可以选择特定的编码器。

这是一个修改后的(现在可用的)颜色分级批处理文件。

[revised code (M$ batch file)]

@echo off
cls
rem ------------------------------------------------------------------------
rem Purpose: color correction, saturation, sharpening for underwater video. 
rem Function: color-grades video, inserts the original video in lower right
rem corner as a PIP (picture-in-picture) overlay, for comparison
rem Error handling: basic. 
rem                 Checks for availability of input video (%IN%)
rem                 Deletes possibly pre-existing output file (%OUTP%) 
rem Inputs: %IN%
rem Outputs: %OUTP% (with ungraded video as PIP) 
rem Parameters: To be tested with actual GoPro footage (manual 6500K setting) 
rem ------------------------------------------------------------------------

::declarations/defines::
set "IN=<path-to-movie>"
set "OUTP=<path-to-movie>"
set "FFMPG=<path-to-executable>"

::test availability of input file::
if not exist %IN% (
echo "Error: No input file (in.mp4) found. Aborting script."
goto eof
)

::remove potentially existing output file:: 
if exist %OUTP% DEL %OUTP%

::convolution (sharpening)::
set "CONV='0 -1 0 -1 5 -1 0 -1 0:0 -1 0 -1 5 -1 0 -1 0:0 -1 0 -1 5 -1 0 -1 0:0 -1 0 -1 5 -1 0 -1 0'"

::equalizer settings::
set "CONTRAST=1.0"        :: Contrast in range -1000 to 1000 (normal is 1.0)
set "BRIGHT=0.0"          :: Brightness in range -1.0 to 1.0 (normal is 0.0)
set "SATUR=1.05"          :: Saturation in range 0.0 to 3.0 (normal is 1.0; the higher, the more pure the colors will get)
set "GAMMA=1.15"          :: Gamma in range 0.1 to 10.0 (normal is 1.0; greater 1.0 is more contrast, darker shades, brighter highlights)

::colorlevels settings::
set "rmin=0.10"           :: colorlevel red minimum
set "gmin=0.05"           :: colorlevel green minimum
set "bmin=0.05"           :: colorlevel blue minimum
set "rmax=0.70"           :: colorlevel red maximum
set "gmax=1.00"           :: colorlevel green maximum
set "bmax=0.95"           :: colorlevel blue maximum

::colorbalance and hue::
set "HUE=-5"              :: Color correction (hue), negative shifts towards red and positive towards blue, normal is 0, typical is -30...+30 range
set "rs=+0.00"            ::   red - cyan    :: Adjust red, green and blue shadows (darkest pixels) 
set "gs=-0.10"            :: green - magenta ::
set "bs=-0.10"            ::  blue - yellow  ::

set "rm=+0.10"            ::   red - cyan    :: Adjust red, green and blue midtones (medium pixels)
set "gm=-0.25"            :: green - magenta ::
set "bm=-0.25"            ::  blue - yellow  ::

set "rh=+0.05"            ::   red - cyan    :: Adjust red, green and blue highlights (brightest pixels)
set "gh=-0.20"            :: green - magenta ::
set "bh=-0.20"            ::  blue - yellow  ::

::equalizer (contrast, brightness, saturation, gamma)::
set "EQUALIZER=contrast=%CONTRAST%:brightness=%BRIGHT%:saturation=%SATUR%:gamma=%GAMMA%"

::colorlevels::
set "COLORLEVELS=rimin=%rmin%:gimin=%gmin%:bimin=%bmin%:rimax=%rmax%:gimax=%gmax%:bimax=%bmax%"

::colorbalance::
set "COLORBALANCE=rs=%rs%:gs=%gs%:bs=%bs%:rm=%rm%:gm=%gm%:bm=%bm%:rh=%rh%:gh=%gh%:bh=%bh%"

::applying all of these filter settings (color-grading and PIP combined)::
::using libx264 encoding and "-preset ultrafast", "-crf 18" for high quality, as recommended (for quick preview purposes rather than smallest file sizes)::
%FFMPG% -i %IN% -filter_complex "[0]scale=iw/3:-1[pip];[0]colorbalance=%COLORBALANCE%[1],[1]hue=h=%HUE%[2],[2]colorlevels=%COLORLEVELS%[3],[3]eq=%EQUALIZER%[4],[4]convolution=%CONV%[bg];[bg][pip]overlay=main_w-overlay_w-10:main_h-overlay_h-10 [v]" -map "[v]" -map 0:a -c:a copy -c:v libx264 -preset ultrafast -crf 18 %OUTP%
goto eof

:: End
:eof

[/revised code]

很好的回复,学到了很多东西,非常感谢:))!!

干杯,乌鸦。