jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
362 stars 59 forks source link

How to capture movie to stdout #15

Closed mfk-smart closed 8 years ago

mfk-smart commented 8 years ago

Hi,

I'm trying to capture movie to stdout and pipe it to ffmpeg to stream video to another computer. I can do it from shell with the following command in shell :

gphoto2 --capture-movie --stdout | ffmpeg -i pipe:0 http://localhost:8080/feed1.ffm

As first step I tried to capture a movie : gp.gp_camera_capture(camera, gp.GP_CAPTURE_VIDEO, context)

but i got the following error:

gphoto2.GPhoto2Error: [-6] Unsupported operation

Is capturing video not supported in python-gphoto2?

jim-easterbrook commented 8 years ago

python-gphoto2 should support everything libgphoto2 does, so the real question is how to do movie capture (with your camera model) in libgphoto2. It may be that the gphoto2 command line application is doing something else, e.g. capturing a sequence of preview stills. I can't find any examples of movie capture with libgphoto2 - they're all using the command line program. Asking on the gphoto2 mailing list might help - no need to mention Python as once we know how to do it in C/C++ it should be easy to write the Python equivalent.

roipoussiere commented 4 years ago

Looking at gphoto sources, it seams that --capture-movie is an infinite loop of capture previews, which can be done with gp.gp_camera_capture_preview(camera) (as used in the preview image example).

ofrzeta commented 4 years ago

For everyone coming here later:


import gphoto2 as gp
from subprocess import Popen, PIPE

camera = gp.Camera()
camera.init()
ffmpeg = Popen(['ffmpeg', '-i', '-', '-vcodec', 'rawvideo', '-pix_fmt', 'yuv420p', '-f', 'v4l2', '/dev/video1'], stdin=PIPE)

while True:
  capture = camera.capture_preview()
  filedata = capture.get_data_and_size()
  data = memoryview(filedata)
  ffmpeg.stdin.write(data.tobytes())