我需要在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文件。因此,我试图找到该文件,但当它运行时,出现另一个错误:“find end of file before of file of header for file”。
源文件如下所示:
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);
}
}发布于 2019-01-23 17:31:23
为colorSpace添加默认值;有时解析的y4m格式的标头可能不包含colorSpace。示例:String colorSpace = "420";
发布于 2021-03-09 13:37:56

重新创建create FileVideoCapture.java并编辑它
https://stackoverflow.com/questions/42173105
复制相似问题