[FFmpeg-user] Make white of photo transparant

Cecil Westerhof Cecil at decebal.nl
Wed Jun 29 14:23:03 EEST 2022


Cecil Westerhof via ffmpeg-user <ffmpeg-user at ffmpeg.org> writes:

> Cecil Westerhof via ffmpeg-user <ffmpeg-user at ffmpeg.org> writes:
>
>> Paul B Mahol <onemda at gmail.com> writes:
>>
>>> On Wed, Jun 29, 2022 at 10:05 AM Bouke / Videotoolshed <
>>> bouke at videotoolshed.com> wrote:
>>>
>>>> On 29 Jun 2022, at 01:48, Cecil Westerhof via ffmpeg-user <
>>>> ffmpeg-user at ffmpeg.org> wrote:
>>>> >
>>>> >
>>>> > The background of the photo is white. Would it be possible to make
>>>> > that transparent? (So where there is white, I do not see white, but
>>>> > the video.)
>>>>
>>>> This is called Luma (or Luminance) key.
>>>>
>>>> Yes, it is possible, yes, it will be ugly unless you know what you are
>>>> doing, and IMHO, FFmpeg is not the tool for this.
>>>> (But someone recently mentioned a GUI for filters, that might help you big
>>>> time on this one.)
>>>>
>>>>
>>> Use colorkey filter, and set color as white.
>>
>> I will look it up.
>> I realise that I have a problem, because in some photos not only the
>> background is white. :'-(
>
> I tried the following:
>      ffmpeg -y -ss 21:50 -to 23:20 -i 00007-00010.MTS -i Photos/output.jpg                  \
>             -filter_complex '[1:v]colorkey=0xFFFFFF\:0.01[ckout];[0:v][ckout]overlay[out]'  \
>             -map '[out]'                                                                    \
>             -pix_fmt yuv420p -acodec copy -vcodec libx264 -preset veryfast -crf 26          \
>             -t 30 greenScreen.mp4
>
> It really does not look that bad. (But in this photo there is no
> white.)
> It does take some time to be generated,
>
> I have two challenges:
> - There is no audio.
> - How do I merge the two filters? (The picture should only displayed
>   for a short while.)

The problem of merging the two parts is solved:
     ffmpeg -y -ss 21:50 -to 23:20 -i input.MTS -i Photos/output.jpg                                \
            -filter_complex "[0:v][1:v] overlay=10:10:enable='between(t, 5, 85)',                   \
                                        colorkey=0xFFFFFF\:0.01[ckout];[0:v][ckout]overlay[out]"    \
            -map '[out]'                                                                            \
            -pix_fmt yuv420p -c:a:0 copy -vcodec libx264 -preset veryfast -crf 26                   \
            -t 30 greenScreen.mp4

How can I get the audio into the output?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the ffmpeg-user mailing list