I am using this command to convert to flat a small region of an equirectangular image (BTW: how can I specify how much large the section is?):

ffmpeg -hide_banner    -i input.png -vf v360=e:flat -y output1.png

full image equirect

Extracted section:


The I modify the cropping as I need:

edited section

Then I convert it back to equirectangular:

ffmpeg  -hide_banner -i output1.png -vf v360=flat:e -y output2.png

I get a big equirectangular white image, with my section in the center:

equi section

Now I want to overlay it to the original image...

ffmpeg  -hide_banner   -i input.png  -i  output2.png -filter_complex "overlay" -y output3.png

... but of course the original image is completely hidden by the white part of output2.png, unless I manually open it in IrfanView, set the white as transparent, and save the image before overlaying it on the original image.

Can I use FFMpeg to set as transparent the white part of the image without usaing IrfanView? I experimented randomly with fillcolor and color, but I don't get it.

But there is an additional issue: the color which ffmpeg uses to fill the empty area surrounding the cropping is not always the same: it's white in this example, but in other tests it is light gray, dark grey, other colors, so a side question is:

  • How can I specify the color used by ffmpeg to surround the cropping converted to equirectangular?
  • If I cannot specify the color to be used, can I at least use ffmpeg to read it, so I can then use it as transparent color?
  • 3
    I’m voting to close this question because it is not about photography and would probably be better suited at Graphic Design SE
    – Michael C
    Aug 15 '21 at 22:44

Found the solution (*) thanks to @Saaru Lindestøkke , using colorkey to replace white color (0xFFFFFF) by "colorkey" (=chromakey = transparent). Script cleaned up and improved:

:: Parameters:
:: 1: source equirectangular image
:: 2: folder of the image
:: 3: yaw of the point of interest
:: 4: pitch of the point of interest
:: 5: quiet: only prints log messages; noquiet: print commands while executing
:: 6: clean: delete all temporary files  (optional)

@set LOGL=error
if %5%==quiet @echo off

Rem Inserts strings into the command environment. The set values
Rem can be used later by programs.
::----------- Extract image section ------------
@echo Centering image on desired point...
:: Keep projection equirectangular (abbreviated in "e"), but poin to another direction specified by yaw/pitch in degrees:
ffmpeg -hide_banner -loglevel %LOGL%   -i %2%1 -vf v360=e:e:yaw=-%3:pitch=-%4 -y %2test_equi_rotated-%1

@echo Extracing region to edit...
:: Convert equirectangular to flat, resulting by default in a small region, editable by the user:
ffmpeg -hide_banner -loglevel %LOGL%   -i %2test_equi_rotated-%1 -vf v360=e:flat -y %2test_crop_flat-%1

@echo Please write your text onto "test_crop_flat-%1"
@set /p=Hit ENTER to continue...

::-------- Convert edited extracted section back to equirectangular ---------------
@echo Converting crop+text back to equirectangular...
:: Convert back to equirectangular the small flat crop, filling the empty pixel by transparent color (i.e. replacing default white color by "colorkey"):
ffmpeg  -hide_banner -loglevel %LOGL% -i %2test_crop_flat-%1 -vf v360=flat:e,colorkey=0xFFFFFF:0.1 -y %2test_crop_equi-%1

::--------- Overlay edited extracted section on original image --------------
@echo Merging edited crop into rotated equirectangular image...
:: Paste edited section over original image
ffmpeg  -hide_banner  -loglevel %LOGL% -i %2test_equi_rotated-%1 -i  %2test_crop_equi-%1 -filter_complex overlay -y %2test_merge_rotated-%1

@echo Rotating the image back to original direction...
:: Rotate equirectangular image back to original direction
:: WARNING: I had to add "roll=2.1", else the image appears rotated w.r.t. origina, is it a FFMpeg bug?
ffmpeg  -hide_banner -loglevel %LOGL%  -i %2test_merge_rotated-%1 -vf v360=e:e:yaw=%3:pitch=%4:roll=2.1  -y %2test_merge-%1
if %6==clean goto :cleanup

@echo Output saved in "test_merge-%1"
@Echo Finished.
goto :eof

@echo Deleting temporary files...
del %2test_equi_rotated-%1
:: don' delete @del %2test_crop_flat-%1 , it's edited by the user
del %2test_crop_equi-%1
del %2test_merge_rotated-%1
@echo Output saved in "test_merge-%1"
@Echo Finished.

Typical usage:

overlay.bat test-base.png .\ 10 10 quiet clean

(*) Currently working only if ffmoeg uses white to fill the surrounding of cropped area.


I didn't test this, but you can probably add the chromakey filter:

ffmpeg  -hide_banner -i output1.png -vf v360=flat:e chromakey=white -y output2.png
  • [NULL @ 000001d6bcda0e80] Unable to find a suitable output format for 'chromakey=white' chromakey=white: Invalid argument
    – jumpjack
    Aug 15 '21 at 15:09
  • ok it's colorkey, not cromakey, I have the answer (but I still don't understand why I need the final "roll=2.1")
    – jumpjack
    Aug 15 '21 at 15:34
  • uh-oh, it is not always working, the color chosen by ffmpeg to fill the blank changes from an image to another. Any idea about how to read the color of a specific pixel with ffmpeg?
    – jumpjack
    Aug 16 '21 at 15:06
  • Have you checked the manual for colorkey? The similarity parameters seems to do what you want, not sure. Aug 16 '21 at 15:08
  • The problem is before: how FFMpeg chooses the color. I need to force it to a value defined by me, or to a value not used in the image, but which I must be able to read in some way.
    – jumpjack
    Aug 16 '21 at 16:30

I didn't test this, but can you use the alpha_mask option to the v360 command to set the unmapped region as transparent, instead of white?

ffmpeg  -hide_banner -i output1.png -vf v360=flat:e:alpha_mask=1 -y output2.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.