c# - Converting Texture2D into a video -
i've did lot of research, can't find suitable solution works unity3d/c#. i'm using fove-hmd , record/make video of integrated camera. far managed every update take snapshot of camera, can't find way merge snapshots video. know way of converting them? or can point me in right direction, in continue research?
public class fovecamera : singletonbase<fovecamera>{ private bool camavailable; private webcamtexture fovecamera; private list<texture2d> snapshots; void start () { //-------------just checking if webcam available webcamdevice[] devices = webcamtexture.devices; if (devices.length == 0) { debug.logerror("fovecamera not found."); camavailable = false; return; } foreach (webcamdevice device in devices) { if (device.name.equals("fove eyes")) fovecamera = new webcamtexture(device.name);//screen.width , screen.height } if (fovecamera == null) { debug.logerror("fovecamera not found."); return; } //-------------camera found, start video fovecamera.play(); camavailable = true; } void update () { if (!camavailable) { return; } //loading snap camera texture2d snap = new texture2d(fovecamera.width,fovecamera.height); snap.setpixels(fovecamera.getpixels()); snapshots.add(snap); } }
the code works far. first part of start-method finding , enabling camera. in update-method i'm taking every update snapshot of video.
after "stop" update-method, convert gathered texture2d object video.
thanks in advance
i see 2 methods here, 1 fast implement, dirty , not platforms, second 1 harder pretty. both rely on ffmpeg.
1) save every frame image file (snap.encodetopng()
) , call ffmpeg create video images (ffmpeg create video images) - slow due many disk operations.
2) use ffmpeg via wrapper implemented in aforge , supply videofilewriter
class images have. image sequence video stream?
problem here uses system.bitmap
, in order convert texture2d bitmap can use: how create bitmap byte array?
so end like:
bitmap bmp; texture2d snap; using (var ms = new memorystream(snap.encodetopng())) { bmp = new bitmap(ms); } vfwriter.writevideoframe(bmp);
both methods not fastest ones though, if performance issue here might want operate on lower level data directx or opengl textures.
Comments
Post a Comment