doc:appunti:linux:video:ffmpeg_stack_horizontally
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
doc:appunti:linux:video:ffmpeg_stack_horizontally [2021/10/28 08:53] – niccolo | doc:appunti:linux:video:ffmpeg_stack_horizontally [2021/10/28 09:28] – niccolo | ||
---|---|---|---|
Line 2: | Line 2: | ||
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**. | 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**. | ||
+ | |||
+ | 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. | ||
+ | |||
+ | < | ||
+ | #!/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.txt · Last modified: 2021/10/28 09:43 by niccolo