简体   繁体   English

libstreaming-如何旋转流视频?

[英]libstreaming - how to rotate streames video?

libstreaming works fine - in landscape mode. libstreaming可以正常工作-在横向模式下。 Unfortunately, my app will have to run in portrait mode. 不幸的是,我的应用程序必须以纵向模式运行。 No problem for the preview window - I can set it upright with 预览窗口没问题-我可以将其垂直设置

session.setPreviewOrientation(90); session.setPreviewOrientation(90);

But the receiver of the stream will still have the video sideways. 但是流的接收器仍然会偏向视频。 Is there a solution for that? 有解决方案吗?

In Android's Mediarecorder, there is a method setOrientationHint(int degrees) that will rotate the streamed/recorded video. 在Android的Mediarecorder中,有一个方法setOrientationHint(int degree)将旋转流/录制的视频。 But I did not find anything like that in libstreaming... 但是我在libstreaming中没有找到类似的东西...

I have encountered this problem before. 我以前遇到过这个问题。 There are 3 possible solutions that I implemented. 我实现了3种可能的解决方案。

  1. Convert each YUV frame that comes out from onPreviewFrame API to a bitmap then rotate the bitmap and finally convert the bitmap back to YUV frame. 将来自onPreviewFrame API的每个YUV帧转换为一个位图,然后旋转该位图,最后将位图转换回YUV帧。 The disadvantage of this solution is video frame has been dropped alot (in my case from 24 to 4-5 FPS). 该解决方案的缺点是视频帧丢失很多(在我的情况下是从24降至4-5 FPS)。

  2. Rotate each YUV frame 90/270 degrees (based on orientation of camera) clockwise using code from here . 使用此处的代码将每个YUV帧顺时针旋转90/270度(基于相机的方向)。 The disadvantage of this solution are images will be distorted and video frame might be dropped as well. 该解决方案的缺点是图像会失真,视频帧也可能会掉落。

  3. Using an open source library from Google called libyuv . 使用Google的开源库libyuv If you have knowledge of JNI, it will be easy for you. 如果您具有JNI知识,这对您来说将很容易。 BTW, you can see demo about this lib here and here . 顺便说一句,您可以在此处此处看到有关此库的演示。 Because rotation process handled at native layer so this is efficient solution and the best one so far. 因为旋转过程是在本机层处理的,所以这是迄今为止最有效的解决方案。

Hope this info will be helpful for anyone who are encountering with this problem. 希望此信息对遇到此问题的任何人都有帮助。

Change the video quality to (1280,720) from (320,240). 将视频质量从(320,240)更改为(1280,720)。 Then once you start it should be changed and rotated. 然后,一旦开始,就应该对其进行更改和旋转。 BTW how did you implement your receiver? 顺便说一句,您是如何实现接收机的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM