在docker文件中使用webcam /dev/vdeio 0

f45qwnt8  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(96)
FROM alpine:edge AS build
RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk add --no-cache gst-rtsp-server-dev
RUN apk add --no-cache libtool
RUN apk add --no-cache gcc
RUN apk add --no-cache musl-dev
RUN apk add --no-cache pkgconf 
COPY src/gst-rtsp-launch.c gst-rtsp-launch.c
RUN libtool --mode=link \
 gcc `pkg-config --cflags --libs gstreamer-1.0` \
 -L/usr/lib/x86_64-linux-gnu -lgstrtspserver-1.0 \
 -o gst-rtsp-launch gst-rtsp-launch.c

FROM alpine:edge
RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk add --no-cache gst-rtsp-server
RUN apk add --no-cache gst-plugins-base
RUN apk add --no-cache gst-plugins-ugly
RUN apk add --no-cache gst-plugins-good
RUN apk add --no-cache gst-plugins-bad
RUN apk add --no-cache gst-libav
RUN apk add --no-cache v4l-utils

COPY --from=build gst-rtsp-launch /usr/bin/gst-rtsp-launch

# Grant necessary privileges to access /dev/video0
RUN addgroup -S mygroup && adduser -S myuser -G mygroup
RUN chown myuser:mygroup -R /dev
USER myuser

EXPOSE 8554

ENTRYPOINT ["/usr/bin/gst-rtsp-launch"]
CMD ["v4l2src device=/dev/video0 ! videoconvert ! queue ! x264enc ! video/x-h264, alignment=au, stream-format=byte-stream, profile=main ! h264parse ! rtph264pay name=pay0 pt=96"]

字符串
我构建以下Dockerfile并启动rtsp服务器
并使用此命令运行docker

docker run --rm -it \
  --privileged \
  --volume=/dev:/dev \
  -p 8554:8554 \
  test_base:latest


1.那么docker可以在初始化时使用/dev/video 0目录吗?
1.我问这个是因为得到以下错误
0:00:04.069205726 1 0x 7 f0769 c994 e0错误rtspclient rtsp-client.c:3412:handle_describe_request:客户端0x 7 f0769 c9 b860:无介质
这意味着没有资源
错误更多详细信息

00:09.947254945     1 0x7f59f2efc4e0 INFO         GST_REFCOUNTING gstelement.c:3470:gst_element_finalize:<rtpbin0> 0x7f59f2828ae0 finalize
0:00:09.947263927     1 0x7f59f2efc4e0 INFO         GST_REFCOUNTING gstelement.c:3475:gst_element_finalize:<rtpbin0> 0x7f59f2828ae0 finalize parent
0:00:09.947273407     1 0x7f59f2efc4e0 DEBUG              rtspmedia rtsp-media.c:2809:gst_rtsp_media_set_status: setting new status to 0
0:00:09.947283034     1 0x7f59f2efc4e0 DEBUG              rtspmedia rtsp-media.c:4078:finish_unprepare: removing bus watch
0:00:09.947293657     1 0x7f59f2efc4e0 DEBUG                GST_BUS gstelement.c:3543:gst_element_get_bus:<media-pipeline> got bus <bus2>
0:00:09.947301723     1 0x7f59f2efc4e0 DEBUG              rtspmedia rtsp-media.c:3421:watch_destroyed:<GstRTSPMedia@0x7f59f3103410> source destroyed
0:00:09.947309835     1 0x7f59f2efc4e0 DEBUG              rtspmedia rtsp-media.c:4083:finish_unprepare: destroy source
0:00:09.947316839     1 0x7f59f2efc4e0 DEBUG                GST_BUS gstbus.c:846:gst_bus_source_dispose:<bus2> disposing source 0x7f59f29bb990
0:00:09.947325059     1 0x7f59f2efc4e0 DEBUG              rtspmedia rtsp-media.c:4089:finish_unprepare: stop thread
0:00:09.947332501     1 0x7f59f2efc4e0 DEBUG                default rtsp-thread-pool.c:178:gst_rtsp_thread_stop: stop thread 0x7f59f29b7bd0
0:00:09.947339272     1 0x7f59f2efc4e0 DEBUG                default rtsp-thread-pool.c:181:gst_rtsp_thread_stop: add idle source to quit mainloop of thread 0x7f59f29b7bd0
0:00:09.947350667     1 0x7f59f2efc4e0 ERROR             rtspclient rtsp-client.c:1115:find_media: client 0x7f59f2efe870: can't prepare media
0:00:09.947359058     1 0x7f59f29b88d0 DEBUG                default rtsp-thread-pool.c:159:do_quit: stop mainloop of thread 0x7f59f29b7bd0
0:00:09.947374070     1 0x7f59f29b88d0 INFO          rtspthreadpool rtsp-thread-pool.c:331:do_loop: exit mainloop of thread 0x7f59f29b7bd0
0:00:09.947383985     1 0x7f59f29b88d0 DEBUG                default rtsp-thread-pool.c:74:_gst_rtsp_thread_free: free thread 0x7f59f29b7bd0
0:00:09.947397351     1 0x7f59f2efc4e0 INFO               rtspmedia rtsp-media.c:530:gst_rtsp_media_finalize: finalize media 0x7f59f3103410
0:00:09.947408315     1 0x7f59f2efc4e0 DEBUG             rtspstream rtsp-stream.c:390:gst_rtsp_stream_finalize: finalize stream 0x7f59f2f1b980
0:00:09.947418939     1 0x7f59f2efc4e0 DEBUG        GST_REFCOUNTING gstpipeline.c:258:gst_pipeline_dispose:<media-pipeline> 0x7f59f31034f0 dispose
0:00:09.947429915     1 0x7f59f2efc4e0 DEBUG        GST_REFCOUNTING gstbin.c:517:gst_bin_dispose:<media-pipeline> 0x7f59f31034f0 dispose
0:00:09.947440879     1 0x7f59f2efc4e0 DEBUG          GST_PARENTAGE gstbin.c:1864:gst_bin_remove: removing element bin0 from bin media-pipeline
0:00:09.947451496     1 0x7f59f2efc4e0 DEBUG                    bin gstbin.c:1563:gst_bin_remove_func:<media-pipeline> element :bin0
0:00:09.947460258     1 0x7f59f2efc4e0 DEBUG                    bin gstbin.c:1650:gst_bin_remove_func:<media-pipeline> we removed the last source
0:00:09.947468917     1 0x7f59f2efc4e0 DEBUG                    bin gstbin.c:1762:gst_bin_remove_func:<media-pipeline> recalc state preroll: 0, other async: 0, this async 0
0:00:09.947475785     1 0x7f59f2efc4e0 DEBUG          GST_PARENTAGE gstelement.c:3488:gst_element_set_bus_func:<bin0> setting bus to 0
0:00:09.947485640     1 0x7f59f2efc4e0 DEBUG              GST_CLOCK gstelement.c:443:gst_element_set_clock:<bin0> setting clock 0
0:00:09.947494788     1 0x7f59f2efc4e0 DEBUG              GST_CLOCK gstelement.c:443:gst_element_set_clock:<capsfilter0> setting clock 0
0:00:09.947503819     1 0x7f59f2efc4e0 DEBUG              GST_CLOCK gstelement.c:443:gst_element_set_clock:<pay0> setting clock 0
0:00:09.947512433     1 0x7f59f2efc4e0 DEBUG              GST_CLOCK gstelement.c:443:gst_element_set_clock:<h264parse0> setting clock 0
0:00:09.947522651     1 0x7f59f2efc4e0 DEBUG              GST_CLOCK gstelement.c:443:gst_element_set_clock:<x264enc0> setting clock 0


.943327607     1 0x7f59f29b88d0 WARN               structure gststructure.c:2093:priv_gst_structure_append_to_gstring: No value transform to serialize field 'gerror' of type 'GError'
0:00:09.943335854     1 0x7f59f2efc4e0 DEBUG                    bin gstbin.c:2576:gst_bin_element_set_state:<media-pipeline> setting element rtpbin0 to NULL, base_time 0:00:00.000000000
0:00:09.943351708     1 0x7f59f29b88d0 DEBUG                GST_BUS gstbus.c:818:gst_bus_source_dispatch:<bus2> source 0x7f59f29bb990 calling dispatch with error message: 0x7f59f2779f40, time 99:99:99.999999999, seq-num 47, element 'v4l2src0', GstMessageError, gerror=(GError)NULL, debug=(string)"../sys/v4l2/v4l2_calls.c\(626\):\ gst_v4l2_open\ \(\):\ /GstPipeline:media-pipeline/GstBin:bin0/GstV4l2Src:v4l2src0:\012system\ error:\ Permission\ denied";
0:00:09.943353650     1 0x7f59f2efc4e0 DEBUG             GST_STATES gstelement.c:2967:gst_element_set_state_func:<rtpbin0> set_state to NULL
0:00:09.943367975     1 0x7f59f29b88d0 WARN               rtspmedia rtsp-media.c:3306:default_handle_message: 0x7f59f3103410: got error Could not open device '/dev/video0' for reading and writing. (../sys/v4l2/v4l2_calls.c(626): gst_v4l2_open (): /GstPipeline:media-pipeline/GstBin:bin0/GstV4l2Src:v4l2src0:
system error: Permission denied)

iovurdzv

iovurdzv1#

NB:这是部分答案;它纠正了你的问题中的几个问题,但至少在我的系统上导致了一个新的错误。尽管如此,我认为它可能仍然是有用的。
对你的问题有几点评论:

  • 如果您使用的是--privileged,则不需要--volume /dev:/dev,因为默认情况下--privileged会公开整个主机/dev
  • 实际上,您可能不需要--privileged;您可以使用--device标志将单个设备暴露给容器。
  • 在安装软件包时,在一个apk命令行中安装多个软件包总是一个更好的主意,而不是多次调用apk add-这意味着apk只需要计算一次依赖关系,而不是多次,因此您的映像将更快地构建。
  • 您可以直接安装gstreamer-tools包,而不是在Dockerfile中构建gst-launch

把所有这些放在一起,我的系统上的/dev/video1是一个网络摄像头。如果我使用这个Dockerfile

FROM alpine:edge
RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk add gst-rtsp-server \
    gst-plugins-base \
    gst-plugins-ugly \
    gst-plugins-good \
    gst-plugins-bad \
    gst-libav \
    v4l-utils \
    gstreamer-tools

CMD ["sh", "-c", "gst-launch-1.0 v4l2src device=${VIDEODEVICE:-/dev/video0} videoconvert ! queue ! x264enc ! video/x-h264, alignment=au, stream-format=byte-stream, profile=main ! h264parse ! rtph264pay name=pay0 pt=96"]

字符串
构建它:

docker build -t gsttest .


像这样运行:

docker run -it --rm -e VIDEODEVICE=/dev/video1 --device /dev/video1  gsttest


它运行并能够成功打开摄像头设备:

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock


不幸的是,它在大约一秒钟后失败了:

ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
../libs/gst/base/gstbasesrc.c(3132): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-linked (-1)
Execution ended after 0:00:01.974160448
Setting pipeline to NULL ...
Freeing pipeline ...

相关问题