doc:appunti:linux:video:ffmpeg_stack_horizontally
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| doc:appunti:linux:video:ffmpeg_stack_horizontally [2021/10/28 10:52] – created niccolo | doc:appunti:linux:video:ffmpeg_stack_horizontally [2021/10/28 11:43] (current) – niccolo | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Stack two videos side-by-side with ffmpeg ====== | ====== Stack two videos side-by-side with ffmpeg ====== | ||
| - | I created a script to do a **side-by-side comparison** between videos recorded with my two action cameras: a new **SJCAM 8 Pro** and the old **Xiaomi Yi**. | + | I created a Unix shell script to do a **side-by-side comparison** between videos recorded with my two action cameras: a new **SJCAM 8 Pro** and the old **Xiaomi Yi**. |
| - | {{.:ffmpeg: | + | Suppose that we have two videos taken simultaneously with the two cameras: |
| - | {{.: | + | |
| - | The result | + | {{.: |
| + | {{.: | ||
| + | |||
| + | The result | ||
| {{.: | {{.: | ||
| + | The script uses **ffmpeg** to do all the incantation. It is required that both videos share **the same resolution**. | ||
| + | |||
| + | The script can take into account that the videos may be **out of sync**: it is possible to pass **two timestamps** referring at the same instant captured into both videos. The script will **shift the videos presentation time** each-other, so that both will be synced. | ||
| + | |||
| + | The script has some constraints. It requires the **Bash shell**, because it uses the **%%((expression))%%** to do arithmetic evaluation. The script requires also the **Python** interpreter, | ||
| + | |||
| + | < | ||
| + | #!/bin/bash | ||
| + | |||
| + | # Take the central part of two videos and stack them horizontally. | ||
| + | # Audio from the first video is merged into the left channel of the | ||
| + | # resulting video, audio from the second video goes to the right. | ||
| + | # Two lables are overlayed on the bottom left and right corners. | ||
| + | |||
| + | # https:// | ||
| + | # https:// | ||
| + | # https:// | ||
| + | |||
| + | # Left and right videos. | ||
| + | # | ||
| + | # | ||
| + | VIDEO_1=" | ||
| + | VIDEO_2=" | ||
| + | |||
| + | # Two timestamps which should be synced. | ||
| + | # | ||
| + | # | ||
| + | TIME_1=" | ||
| + | TIME_2=" | ||
| + | |||
| + | # Labels to be superimposed on the two halves. | ||
| + | # | ||
| + | # | ||
| + | LABEL_1=" | ||
| + | LABEL_2=" | ||
| + | |||
| + | # | ||
| + | OUTPUT=" | ||
| + | |||
| + | if [ -z " | ||
| + | -z " | ||
| + | -z " | ||
| + | -z " | ||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | # Do the math, etc... | ||
| + | if (( $(echo " | ||
| + | TO_1=" | ||
| + | TO_2=' | ||
| + | else | ||
| + | TO_1=' | ||
| + | TO_2=" | ||
| + | fi | ||
| + | |||
| + | # Font and style for labels. | ||
| + | FONT=' | ||
| + | STYLE=' | ||
| + | # Labels placement. | ||
| + | L1X=' | ||
| + | L2X=' | ||
| + | L1Y=' | ||
| + | L2Y=' | ||
| + | |||
| + | ffmpeg -ss " | ||
| + | -filter_complex \ | ||
| + | " | ||
| + | [1: | ||
| + | [left][right]hstack=shortest=1[vs]; | ||
| + | [0: | ||
| + | [vs]drawtext=${FONT}text=' | ||
| + | -map ' | ||
| + | " | ||
| + | </ | ||
doc/appunti/linux/video/ffmpeg_stack_horizontally.1635411154.txt.gz · Last modified: by niccolo
