Cropping video stream in android-studio

时光毁灭记忆、已成空白 提交于 2019-12-25 02:26:43

问题


I want stream a very large video (lets say 5000x5000) and I want to crop it to show 1000x1000 chunks. Currently I do so by streaming the video via TextureView.SurfaceTextureListener. Scaling the video up to the point where one chunk fits my view and can be played. Here is a little snippit:

Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY, 0, 0);
matrix.postTranslate(positionX, positionY);

textureView.setTransform(matrix);

However, since its such a big video, some devices cant play it. Smaller videos work fine, even with the same codec. It seems like decoding it takes too long for it to be able to play. This even occured when I stored the video in resources. (maybe has something to do with the second answer in this question)

I tried using ffmpeg, but when I did, according to this question, i got the error Message in ExecuteBinaryResponseHandler.onFailure(): "CANNOT LINK EXECUTABLE "/data/user/0/packageName/files/ffmpeg": /data/data/packageName/files/ffmpeg: has text relocations". So it seems that ffmpeg is not an option anymore, and wont ever be, according to these issues:

  • https://issuetracker.google.com/issues/37067983
  • https://trac.ffmpeg.org/ticket/4928

So, a few questions about this.

  1. Is there an alternative to ffmpeg that lets me crop videos programmatically and with high performance, before they are decoded by the player?
  2. Is there a way to restrict android to only load the parts 'visible' of a video after it has been scaled? Boosting the performance of my first attempt, scaling the video up to a point where I only see a particular area?
  3. Is there a way, other than lowering the quality of my video source, to ensure that a device can play the video or at least to detect programmatically that a video can not be played?
  4. Is there another technique or a workaround that I can use to show a cropped part of a vide?

UPDATE

As suggested in the comments, to boil it down to one question: Is there a way for me to crop a video programmatically from url so that it plays on all modern devices?

来源:https://stackoverflow.com/questions/54363211/cropping-video-stream-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!