This code generates remapping projections for ffmpeg to convert from dual-fish-eye images/video (spherical) to equirectangular output. It can be used to map both images and video.
The code was adapted from examples given for ffmpeg's RemapFilter
, with added support for video captured with Insta360 Air devices.
- Install ffmpeg, (make sure it's a recent version)
- Checkout the source of this repository
- Build:
gcc projection.c -lm -o project
$ ./project -x xmap.pgm -y ymap.pgm -h 960 -w 960 -c 1920 -r 960 -m theta --verbose
This creates two ASCII encoded PGM files which act as a lookup table for ffmpeg to remap the video.
$ ffmpeg -i input.mp4 -i xmap.pgm -i ymap.pgm -q 0 -lavfi "format=pix_fmts=rgb24,remap" remapped.mp4
There are various pre-generated lookup tables included:
-
camera in uptight position (USB connector down) run:
./remap_vid_down.sh
-
camera in hanging position (USB connector up) run:
./remap_vid_up.sh
-
camera placed sideways (USB connector right or left) run:
./remap_vid.sh
The Lens mapping isn't perfect yet. Unfortunatly the "seam" between both pictures will only be perfect for objects that have a certain/specific distance from the camera. This distance can be fine tuned in the code but it will be fixed. Basically this image illustrates the challange quite well:
In this example the distance is perfectly tuned for Distance "B"....
Hence creating a crop effect at Distance "C" and an Overlap effect at Distance "A".
If you want to upload your video to youtube as a 360 video, make sure you encoded it as a .mp4, and use this tool from google. On linux, you can install python-tk
and use the gui, or use it via command line.
The instructions there say to run python spatialmedia
but there isn't anything called that, so replace spatialmedia
with __main__.py
and it works.
python __main__.py -i remapped.mp4 remapped_injected.mp4
Your file is now ready for YouTube/etc.
Stabilizing output videos via Hugin with Matthew Petroff's method reveals a wobble that would not be present if the mapping was perfect; Convieniently, I think i can use Hugin's Lens Calibration tools on the source frames to find a better mapping.
Some referrence links:
- Rotate Excel tables in 90 oder 180 degree:
https://www.extendoffice.com/de/documents/excel/4602-excel-rotate-table-90-degree-180-degree.html#a1 - PGM Format Specification:
http://netpbm.sourceforge.net/doc/pgm.html - Transpose a matrix in C
https://www.programmingsimplified.com/c-program-transpose-matrix