back

update panoramas with lost original files to
cubefaces and back to equirectangular for html5

I normally use Pano2VR 5.2.x (https://ggnome.com/doc/converting-images/) to convert QTVRs to html5. When that doesn't work - on very old ones or compressed with unusual software, ffmpeg works if the file at least can be opened.

Extract
zipped file "mh.mov.zip"
Open the QTVR file in ffmpeg:
$ ffmpeg -i mh.mov
and you get a lot of information from the file:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mh.mov':
  Metadata:
    creation_time : 1998-09-21T11:56:24.000000Z
  Duration: 00:00:01.00, start: 0.000000, bitrate: 1759 kb/s
    Stream #0:0(eng): Data: none (qtvr / 0x72767471), 0 kb/s (default)
  Metadata:

  Stream #0:3(eng): Video: mjpeg (Baseline) (jpeg / 0x6765706A), yuvj420p(pc, bt470bg/unknown/unknown), 576x160 [SAR 72:72 DAR 18:5], 1649 kb/s, 12 fps, 12 tbr, 3600 tbn, 3600 tbc …

Here you can see that the pano is 1 s at 12 fps 576x160 px.
ffmpeg goes for the highest resolution stream unless you tell it another, using $ -map
ffmpeg wiki: Map

$ ffmpeg -i mh.mov folder/%02d.png
and you get 12 pngs, they are 90° counterclockwise, CCV:

"%03d" is a formatting string, or sequence wildcards,
3 shows how many digits the printed number will have: 000-999,
0 before 3 shows that leading spaces should be replaced by zeroes,
"%d" only takes one digit: 0-9, "%02d" takes two: 00-99, etc.



Here is the first tile.

Then combine the strips:
ffmpeg tile filter
$ ffmpeg -i folder/%02d.png -vf "tile=12x1" mh_ccv.png

And rotate it 90° clockwise, CV (right):
ffmpeg transpose filter
"transpose=0" 90° counterclockwise and vertical flip (default)
"transpose=1" 90° clockwise
"transpose=2" 90° counterclockwise
"transpose=3" 90° clockwise and vertical flip
"transpose=2,transpose=2" 180 degrees
Flip video horizontally: "hflip"
Flip video vertically: "vflip"

$ ffmpeg -i mh_ccv.png -vf "transpose=1" mh.png
You can also combine the two scripts into one:
$ ffmpeg -i folder/%02d.png -vf "tile=1x12,transpose=1" mh.png



Here is the combined image in circular projection. No need for cubefaces here.
ffmpeg pad filter
Most pano viewers/software need the panorama file to be in the 2:1 ratio, pad the output, black is default:
1920x576 to 1920x960
$ ffmpeg -i mh.png -vf "pad=1920:960:(ow-iw)/2:(oh-ih)/2" mh_eq.tif
ow and oh are output width and height, iw and ih are input width and height
or do 960-576=384 384/2=192
$ ffmpeg -i mh.png -vf "pad=1920:960:1920:192" mh_eq.tif
or do
$ ffmpeg -i mh.png -vf "pad=1920:960:0:192" mh_eq.tif

You can combine this with the preceding two commands:
$ ffmpeg -i folder/%02d.png -vf "tile=1x12,transpose=1,pad=1920:960:0:192" mh_eq.tif



Here is the final image in 2:1 ratio.

And then to Pano2VR or similar for the html5 conversion.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

For spherical panos you may find the tiles in six folders.
The tiles in the folders named similar to this:
c0_l0_0_0.jpg, c0_l0_0_1.jpg, c0_l0_0_2.jpg, c0_l0_1_0.jpg, c0_l0_1_1.jpg, c0_l0_1_2.jpg, c0_l0_2_0.jpg, c0_l0_2_1.jpg, c0_l0_2_2.jpg

9 tiles 514x514 px, square and same size, that is good.
But the tiling software may have expanded the tile with one pixel in each direction. In this case scale the tile to 512x512 px, and you get files that are easy to compress (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384).
(With a 24 megapixel APS-C camera and a 10.5 fisheye I set panoramas to 16384x8192.)
To handle them you either rename them to numeric sequential order and use the "%d" string:
$ ffmpeg -i folder/%d.jpg -vf "scale=w=512:h=512,tile=3x3" 1.png

Or if you are not on Windows, you may use the "-pattern_type glob" which uses lexicographic order, not numeric.
$ ffmpeg -pattern_type glob -i "folder/*.jpg" -vf 'scale=512:512,tile=3x3' 1.png

And you get one cubic face. Then reassemble the other five cube faces, add them together in a strip and convert them into an equirectangular. Using the up arrow in Shell/Terminal give you back your last command, and if you keep pressing it you will slowly go through your shell history.

Reassembly the cubemap.
ffmpeg tile filter
v360 filter, cubemap face names: right 'r', left 'l', up 'u', down 'd', forward 'f', back 'b'. Default value is 'rludfb'. Extract each cubemap and rename right to 1.tif, left to 2.tif etc. Then reassemble them.
$ ffmpeg -i folder/%d.tif -filter_complex "tile=6x1" cubemap.tif
This is not the same order that Adobe, Apple, Hugin, Pano2VR, Panotools, Quake II or RealViz has been using (frblud). WHY?!, so if you have cubemaps from them you have to untile and reassemble them to work with this filter (or use Pano2VR or similar). It seems to be the order of 'NVIDIA Texture Tools Exporter'.

ffmpeg's v360 filter can convert the cubemap back to equirectangular after reassembly:
$ ffmpeg -i cubemap.tif -vf "v360=c6x1:e" equirectangular.tif
The forward cube face gets placed in the center of the equirectangular file.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

But if the tiles in one of the six folders look like this (with a total of 129 tiles):
c0_l0_0_0.jpg, 514x514 px
c0_l0_0_1.jpg, 514x514 px
c0_l0_0_2.jpg, 514x514 px
c0_l0_0_3.jpg, 377x514 px
c0_l0_1_0.jpg, 514x514 px
c0_l0_1_1.jpg, 514x514 px
c0_l0_1_2.jpg, 514x514 px
c0_l0_1_3.jpg, 377x514 px
c0_l0_2_0.jpg, 514x514 px
c0_l0_2_1.jpg, 514x514 px
c0_l0_2_2.jpg, 514x514 px
c0_l0_2_3.jpg, 377x514 px
c0_l0_3_0.jpg, 514x377 px
c0_l0_3_1.jpg, 514x377 px
c0_l0_3_2.jpg, 514x377 px
c0_l0_3_3.jpg, 377x377 px

next folder:
c1_l0_0_0.jpg, 514x514 px
etc.
exiftool (not ffmpeg!)
I used exiftool to get the list with sizes:
$ exiftool -ImageSize -csv folder/ > sizes.txt

I shorten the file names here, adding them together:
0_0.jpg + 0_1.jpg + 0_2.jpg = 0.png 1542x514 (horizontal)
1_0.jpg + 1_1.jpg + 1_2.jpg = 1.png 1542x514
2_0.jpg + 2_1.jpg + 2_2.jpg = 2.png 1542x514

$ ffmpeg -pattern_type glob -i "folder/*.jpg" -vf 'tile=3x1' folder/0.png
or
$ ffmpeg -i folder/%02d.jpg -filter_complex 'tile=3x1' folder/0.png

0.png + 0_3.jpg = 0a.png 1919x514
1.png + 1_3.jpg = 1a.png 1919x514
2.png + 2_3.jpg = 2a.png 1919x514

$ ffmpeg -i folder/0.png -i folder/0_3.jpg -filter_complex hstack folder/0a.png

You can have more than two sources in hstack and vstack: $ 'hstack=inputs=3'

0a.png + 1a.png + 2a.png = 012.png 1919x1542 vertical

3_0.jpg + 3_1.jpg + 3_2.jpg = 3210.png 1542x377 horizontal

3210.png + 3_3.jpg = 3233.png 1919x377 horizontal

And a final addition and we get the first cubic frame of the panorama at 1919x1919 px.
012.png + 3233.png = frame1919.png 1919x1919 px $ vertical

Now there is one problem with this. The file is odd sized. This is not good for file compression.
And some codecs don't work at all with odd sized files. Scale to a near number to keep size divisible by at least 2 (preferably 4, 8 or 16)
$ ffmpeg -i frame1919.png -vf "scale=1920:1920" frame1.tif
Repeat for the next five folders.
And then combine the cubic frames and convert them to equirectangular as above.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Some other tools (commands, filters) of use for panoramic photographers:
$ coming…

back