0

I need to cast a stream from a USB camera via RTSP as stable as possible (at any moment i need to be able to get a static picture on a remote host, reflecting the real state of affairs in front of the camera) and economically on the used resources (the hardware is very weak).

Trying to write mjpeg to rtsp only displays green screen:

enter image description here

Camera information:

[dshow @ 000001e6a938b880] DirectShow video device options (from video devices)
[dshow @ 000001e6a938b880]   vcodec=mjpeg  min s=1280x720 fps=30 max s=1280x720 fps=30
[dshow @ 000001e6a938b880]   vcodec=mjpeg  min s=640x360 fps=30 max s=640x360 fps=30
[dshow @ 000001e6a938b880]   vcodec=mjpeg  min s=640x480 fps=30 max s=640x480 fps=30
[dshow @ 000001e6a938b880]   vcodec=mjpeg  min s=848x480 fps=30 max s=848x480 fps=30
[dshow @ 000001e6a938b880]   vcodec=mjpeg  min s=960x540 fps=30 max s=960x540 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=160x120 fps=30 max s=160x120 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=320x180 fps=30 max s=320x180 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=320x240 fps=30 max s=320x240 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=424x240 fps=30 max s=424x240 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=640x360 fps=30 max s=640x360 fps=30
[dshow @ 000001e6a938b880]   pixel_format=yuyv422  min s=640x480 fps=30 max s=640x480 fps=30

Mediamtx output output:

ffmpeg version 6.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, dshow, from 'video=Integrated Webcam':
  Duration: N/A, start: 152089.739306, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 30 fps, 30 tbr, 10000k tbn
2024/06/28 14:58:55 INF [RTSP] [conn [::1]:36681] opened
2024/06/28 14:58:55 INF [RTSP] [session f3037426] created by [::1]:36681
2024/06/28 14:58:55 INF [RTSP] [session f3037426] is publishing to path 'camera01', 1 track (M-JPEG)
Output #0, rtsp, to 'rtsp://localhost:8554/camera01':
  Metadata:
    encoder         : Lavf60.16.100
  Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, q=2-31, 30 fps, 30 tbr, 90k tbn
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
2024/06/28 14:59:00 INF [RTSP] [conn 127.0.0.1:36683] opened=N/A
2024/06/28 14:59:00 INF [RTSP] [session 0462ceb2] created by 127.0.0.1:36683
2024/06/28 14:59:00 INF [RTSP] [session 0462ceb2] is reading from path 'camera01', with UDP, 1 track (M-JPEG)

runOnInit in mediamtx.yml:

FFmpeg -hwaccel_output_format qsv -fflags nobuffer -f dshow -vcodec mjpeg_qsv -s 640x480 -i video="Integrated Webcam" -vcodec copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH

UPD (ffplay output):

ffplay rtsp://localhost:8554/camera01
Input #0, rtsp, from 'rtsp://localhost:8554/camera01':   0B f=0/0
  Metadata:
    title           : No Name
  Duration: N/A, start: 0.120878, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 640x480 [SAR 1:1 DAR 4:3], 90k tbr, 90k tbn

[rtsp @ 0000013b6f19dc00] video codec set to: mjpeg
[rtp @ 0000013b6f1a6fc0] No default whitelist set
[udp @ 0000013b6f197080] No default whitelist set
[udp @ 0000013b6f197080] end receive buffer size reported is 393216
[udp @ 0000013b6f196540] No default whitelist set
[udp @ 0000013b6f196540] end receive buffer size reported is 393216
[rtsp @ 0000013b6f19dc00] setting jitter buffer size to 500
[rtsp @ 0000013b6f19dc00] hello state=0
[mjpeg @ 0000013b6f1a2a40] marker=d8 avail_size_in_buf=32048f=0/0
[mjpeg @ 0000013b6f1a2a40] marker parser used 0 bytes (0 bits)
[mjpeg @ 0000013b6f1a2a40] marker=e0 avail_size_in_buf=32046
[mjpeg @ 0000013b6f1a2a40] marker parser used 16 bytes (128 bits)
[mjpeg @ 0000013b6f1a2a40] marker=db avail_size_in_buf=32028
[mjpeg @ 0000013b6f1a2a40] index=0
[mjpeg @ 0000013b6f1a2a40] qscale[0]: 2
[mjpeg @ 0000013b6f1a2a40] index=1
[mjpeg @ 0000013b6f1a2a40] qscale[1]: 4
[mjpeg @ 0000013b6f1a2a40] marker parser used 132 bytes (1056 bits)
[mjpeg @ 0000013b6f1a2a40] marker=c4 avail_size_in_buf=31894
[mjpeg @ 0000013b6f1a2a40] marker parser used 0 bytes (0 bits)
[mjpeg @ 0000013b6f1a2a40] marker=c0 avail_size_in_buf=31474
[mjpeg @ 0000013b6f1a2a40] Changing bps from 0 to 8
[mjpeg @ 0000013b6f1a2a40] sof0: picture: 640x480
[mjpeg @ 0000013b6f1a2a40] component 0 2:1 id: 1 quant:0
[mjpeg @ 0000013b6f1a2a40] component 1 1:1 id: 2 quant:1
[mjpeg @ 0000013b6f1a2a40] component 2 1:1 id: 3 quant:1
[mjpeg @ 0000013b6f1a2a40] pix fmt id 21111100
[mjpeg @ 0000013b6f1a2a40] Format yuvj422p chosen by get_format().
[mjpeg @ 0000013b6f1a2a40] marker parser used 17 bytes (136 bits)
[mjpeg @ 0000013b6f1a2a40] escaping removed 73 bytes
[mjpeg @ 0000013b6f1a2a40] marker=da avail_size_in_buf=31455
[mjpeg @ 0000013b6f1a2a40] marker parser used 31382 bytes (251056 bits)
[mjpeg @ 0000013b6f1a2a40] marker=d9 avail_size_in_buf=0
[mjpeg @ 0000013b6f1a2a40] decode frame unused 0 bytes
[rtsp @ 0000013b6f19dc00] All info found
[mjpeg @ 0000013b6f247cc0] marker=d8 avail_size_in_buf=32048f=0/0
[mjpeg @ 0000013b6f247cc0] marker parser used 0 bytes (0 bits)
[mjpeg @ 0000013b6f247cc0] marker=e0 avail_size_in_buf=32046
[mjpeg @ 0000013b6f247cc0] marker parser used 16 bytes (128 bits)
[mjpeg @ 0000013b6f247cc0] marker=db avail_size_in_buf=32028
[mjpeg @ 0000013b6f247cc0] index=0
[mjpeg @ 0000013b6f247cc0] qscale[0]: 2
[mjpeg @ 0000013b6f247cc0] index=1
[mjpeg @ 0000013b6f247cc0] qscale[1]: 4
[mjpeg @ 0000013b6f247cc0] marker parser used 132 bytes (1056 bits)
[mjpeg @ 0000013b6f247cc0] marker=c4 avail_size_in_buf=31894
[mjpeg @ 0000013b6f247cc0] class=0 index=0 nb_codes=12
[mjpeg @ 0000013b6f247cc0] class=0 index=1 nb_codes=12
[mjpeg @ 0000013b6f247cc0] class=1 index=0 nb_codes=162
[mjpeg @ 0000013b6f247cc0] class=1 index=1 nb_codes=162
[mjpeg @ 0000013b6f247cc0] marker parser used 418 bytes (3344 bits)
[mjpeg @ 0000013b6f247cc0] marker=c0 avail_size_in_buf=31474
[mjpeg @ 0000013b6f247cc0] sof0: picture: 640x480
[mjpeg @ 0000013b6f247cc0] component 0 2:1 id: 1 quant:0
[mjpeg @ 0000013b6f247cc0] component 1 1:1 id: 2 quant:1
[mjpeg @ 0000013b6f247cc0] component 2 1:1 id: 3 quant:1
[mjpeg @ 0000013b6f247cc0] pix fmt id 21111100
[mjpeg @ 0000013b6f247cc0] Format yuvj422p chosen by get_format().
[mjpeg @ 0000013b6f247cc0] marker parser used 17 bytes (136 bits)
[mjpeg @ 0000013b6f247cc0] escaping removed 73 bytes
[mjpeg @ 0000013b6f247cc0] marker=da avail_size_in_buf=31455
[mjpeg @ 0000013b6f247cc0] component: 1
[mjpeg @ 0000013b6f247cc0] component: 2
[mjpeg @ 0000013b6f247cc0] component: 3
[mjpeg @ 0000013b6f247cc0] mjpeg_decode_dc: bad vlc: 0:0 (0000013b6f1c95c8)
[mjpeg @ 0000013b6f247cc0] error dc
[mjpeg @ 0000013b6f247cc0] error y=1 x=0
[mjpeg @ 000002b37b115480] mjpeg_decode_dc: bad vlc: 0:0 (000002b37b0a8388)
[mjpeg @ 000002b37b115480] error dc
[mjpeg @ 000002b37b115480] error y=1 x=0
[swscaler @ 000002b37eb8b540] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 000002b37ec200c0] deprecated pixel format used, make sure you did set range correctly
    Last message repeated 2 times
[mjpeg @ 000002b37b115480] mjpeg_decode_dc: bad vlc: 0:0 (000002b37b0a8388)
[mjpeg @ 000002b37b115480] error dc
[mjpeg @ 000002b37b115480] error y=1 x=0
New contributor
Pavel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
9
  • 1
    A green screen often means its missing a codec on the device playing the video/stream.
    – LPChip
    Commented 2 days ago
  • Is it working with output file instead of RTSP: ffmpeg -hwaccel_output_format qsv -fflags nobuffer -f dshow -vcodec mjpeg_qsv -s 640x480 -i video="Integrated Webcam" -vcodec copy -t 10 output.mp4 for example? Instead of -hwaccel_output_format qsv -vcodec mjpeg_qsv, try: -input_format mjpeg. Since you are using stream copy: -vcodec copy, the camera output suppose to be MJPEG encoded video stream.
    – Rotem
    Commented yesterday
  • @LPChip unfortunately, apparently, this is not my option. VLC is now running on the same host and under the same user as the mediamtx server
    – Pavel
    Commented 23 hours ago
  • @Pavel it can still be an issue, but it might be that it just encodes the video with a codec that is non-existent. I just said what the green screen means. So check that you are actually encoding with the right codec
    – LPChip
    Commented 22 hours ago
  • @Rotem output: Input #0, dshow, from 'video=Integrated Webcam': Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 30 fps, 30 tbr, 10000k tbn encoder : Lavf60.16.100 Stream #0:0: Video: mjpeg (Baseline) (mp4v / 0x7634706D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, q=2-31, 30 fps, 30 tbr, 10000k tbn [out#0/mp4 @ 000001ebef28fb00] video:13877kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.031674% size= 13882kB time=00:00:09.96 bitrate=11408.3kbits/s
    – Pavel
    Commented 22 hours ago

0

You must log in to answer this question.

Browse other questions tagged .