【问题标题】:Playing a video as a camera in AppRTCDemo在 AppRTCDemo 中将视频作为相机播放
【发布时间】:2017-06-29 14:40:43
【问题描述】:

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

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

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

源文件如下:

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

【问题讨论】:

  • 嗨@JohnPekl,你有想过吗?我也有同样的问题
  • @RickSanchez 打开 org.appspot.apprtc 文件并在之前编辑它 -> String colorSpace = "";之后 -> String colorSpace = "420";

标签: android video video-streaming webrtc yuv


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    重新创建 FileVideoCapture.java 并编辑它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 2014-05-01
      • 2011-07-04
      • 2022-01-26
      • 2013-03-05
      相关资源
      最近更新 更多