按照说明安装v4l2loopback
内核模块和gphoto2
.
我可以使用 控制相机和拍照Entangle
,还可以在其中查看实时预览视频Entangle
,但我无法使用 ffmpeg 流式传输视频以在其他应用程序中使用它。
$ gphoto2 --abilities
Abilities for camera : Sony DSC-RX100M4
Serial port support : no
USB support : yes
Capture choices :
: Image
: Preview
: Trigger Capture
Configuration support : yes
Delete selected files on camera : yes
Delete all files on camera : no
File preview (thumbnail) support : yes
File upload support : yes
杀死所有现有实例
$ sudo killall gvfs-gphoto2-volume-monitor
gvfs-gphoto2-volume-monitor: no process found
有 3 个 /dev/video*
$ ll /dev/video*
crw-rw----+ 1 root video 81, 0 Nov 7 08:46 /dev/video0
crw-rw----+ 1 root video 81, 1 Nov 7 08:46 /dev/video1
crw-rw----+ 1 root video 81, 2 Nov 7 09:35 /dev/video2
运行将视频传送到 /dev/video* 的命令对其中任何一个都不起作用:
$ gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc ! decodebin3 name=dec ! queue ! videoconvert ! v4l2sink device=/dev/video2
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Device '/dev/video2' is not a output device.
Additional debug info:
v4l2_calls.c(636): gst_v4l2_open (): /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0:
Capabilities: 0x85208000
Setting pipeline to NULL ...
Freeing pipeline ...
*** Error ***
Sorry, your Sony camera does not seem to return a JPEG image in LiveView mode
ERROR: Movie capture error... Exiting.
Movie capture finished (0 frames)
如官方说明中所述,我尝试了在相机上的 AUTO 和 MOVIE 模式之间切换的不同方法,但没有运气......
知道我错过了什么吗?
是否Sorry, your Sony camera does not seem to return a JPEG image in LiveView mode
意味着它不适用于我的相机?( Sony DSC-RX100M4
)
另一个命令(ffmpeg
):
$ gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mjpeg @ 0x55bb2836b0c0] Format mjpeg detected only with low score of 25, misdetection possible!
Input #0, mjpeg, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1024x680, 25 tbr, 1200k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
[swscaler @ 0x55bb283bef00] deprecated pixel format used, make sure you did set range correctly
[video4linux2,v4l2 @ 0x55bb28370dc0] Unable to open V4L2 device '/dev/video1'
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted
Error initializing output stream 0:0 --
Conversion failed!
因此,要么使用带有 libgphoto2>=2.5.26 的现代发行版,要么使用以下脚本进行升级:https ://github.com/gonzalo/gphoto2-updater/
检查 libgphoto2 版本
之后,将相机 USB 模式切换到 PC 控制(PC 远程)模式。如果需要,更改省电设置(以便在超时后不会关闭)。
检查照片拍摄
ffmpeg
to/dev/video2
。然后用VLC打开V4L2摄像头流进行测试。(v4l2-ctl
是列出 V4L2 设备,之后rmmod
可以选择卸载v4l2loopback
)。