Commit Graph
101 Commits
Author SHA1 Message Date
Isaac Connor a0e6356c4c Merge pull request #6265 from singhharsh1708/fix/mpeg-write-error-text
fix: report the real ffmpeg error when an mpeg stream write fails
2026-11-15 19:10:21 -05:00
singhharsh1708 e0dfd133fd fix: open mpeg streams below 1 fps instead of failing on a zero time base 2026-11-16 04:01:35 +05:30
singhharsh1708 96737b7190 fix: report the real ffmpeg error when an mpeg stream write fails 2026-11-16 03:56:51 +05:30
Jash 56470ac90a fix: free VideoStream codec_and_format with delete[] fixes #5575 2026-11-12 02:32:26 +05:30
Isaac ConnorandClaude Opus 5.5 954b14a728 fix: fit frames of another shape inside the stream instead of stretching refs #4186
The MPEG encoder's size is set by the stream's first frame. When playback moved
on to an event from a monitor with another aspect ratio, PackImage scaled its
frames to that size and distorted them. Scale them to fit inside it, centred on
black, with even sizes and offsets so subsampled chroma stays aligned. The black
fill is done by hand because av_image_fill_black needs FFmpeg 4.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 19:55:35 -05:00
Isaac ConnorandClaude Opus 5.5 4ff9e0c98f fix: try the packed layout when the 32-byte one does not fit the image refs #4186
A packed planar frame whose width is a multiple of 32, such as 32x16 YUV420P,
has the same luma stride as the 32-byte layout, so PackImage picked that layout
and then refused the image because it needs more bytes than the frame has. The
frame was dropped. Accept a layout only if it also fits Size(), so the packed
one is tried next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 08:45:56 -05:00
Isaac ConnorandClaude Opus 5.5 d30739272e fix: map an Image's rows at its own stride when packing for the encoder refs #4186
PackImage assumed every Image has 32-byte-aligned rows. An Image that wraps a
caller's buffer is packed (width * colours), and one wrapping an AVFrame keeps
the frame's stride, so mapping them on a 32-byte stride read the wrong rows
and ran past the end of the buffer. Use LineSize() for packed formats, match it
against the 32-byte or packed layout for planar ones, and refuse a mapping
larger than Size().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 08:30:56 -05:00
Isaac ConnorandClaude Opus 5.5 fc8791e52a fix: wait for the UI's next event in zms and encode any frame safely refs #4186
Gapless playback over zms follows the next/prev events the event view
sends with CMD_SET_EVENT. Reviewing the first version found these gaps:

- An event that ended before the UI's hint for it arrived fell back to
  zms's same-monitor query and skipped the other monitors' events again.
  The page needs a status poll and two requests to send that hint, and
  at 10x a ten second event lasts one second. Once a UI has sent any
  hint (ui_managed) zms never uses the same-monitor query: it holds on
  the last frame, like a pause, until the hint arrives, and stops after
  kHintWait (10s) if none does. Streams with no UI behave as before.
  The choice is EventStream::ChooseNeighbour, a static so it is tested.
- A hinted event deleted since the UI found it fell back to the
  same-monitor query, leaving the filter. It now stops there, as
  stream.php already does for a target deleted before forwarding.
- MPEG streams copied each frame into encoder buffers sized for the
  first frame's dimensions, format and packed stride. Text frames are
  drawn in the monitor's colours (usually RGB32) while event frames are
  RGB24, a frame from another monitor can be larger, and Image rows are
  padded to 32 bytes, so all three overran those buffers. The scaling
  added to StreamBase only handled size, and the live stream never set
  the tracked size. VideoStream::EncodeImage now converts any Image to
  the encoder's own size, format and stride with sws_scale, and every
  MPEG path uses it; the tracking in StreamBase is gone.
- loadEventData kept the previous event's video decoder when the new
  event had none, so a missing jpeg showed the previous camera's frame
  under the new event. It now drops it.
- The MPEG path only read jpegs, so an event recorded as video only
  streamed nothing. Both paths now take frames from loadFrameImage,
  which falls back to the event's video as the jpeg path already did.

tests/zm_eventstream_hints.cpp covers the message decoding, which hint
applies to which event, ChooseNeighbour (including Id order
10(M1) 11(M2) 12(M1) 13(M2), which went 11 -> 13) and PackImage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 19:32:53 -05:00
Isaac ConnorandClaude Opus 4.7 e5446d3af5 fix: report AVPixelFormat in Panic messages for actionable diagnosis (PR #4788)
Six format-dispatch fallbacks were still printing only the legacy
`colours` value, but the dispatch in each spot is now keyed off
pixelFormat/imagePixFormat. With the GRAY8/YUV420P alias collision
(both colours=1) the legacy value frequently doesn't identify the true
format, so a "Unexpected colours: 1" log on a misroute is useless.

Updated each Panic to include the AVPixelFormat enum value and its
human-readable name (via av_get_pix_fmt_name), plus the legacy
(colours, subpixelorder) for context:
- RemoteCameraRtsp constructor
- FfmpegCamera constructor
- VncCamera constructor
- LocalCamera conversion-selection branch
- VideoStream::SetupCodec mpeg helper
- Image::Delta unknown-format fallback

refs #4788

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 23:03:33 -04:00
Isaac Connor 7b21371083 Reapply "fix: replace ZM_COLOUR system with AVPixelFormat for format dispatch"
This reverts commit 60b6b37c60.
2026-05-03 12:24:43 -04:00
Isaac Connor 60b6b37c60 Revert "fix: replace ZM_COLOUR system with AVPixelFormat for format dispatch" 2026-05-02 18:26:48 -04:00
Isaac ConnorandClaude Opus 4.6 b416aa5293 fix: replace ZM_COLOUR_*/ZM_SUBPIX_ORDER_* with AVPixelFormat for format dispatch
ZM_COLOUR_GRAY8, ZM_COLOUR_YUV420P, and ZM_COLOUR_YUVJ420P were all
defined to 1, making format identification via colours ambiguous.
LocalCamera misidentified YUV420P as GRAY8, causing V4L2 MJPEG cameras
to decode to grayscale via expensive sws_scale conversion.

Replace the legacy ZM_COLOUR_*/ZM_SUBPIX_ORDER_* integer pair with
AVPixelFormat as the single source of truth for pixel format dispatch:

- Add src/zm_pixformat.h with central format helpers:
  zm_pixformat_from_colours, zm_colours_from_pixformat,
  zm_bytes_per_pixel, zm_db_colours_to_pixformat, zm_is_rgb32,
  zm_is_rgb24, zm_is_yuv420
- Add AVPixelFormat pixelFormat member + PixelFormat() accessor to Camera
- Add PixFormat() accessor to Image, delegate AVPixFormat methods
  to shared helpers
- Migrate all ~100 format dispatch comparisons in zm_image.cpp,
  zm_local_camera.cpp, zm_ffmpeg_camera.cpp, zm_remote_camera_rtsp.cpp,
  zm_libvlc_camera.cpp, zm_libvnc_camera.cpp, zm_monitor.cpp,
  zm_mpeg.cpp from colours/subpixelorder checks to imagePixFormat/
  AVPixelFormat checks
- Deprecate GetFFMPEGPixelFormat, delegate to zm_pixformat_from_colours
- Fix DeColourise bug: imagePixFormat was not updated to GRAY8
- Deprecate ZM_COLOUR_* and ZM_SUBPIX_ORDER_* constants in zm_rgb.h
- Add deprecation notice on Monitor.Colours web UI dropdown
- Add 13 Catch2 test cases (105 assertions) for format mapping helpers

refs #4735

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 11:42:06 -04:00
copilot-swe-agent[bot]andconnortechnology 2dfb79975d fix: prevent segfault when MPEG stream codec fails to open
Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
2026-03-05 02:15:08 +00:00
Isaac Connor 643fe97b25 Deprecate zm_av_frame_alloc 2025-09-18 14:48:52 -04:00
Steve Gilvarry 88227105b8 Removing avcodec_close, avcodec_free_context is replacement and been around since 2014, so should be no reason to version test. 2024-09-14 11:06:55 +10:00
Isaac Connor df29df0f0a Handle ffmpeg 7 deprecations 2024-05-08 14:28:18 -04:00
Aaron Kling c4683d90a9 Format code using astyle google format
Commands used:
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.cpp
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.h
2024-03-26 13:43:58 -05:00
Doug Nazar f4dd897ef4 Convert AVFrame* to custom unique_ptr (av_frame_ptr).
Switch all owning AVFrame* variables to av_frame_ptr for
automatic cleanup.

Use AVBufferRef to store frame data in AVFrame where appropriate
so that it can be freed automatically with it's AVFrame.

Handle allocation errors.
2022-07-30 13:21:11 -04:00
Doug Nazar 110cc436a3 Switch from av_init_packet() to av_packet_alloc()
Remove all uses of deprecated av_init_packet() and switch any stack
based AVPackets to unique_ptrs allocated with av_packet_alloc().

Ensure that all code paths call av_packet_unref() after use to reset
before next usage.
2022-07-29 14:56:26 -04:00
Isaac Connor 4f2dc894d5 get rid of got_packet to quiet cppcheck 2022-07-14 10:35:22 -04:00
Isaac Connor 513c228ff3 Merge branch 'master' of github.com:ZoneMinder/zoneminder 2022-04-03 16:29:15 -04:00
Isaac Connor d1cc451037 packet size should be buffer size, not the size of a pointer... 2022-04-03 16:28:38 -04:00
Exuvo a2cf001f66 Crude fix for AVPicture being removed in ffmpeg 5 2022-03-11 21:45:34 +01:00
Exuvo d1395dab9a Fix ffmpeg 5 const errors 2022-03-11 21:40:25 +01:00
Isaac Connor 037771539d spacing, return a success value from setupCodec instead of using Fatal 2022-01-10 17:36:49 -05:00
Peter Keresztes Schmidt 7c6a6ac309 VideoStream: Convert internals to std::chrono 2021-06-13 23:20:24 +02:00
Peter Keresztes Schmidt 2d71743372 FFmpeg: Remove code paths required only by 2.8 and older
With Xenial support dropped we require FFmpeg 3.2 and newer.
2021-06-05 20:40:12 +02:00
Peter Keresztes Schmidt 762476ec76 Build: Promote libswscale to a required dependency
FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies.
This reduces the possible build configurations greatly and thus maintenance burden.
2021-06-05 14:27:31 +02:00
Peter Keresztes Schmidt a9ad5c5eee Build: Promote libavcodec to a required dependency
FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies.
This reduces the possible build configurations greatly and thus maintenance burden.
2021-06-05 14:25:54 +02:00
Peter Keresztes Schmidt 68bedfe48f Fix logging format string mismatches
* Remove SZFMTD format macro and use %zu instead for size_t. %zu is understood by every compiler nowadays.
2021-04-30 00:26:24 +02:00
Peter Keresztes Schmidt d9568a98c0 Drop zm_thread which has been replaced by STL implementations 2021-03-04 10:55:46 +01:00
Isaac Connor 010674b3dd Fix use of local mem in return value reported by cppcheck 2021-02-06 20:11:38 -05:00
Peter Keresztes Schmidt 0dbc39ee25 Cleanup and reorganize includes
With this commit a unified structure for includes is introduced.
The general rules:
 * Only include what you need
 * Include wherever possible in the cpp and forward-declare in the header

 The includes are sorted in a local to global fashion. This means for the include order:
  0. If cpp file: The corresponding h file and an empty line
  1. Includes from the project sorted alphabetically
  2. System/library includes sorted alphabetically
  3. Conditional includes
2021-02-04 18:02:01 +01:00
Peter Keresztes Schmidt 5a57efdfe2 Replace deprecated C header includes with the C++ ones. 2021-02-04 05:39:03 +01:00
Peter Keresztes Schmidt 8f980a1168 Convert NULL/0 to nullptr
The 0 -> nullptr changes should definitely improve readability.
2020-08-26 22:03:40 +02:00
Isaac Connor 4d4fab46d6 Spacing, use FFMpegInit instead of deprecated ffmpeg calls 2020-08-05 19:17:00 -04:00
Isaac Connor 8518278476 coverity scan fixes/cleanups 2018-04-12 11:29:35 -04:00
Isaac Connor 882a242b76 Fix mpeg streaming. 2018-01-31 14:35:00 -05:00
Isaac Connor 5f0db60c38 quiet coverity 2017-12-12 13:25:41 -05:00
Isaac Connor 3c44c1f9be quiet coverity by returning after Panic 2017-12-12 13:19:23 -05:00
Isaac Connor 64816aa005 fixes from cppcheck. 2017-11-18 16:00:10 -05:00
Isaac Connor 159c0a7165 moer cppcheck fixes 2017-11-17 07:52:26 -05:00
APHW2 MFGENG e17bcb9178 updates for mast ffmpeg 2017-11-07 18:21:51 -08:00
Isaac Connor 83219d3e34 define av_frame_free to av_freep on older ffmpeg. Undo c++11 requirements. 2017-04-13 09:47:19 -04:00
Isaac Connor 0d5910644e whitespace and braces fixes. Also add some braces to fixup a compiler error about the else not doing what it should be. 2017-01-11 14:18:11 -05:00
Isaac Connor 5ae34a7561 Merge branch 'master' into storageareas 2017-01-02 09:39:10 -05:00
Andy Bauer 254fcbcef7 update gpl 2 mailing address in source files 2016-12-26 09:23:16 -06:00
Isaac Connor c3628a8dfd Merge branch 'updated-console' into storageareas 2016-05-03 14:34:58 -04:00
Steve Gilvarry 8452c4bce5 Fix tab to spaces merge issues 2016-04-29 21:27:28 +10:00
Isaac Connor 03b1ced568 tabs to spaces and use 2space indenting 2016-04-04 10:11:48 -04:00