Linux下ffmpeg添加Facebook/transform
Linux下ffmpeg添加Facebook/transform代码块实现将全景视频的球模型转换成立方体模型
Facebook事实上已开始在平台中支持360度全景视频的流播,但公司对此并不满足。其工程师更是基于锥体几何学设计出了一套全新的视频编码,号称最高能将全景视频的文件大小减少80%。(VR最新突破:全景视频压缩率达80%,即将普及爆发)

1、Facebook开源了其将2:1球模型视频转换成立方体模型的代码
https://github.com/facebook/transform
README:
1# Transform
2
3Transformisa video filter that transforms360videoin equirectangular projection into a cubemap projection
4
5## Building
6
7Transformisimplementedas an ffmpeg video filter. To build Transform, follow these steps:
8
9 1. Checkout the sourcefor ffmpeg
10 2. Copy `vf_transform.c` to the libavfilter subdirectoryin ffmpeg source
11 3. Edit `libavfilter/allfilters.c` and register the filter by adding the line: `REGISTER_FILTER(TRANSFORM, transform, vf);`in the video filter registration section
12 4. Edit `libavfilter/Makefile` and add the filter to adding the line: `OBJS-$(CONFIG_TRANSFORM_FILTER) += vf_transform.o`in the filter section
13 5. Configure and build ffmpegas usual
14
15## Running
16
17Checkoutthe optionsforthe filter by running `ffmpeg -h filter=transform`
18A typical execution would be something like `ffmpeg -i input.mp4 -vf transform=input_stereo_format=MONO:w_subdivisons=4:h_subdivisons=4:max_cube_edge_length=512`
2、facebook/transform代码实现浅析
2.1、据facebook称将球模型转成立方体模型科技减少25%的数据量

2.2、转换成四棱锥可以减少80%的数据量,但这部分代码没有开源。

2.3、现有球模型是怎么展开成2:1的视频的,以地球仪和世界地图为例:

2.4、根据其开源代码在linux下用ffmpeg实现的结果,实现方法参见:Linux下编译ffmpeg并用GDB调试以及根据README修改相应源码



2.5、立方体展开成十字形的结果:

2.6、源码的转换核心是坐标之间的转换,即怎么把球模型上的点和立方体对应以来,其实现方法是给定立方体模型上的坐标,根据坐标算出α和β(可以想成极坐标,水平一圈360度,上下180度);α、β分别除以360度和180度,按比例找出在球上对应的点(在2:1视频中的像素点)。

2.7、以正前方这个面为例:

2.8、将坐标转换成在空间内的立方体坐标(qx,qy,qz);qz表示球心(立方体中心)到前方平面的距离

2.9、转换成(tx,ty,tz)是考虑到视线可能移动,正前方的面也变了,但此处默认(y,p)都为0;故坐标不变

2.10、在立体空间内算出(α,β),α是水平偏向角,范围:(-180度,180度);β是竖直偏向角,范围:(-90度,90度)

2.11、算出(α,β)角度,就可以根据比例得到对应在2:1视频中相应的像素点


文末也给大家,分享主要有C/C++,Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,TCP/IP,协程,DPDK技术,面试技巧方面的资料技术讨论。
感兴趣的朋友可以加群:812855908