1

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

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

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

我想使用 ffmpeg 的“-filter_complex”选项来做 PIP,但我可以在“-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]
4

2 回答 2

1

这是一个修改过的(现在正在工作的)颜色分级批处理文件。

[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]

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

干杯,乌鸦。

于 2019-10-03T01:01:38.940 回答
1
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]。你可以给它任何你喜欢的名字。有关详细信息,请参阅过滤简介、过滤图描述和过滤图语法
  2. [0]也用作卷积的输入。卷积的输出直接馈送到色彩平衡。过滤器的线性链通过逗号连接(见上面的链接)。colorbalance 的输出名为[bg]
  3. 覆盖需要两个输入,它们是[bg][pip][pip]覆盖在 上[bg]。覆盖的输出名为[v].
  4. -map选项用于手动选择要放入输出的流。-map除非您完全了解默认流选择行为,否则养成使用习惯通常是一个好主意。
  5. 我假设输入音频是 AAC,因此您可以流式复制音频而不是重新编码。如果没有,那么您可以删除-c:a copy并根据您的输出文件格式选择默认编码器,或者您可以选择特定的编码器。
于 2019-10-02T21:38:28.033 回答