Search code examples
videojuliawebcam

How can I capture video from webcam in julia?


I want to capture video from webcam, and save file in my computer.

I did it in Python. But how it do in Julia, and don't use "PyCall". Thanks.

This is my code in Python:

from ffmpy import FFmpeg

ff=FFmpeg(
    inputs={"rtsp://......@.....":None},
    outputs={'./Video.mp4':'-t 00:01:00'})

print(ff.cmd)
ff.run()

Solution

  • It looks like ffmpy just run an external ffmpeg program. You can do the same in Julia with the usual mechanisms. I wasn't able to reproduce rtsp example, but according to ffmpeg docs one can use something like ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv, which in julia can be written as

    run(`ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv`)
    

    I think it can be adapted to rtsp straightforwardly.

    Also you can use FFMPEG.jl which basically does the same, but it adds some convinience wrappers.

    using FFMPEG
    
    FFMPEG.exe("-f", "v4l2", "-framerate", "25", "-video_size", "640x480", "-i", "/dev/video0", "output.mkv")