在AppRTCDemo中将视频作为相机播放

时间:2017-02-11 06:38:00

标签: android video video-streaming webrtc yuv

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

CallActivity.java (AppRTCDemo);
private VideoCapturer createVideoCapturer();
videoCapturer = new FileVideoCapturer(videoFileAsCamera);

当我在应用程序中打开视频(.mp4,.avi)时,它出现错误“不支持除I420或I420mpeg2之外的任何其他颜色空间”。花了几个小时后,我发现该库只支持YUV文件,颜色空间为I420。所以我试图找到该文件但是当它运行时,还有另一个错误“在文件头部结束之前找到文件结尾”。

源文件如下:

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);
        }
    }

2 个答案:

答案 0 :(得分:0)

为colorSpace添加默认值;有时,已解析的y4m格式的标头可能不包含colorSpace。 示例:字符串colorSpace =“ 420”;

答案 1 :(得分:0)

enter image description here

重新创建 FileVideoCapture.java 并编辑它