Motion-Project / motion

Motion, a software motion detector. Home page: https://motion-project.github.io/
GNU General Public License v2.0
3.69k stars 550 forks source link

Could not find codec parameters for stream 0 (Video: h264, none): unspecified size #1735

Closed tosiara closed 10 months ago

tosiara commented 11 months ago

Did you read the guide?

Yes

What is the base version number of Motion being used?

4.6.x

What was the install method?

Installed via package tool

What is base architecture?

x86

What is the distro being used?

Ubuntu

Disto version number

22.04

Camera type(s) being used?

Network camera with RTSP

Describe the issue/problem and steps to reproduce

Motion fails with error:

[1:ml1] [INF] [ENC] ffmpeg_avcodec_log: Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options

The same error is given by ffprobe:

$ ffprobe -rtsp_transport udp -analyzeduration 30 "rtsp://admin:123456789abc@14.233.86.163:554/onvif1"
ffprobe version 4.2.7-0ubuntu0.1 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --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-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --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-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --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-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[rtsp @ 0x5651f34eef40] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, rtsp, from 'rtsp://admin:123456789abc@14.233.86.163:554/onvif1':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
  Duration: N/A, start: 0.000000, bitrate: 128 kb/s
    Stream #0:0: Video: h264, none, 90k tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_alaw, 16000 Hz, 1 channels, s16, 128 kb/s

However, the newer ffmpeg is able to read the stream:

 ffprobe -rtsp_transport udp "rtsp://admin:123456789abc@14.233.86.163:554/onvif1"
ffprobe version 6.0 Copyright (c) 2007-2023 the FFmpeg developers
  built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[rtsp @ 0x11ef04080] RTP: dropping old packet received too late
[h264 @ 0x1200046a0] deblocking filter parameters 8 0 out of range
[h264 @ 0x1200046a0] decode_slice_header error
[h264 @ 0x1200046a0] no frame!
[h264 @ 0x1200046a0] Missing reference picture, default is 0
[h264 @ 0x1200046a0] decode_slice_header error
[h264 @ 0x1200046a0] deblocking_filter_idc 31 out of range
[h264 @ 0x1200046a0] decode_slice_header error
[h264 @ 0x1200046a0] no frame!
[rtsp @ 0x11ef04080] RTP: dropping old packet received too late
Input #0, rtsp, from 'rtsp://admin:123456789abc@14.233.86.163:554/onvif1':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 15 fps, 15 tbr, 90k tbn
  Stream #0:1: Audio: pcm_alaw, 16000 Hz, mono, s16, 128 kb/s

$ ffprobe -rtsp_transport udp "rtsp://admin:123456789abc@14.233.86.163:554/onvif1"
ffprobe version 6.0 Copyright (c) 2007-2023 the FFmpeg developers
  built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[rtsp @ 0x134e05040] RTP: dropping old packet received too late
Input #0, rtsp, from 'rtsp://admin:123456789abc@14.233.86.163:554/onvif1':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 15 fps, 10 tbr, 90k tbn
  Stream #0:1: Audio: pcm_alaw, 16000 Hz, mono, s16, 128 kb/s

Motion log output at log_level 8

[1:ml1] [NTC] [VID] vid_start: Opening Netcam RTSP
[1:ml1] [DBG] [ALL] util_parms_parse: Parsing: rtsp_transport=udp,analyzeduration=30
[1:ml1] [DBG] [ALL] util_parms_add: Parsed: >rtsp_transport< >udp<
[1:ml1] [DBG] [ALL] util_parms_add: Parsed: >analyzeduration< >30<
[1:ml1] [INF] [NET] netcam_rtsp_set_parms: Setting up norm stream.
[1:ml1] [DBG] [ALL] util_parms_add: Parsed: >decoder< >NULL<
[1:ml1] [INF] [NET] netcam_rtsp_set_path: Setting up rtsp via netcam
[1:ml1] [INF] [NET] netcam_rtsp_set_options: norm: Setting rtsp/rtmp
[1:ml1] [INF] [NET] netcam_rtsp_set_options: norm: option: rtsp_transport = udp
[1:ml1] [INF] [NET] netcam_rtsp_set_options: norm: option: analyzeduration = 30
[1:ml1] [INF] [NET] netcam_rtsp_open_context: norm: Opened camera((null))
[1:ml1] [INF] [ENC] ffmpeg_avcodec_log: Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[1:av0] [INF] [NET] netcam_init_swdecoder: norm: Initializing decoder
[1:av0] [INF] [NET] netcam_rtsp_open_codec: norm: Decoder opened
[1:ml1] [ERR] [NET] netcam_rtsp_open_context: norm: Camera image size is invalid
[1:ml1] [INF] [NET] netcam_rtsp_cleanup: norm: Shutting down network camera.
tosiara commented 11 months ago

Here is how to patch ffmpeg and force camera to TCP to workaround a non-compliant RTSP camera Related: https://github.com/Motion-Project/motion/issues/1071, https://sourceforge.net/p/motion/mailman/message/58717607/

  1. Get ffmpeg sources: git clone https://github.com/ffmpeg/ffmpeg
  2. cd ffmpeg
  3. Pull the patch: wget https://raw.githubusercontent.com/eusoubrasileiro/motion_server_nvr/jetson-nano/ansible/roles/jnano/files/RTSP_lower_transport_TCP.patch
  4. Apply patch: git apply < RTSP_lower_transport_TCP.patch
  5. Install ffmpeg dependencies: sudo apt-get install yasm lib264-dev
  6. ./configure --prefix=/full/path/to/ffmpeg/out --enable-gpl --enable-libx264
  7. make -j4
  8. make install
  9. cd ..
  10. Get motion sources: git clone https://github.com/Motion-Project/motion
  11. cd motion
  12. Install build dependencies: sudo apt-get -y install autoconf automake build-essential pkgconf libtool libzip-dev libjpeg-dev libwebp-dev libmicrohttpd-dev autopoint
  13. Remove ffmpeg system libs: sudo apt-get remove libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libavdevice-dev
  14. autoreconf -fiv
  15. ./configure --with-ffmpeg=/full/path/to/ffmpeg/out
  16. make
  17. Test: ./src/motion -c your_config.conf -d 9 -n
bytes-commerce commented 11 months ago

Nice. Whats the downsize of doing it this way? It seems like out of the box, motion does not support h.264 codec.

tosiara commented 11 months ago

Packaged Motion uses ffmpeg libs to decode H264 and it comes out of the box. It's only a problem with some non-compliant cameras that require a custom ffmpeg build with a workaround to force TCP

bytes-commerce commented 11 months ago

After writing the comment, I figured that mkv for example is h264 encoded, so that worked. Sorry for the irrelevant weight to the issue.

Mr-Dave commented 10 months ago

Can you explain this issue more? Generally, we don't want UDP we want rtsp_transport tcp and this can be specified via the Motion option of netcam_params. (It is actually already the default). I didn't think that any such patch to ffmpeg was required. Simply specify it as the option instead of UDP.

For general issues with the camera not being detected or failing to analyze, the solution is usually to lower the camera GOP/I-Frame interval.

tosiara commented 10 months ago

The issue here is that ffmpeg out of the box tries to follow RTSP protocol. The camera in turn, supports TCP, but does not advertise it correctly, and motion fails to connect since motion forces TCP by default (perfectly explained by @eusoubrasileiro at https://stackoverflow.com/questions/66280861/ffmpeg-nonmatching-transport-in-server-reply-but-openrtsp-works)

There are two workarounds here.

  1. Configure motion to use UDP
  2. Or, patch ffmpeg to force use TCP even though the camera does follow RTSP protocol standards
Mr-Dave commented 10 months ago

I'm still not following the issue/problem for Motion to resolve. Is this just a FYI/"How to" for those that have one of these cameras?

tosiara commented 10 months ago

Yes, this was more like FYI for everyone as there were many users affected