以编程方式将图像发送到v4l2-device

时间:2013-10-30 21:33:16

标签: python webcam gstreamer v4l2

我有一个生成jpgs的程序。我想将这些图像发送到我的虚拟网络摄像头。我可以使用v4l2loopback创建一个虚拟网络摄像头,并且一直在关注gstreamer,但是无法让它工作。

我已尝试使用multifilesrc进行gst-launch,但这似乎只有在我已生成图像时才有效。我还尝试将gst-launch设置为只将一个图像发送到网络摄像头,然后在生成新图像时覆盖图像。不幸的是,这导致gstreamer崩溃。

有谁知道我怎么能这样做?我不必使用gstreamer,但我希望在Linux中实现这一点,最好是在Python中实现。

2 个答案:

答案 0 :(得分:1)

以下脚本将监视目录并将每个新添加的图像传递给gstreamer,gstreamer会将其发送到视频设备(/dev/video0,但随意更改)。

调用监视路径作为唯一参数(例如./pics2v4l2 /tmp/pics

#!/bin/sh

DIR=$1
DEVICE=/dev/video0

inotifywait -m "${DIR}" \
| awk '$2== "CLOSE_WRITE,CLOSE" {print $1"/"$3; fflush()}' \
| while read f; do
 gst-launch-0.10 uridecodebin uri="file://${f}" \
 ! ffmpegcolorspace \
 ! videoscale \
 ! imagefreeze \
 ! identity error-after=2 \
 ! v4l2sink show-preroll-frame=false device=${DEVICE}
done

答案 1 :(得分:0)

gst-launch-1.0 脚本


DIR=$1
DEVICE=/dev/video0

inotifywait -m "${DIR}" \
| awk '$2== "CLOSE_WRITE,CLOSE" {print $1"/"$3; fflush()}' \
| while read f; do
 gst-launch-1.0 uridecodebin uri="file://${f}" \
 ! videoconvert \
 ! videoscale \
 ! imagefreeze \
 ! identity error-after=2 \
 ! v4l2sink show-preroll-frame=false device=${DEVICE}
done

执行使用

sh <FILE_NAME>.sh <DIRECTORY_PATH>