keshavdv / unifi-cam-proxy

Enable non-Ubiquiti cameras to work with Unifi NVR
MIT License
1.65k stars 230 forks source link

Docker + ffmpeg 4.3 broken #124

Closed evilworm closed 2 years ago

evilworm commented 2 years ago

I have Unifi Cloud Key Gen2 and wanted to have my Hikvision camera displayed in my Viewport. Tried the dockerised unifi-cam-proxy version, but I could only get the snapshot image displayed however live streaming did not work. After digging around I found out that the Dockerfile pulls in ffmpeg 4.3 which unfortunately does not work for some reason... running ffmpeg on the stream outputs this:

root@1937771de3b9:/app# ffmpeg -nostdin -y -stimeout 15000000 -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i "rtsp://xxx:xxx@10.0.30.254:554/Streaming/Channels/101/" -c:v copy -ar 32000 -ac 1 -codec:a aac
-b:a 32k -metadata streamname=8fYie4leC7cIGT7P -f flv - | /usr/local/bin/python -m unifi.clock_sync | nc 10.0.30.10 7550
ffmpeg version 4.3.2-0+deb11u2 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr --extra-version=0+deb11u2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, rtsp, from 'rtsp://xxx:xxx@10.0.30.254:554/Streaming/Channels/101/':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 1638358564.523478, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, 90k tbr, 90k tbn, 180k tbc
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (pipe:) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Output #0, flv, to 'pipe:':
  Metadata:
    title           : Media Presentation
    streamname      : 8fYie4leC7cIGT7P
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007), yuv420p(progressive), 1920x1080, q=2-31, 90k tbr, 1k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
[flv @ 0x55e25903cb00] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[flv @ 0x55e25903cb00] Packet is missing PTS
av_interleaved_write_frame(): Invalid argument
[flv @ 0x55e25903cb00] Failed to update header with correct duration.
[flv @ 0x55e25903cb00] Failed to update header with correct filesize.
frame=    1 fps=0.0 q=-1.0 Lsize=       0kB time=00:00:00.00 bitrate=2576.0kbits/s speed=13.3x
video:496kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

I tried running the same ffmpeg command locally and it worked. I compared ffmpeg versions and found out that I have 3.4 and docker image has 4.3. Modified the Dockerfile to the following:

FROM jrottenberg/ffmpeg:3.4-ubuntu
WORKDIR /app

RUN apt-get -y update && apt-get install -y \
  python3 \
  pip \
  netcat-openbsd

COPY . .

RUN pip install .

COPY ./docker/entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
CMD ["unifi-cam-proxy"]

... and then docker-compose build && docker-compose up and I got the live image on my viewport

It would probably be a good idea to have fixed ffmpeg version in the Dockerfile apt-get part

hope this helps someone having similar issues...

Geraldf commented 2 years ago

@evilworm, I have exactly the same issue. I only see the "still" image, but no streaming. I tried your modified docker file, but it did not help. I verified that I really have ffmpeg version 3.4

ffmpeg version 3.4.9 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04) configuration: --disable-debug --disable-doc --disable-ffplay --enable-avresample --enable-chromaprint --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfdk_aac --enable-libfreetype --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-libzmq --enable-nonfree --enable-openssl --enable-postproc --enable-shared --enable-small --enable-version3 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --extra-libs=-ldl --prefix=/opt/ffmpeg

Did you change something else in addition?

evilworm commented 2 years ago

Docker-compose fix will help the video to be transfered to unifi protect however it seems that there are some other issues too 1) I get live video on my Unifi Viewport 2) I dont get live video in web UI, it just keeps "loading" forever 3) I have live video on my phone application 4) on the phone - when scrolling/seeking video to some specific time, it will not play the video but shows still image ... on desktop web ui it does not seek the video at all

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.