ffmpeg jpeg流到webm仅创建具有一帧(快照)的文件.webm或空的.webm文件(mjpeg) [英] ffmpeg jpeg stream to webm only creates a file .webm with 1 frame (snapshot) or empty .webm file (mjpeg)
问题描述
我的问题是,当我尝试将一系列jpeg转换为webm视频时.我要么得到一个带有单个框架的webm文件,要么得到一个没有任何内容(0 kb)的webm文件.
my problem is that when i try to turn a series of jpegs into a webm video. I either get a webm file with a single frame or a webm file with nothing in it (0 kb).
var fs = require('fs');
var path = require('path');
var outStream = fs.createWriteStream(__dirname+'/output.webm');
var ffmpeg = require('fluent-ffmpeg');
这是一个mjpeg流URL.它会产生一个没有任何内容的文件.
this one is a mjpeg stream URL. it produces a file with nothing.
//var proc = new ffmpeg({source:'http://xxx.xxx.xxx.xxx/goform/stream?cmd=get&channel=0',timeout:0})
这是一个快照URL.它会产生一个具有单个帧的文件.
this one is a snapshot URL. it produces a file with a single frame.
var proc = new ffmpeg({source:'http://xxx.xxx.xxx.xxx/snapshot/view0.jpg',timeout:0})
.fromFormat('mjpeg')
.size('2048x1536')
.toFormat('webm')
.withVideoBitrate('800k')
.withFps(20)
我尝试使用管道代替,但没有骰子:(
I have tried to use pipe instead but no dice :(
//.pipe(outStream,{end:false});
.writeToStream(outStream,{end:false})
感谢您的帮助.
在这一点上,我准备将基本的shell命令与exec一起使用,但是当我尝试这样做时,我也会得到错误.是的,不用说我是菜鸟.
at this point i am up for using a basic shell command with exec but when i try that i just get errors also. Yes, it goes without saying I am a noob.
旁注:
我已经尝试过诸如zoneminder之类的事情,但这只是与我们的相机和相机数量有关.所以我正在做一个空洞的解决方案来记录它们.使用我们当前的云服务,我们错过了非常重要的时刻,并且浪费了更多的精力和时间.
I have tried things like zoneminder but it just breaks with our cameras and the number of cameras. so i am making a bare bones solution to record them. With our current cloud service we are missing very important moments and its costing more in energy and time.
推荐答案
感谢所有看过并试图找出答案的人:)
thanks everyone that had a look and tried to figure it out :)
我在这种方法上取得了一些成功.它实际上是根据快照URL 而不是MJPEG起作用的.这使用了请求.但由于该方法使用的是管道,因此您可以从技术上使用任何东西. image2pipe .
i have had some success with this method. It essentially works off a snapshot URL instead of the MJPEG. this uses request. but you could technically use anything since the method is using a pipe. image2pipe.
var spawn = require('child_process').spawn;
var request = require('request');
var args = '-f image2pipe -r 1 -vcodec mjpeg -i - -f webm -r 1 test3.webm';
var encoder = spawn('ffmpeg', args.split(' '));
encoder.stderr.pipe(process.stdout);
var interval = function(){
request('http://xxx.xxx.xxx.xxx/snapshot/view0.jpg',function(er){
if(er){console.log(er)}
setTimeout(function(){interval()},1000)
}).pipe(encoder.stdin,{end:false})
}
interval();
我本可以使用 setInterval ,但我只希望它在完成请求后再试一次.
i could have used setInterval but i only wanted it to try again after it finished the request.
原来我尝试在最初的问题中使用该方法时,我的相机坏了,所以我不确定它是否有效...但是我知道这对 MJPEG
it turns out my camera was down when i was trying to use the method in the initial questions so im not sure if it works... but i know this does for MJPEG
var spawn = require('child_process').spawn;
var args = '-f mjpeg -framerate 1 -i http://xxx.xxx.xxx.xxx/goform/stream?cmd=get&channel=0 -vcodec libvpx -framerate 1 -bitrate 256k video_file.webm -y';
console.log(args)
var encoder = spawn('ffmpeg', args.split(' '));
encoder.stderr.pipe(process.stdout);
这篇关于ffmpeg jpeg流到webm仅创建具有一帧(快照)的文件.webm或空的.webm文件(mjpeg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!