首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在AppRTCDemo中将视频作为摄像机播放

在AppRTCDemo中将视频作为摄像机播放
EN

Stack Overflow用户
提问于 2017-02-11 14:38:00
回答 2查看 574关注 0票数 2

我需要在Android上运行一个WebRTC实验,以便找到一个有用的Android源应用程序AppRTCDemo (https://github.com/webrtc/apprtc)。它使用了一个WebRTC库(libjingle_peerconnection),该库支持将视频作为摄像头打开。它可以在AppRTCDemo源代码中通过变量EXTRA_VIDEO_FILE_AS_CAMERA来确定。

代码语言:javascript
复制
CallActivity.java (AppRTCDemo);
private VideoCapturer createVideoCapturer();
videoCapturer = new FileVideoCapturer(videoFileAsCamera);

当我在应用程序中打开视频(.mp4、.avi)时,它会出现错误“不支持除I420或I420mpeg2之外的任何其他颜色空间”。花了几个小时后,我发现这个库只支持色彩空间为I420的YUV文件。因此,我试图找到该文件,但当它运行时,出现另一个错误:“find end of file before of file of header for file”。

源文件如下所示:

代码语言:javascript
复制
public VideoReaderY4M(String file) throws IOException {
        this.mediaFileStream = new RandomAccessFile(file, "r");
        StringBuilder builder = new StringBuilder();

        while(true) {
            int header = this.mediaFileStream.read();
            if(header == -1) {
                throw new RuntimeException("Found end of file before end of header for file: " + file);
            }

            if(header == 10) {
                this.videoStart = this.mediaFileStream.getFilePointer();
                String var13 = builder.toString();
                String[] headerTokens = var13.split("[ ]");
                int w = 0;
                int h = 0;
                String colorSpace = "";
                String[] arr$ = headerTokens;
                int len$ = headerTokens.length;

                for(int i$ = 0; i$ < len$; ++i$) {
                    String tok = arr$[i$];
                    char c = tok.charAt(0);
                    switch(c) {
                    case 'C':
                        colorSpace = tok.substring(1);
                        break;
                    case 'H':
                        h = Integer.parseInt(tok.substring(1));
                        break;
                    case 'W':
                        w = Integer.parseInt(tok.substring(1));
                    }
                }

                Logging.d("VideoReaderY4M", "Color space: " + colorSpace);
                if(!colorSpace.equals("420") && !colorSpace.equals("420mpeg2")) {
                    throw new IllegalArgumentException("Does not support any other color space than I420 or I420mpeg2");
                }

                if(w % 2 != 1 && h % 2 != 1) {
                    this.frameWidth = w;
                    this.frameHeight = h;
                    this.frameSize = w * h * 3 / 2;
                    Logging.d("VideoReaderY4M", "frame dim: (" + w + ", " + h + ") frameSize: " + this.frameSize);
                    return;
                }

                throw new IllegalArgumentException("Does not support odd width or height");
            }

            builder.append((char)header);
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2019-01-23 17:31:23

为colorSpace添加默认值;有时解析的y4m格式的标头可能不包含colorSpace。示例:String colorSpace = "420";

票数 0
EN

Stack Overflow用户

发布于 2021-03-09 13:37:56

重新创建create FileVideoCapture.java并编辑它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42173105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档