News:

--

Main Menu

How to make two videos side by side ?

Started by still dont know, January 08, 2020, 06:59:51 PM

Previous topic - Next topic

still dont know

Hi everyone, somebody will explain to me how to make two movies side by side? That's even possible in this program?


dosdan

#2
I wasn't aware of FFMPEG's hstack. But I've done a side-by-side comparison of original vs processed clips (processed using FFMPEG's Image Stabiliser filter vid.stab). (Specifically, see Mode 2 in Part 3's stab_testbench.bat.):

PART 1 of 3
I believe the performance of FFMPEG's vid.stab, in 2-pass mode, is superior to Vdub's deshaker plugin. Unfortunately, vid.stab came from the linux world so some of the documentation is scanty, out of date (vid.stab was part of Transcode, http://public.hronopik.de/vid.stab/index.php?lang=en, but it was later added to FFMPEG), or not very helpful for Windows users.

The function of the "stepsize" parameter described in https://www.imakewebsites.ca/posts/2018/02/17/stabilizing-gopro-video-with-ffmpeg-and-vid.stab/  is wrong. A smaller stepsize is more accurate.

Also there was an undocumented change in the way stepsize interacts with accuracy. If you use a high accuracy setting between 10 and the max. of 15, the program automatically alters the stepsize to 6 (and the comments in the source code suggest that a stepsize of 4 may be more suitable).

Anyway, I'll post a couple of comparison examples and a FFMPEG stabilisation testbench.  First off, here's a purposely jerky (sped-up) YT clip that irritated me enough to get interested in applying software IS:

"What is "no-chilling" home brew?" (3m33s)
https://www.youtube.com/watch?v=Ih3jg3Xdcvs

I'm using this as a test clip. You can d/l this clip using youtube-dl.exe (https://ytdl-org.github.io/youtube-dl/index.html):

youtube-dl Ih3jg3Xdcvs  (You can use the full YouTube URL if you want, but it's not needed.)

This will d/l the highest resolution version which is 1080p48 (130MB). I used this for most of the testing, but the big size takes longer to process each time you change something.

For quick IS comparisons, the 480p30 works well enough. To see a list of available formats:

youtube-dl -F Ih3jg3Xdcvs


format code  extension  resolution note
249          webm       audio only tiny   58k , opus @ 50k (48000Hz), 1.35MiB
250          webm       audio only tiny   82k , opus @ 70k (48000Hz), 2.02MiB
140          m4a        audio only tiny  128k , m4a_dash container, mp4a.40.2@128k (44100Hz), 3.24MiB
251          webm       audio only tiny  160k , opus @160k (48000Hz), 3.92MiB
160          mp4        256x144    144p  112k , avc1.42c00c, 15fps, video only, 2.83MiB
278          webm       256x144    144p  117k , webm container, vp9, 15fps, video only, 2.55MiB
242          webm       426x240    240p  236k , vp9, 30fps, video only, 5.41MiB
133          mp4        426x240    240p  252k , avc1.4d4015, 30fps, video only, 6.30MiB
243          webm       640x360    360p  440k , vp9, 30fps, video only, 9.91MiB
134          mp4        640x360    360p  608k , avc1.4d401e, 30fps, video only, 10.74MiB
244          webm       854x480    480p  801k , vp9, 30fps, video only, 17.88MiB
135          mp4        854x480    480p 1114k , avc1.4d401f, 30fps, video only, 21.54MiB
247          webm       1280x720   720p 1613k , vp9, 30fps, video only, 35.44MiB
136          mp4        1280x720   720p 2220k , avc1.4d401f, 30fps, video only, 40.48MiB
302          webm       1280x720   720p48 2701k , vp9, 48fps, video only, 54.65MiB
248          webm       1920x1080  1080p 2919k , vp9, 30fps, video only, 65.28MiB
298          mp4        1280x720   720p48 3319k , avc1.4d4020, 48fps, video only, 69.27MiB
137          mp4        1920x1080  1080p 4275k , avc1.640028, 30fps, video only, 77.58MiB
303          webm       1920x1080  1080p48 4758k , vp9, 48fps, video only, 103.27MiB
299          mp4        1920x1080  1080p48 5519k , avc1.64002a, 48fps, video only, 130.66MiB
43           webm       640x360    360p , vp8.0, vorbis@128k, 21.66MiB
18           mp4        640x360    360p  730k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 18.61MiB
22           mp4        1280x720   720p 1713k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)


To d/l the 480p version with audio and rename it while ignoring any FFMPEG output template file you might have already have set up:

youtube-dl -f135+249  Ih3jg3Xdcvs  --ignore-config -o shaky_480p

[youtube] Ih3jg3Xdcvs: Downloading webpage
[youtube] Ih3jg3Xdcvs: Downloading video info webpage
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[download] Destination: shaky_480p.f135
[download] 100% of 21.54MiB in 00:12
[download] Destination: shaky_480p.f249
[download] 100% of 1.35MiB in 00:00
[ffmpeg] Merging formats into "shaky_480p.mkv"
Deleting original file shaky_480p.mkv.f135 (pass -k to keep)
Deleting original file shaky_480p.mkv.f249 (pass -k to keep)


The youtube_dl options like "-f" (format) are case-sensitive. ("-F" is a different option.)  The "+" here muxes the two separate streams automatically after they have been d/led.  You will need to have ffmpeg.exe in your PATH list or in your current directory for this merging to occur.  The audio stream is incompatible with a MP4 container. The more flexible MKV container is substituted and, for this IS test, this is fine. Also, the low-bitrate audio is fine here.

Dan.

dosdan

#3
PART 2 of 3
Not all builds of FFMPEG include the vid.stab library. It's included in Zeranoe's Windows builds: https://ffmpeg.zeranoe.com/builds/win64/

I find it difficult judging the effect of an adjustment without a comparison to the unprocessed clip. So I place two clips side-by-side. The two 854x480 @ 30fps clips, when combined, become 1708x480 @ 30fps. If you choose to work with the full-res version, the comparison clip will be 3840x1080 @ 48 fps.

The first 30s of YT clip. Original vs Processed (7.9MB):
https://dl.dropbox.com/s/iqko3vurv5z21pn/compared.mkv

Analysis settings used (default; parameter range in brackets):
stepsize=4 [6; 1-32]
shakiness=10 [4; 1-10]
accuracy=15 [4; 1-15; must be >= shakiness].

Stabilisation processing settings used:
smoothing=15 [10; number of frames considered before & after the current frame]
unsharp=5:5:0.8:3:3:0.4

The parameters for FFMPEG's unsharp filter:

luma_msize_x, lx
Set the luma matrix horizontal size. It must be an odd integer between 3 and 23. The default value is 5.

luma_msize_y, ly
Set the luma matrix vertical size. It must be an odd integer between 3 and 23. The default value is 5.

luma_amount, la
Set the luma effect strength. It must be a floating point number, reasonable values lay between -1.5 and 1.5.
Negative values will blur the input video, while positive values will sharpen it, a value of zero will disable the effect.
Default value is 1.0.

chroma_msize_x, cx
Set the chroma matrix horizontal size. It must be an odd integer between 3 and 23. The default value is 5.

chroma_msize_y, cy
Set the chroma matrix vertical size. It must be an odd integer between 3 and 23. The default value is 5.

chroma_amount, ca
Set the chroma effect strength. It must be a floating point number, reasonable values lay between -1.5 and 1.5.
Negative values will blur the input video, while positive values will sharpen it, a value of zero will disable the effect.
Default value is 0.0.

All parameters are optional and default to the equivalent of the string '5:5:1.0:5:5:0.0'.


Notice how the maniacal movement of the quick hands is not reduced, but the tilting of the frame is. Notice how the stabilised version is zoomed in a little and has tighter framing. (This why the zoomed-in version needs a bit of unsharping.) This is to crop off the excess generated though levelling and x,y translation. Also the rapid zoom-in-zoom-out at 21s appears to be reduced.

The smoothing parameter has a significant effect. Here's a comparison of the same section, but with smoothing=5 vs smoothing=30 (8.8MB):

https://dl.dropbox.com/s/aqyfo3sq34r8dl8/compared_smoothing5_vs_30.mkv

Dan.

dosdan

#4
PART 3 of 3
Here'a a FFMPEG vid.stab testbench. (It could be modified to suit testing the effect of other filter changes).

There are 5 modes of operation:

  • Mode 1: Process file & then compare against original.
  • Mode 2: Compare two clips – no processing.
  • Mode 3: Final output processing of file – reanalyse.
  • Mode 4: Final output processing of file – reuse transform_vectors.trf.
  • Mode 5: Compares 2 processed versions – modes 3, 4, then 2.
If you are just altering the smoothing or unsharp parameters, there is no need to reanalyse motion and contrast. So for the 1st processed version you'd use Mode 3, and then use Mode 4 for the 2nd processed version to save a little time. Then you'd use Mode 2 to compare these two versions. While separating the steps out like this allows more flexibility in what you can do, it also requires more user effort. So I created Mode 5 to combine these 3 steps to reduce the possibility of mistakes.

stab_testbench.bat
@echo off
setlocal
cls
rem Mode 1: Process file & then compare against original.
rem Mode 2: Compare two clips – no processing.
rem Mode 3: Final output processing of file – reanalyse.
rem Mode 4: Final output processing of file – reuse transform_vectors.trf.
rem Mode 5: Compares 2 processed versions – modes 3, 4, then 2.

set mode=1
set duration=30
set loglevel=info

rem *** Analysis Settings Modes 1,3 ***
set stepsize=4
set shakiness=10
set accuracy=15
set in_file=shaky_480p.mkv

rem *** Analysis Settings Mode 5 (2nd clip)***
set stepsize=4
set shakiness=10
set accuracy=15

rem *** Comparison Settings Modes 2,5 ***
set file1=30s_smoothing5.mkv
set file2=30s_smoothing30.mkv
set fontfile='c\:/windows/fonts/ariblk.ttf'
set fontsize=48

rem *** Output Settings Modes 1,3,4,5 ****
set outputname=Final.mkv
set smoothing=10
set unsharp=5:5:0.8:3:3:0.4
if %mode%.==5. set outputname=%file1%

rem *** Output Settings Mode 5 (clip from 2nd run) ****
set smoothing2=30
set unsharp2=5:5:0.8:3:3:0.4

if %mode%.==2. goto :COMPARE
if %mode%.==4. goto :OUTPUT_MODE
if %mode%. NEQ 1. (if %mode%. NEQ 3. (If %mode%. NEQ 5. (Echo Invalid mode # & goto :EOF)))

echo ***************************************************************************************
echo Analysing...
echo.
ffmpeg -i %in_file% -t %duration% -y -hide_banner -loglevel %loglevel% -vf vidstabdetect=stepsize=%stepsize%:shakiness=%shakiness%:accuracy=%accuracy%:result=transform_vectors.trf -f null –
echo.
if %mode%.==3.  goto :OUTPUT_MODE
if %mode%.==5.  goto :OUTPUT_MODE

:STAB_and_COMP
echo ***************************************************************************************
echo Stabilising and Comparing...
echo.
if "%loglevel%"=="debug" pause & echo.
ffmpeg -i %in_file% -t %duration%  -y -hide_banner -loglevel %loglevel% -preset slow -codec:a copy -filter_complex "vidstabtransform=input=transform_vectors.trf:zoom=0:smoothing=%smoothing%,unsharp=%unsharp%[stab],[0:v:0]pad=iw*2:ih[bg];[bg][stab]overlay=w,drawtext=text=Shaky:fontfile=%fontfile%:fontsize=%fontsize%:x=0:y=0,drawtext=text=Stabilised:fontfile=%fontfile%:fontsize=%fontsize%:x=w/2:y=0" compared.mkv
start /wait "C:\Program Files\MPC-BE x64\mpc-be64.exe" compared.mkv
goto :EOF

:COMPARE
echo ***************************************************************************************
echo Comparing...
echo.
ffmpeg -i %file1% -t %duration%  -i %file2% -t %duration% -y -hide_banner -loglevel %loglevel% -preset fast -codec:a copy -filter_complex "[0:v:0]pad=iw*2:ih[bg];[bg][1:v:0]overlay=w,drawtext=text=%file1%:fontfile=%fontfile%:fontsize=%fontsize%:x=0:y=0,drawtext=text=%file2%:fontfile=%fontfile%:fontsize=%fontsize%:x=w/2:y=0" compared.mkv
start /wait "C:\Program Files\MPC-BE x64\mpc-be64.exe" compared.mkv
goto :EOF

:OUTPUT_MODE
echo ***************************************************************************************
echo Stabilising and Outputting... 
echo.
ffmpeg -i %in_file% -t %duration%  -y -hide_banner -loglevel %loglevel% -vcodec libx264 -tune film -preset slow -codec:a copy -filter_complex "vidstabtransform=input=transform_vectors.trf:zoom=0:smoothing=%smoothing%,unsharp=%unsharp%" %outputname%
if %mode%.==5. goto :2ND_RUN
goto :EOF

:2ND_RUN
echo ***************************************************************************************
echo Stabilising and Outputting (2nd run)... 
ffmpeg -i %in_file% -t %duration%  -y -hide_banner -loglevel %loglevel% -vcodec libx264 -tune film -preset slow -codec:a copy -filter_complex "vidstabtransform=input=transform_vectors.trf:zoom=0:smoothing=%smoothing2%,unsharp=%unsharp2%" %file2%
goto :COMPARE


The fontfile used for the overlayed titles is Arial Black. You can choose another. Notice how I had to escape the ":" character in "c:" by using "c\:" and used forward slashes in the pathname.

If you change the loglevel EV from "info" (FFMPEG's default) to "debug" you can see how FFMPEG is phrasing its command line. Since there is a lot of info scrolling past on the screen when it starts processing, the idea is to hit the Pause/Break key as soon as possible after starting, and then use the mouse pointer to drag the scroll bar back up the RHS of the windowed console session so as to see the parsing near the very start of the Analysis process. Since you may also want to do this at the start of the Stablisation process, I've added in a PAUSE command, if in "debug" mode, between these 2 stages, so you can press Spacebar and then press the Pause key immediately to inspect the phrasing at the start of the 2nd stage.

start /wait "C:\Program Files\MPC-BE x64\mpc-be64.exe" compared.mkv invokes my media player, MPC-BE, to view the side-by-side clip. You could use another player program. I wait for it to finish before ending the batchfile. This is not strictly necessary, but it forces you to exit the media player and free up the comparison file so it can be overwritten, if you then decide you want to alter a parameter in the batchfile, save the change and rerun it.

Set "duration" to a large number, say 9999(s), if you want to output the full clip in Modes 3 or 4.

Dan.

still dont know

@eumagga0x2a , @dosdan  Thanks for the tip, I appreciate it  ;)