javascript - 如何使用 JMuxer.js 播放 Java 的 FFmpegFrameGrabber Frame
问题描述
1.我有来自 JAVA UDP 的原始数据
Log.d(TAG,Arrays.toString(temp2));//Length 951
[0, 0, 0, 1, 103, 77, 0, 40, -87, 80, 10, 0, -73, 66, 0, 0, 7, -48, 0, 1, -122, -96, 8, 0, 0, 0, 1, 104, -18, 60, -128, 0, 0, 0, 0, ...]
2.JMuxer可以播放h264数据
//html
<video controls autoplay id="_play" style="width: 300px; height: 300px;>
</video>
javascript
var nn1=[0,0,0,1,103,66,192,30,218,2,128,191,229,192,90,128,128,128,160,0,0,125,32,0,23,112,1,226,197,212,0,0,0,1,104,206,60,128,0,0,0,1,101,136,132,55,255,255,208,92,80,0,16,89,...];
//Length 26139
player = new JMuxer({
node: '_play',
mode: 'video',
fps: 25,
debug: true
});
setTimeout(function () {
player.feed({
video: new Uint8Array(nn1)
});
}, 500);
3.问:我可以把FFmpegFrameGrabber Frame转成Javascript吗?
我努力了
- 帧传输到位图,
- 位图传输到 Base64
- Base64 返回 Javascript 的 Canvas ,但是这种方式太慢了;
//JAVA
...
private PipedOutputStream outputStream = null;
private PipedInputStream inputStream = null;
private FFmpegFrameGrabber grabber = null;
private void init() {
if (this.grabber == null) {
this.grabber = new FFmpegFrameGrabber(this.inputStream);
this.grabber.setVideoCodec(27);
this.grabber.setFrameRate(25.0D);
this.grabber.setVideoBitrate(1200000);
this.grabber.setImageWidth(1280);
this.grabber.setImageHeight(720);
this.grabber.setVideoCodecName("libx264");
this.grabber.setOption("bufsize", "10000");
this.grabber.setOption("filter:v", "fps=fps=25");
...
}
}
public void run() {
super.run();
try {
this.outputStream.write(new byte[1024]);
this.outputStream.flush();
} catch (IOException var6) {
System.out.println(var6);
}
try {
this.grabber.startUnsafe(false);
try {
Thread.sleep(50L);
} catch (InterruptedException var5) {
}
Frame frame;
while((frame = this.grabber.grabFrame(false,true,false,false,false)) != null){
//Can I transfer frame to buffer array? //[0,0,0,1,103,66,192,30,...]
//I need a complete frame to play
}
} catch (FrameGrabber.Exception e) {
e.printStackTrace();
}
System.out.println("FFmpeg stop && release");
}
解决方案
推荐阅读
- javascript - 使用节点 js 每秒加载一次查询
- javascript - 如果在另一个选择框 JavaScript 中选择了该选项,则隐藏该选项
- r - 如何在 for 循环中为列名设置别名?
- arduino - 如何使用 arduino 将我的 ESP8266 连接到我的 Flutter 应用程序。在这里完成初学者
- asp.net-core - 两个 .net 核心 API 和身份
- machine-learning - Keras 模型精度没有提高
- sql - 根据值拆分列
- excel - 选择行并复制到列
- vue.js - 是否可以将 Webpack/VueJS 与 Odoo 框架(v12)集成?
- c# - WPF 和托管 WCF 服务之间的通信