Video not playing in PC and web randomly, why?

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Video not playing in PC and web randomly, why?

Post by zmaximz »

Hello, after updating/fresh installation to 1.36.33 (I believe.. or I've played with I-frame in camera settings?.. not remember) sometimes have this problem.
I'm using Camera Passthrough only and video wrote wrongly randomly?, it's playing in K-Lite Codec Pack Media Player (but without timeline) and video from same camera sometimes playing ok. Default settings in ffmpeg and etc.
If I try play corrupted video Zonemider has error:

Code: Select all

Can't create frame images from video for this event 2668-video.mp4Command was: /usr/bin/ffmpeg -ss 51.99 -i /data/events/2/2023-08-11/2668/2668-video.mp4 -frames:v 1 /data/events/2/2023-08-11/2668/00521-capture.jpg 2>&1Output was: ffmpeg version 4.3.5-0+deb11u1 Copyright (c) 2000-2022 the FFmpeg developers built with gcc 10 (Debian 10.2.1-6) configuration: --prefix=/usr --extra-version=0+deb11u1 --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.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/events/2/2023-08-11/2668/2668-video.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso6iso2avc1mp41 title : Zoneminder Security Recording encoder : Lavf58.45.100 Duration: 00:00:00.10, start: 0.000000, bitrate: 265897 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 2304x1296, 265586 kb/s, 5230 fps, 10 tbr, 90k tbn, 20 tbc (default) Metadata: rotate : 90 handler_name : VideoHandler Side data: displaymatrix: rotation of -90.00 degreesStream mapping: Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))Press [q] to stop, [?] for help[swscaler @ 0x55cc13107cc0] deprecated pixel format used, make sure you did set range correctlyOutput #0, image2, to '/data/events/2/2023-08-11/2668/00521-capture.jpg': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso6iso2avc1mp41 title : Zoneminder Security Recording encoder : Lavf58.45.100 Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 1296x2304, q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc (default) Metadata: encoder : Lavc58.91.100 mjpeg handler_name : VideoHandler Side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A displaymatrix: rotation of -0.00 degreesframe= 0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed= 0xvideo:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknownOutput file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
I've attached camera settings, and media info from good and corrupted video from same cameras. Why they wrote with different parameters? Wrong Duration and Frame Rate mode.
Or maybe I can force correct settings in ffmpeg? What settings?

Guess I need to force Frame Rate mode to Constant... but my IPC has Variable Frame Rate, or I need to disable IPC Smart Encode (it's changing I-frame dynamically when there is static picture to reduce net load), or to use IPC Constant Bitrate in worst case


Can anyone help please?
Screenshot 2023-08-11 174115.png
Screenshot 2023-08-11 174115.png (83.14 KiB) Viewed 1863 times
Screenshot 2023-08-11 173723.png
Screenshot 2023-08-11 173723.png (80.41 KiB) Viewed 1863 times
Screenshot 2023-08-11 174944.png
Screenshot 2023-08-11 174944.png (15.29 KiB) Viewed 1863 times
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Re: Video not playing in PC and web randomly, why?

Post by zmaximz »

Or maybe when I imported/exported settings from database with dbeaver something was a bit wrong :? ... I will fix and watch for now...
But guess it's not issue, there must be default value if nothing has passed, and in past there was also problems...
Maybe something about "frag_keyframe" option, don't know
Screenshot 2023-08-11 184839.png
Screenshot 2023-08-11 184839.png (16.79 KiB) Viewed 1856 times
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Re: Video not playing in PC and web randomly, why?

Post by zmaximz »

I think with Passthrough enabled encoding settings doesn't has any impact, like "FFMPEG_OUTPUT_OPTIONS" or "Optional Encoder Parameters (?)"
Maybe some network error...

"H264 Camera Passthrough – this option assumes that the camera is already sending an h264 stream. Video will be recorded as is, without any post-processing in zoneminder. Video characteristics such as bitrate, encoding mode, etc. should be set directly in the camera." (c)
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Re: Video not playing in PC and web randomly, why?

Post by zmaximz »

Still have same issue. Changing ipc params not have result.
At server start everything works fine, but after ~12hours of work recorded files has same time problem, file has all frames, but it doesn't has correct time length tag or something in properties, restarting zoneminder helps for next 12 hours, guess everything was ok with 1.34, but after updating to 1.36 or using 1.36 docker this happens.
Also I've checked something like udp and "allowed_media_types=video, reorder_queue_size=3000, buffer_size=8388608", with no results, changing resolution, codec, bitrate, color depth etc...
At first I thought it happens because of lack of resources, so now I have decoding disabled and using external motion trigger, so cpu is 0.71 and ram usage up to 6Gb of 32 Gb.
Don't have any ideas why this happens for now, can see only solution to restart zoneminder every 12 hours, or return to 1.34
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Re: Video not playing in PC and web randomly, why?

Post by zmaximz »

Can see many differences in 1.34.26, 1.36.33, 1.37.43 in zm_videostore.cpp, maybe it's about this remark in 1.37.43 "// Special flag to tell us to open a codec to get new extraflags to fix weird h265". I'll check 1.37.43
My cameras doesn't have h264 at all, only h265
But it's pity there are no stable version for h265 with security fixes

Maybe differences in this code, but I don't really know why after some time, some cameras h265 have wrong video parameters in 1.36.33, and it is fixed with restarting monitor, can't see errors in logs, zoneminder showing time correctly from database in web
1.36.33

Code: Select all

if (monitor->GetOptVideoWriter() == Monitor::PASSTHROUGH) {
      // Don't care what codec, just copy parameters
      video_out_ctx = avcodec_alloc_context3(nullptr);
1.37.43

Code: Select all

if (monitor->GetOptVideoWriter() == Monitor::PASSTHROUGH) {
      video_out_stream = avformat_new_stream(oc, nullptr);
      if (!video_out_stream) {
        Error("Unable to create video out stream");
        return false;
      }
      avcodec_parameters_copy(video_out_stream->codecpar, video_in_stream->codecpar);
      zm_dump_codecpar(video_out_stream->codecpar);

      video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
      // Only set orientation if doing passthrough, otherwise the frame image will be rotated
      Monitor::Orientation orientation = monitor->getOrientation();
      if (orientation) {
        Debug(3, "Have orientation %d", orientation);
        if (orientation == Monitor::ROTATE_0) {
        } else if (orientation == Monitor::ROTATE_90) {
          ret = av_dict_set(&video_out_stream->metadata, "rotate", "90", 0);
          if (ret < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__);
        } else if (orientation == Monitor::ROTATE_180) {
          ret = av_dict_set(&video_out_stream->metadata, "rotate", "180", 0);
          if (ret < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__);
        } else if (orientation == Monitor::ROTATE_270) {
          ret = av_dict_set(&video_out_stream->metadata, "rotate", "270", 0);
          if (ret < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__);
        } else {
          Warning("Unsupported Orientation(%d)", orientation);
        }
      } // end if orientation

      if (av_dict_get(opts, "new_extradata", nullptr, AV_DICT_MATCH_CASE)) {
        av_dict_set(&opts, "new_extradata", nullptr, 0);
        // Special flag to tell us to open a codec to get new extraflags to fix weird h265
        video_out_codec = avcodec_find_encoder(video_in_stream->codecpar->codec_id);
        if (video_out_codec) {
          video_out_ctx = avcodec_alloc_context3(video_out_codec);
          ret = avcodec_parameters_to_context(video_out_ctx, video_in_stream->codecpar);

          if (ret < 0) {
            Error("Could not initialize ctx parameters");
            return false;
          }
          //video_out_ctx->pix_fmt = fix_deprecated_pix_fmt(video_out_ctx->pix_fmt);
          if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
            video_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
          }
          video_out_ctx->time_base = video_in_ctx->time_base;
          if (!(video_out_ctx->time_base.num && video_out_ctx->time_base.den)) {
            Debug(2,"No timebase found in video in context, defaulting to Q");
            video_out_ctx->time_base = AV_TIME_BASE_Q;
          }
          video_out_ctx->bit_rate = video_in_ctx->bit_rate;
          video_out_ctx->gop_size = video_in_ctx->gop_size;
          video_out_ctx->has_b_frames = video_in_ctx->has_b_frames;
          video_out_ctx->max_b_frames = video_in_ctx->max_b_frames;
          video_out_ctx->qmin = video_in_ctx->qmin;
          video_out_ctx->qmax = video_in_ctx->qmax;

          if (!av_dict_get(opts, "crf", nullptr, AV_DICT_MATCH_CASE)) {
            if (av_dict_set(&opts, "crf", "23", 0)<0)
              Warning("Can't set crf to 23");
          }

          if ((ret = avcodec_open2(video_out_ctx, video_out_codec, &opts)) < 0) {
            Warning("Can't open video codec (%s) %s",
                video_out_codec->name,
                av_make_error_string(ret).c_str()
                );
            video_out_codec = nullptr;
          }
        }  // end if video_out_codec

        ret = avcodec_parameters_from_context(video_out_stream->codecpar, video_out_ctx);
        if (ret < 0) {
          Error("Could not initialize stream parameters");
        }
        av_dict_free(&opts);
        // Reload it for next attempt and/or avformat open
        ret = av_dict_parse_string(&opts, options.c_str(), "=", "#,\n", 0);
        if (ret < 0) {
          Warning("Could not parse ffmpeg output options '%s'", options.c_str());
        } else {
          if (reorder_queue_size) {
            av_dict_set(&opts, "reorder_queue_size", nullptr, AV_DICT_MATCH_CASE);
          }
        }
      }  // end if extradata_entry
1.34.26

Code: Select all

#if 0
#else
  ret = avcodec_parameters_from_context(video_out_stream->codecpar, video_in_ctx);
  if ( ret < 0 ) {
    Error("Could not initialize video_out_ctx parameters");
    return;
  } else {
    zm_dump_codec(video_out_ctx);
  }
#endif
  zm_dump_codecpar(video_in_stream->codecpar);
  zm_dump_codecpar(video_out_stream->codecpar);
#endif
Magic919
Posts: 1381
Joined: Wed Sep 18, 2013 6:56 am

Re: Video not playing in PC and web randomly, why?

Post by Magic919 »

Would be worth seeing if your camera can produce standard H.265. H.265X, whatever that does, is probably not.
-
zmaximz
Posts: 29
Joined: Mon Sep 03, 2018 12:27 pm

Re: Video not playing in PC and web randomly, why?

Post by zmaximz »

Sorry, seems problem in ipc firmware autoupdate, after downgrading firmware one step, weird incompatibility problem disappeared. With some oldest ipc firmware versions I've got "No width and height in video stream. Trying again" error, so there must be something wrong. Looks like there are broken latest firmware also.
Anyway 37.43 working fine. Especially decoding on demand. So with 64 ipc and external trigger I have 1.09 CPU and 6-15Gb of Ram usage. Only, one time I've seen unexplained Ram usage spikes, like from 6 to 32, and then drop to 6
Post Reply