How to add a 2D texture to an Equirectangular image - theory

I have a 2D texture like some text and want to add it to an equirectangular image without it being distorted as it would be if I just paste it on top.
To clarify:
I have a 2D texture:
I have an equirectangular image (source):
if I just put the 2D texture on top in a 360 degree viewer it will look distorted so how do I get around this and convert it to an equirectangular texture? any help is greatly appreciated :)

I use this Windows Shell/DOS script, but there are some caveats, see below:
:: Parameters:
:: 1: source equirectangular image
:: 2: folder of the image
:: 3: yaw of the point of interest
:: 4: pitch of the point of interest
#set LOGL=error
Rem Inserts strings into the command environment. The set values
Rem can be used later by programs.
::----------- Extract image section ------------
#echo.
#echo Centering image on desired point...
ffmpeg -hide_banner -loglevel %LOGL% -i %2%1 -vf v360=e:e:yaw=-%3:pitch=-%4 -y %2test_equi_rotated-%1
#echo.
#echo Extracing region to edit...
ffmpeg -hide_banner -loglevel %LOGL% -i %2test_equi_rotated-%1 -vf v360=e:flat -y %2test_crop_flat-%1
#echo.
#echo Please write your text onto "test_crop_flat-%1"
#echo.
#set /p=Hit ENTER to continue...
::-------- Convert edited extracted section back to equirectangular ---------------
#echo.
#echo Converting crop+text back to equirectangular...
ffmpeg -hide_banner -loglevel %LOGL% -i %2test_crop_flat-%1 -vf v360=flat:e -y %2test_crop_equi-%1
#echo.
#echo Please save "%2test_crop_equi-%1" with transparency
#echo.
#set /p=Hit ENTER to continue...
::--------- Overlay edited extracted section on original image --------------
#echo.
#echo Merging edited crop into rotated 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.
#echo Rotating the image back to original direction:
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
#del %2test_merge_rotated-%1
#echo.
#echo Output saved in "test_merge-%1"
Example usage:
overlay.bat test-base.png .\ 10 10
Script is divided in 3 parts:
Extract from original ER image the region of interest and convert to flat projection
After this part the script stops, waiting for user to edit the extracted image at wish.
Reproject the edited section into equirectangular
After this part the script stops, waiting for user to save the temporary output adding transparency to image (I don't know how to do it with ffmpeg).
Paste the section back on the original image
Warning: I had to add a small roll to the final image, else upon converting back to equirectangular it appears slightly rotated, don't know why.

Related

FFMPEG, convert video same as input size with watermark in Batch

I would like to watermark some videos in a directory. I use a png watermark of 3840x2160 in size. The watermark should go in fullsize on the video. Because my videos have different resolutions I use this batch script
set /p add_watermark=Wasserzeichen Addieren? (Standard: ja/nein):
if /i "%add_watermark%" == "" set add_watermark=ja
if /i "%add_watermark%" == "ja" (
for %%f in (%cd%\output\tmp\*.mp4) do (
set "filename=%%~nf"
ffmpeg -i "%%f" -i %cd%\watermark\watermark.png -filter_complex "[0:v][1:v]scale2ref=oh*mdar:ih[v0][v1];[v0][v1]overlay=main_w-overlay_w-0:0" -c:a copy -map 0 -y "%cd%\output\%%~nf.mp4"
)
)
That works well with videos in 4k but if my input is a HD video it will scale the output up to 4k in the size of the watermark.
If I try to add
-c:v copy FFMPEG is giving out the error
Streamcopy requested for output stream fed from a complex filtergraph. Filtering and streamcopy cannot be used together.
My question is, how can I set the output as same size as the input video with the scaled watermark without doing this in two steps.
Because it seems there is no other idea how to archive this in on step without re-encoding i did a batch script that extracts the resolution from the video files and use it to change the link to a watermark.png in different resolutions.
As example:
watermark_1920x1080.png
watermark_2560x1440.png
watermark_3840x2160.png
and so on. This is only a impractical workarround (but well it works) i let this question open.

Run through files and applying filter for similar names BATCH and FFMPEG

I want to be able to run a script in a folder that contains different angles of a video for example: 0007A,0007B,0008A,0008B. I was able to create it by writing the group of videos but I have like 300 different pairs of those video files and I would like to automatize it, here the one I created using 4 angles:
set n=%1
set i=
set /p savingFolder=Please specify URL of the folder to save the files to:
:loop
set i=%i%!
SET /p groupOfVideos=Please write the group of videos you want me to process:
ffmpeg -i %groupOfVideos%E.avi -i %groupOfVideos%F.avi -i %groupOfVideos%G.avi -i %groupOfVideos%H.avi -filter_complex "[0:v][1:v]hstack=inputs=2[top]; [2:v][3:v]hstack=inputs=2[bottom]; [top][bottom]vstack=inputs=2[v]" -map "[v]" -c:v libx264 -pix_fmt yuv420p %groupOfVideos%Z.avi
if i == n GOTO end
move /Y %groupOfVideos%Z.avi %savingFolder%
GOTO loop
As You can see, the loop is created to go back to the question and asks for the next group of video to execute the command with ffmpeg. This time I just would like to include this maybe in a for so each time the for runs gets the pair and then execute the ffmpeg command without asking anything. I have two days thinking on this but maybe I'm looking in a different way.
ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for %%G in (*A.mp4) do (
set /p MP4A='file %%G'
if exist %MP4A:~0,4%B.mp4 (
set /p MP4B=%MP4A:~0,4%B.mp4
)
ffmpeg -i %MP4A% -i %MP4B% -filter_complex hstack=inputs=2 -c:v libx264 -pix_fmt yuv420p %MP4A:~0,4%L.mp4
pause
)

How to add cover art to MP4?

I'm trying to find an effective way to update the metadata for my MP4 files that I plan to put on a DLNA server. First thing, I want to have the video files have a cover art.
I'm specifically using 640x360 JPG files to be the cover art.
I might also want to add some other tags, like media type or update the Title. Please let me know what can be done.
If code suggestions are available, please know I have the file name details in a variable %file% to handle things. The JPG has the same name as the source MP4 file, so it's easy enough to get the file type and remove the extension, which is what I've done so far.
My goal is to be able to simply drop the MP4 file on the following batch file and know its filename and full path, the JPG file, and attach it to the orgininal MP4 file. Apparently ffmpeg.exe won't write to the file it pulled from, so I have it go to a temp file and then use MOVE to replace the old file with the fixed file.
#ECHO OFF
set arg=%1
set file=%arg:~1,-5%
ffmpeg -i "%file%.mp4" -i "%file%.jpg" -acodec copy -vcodec copy -map 0 -map 1:0 "%file%WIP.mp4"
move /Y "%file%WIP.mp4" "%file".mp4"
This code did not seem to work. It doesn't show up in Windows as the cover art, so I'd say it failed.
Can would do a try, by to change the argument and the position of -map 0 -map 1:0 to immediately after name file input -map 1 -map 0 along command line, so, this work to me...
Sorry my limited English.
#echo off & cd "%~dp0" && setlocal enableextensions enabledelayedexpansion
for %%i in (%*) do (
set "_arg=%%i"
set "_file=!_arg:~1,-5!"
if exist "!_file!.mp4" ffmpeg -i "!_file!.mp4" -i "!_file!.jpg"--map 1 -map 0 -acodec copy -vcodec copy "!_file!WIP.mp4" && move /Y "!_file!WIP.mp4" "!_file!".mp4"
shift
)

Timestamp doesn't work in batch file

c:
cd c:\ffmpeg\bin
ffmpeg -f dshow -video_size 320x240 -framerate 30 -pixel_format yuv420p -i video="Logitech HD Pro Webcam C910" -t 00:00:10 C:\ffmpeg\bin\video.mp4
ffmpeg -f dshow -i video="Logitech HD Pro Webcam C910" C:\ffmpeg\bin\picture1.jpeg
ffmpeg -f dshow -i video="Logitech HD Pro Webcam C910" C:\ffmpeg\bin\picture2.jpeg
move C:\ffmpeg\bin\picture1.jpeg C:\Users\Owner\Desktop\TestFolder
move C:\ffmpeg\bin\picture2.jpeg C:\Users\Owner\Desktop\TestFolder
move C:\ffmpeg\bin\video.mp4 C:\Users\Owner\Desktop\TestFolder
ren C:\Users\Owner\Desktop\TestFolder\picture1.jpeg Picture-%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.jpeg
ren C:\Users\Owner\Desktop\TestFolder\picture2.jpeg Picture-%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.jpeg
ren C:\Users\Owner\Desktop\TestFolder\video.mp4 Video-%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.mp4
taskkill /im ffmpeg.exe /t /f
I've created a batch file that will take a ten second video and two screenshots from my webcam. My batch file works correctly until I try to rename the files. I don't understand why it is not working because I've used this code on another computer before and just copied, pasted it, and adjusted the file names around so it would work for my purposes. Any help would be greatly appreciated.

how to strip a series of characters in dos batch file for filename generation

I've made a batch file for drag and drop conversion of video using ffmpeg.
I'm using avisynth script "avs" as input.
The generated video is "my video file.avs.mp4"
How can i make the generated video filename to be "my video file.mp4" ?
here is my batch:
#echo off
title Converting video for mobile phone... by xXx
ffmpeg.exe -y -i %1 -f mp4 -vcodec libxvid -b 150k -r 25 -maxrate 150k -bt 1k -bufsize 4M -acodec libfaac -ac 1 -ab 32 -ar 22050 -vol 20 -aspect 4:3 %1.mp4
title Finished!!! Press any key to close the window
echo.
echo.
echo.
echo "Success... press any key to close the window."
pause > nul
Thanks in advance!
I suppose your param %1 contains "my video file.avs"
Then this should work
ren "%~1.mp4" "%~n1.mp4"

Resources