more capture options in BGE VideoFFmpeg module
OpenPublic

Description

Currently the video capture options in the BGE are very limited. I discovered there's no apparent reason for this since the capture options are hardcoded to vfwcap on Win platform and video4linux of dv1394 on linux platforms. FFMpeg supports more options like directshow, x11grab, video4linux2, rawvideo etc.

Attached is a patch to open up these options.

Currenlty in BGE you add this python line to capture video from a webcam:
obj['video'].source = texture.VideoFFmpeg('/dev/video0', 0, 15, 320, 240)

With my patch an option is added to force a format. (Forcing a format is needed for capturing in ffmpeg)
obj['video'].source = texture.VideoFFmpeg('/dev/video0', 0, 15, 320, 240, "video4linux2")

Attached a blend file which works with the patched blender on linux64.

I haven't been able to test any other platforms since I don't have those and OSX doesn't have any capture support anyway. I'm ver curious if this opens up dshow capturing.

I would consider to change this patch a bit more since the second parameter shouldn't be necessary and could be used to handle the format parameter. However than existing code won't work no more. I also would like to remove the old code which generates the capture device since it's hardcoded and made obsolete by this patch?




sphaero (Arnaud Loonstra) added a comment.Via Old WorldMay 29 2012, 12:47 PM

I've been talking to Thomas Achtner who had a better suggestion into patching this code. I haven't reveived the patch though... :

Anyway, I was reading the code, I think your changes are not such a good
deciscion. The original code suggests more, to use the first parameter
for the purpose you added your additional.

Thats one of the possible notations, nobody used it, I guess:
bge.texture.VideoFFmpeg("v4l", 0, 640, 480)

while:
bge.texture.VideoFFmpeg("/dev/video0", 0, 640, 480)
is just using the "fallback" code

So it's better to implement something like this:
bge.texture.VideoFFmpeg("v4l2", 0, 640, 480) for v4l2 device /dev/video0
bge.texture.VideoFFmpeg("v4l2", 1, 640, 480) for /dev/video1
bge.texture.VideoFFmpeg("x11grab", 0, 640, 480) for screen :0.0
bge.texture.VideoFFmpeg("x11grab", 1, 640, 480) for screen :0.1

and so on.

If you interessted I can send you my patch.

offtools.

Add Comment