windowsbatch-fileffmpeggopropicture-in-picture

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


this is my first post on this forum, so please be gentle in case I accidentally do trip over any forum rules that I would not know of yet :).

I would like to apply some color-grading to underwater GoPro footage. To quicker gauge the effect of my color settings (trial-and-error, as of yet), would like to see the original input video stream as a PIP (e.g., scaled down to 50% or even 30%), in the bottom-right corner of the converted output movie.

I have one input movie that is going to be color graded. The PIP should use the original as an input, just a scaled-down version of it.

I would like to use ffmpeg's "-filter_complex" option to do the PIP, but all examples I can find on "-filter_complex" would use two already existing movies. Instead, I would like to make the color-corrected stream an on-the-fly input to "-filter_complex", which then renders the PIP.

Is that doable, all in one go?

Both the individual snippets below work fine, I now would like to combine these and skip the creation of an intermediate color-graded TMP output which then gets combined, with the original, in a final PIP creation process. Your help combining these two separate steps into one single "-filter_complex" action is greatly appreciated!

Thanks in advance, raven.

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

Solution

  • 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
    

    This is a simplified command. You'll need to enter your convolution and colorbalance values and integrate it into your batch file.

    Description:

    1. [0] refers to the first (and only in this case) input file and is the input for the scale filter. The output from scale is arbitrarily named [pip]. You can give it just about any name you prefer. See Filtering Introduction, Filtergraph description, and Filtergraph syntax for more info.
    2. [0] is also used as the input for convolution. The output from convolution is fed directly to colorbalance. Linear chains of filters are connected via a comma (see above link). The output from colorbalance is named [bg].
    3. overlay needs two inputs which are [bg] and [pip]. [pip] is overlaid on [bg]. The output from overlay is named [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 behavior.
    5. I'm assuming the input audio is AAC, so you can stream copy the audio instead of re-encoding it. If not then you can remove -c:a copy and a default encoder will be chosen depending on your output file format or you can choose a specific encoder.