Im running into an speed optimization issue. Im building a video cut tool in web technologies on desktop with TideSDK. On of the tools has a timeline with a position slider
basically, whenever the slider moves, (using jquery UI), I get the position, translate this into a timecode and asks FFMPEG to encode to a file, when a get the finished event, I simply update the background-image attribute of the 'viewer' to this file. The file is located in some temporary folder.
The thing is, it is just a bit too slow. Usable, but slow (approx 2 fps on a High end Computer) I think there are 2 bottlenecks on this strategy: - Writing ffmpeg output to a file & reading back in css - repeatedly loading the same movie file in ffmpeg
This is the code executed on each move (var timecode is the calculated timecode based on the pointer position)
var cmd = [FFMPEG];
cmd.push('-y'); //overwrite existing files
cmd.push('-ss',timecode); //CUE position
cmd.push('-i',input); //input file
cmd.push('-f','image2'); //output format
cmd.push('-vframes','1'); //number of images to render
cmd.push(Ti.API.Application.getDataPath( )+"/encoderframe.jpg"); //output file
var makeframe = Ti.Process.createProcess(cmd);
makeframe.setOnReadLine(function(data){ /*console.log(data);*/ });
var time = new Date().getTime();
makeframe.setOnExit(function(){ ffmpegrunning = false; $('#videoframe').css('background-image','url(file://'+Ti.API.Application.getDataPath( ).replace(" ","%20")+'/encoderframe.jpg?'+time+')'); });
makeframe.launch();
Basically, this repeatedly asks the same Command:
ffmpeg -y -ss 00:00:01.04 -i /somepath/somevideo.mov -f image2 -vframes 1 /path/to/output/encoderframe204.jpg
How can I optimize this code, Pipe to output straight to css background with Base64 data, or reuse loaded memory file in ffmpeg. ?
Thanks!