2013-03-17 07:45:21 +08:00
|
|
|
//
|
2019-07-02 23:14:24 +08:00
|
|
|
// ZoneMinder Ffmpeg Camera Class Implementation
|
2013-03-17 07:45:21 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2019-07-02 23:14:24 +08:00
|
|
|
//
|
2013-03-17 07:45:21 +08:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
2019-07-02 23:14:24 +08:00
|
|
|
//
|
2013-03-17 07:45:21 +08:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2019-07-02 23:14:24 +08:00
|
|
|
//
|
2013-03-17 07:45:21 +08:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2019-07-02 23:14:24 +08:00
|
|
|
//
|
2013-03-17 07:45:21 +08:00
|
|
|
|
|
|
|
#include "zm.h"
|
2018-05-01 03:09:00 +08:00
|
|
|
#include "zm_signal.h"
|
2019-09-17 22:31:31 +08:00
|
|
|
#include "zm_utils.h"
|
2013-03-17 07:45:21 +08:00
|
|
|
|
|
|
|
#if HAVE_LIBAVFORMAT
|
|
|
|
|
|
|
|
#include "zm_ffmpeg_camera.h"
|
|
|
|
|
2017-06-03 04:52:52 +08:00
|
|
|
extern "C" {
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
#include "libavutil/time.h"
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-07-02 23:14:24 +08:00
|
|
|
#include "libavutil/hwcontext.h"
|
2017-08-17 00:16:15 +08:00
|
|
|
#endif
|
2019-06-12 01:55:57 +08:00
|
|
|
#include "libavutil/pixdesc.h"
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2014-03-23 08:08:39 +08:00
|
|
|
#ifndef AV_ERROR_MAX_STRING_SIZE
|
|
|
|
#define AV_ERROR_MAX_STRING_SIZE 64
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
#include <string>
|
2015-05-18 08:18:54 +08:00
|
|
|
|
2017-08-16 23:31:47 +08:00
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-08-08 21:26:40 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
2019-06-25 05:22:59 +08:00
|
|
|
static enum AVPixelFormat hw_pix_fmt;
|
|
|
|
static enum AVPixelFormat get_hw_format(
|
|
|
|
AVCodecContext *ctx,
|
|
|
|
const enum AVPixelFormat *pix_fmts
|
|
|
|
) {
|
2019-06-26 09:47:19 +08:00
|
|
|
const enum AVPixelFormat *p;
|
2019-06-25 05:22:59 +08:00
|
|
|
|
2019-06-26 09:47:19 +08:00
|
|
|
for ( p = pix_fmts; *p != -1; p++ ) {
|
|
|
|
if ( *p == hw_pix_fmt )
|
|
|
|
return *p;
|
|
|
|
}
|
2019-06-25 05:22:59 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
Error("Failed to get HW surface format for %s.",
|
|
|
|
av_get_pix_fmt_name(hw_pix_fmt));
|
2019-06-26 09:47:19 +08:00
|
|
|
for ( p = pix_fmts; *p != -1; p++ )
|
2019-07-02 23:14:24 +08:00
|
|
|
Error("Available HW surface format was %s.",
|
|
|
|
av_get_pix_fmt_name(*p));
|
2019-06-26 09:47:19 +08:00
|
|
|
|
|
|
|
return AV_PIX_FMT_NONE;
|
2019-06-25 05:22:59 +08:00
|
|
|
}
|
2019-06-26 04:35:07 +08:00
|
|
|
#if !LIBAVUTIL_VERSION_CHECK(56, 22, 0, 14, 0)
|
|
|
|
static enum AVPixelFormat find_fmt_by_hw_type(const enum AVHWDeviceType type) {
|
2020-07-08 04:12:14 +08:00
|
|
|
enum AVPixelFormat fmt;
|
|
|
|
switch (type) {
|
2019-06-26 04:35:07 +08:00
|
|
|
case AV_HWDEVICE_TYPE_VAAPI:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_VAAPI;
|
|
|
|
break;
|
2019-06-26 04:35:07 +08:00
|
|
|
case AV_HWDEVICE_TYPE_DXVA2:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_DXVA2_VLD;
|
|
|
|
break;
|
2019-06-26 04:35:07 +08:00
|
|
|
case AV_HWDEVICE_TYPE_D3D11VA:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_D3D11;
|
|
|
|
break;
|
2019-06-26 04:35:07 +08:00
|
|
|
case AV_HWDEVICE_TYPE_VDPAU:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_VDPAU;
|
|
|
|
break;
|
2019-06-26 09:47:19 +08:00
|
|
|
case AV_HWDEVICE_TYPE_CUDA:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_CUDA;
|
|
|
|
break;
|
2019-06-26 04:35:07 +08:00
|
|
|
case AV_HWDEVICE_TYPE_VIDEOTOOLBOX:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_VIDEOTOOLBOX;
|
|
|
|
break;
|
2019-06-26 04:35:07 +08:00
|
|
|
default:
|
2020-07-08 04:12:14 +08:00
|
|
|
fmt = AV_PIX_FMT_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return fmt;
|
2019-06-26 04:35:07 +08:00
|
|
|
}
|
|
|
|
#endif
|
2017-08-17 00:16:15 +08:00
|
|
|
#endif
|
2019-08-08 21:26:40 +08:00
|
|
|
#endif
|
2017-08-16 23:31:47 +08:00
|
|
|
|
2018-10-15 22:51:56 +08:00
|
|
|
FfmpegCamera::FfmpegCamera(
|
|
|
|
int p_id,
|
|
|
|
const std::string &p_path,
|
|
|
|
const std::string &p_method,
|
|
|
|
const std::string &p_options,
|
|
|
|
int p_width,
|
|
|
|
int p_height,
|
|
|
|
int p_colours,
|
|
|
|
int p_brightness,
|
|
|
|
int p_contrast,
|
|
|
|
int p_hue,
|
|
|
|
int p_colour,
|
|
|
|
bool p_capture,
|
2019-06-26 03:33:54 +08:00
|
|
|
bool p_record_audio,
|
|
|
|
const std::string &p_hwaccel_name,
|
2019-07-02 23:14:24 +08:00
|
|
|
const std::string &p_hwaccel_device) :
|
2018-10-15 22:51:56 +08:00
|
|
|
Camera(
|
|
|
|
p_id,
|
|
|
|
FFMPEG_SRC,
|
|
|
|
p_width,
|
|
|
|
p_height,
|
|
|
|
p_colours,
|
|
|
|
ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours),
|
|
|
|
p_brightness,
|
|
|
|
p_contrast,
|
|
|
|
p_hue,
|
|
|
|
p_colour,
|
|
|
|
p_capture,
|
|
|
|
p_record_audio
|
|
|
|
),
|
2019-06-26 03:33:54 +08:00
|
|
|
mPath(p_path),
|
|
|
|
mMethod(p_method),
|
|
|
|
mOptions(p_options),
|
|
|
|
hwaccel_name(p_hwaccel_name),
|
|
|
|
hwaccel_device(p_hwaccel_device)
|
2013-03-17 07:45:21 +08:00
|
|
|
{
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( capture ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
Initialise();
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
mFormatContext = nullptr;
|
2016-04-04 22:11:48 +08:00
|
|
|
mVideoStreamId = -1;
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
mAudioStreamId = -1;
|
2020-08-26 07:45:48 +08:00
|
|
|
mVideoCodecContext = nullptr;
|
|
|
|
mAudioCodecContext = nullptr;
|
|
|
|
mVideoCodec = nullptr;
|
|
|
|
mAudioCodec = nullptr;
|
|
|
|
mRawFrame = nullptr;
|
|
|
|
mFrame = nullptr;
|
2016-04-04 22:11:48 +08:00
|
|
|
frameCount = 0;
|
|
|
|
mCanCapture = false;
|
2020-08-26 07:45:48 +08:00
|
|
|
videoStore = nullptr;
|
2017-08-10 00:50:46 +08:00
|
|
|
have_video_keyframe = false;
|
2020-08-26 07:45:48 +08:00
|
|
|
packetqueue = nullptr;
|
2018-11-30 02:09:29 +08:00
|
|
|
error_count = 0;
|
2020-05-13 03:10:08 +08:00
|
|
|
use_hwaccel = true;
|
2019-06-26 10:19:09 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2020-08-26 07:45:48 +08:00
|
|
|
hwFrame = nullptr;
|
|
|
|
hw_device_ctx = nullptr;
|
2019-08-08 21:26:40 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
2019-06-26 10:19:09 +08:00
|
|
|
hw_pix_fmt = AV_PIX_FMT_NONE;
|
|
|
|
#endif
|
2019-08-08 21:26:40 +08:00
|
|
|
#endif
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
#if HAVE_LIBSWSCALE
|
2020-08-26 07:45:48 +08:00
|
|
|
mConvertContext = nullptr;
|
2013-03-17 07:45:21 +08:00
|
|
|
#endif
|
2019-07-02 23:14:24 +08:00
|
|
|
/* Has to be located inside the constructor so other components such as zma
|
|
|
|
* will receive correct colours and subpixel order */
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( colours == ZM_COLOUR_RGB32 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
subpixelorder = ZM_SUBPIX_ORDER_RGBA;
|
|
|
|
imagePixFormat = AV_PIX_FMT_RGBA;
|
2017-08-04 00:41:26 +08:00
|
|
|
} else if ( colours == ZM_COLOUR_RGB24 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
subpixelorder = ZM_SUBPIX_ORDER_RGB;
|
|
|
|
imagePixFormat = AV_PIX_FMT_RGB24;
|
2017-08-04 00:41:26 +08:00
|
|
|
} else if ( colours == ZM_COLOUR_GRAY8 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
subpixelorder = ZM_SUBPIX_ORDER_NONE;
|
|
|
|
imagePixFormat = AV_PIX_FMT_GRAY8;
|
|
|
|
} else {
|
2019-06-27 15:40:18 +08:00
|
|
|
Panic("Unexpected colours: %d", colours);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2020-07-08 04:12:14 +08:00
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
frame_buffer = nullptr;
|
2020-07-08 04:12:14 +08:00
|
|
|
// sws_scale needs 32bit aligned width and an extra 16 bytes padding, so recalculate imagesize, which was width*height*bytes_per_pixel
|
|
|
|
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
|
|
|
alignment = 32;
|
|
|
|
imagesize = av_image_get_buffer_size(imagePixFormat, width, height, alignment);
|
|
|
|
// av_image_get_linesize isn't aligned, so we have to do that.
|
|
|
|
linesize = FFALIGN(av_image_get_linesize(imagePixFormat, width, 0), alignment);
|
|
|
|
#else
|
|
|
|
alignment = 1;
|
|
|
|
linesize = FFALIGN(av_image_get_linesize(imagePixFormat, width, 0), alignment);
|
|
|
|
imagesize = avpicture_get_size(imagePixFormat, width, height);
|
|
|
|
#endif
|
2020-07-25 00:37:24 +08:00
|
|
|
if ( linesize != width * colours ) {
|
|
|
|
Debug(1, "linesize %d != width %d * colours %d = %d, allocating frame_buffer", linesize, width, colours, width*colours);
|
|
|
|
frame_buffer = (uint8_t *)av_malloc(imagesize);
|
|
|
|
}
|
2020-07-08 04:12:14 +08:00
|
|
|
|
2020-07-25 00:37:24 +08:00
|
|
|
Debug(1, "ffmpegcamera: width %d height %d linesize %d colours %d image linesize %d imagesize %d",
|
|
|
|
width, height, linesize, colours, width*colours, imagesize);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // FfmpegCamera::FfmpegCamera
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
FfmpegCamera::~FfmpegCamera() {
|
2018-04-17 22:02:52 +08:00
|
|
|
Close();
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( capture ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
Terminate();
|
|
|
|
}
|
2019-04-02 01:39:11 +08:00
|
|
|
FFMPEGDeInit();
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
void FfmpegCamera::Initialise() {
|
2018-04-24 23:41:31 +08:00
|
|
|
FFMPEGInit();
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
void FfmpegCamera::Terminate() {
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
int FfmpegCamera::PrimeCapture() {
|
2018-02-01 03:34:39 +08:00
|
|
|
if ( mCanCapture ) {
|
2020-07-14 03:03:04 +08:00
|
|
|
Debug(1, "Priming capture from %s, Closing", mPath.c_str());
|
2018-04-17 22:02:52 +08:00
|
|
|
Close();
|
2018-02-01 03:34:39 +08:00
|
|
|
}
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
mVideoStreamId = -1;
|
|
|
|
mAudioStreamId = -1;
|
2020-07-14 03:03:04 +08:00
|
|
|
Debug(1, "Priming capture from %s", mPath.c_str());
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2017-08-12 00:03:37 +08:00
|
|
|
return OpenFfmpeg();
|
2014-03-22 00:50:49 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:41:26 +08:00
|
|
|
int FfmpegCamera::PreCapture() {
|
2017-08-12 00:03:37 +08:00
|
|
|
// If Reopen was called, then ffmpeg is closed and we need to reopen it.
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( !mCanCapture )
|
2017-08-12 00:03:37 +08:00
|
|
|
return OpenFfmpeg();
|
2016-04-04 22:11:48 +08:00
|
|
|
// Nothing to do here
|
2018-10-15 22:51:56 +08:00
|
|
|
return 0;
|
2014-03-22 00:50:49 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
int FfmpegCamera::Capture(Image &image) {
|
|
|
|
if ( !mCanCapture ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-06-26 03:33:54 +08:00
|
|
|
int ret;
|
2019-07-02 23:14:24 +08:00
|
|
|
// If the reopen thread has a value, but mCanCapture != 0, then we have just
|
|
|
|
// reopened the connection to the device, and we can clean up the thread.
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
int frameComplete = false;
|
2019-07-02 23:14:24 +08:00
|
|
|
while ( !frameComplete && !zm_terminate ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
ret = av_read_frame(mFormatContext, &packet);
|
|
|
|
if ( ret < 0 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
if (
|
2017-05-17 00:04:56 +08:00
|
|
|
// Check if EOF.
|
2019-07-02 23:14:24 +08:00
|
|
|
(
|
|
|
|
ret == AVERROR_EOF
|
|
|
|
||
|
|
|
|
(mFormatContext->pb && mFormatContext->pb->eof_reached)
|
|
|
|
) ||
|
2017-05-17 00:04:56 +08:00
|
|
|
// Check for Connection failure.
|
2019-06-26 03:33:54 +08:00
|
|
|
(ret == -110)
|
2017-05-17 00:04:56 +08:00
|
|
|
) {
|
2019-06-26 02:11:59 +08:00
|
|
|
Info("Unable to read packet from stream %d: error %d \"%s\".",
|
2019-06-26 03:33:54 +08:00
|
|
|
packet.stream_index, ret, av_make_error_string(ret).c_str());
|
2018-03-22 21:25:35 +08:00
|
|
|
} else {
|
2019-06-26 02:11:59 +08:00
|
|
|
Error("Unable to read packet from stream %d: error %d \"%s\".",
|
2019-06-26 03:33:54 +08:00
|
|
|
packet.stream_index, ret, av_make_error_string(ret).c_str());
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2018-02-18 00:07:06 +08:00
|
|
|
return -1;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
bytes += packet.size;
|
2017-08-14 23:15:09 +08:00
|
|
|
|
|
|
|
int keyframe = packet.flags & AV_PKT_FLAG_KEY;
|
|
|
|
if ( keyframe )
|
|
|
|
have_video_keyframe = true;
|
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(5, "Got packet from stream %d dts (%d) pts(%d)",
|
|
|
|
packet.stream_index, packet.pts, packet.dts);
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
// What about audio stream? Maybe someday we could do sound detection...
|
2019-07-02 23:14:24 +08:00
|
|
|
if (
|
|
|
|
(packet.stream_index == mVideoStreamId)
|
|
|
|
&&
|
|
|
|
(keyframe || have_video_keyframe)
|
|
|
|
) {
|
2019-09-13 22:55:30 +08:00
|
|
|
ret = zm_send_packet_receive_frame(mVideoCodecContext, mRawFrame, packet);
|
2019-10-19 01:52:07 +08:00
|
|
|
if ( ret < 0 ) {
|
|
|
|
if ( AVERROR(EAGAIN) != ret ) {
|
|
|
|
Warning("Unable to receive frame %d: code %d %s. error count is %d",
|
|
|
|
frameCount, ret, av_make_error_string(ret).c_str(), error_count);
|
|
|
|
error_count += 1;
|
|
|
|
if ( error_count > 100 ) {
|
|
|
|
Error("Error count over 100, going to close and re-open stream");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
2017-06-14 05:06:50 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-16 23:31:47 +08:00
|
|
|
|
2017-06-14 05:06:50 +08:00
|
|
|
frameComplete = 1;
|
2019-08-21 22:11:58 +08:00
|
|
|
zm_dump_video_frame(mRawFrame, "raw frame from decoder");
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-08-21 22:11:58 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
|
|
|
if (
|
|
|
|
(hw_pix_fmt != AV_PIX_FMT_NONE)
|
|
|
|
&&
|
|
|
|
(mRawFrame->format == hw_pix_fmt)
|
|
|
|
) {
|
|
|
|
/* retrieve data from GPU to CPU */
|
|
|
|
ret = av_hwframe_transfer_data(hwFrame, mRawFrame, 0);
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
Error("Unable to transfer frame at frame %d: %s, continuing",
|
|
|
|
frameCount, av_make_error_string(ret).c_str());
|
|
|
|
zm_av_packet_unref(&packet);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
zm_dump_video_frame(hwFrame, "After hwtransfer");
|
|
|
|
|
|
|
|
hwFrame->pts = mRawFrame->pts;
|
|
|
|
input_frame = hwFrame;
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
input_frame = mRawFrame;
|
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( transfer_to_image(image, mFrame, input_frame) < 0 ) {
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
frameCount++;
|
2017-05-17 00:04:56 +08:00
|
|
|
} else {
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(4, "Different stream_index %d", packet.stream_index);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if packet.stream_index == mVideoStreamId
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end while ! frameComplete
|
2018-05-01 03:09:00 +08:00
|
|
|
return frameComplete ? 1 : 0;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // FfmpegCamera::Capture
|
2014-05-05 19:29:12 +08:00
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
int FfmpegCamera::PostCapture() {
|
2016-04-04 22:11:48 +08:00
|
|
|
// Nothing to do here
|
2018-05-01 03:09:00 +08:00
|
|
|
return 0;
|
2014-03-22 00:50:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int FfmpegCamera::OpenFfmpeg() {
|
2016-07-28 21:15:01 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-08-14 23:15:09 +08:00
|
|
|
have_video_keyframe = false;
|
2018-11-30 02:09:29 +08:00
|
|
|
error_count = 0;
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Open the input, not necessarily a file
|
2015-05-29 23:38:02 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
|
2020-08-26 07:45:48 +08:00
|
|
|
if ( av_open_input_file(&mFormatContext, mPath.c_str(), nullptr, 0, nullptr) != 0 )
|
2013-03-17 07:45:21 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
// Handle options
|
2020-08-26 07:45:48 +08:00
|
|
|
AVDictionary *opts = nullptr;
|
2016-07-28 21:15:01 +08:00
|
|
|
ret = av_dict_parse_string(&opts, Options().c_str(), "=", ",", 0);
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( ret < 0 ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
Warning("Could not parse ffmpeg input options '%s'", Options().c_str());
|
2016-07-28 21:15:01 +08:00
|
|
|
}
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Set transport method as specified by method field, rtpUni is default
|
2019-09-18 02:58:16 +08:00
|
|
|
std::string protocol = mPath.substr(0, 4);
|
2019-09-17 22:31:31 +08:00
|
|
|
string_toupper(protocol);
|
|
|
|
if ( protocol == "RTSP" ) {
|
2019-09-18 02:58:16 +08:00
|
|
|
const std::string method = Method();
|
2019-09-17 22:31:31 +08:00
|
|
|
if ( method == "rtpMulti" ) {
|
|
|
|
ret = av_dict_set(&opts, "rtsp_transport", "udp_multicast", 0);
|
|
|
|
} else if ( method == "rtpRtsp" ) {
|
|
|
|
ret = av_dict_set(&opts, "rtsp_transport", "tcp", 0);
|
|
|
|
} else if ( method == "rtpRtspHttp" ) {
|
|
|
|
ret = av_dict_set(&opts, "rtsp_transport", "http", 0);
|
|
|
|
} else if ( method == "rtpUni" ) {
|
|
|
|
ret = av_dict_set(&opts, "rtsp_transport", "udp", 0);
|
|
|
|
} else {
|
|
|
|
Warning("Unknown method (%s)", method.c_str());
|
|
|
|
}
|
2019-09-18 02:58:16 +08:00
|
|
|
if ( ret < 0 ) {
|
|
|
|
Warning("Could not set rtsp_transport method '%s'", method.c_str());
|
|
|
|
}
|
|
|
|
} // end if RTSP
|
2019-07-02 23:14:24 +08:00
|
|
|
// #av_dict_set(&opts, "timeout", "10000000", 0); // in microseconds.
|
2016-07-28 21:15:01 +08:00
|
|
|
|
2018-04-07 05:21:40 +08:00
|
|
|
Debug(1, "Calling avformat_open_input for %s", mPath.c_str());
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
mFormatContext = avformat_alloc_context();
|
2017-08-12 00:03:37 +08:00
|
|
|
// Speed up find_stream_info
|
2019-07-02 23:14:24 +08:00
|
|
|
// FIXME can speed up initial analysis but need sensible parameters...
|
|
|
|
// mFormatContext->probesize = 32;
|
|
|
|
// mFormatContext->max_analyze_duration = 32;
|
2018-05-09 00:02:08 +08:00
|
|
|
mFormatContext->interrupt_callback.callback = FfmpegInterruptCallback;
|
|
|
|
mFormatContext->interrupt_callback.opaque = this;
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
ret = avformat_open_input(&mFormatContext, mPath.c_str(), nullptr, &opts);
|
2019-06-26 03:33:54 +08:00
|
|
|
if ( ret != 0 )
|
2016-04-04 22:11:48 +08:00
|
|
|
#endif
|
|
|
|
{
|
2019-07-02 23:14:24 +08:00
|
|
|
Error("Unable to open input %s due to: %s", mPath.c_str(),
|
|
|
|
av_make_error_string(ret).c_str());
|
2018-02-13 23:11:05 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0)
|
2018-04-07 05:21:40 +08:00
|
|
|
av_close_input_file(mFormatContext);
|
2018-02-13 23:11:05 +08:00
|
|
|
#else
|
2018-04-07 05:02:15 +08:00
|
|
|
if ( mFormatContext ) {
|
2018-04-07 05:21:40 +08:00
|
|
|
avformat_close_input(&mFormatContext);
|
2020-08-26 07:45:48 +08:00
|
|
|
mFormatContext = nullptr;
|
2018-04-07 05:02:15 +08:00
|
|
|
}
|
2018-02-13 23:11:05 +08:00
|
|
|
#endif
|
|
|
|
av_dict_free(&opts);
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2020-08-26 07:45:48 +08:00
|
|
|
AVDictionaryEntry *e = nullptr;
|
|
|
|
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr ) {
|
2019-06-27 15:40:18 +08:00
|
|
|
Warning("Option %s not recognized by ffmpeg", e->key);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2018-02-13 23:11:05 +08:00
|
|
|
av_dict_free(&opts);
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2015-05-29 23:38:02 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 6, 0, 6, 0)
|
2019-07-02 23:14:24 +08:00
|
|
|
ret = av_find_stream_info(mFormatContext);
|
2013-03-17 07:45:21 +08:00
|
|
|
#else
|
2020-08-26 07:45:48 +08:00
|
|
|
ret = avformat_find_stream_info(mFormatContext, nullptr);
|
2013-03-17 07:45:21 +08:00
|
|
|
#endif
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( ret < 0 ) {
|
2019-08-21 02:09:47 +08:00
|
|
|
Error("Unable to find stream info from %s due to: %s",
|
|
|
|
mPath.c_str(), av_make_error_string(ret).c_str());
|
2018-02-03 05:07:13 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2015-05-29 23:38:02 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Find first video stream present
|
2017-05-17 00:04:56 +08:00
|
|
|
// The one we want Might not be the first
|
2016-04-04 22:11:48 +08:00
|
|
|
mVideoStreamId = -1;
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
mAudioStreamId = -1;
|
2017-08-04 00:41:26 +08:00
|
|
|
for ( unsigned int i=0; i < mFormatContext->nb_streams; i++ ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
AVStream *stream = mFormatContext->streams[i];
|
|
|
|
if ( is_video_stream(stream) ) {
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
if ( mVideoStreamId == -1 ) {
|
|
|
|
mVideoStreamId = i;
|
|
|
|
// if we break, then we won't find the audio stream
|
|
|
|
continue;
|
|
|
|
} else {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(2, "Have another video stream.");
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} else if ( is_audio_stream(stream) ) {
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
if ( mAudioStreamId == -1 ) {
|
|
|
|
mAudioStreamId = i;
|
|
|
|
} else {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(2, "Have another audio stream.");
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end foreach stream
|
2019-08-21 02:09:47 +08:00
|
|
|
if ( mVideoStreamId == -1 ) {
|
|
|
|
Error("Unable to locate video stream in %s", mPath.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(3, "Found video stream at index %d, audio stream at index %d",
|
|
|
|
mVideoStreamId, mAudioStreamId);
|
|
|
|
packetqueue = new zm_packetqueue(
|
|
|
|
(mVideoStreamId > mAudioStreamId) ? mVideoStreamId : mAudioStreamId);
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2017-06-16 01:02:54 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
2019-07-02 23:14:24 +08:00
|
|
|
// mVideoCodecContext = avcodec_alloc_context3(NULL);
|
|
|
|
// avcodec_parameters_to_context(mVideoCodecContext,
|
|
|
|
// mFormatContext->streams[mVideoStreamId]->codecpar);
|
2018-09-11 05:10:39 +08:00
|
|
|
// this isn't copied.
|
2019-07-02 23:14:24 +08:00
|
|
|
// mVideoCodecContext->time_base =
|
|
|
|
// mFormatContext->streams[mVideoStreamId]->codec->time_base;
|
2017-06-14 05:06:50 +08:00
|
|
|
#else
|
|
|
|
#endif
|
2018-09-11 05:10:39 +08:00
|
|
|
mVideoCodecContext = mFormatContext->streams[mVideoStreamId]->codec;
|
2017-11-08 10:21:51 +08:00
|
|
|
#ifdef CODEC_FLAG2_FAST
|
2019-07-02 23:14:24 +08:00
|
|
|
mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG_LOW_DELAY;
|
2017-11-08 10:21:51 +08:00
|
|
|
#endif
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2018-02-23 07:33:11 +08:00
|
|
|
if ( mVideoCodecContext->codec_id == AV_CODEC_ID_H264 ) {
|
2020-08-26 07:45:48 +08:00
|
|
|
if ( (mVideoCodec = avcodec_find_decoder_by_name("h264_mmal")) == nullptr ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(1, "Failed to find decoder (h264_mmal)");
|
2018-02-23 07:33:11 +08:00
|
|
|
} else {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(1, "Success finding decoder (h264_mmal)");
|
2018-02-23 07:33:11 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 04:15:11 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( !mVideoCodec ) {
|
|
|
|
mVideoCodec = avcodec_find_decoder(mVideoCodecContext->codec_id);
|
|
|
|
if ( !mVideoCodec ) {
|
|
|
|
// Try and get the codec from the codec context
|
|
|
|
Error("Can't find codec for video stream from %s", mPath.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 05:22:59 +08:00
|
|
|
|
|
|
|
zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0);
|
|
|
|
|
2020-05-13 03:10:08 +08:00
|
|
|
if ( use_hwaccel && (hwaccel_name != "") ) {
|
2019-06-26 03:58:55 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-08-08 21:26:40 +08:00
|
|
|
// 3.2 doesn't seem to have all the bits in place, so let's require 3.3 and up
|
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
2019-06-27 15:40:18 +08:00
|
|
|
// Print out available types
|
2019-06-26 03:33:54 +08:00
|
|
|
enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
|
|
|
|
while ( (type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE )
|
|
|
|
Debug(1, "%s", av_hwdevice_get_type_name(type));
|
2019-06-25 05:22:59 +08:00
|
|
|
|
2019-06-26 03:33:54 +08:00
|
|
|
const char *hw_name = hwaccel_name.c_str();
|
|
|
|
type = av_hwdevice_find_type_by_name(hw_name);
|
|
|
|
if ( type == AV_HWDEVICE_TYPE_NONE ) {
|
|
|
|
Debug(1, "Device type %s is not supported.", hw_name);
|
|
|
|
} else {
|
|
|
|
Debug(1, "Found hwdevice %s", av_hwdevice_get_type_name(type));
|
2019-06-25 05:22:59 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 04:35:07 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(56, 22, 0, 14, 0)
|
2019-08-21 02:09:47 +08:00
|
|
|
// Get hw_pix_fmt
|
2019-06-26 03:33:54 +08:00
|
|
|
for ( int i = 0;; i++ ) {
|
|
|
|
const AVCodecHWConfig *config = avcodec_get_hw_config(mVideoCodec, i);
|
|
|
|
if ( !config ) {
|
|
|
|
Debug(1, "Decoder %s does not support device type %s.",
|
|
|
|
mVideoCodec->name, av_hwdevice_get_type_name(type));
|
2019-07-03 21:49:53 +08:00
|
|
|
break;
|
2019-06-26 03:33:54 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
|
|
|
|
&& (config->device_type == type)
|
2019-06-26 03:33:54 +08:00
|
|
|
) {
|
|
|
|
hw_pix_fmt = config->pix_fmt;
|
|
|
|
break;
|
2019-07-03 21:49:53 +08:00
|
|
|
} else {
|
2020-05-13 03:10:08 +08:00
|
|
|
Debug(1, "decoder %s hwConfig doesn't match our type: %s != %s, pix_fmt %s.",
|
2019-07-03 21:49:53 +08:00
|
|
|
mVideoCodec->name,
|
2020-05-13 03:10:08 +08:00
|
|
|
av_hwdevice_get_type_name(type),
|
2019-07-07 20:57:22 +08:00
|
|
|
av_hwdevice_get_type_name(config->device_type),
|
|
|
|
av_get_pix_fmt_name(config->pix_fmt)
|
2019-07-03 21:49:53 +08:00
|
|
|
);
|
2019-06-26 03:33:54 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end foreach hwconfig
|
|
|
|
#else
|
2019-06-26 04:35:07 +08:00
|
|
|
hw_pix_fmt = find_fmt_by_hw_type(type);
|
|
|
|
#endif
|
2019-07-03 21:49:53 +08:00
|
|
|
if ( hw_pix_fmt != AV_PIX_FMT_NONE ) {
|
2019-08-19 23:12:47 +08:00
|
|
|
Debug(1, "Selected hw_pix_fmt %d %s",
|
2019-08-21 02:09:47 +08:00
|
|
|
hw_pix_fmt, av_get_pix_fmt_name(hw_pix_fmt));
|
2019-06-25 05:22:59 +08:00
|
|
|
|
2019-07-03 21:49:53 +08:00
|
|
|
ret = av_hwdevice_ctx_create(&hw_device_ctx, type,
|
2020-08-26 07:45:48 +08:00
|
|
|
(hwaccel_device != "" ? hwaccel_device.c_str(): nullptr), nullptr, 0);
|
2019-07-03 21:49:53 +08:00
|
|
|
if ( ret < 0 ) {
|
2020-01-08 00:03:45 +08:00
|
|
|
Error("Failed to create hwaccel device. %s",av_make_error_string(ret).c_str());
|
2020-01-06 06:27:45 +08:00
|
|
|
hw_pix_fmt = AV_PIX_FMT_NONE;
|
|
|
|
} else {
|
|
|
|
Debug(1, "Created hwdevice for %s", hwaccel_device.c_str());
|
|
|
|
mVideoCodecContext->get_format = get_hw_format;
|
|
|
|
mVideoCodecContext->hw_device_ctx = av_buffer_ref(hw_device_ctx);
|
|
|
|
hwFrame = zm_av_frame_alloc();
|
2019-07-03 21:49:53 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-01-08 00:03:45 +08:00
|
|
|
Debug(1, "Failed to find suitable hw_pix_fmt.");
|
2019-06-26 03:33:54 +08:00
|
|
|
}
|
2019-08-08 21:26:40 +08:00
|
|
|
#else
|
|
|
|
Debug(1, "AVCodec not new enough for hwaccel");
|
|
|
|
#endif
|
2019-07-02 23:14:24 +08:00
|
|
|
#else
|
2019-06-26 03:58:55 +08:00
|
|
|
Warning("HWAccel support not compiled in.");
|
|
|
|
#endif
|
2020-01-06 06:27:45 +08:00
|
|
|
} // end if hwaccel_name
|
2019-06-25 05:22:59 +08:00
|
|
|
|
|
|
|
// Open the codec
|
2017-05-17 00:04:56 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
2019-06-25 05:22:59 +08:00
|
|
|
ret = avcodec_open(mVideoCodecContext, mVideoCodec);
|
2017-05-17 00:04:56 +08:00
|
|
|
#else
|
2019-06-25 05:22:59 +08:00
|
|
|
ret = avcodec_open2(mVideoCodecContext, mVideoCodec, &opts);
|
2017-05-17 00:04:56 +08:00
|
|
|
#endif
|
2020-08-26 07:45:48 +08:00
|
|
|
e = nullptr;
|
|
|
|
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
Warning("Option %s not recognized by ffmpeg", e->key);
|
2019-06-25 05:22:59 +08:00
|
|
|
}
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
Error("Unable to open codec for video stream from %s", mPath.c_str());
|
|
|
|
av_dict_free(&opts);
|
|
|
|
return -1;
|
2017-05-17 00:04:56 +08:00
|
|
|
}
|
2019-06-25 05:22:59 +08:00
|
|
|
zm_dump_codec(mVideoCodecContext);
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2019-08-21 02:09:47 +08:00
|
|
|
Debug(1, hwFrame ? "HWACCEL in use" : "HWACCEL not in use");
|
2019-06-25 05:22:59 +08:00
|
|
|
|
2017-06-02 05:48:52 +08:00
|
|
|
if ( mAudioStreamId >= 0 ) {
|
2019-04-05 05:20:21 +08:00
|
|
|
if ( (mAudioCodec = avcodec_find_decoder(
|
2017-06-16 01:02:54 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
2019-04-05 05:20:21 +08:00
|
|
|
mFormatContext->streams[mAudioStreamId]->codecpar->codec_id
|
2017-06-14 05:06:50 +08:00
|
|
|
#else
|
2019-04-05 05:20:21 +08:00
|
|
|
mFormatContext->streams[mAudioStreamId]->codec->codec_id
|
2017-06-14 05:06:50 +08:00
|
|
|
#endif
|
2020-08-26 07:45:48 +08:00
|
|
|
)) == nullptr ) {
|
2017-05-17 00:04:56 +08:00
|
|
|
Debug(1, "Can't find codec for audio stream from %s", mPath.c_str());
|
|
|
|
} else {
|
2019-04-05 05:20:21 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
|
|
|
mAudioCodecContext = avcodec_alloc_context3(mAudioCodec);
|
2019-07-02 23:14:24 +08:00
|
|
|
avcodec_parameters_to_context(
|
|
|
|
mAudioCodecContext,
|
|
|
|
mFormatContext->streams[mAudioStreamId]->codecpar
|
|
|
|
);
|
2019-04-05 05:20:21 +08:00
|
|
|
#else
|
|
|
|
mAudioCodecContext = mFormatContext->streams[mAudioStreamId]->codec;
|
|
|
|
// = avcodec_alloc_context3(mAudioCodec);
|
|
|
|
#endif
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
zm_dump_stream_format(mFormatContext, mAudioStreamId, 0, 0);
|
2018-02-01 03:34:39 +08:00
|
|
|
// Open the codec
|
2015-05-29 23:38:02 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
2018-02-01 03:34:39 +08:00
|
|
|
if ( avcodec_open(mAudioCodecContext, mAudioCodec) < 0 ) {
|
2013-03-17 07:45:21 +08:00
|
|
|
#else
|
2020-08-26 07:45:48 +08:00
|
|
|
if ( avcodec_open2(mAudioCodecContext, mAudioCodec, nullptr) < 0 ) {
|
2013-03-17 07:45:21 +08:00
|
|
|
#endif
|
2019-07-02 23:14:24 +08:00
|
|
|
Error("Unable to open codec for audio stream from %s", mPath.c_str());
|
2018-02-01 03:34:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2019-04-09 01:51:41 +08:00
|
|
|
zm_dump_codec(mAudioCodecContext);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if find decoder
|
|
|
|
} // end if have audio_context
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Allocate space for the native video frame
|
2017-05-17 00:04:56 +08:00
|
|
|
mRawFrame = zm_av_frame_alloc();
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Allocate space for the converted video frame
|
2017-05-17 00:04:56 +08:00
|
|
|
mFrame = zm_av_frame_alloc();
|
2015-05-29 23:38:02 +08:00
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
if ( mRawFrame == nullptr || mFrame == nullptr ) {
|
2018-02-01 03:34:39 +08:00
|
|
|
Error("Unable to allocate frame for %s", mPath.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
2020-02-24 07:14:17 +08:00
|
|
|
mFrame->width = width;
|
|
|
|
mFrame->height = height;
|
2014-03-22 00:50:49 +08:00
|
|
|
|
|
|
|
|
2013-03-17 07:45:21 +08:00
|
|
|
#if HAVE_LIBSWSCALE
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( !sws_isSupportedInput(mVideoCodecContext->pix_fmt) ) {
|
2019-08-21 02:09:47 +08:00
|
|
|
Error("swscale does not support the codec format for input: %s",
|
|
|
|
av_get_pix_fmt_name(mVideoCodecContext->pix_fmt)
|
2019-06-26 03:33:54 +08:00
|
|
|
);
|
2018-02-01 03:34:39 +08:00
|
|
|
return -1;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( !sws_isSupportedOutput(imagePixFormat) ) {
|
2019-08-21 02:09:47 +08:00
|
|
|
Error("swscale does not support the target format: %s",
|
|
|
|
av_get_pix_fmt_name(imagePixFormat)
|
2019-06-26 03:33:54 +08:00
|
|
|
);
|
2018-02-01 03:34:39 +08:00
|
|
|
return -1;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
#else // HAVE_LIBSWSCALE
|
|
|
|
Fatal("You must compile ffmpeg with the --enable-swscale "
|
|
|
|
"option to use ffmpeg cameras");
|
|
|
|
#endif // HAVE_LIBSWSCALE
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2019-06-26 03:33:54 +08:00
|
|
|
if (
|
|
|
|
((unsigned int)mVideoCodecContext->width != width)
|
|
|
|
||
|
|
|
|
((unsigned int)mVideoCodecContext->height != height)
|
|
|
|
) {
|
|
|
|
Warning("Monitor dimensions are %dx%d but camera is sending %dx%d",
|
2019-07-02 23:14:24 +08:00
|
|
|
width, height, mVideoCodecContext->width, mVideoCodecContext->height);
|
2017-05-17 00:04:56 +08:00
|
|
|
}
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mCanCapture = true;
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return 0;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // int FfmpegCamera::OpenFfmpeg()
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2018-04-17 22:02:52 +08:00
|
|
|
int FfmpegCamera::Close() {
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mCanCapture = false;
|
2014-03-22 00:50:49 +08:00
|
|
|
|
2017-08-12 00:03:37 +08:00
|
|
|
if ( mFrame ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
av_frame_free(&mFrame);
|
2020-08-26 07:45:48 +08:00
|
|
|
mFrame = nullptr;
|
2017-08-12 00:03:37 +08:00
|
|
|
}
|
|
|
|
if ( mRawFrame ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
av_frame_free(&mRawFrame);
|
2020-08-26 07:45:48 +08:00
|
|
|
mRawFrame = nullptr;
|
2017-08-12 00:03:37 +08:00
|
|
|
}
|
2019-07-18 08:33:23 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-07-17 22:06:30 +08:00
|
|
|
if ( hwFrame ) {
|
|
|
|
av_frame_free(&hwFrame);
|
2020-08-26 07:45:48 +08:00
|
|
|
hwFrame = nullptr;
|
2019-07-17 22:06:30 +08:00
|
|
|
}
|
2019-07-18 08:33:23 +08:00
|
|
|
#endif
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2014-03-22 00:50:49 +08:00
|
|
|
#if HAVE_LIBSWSCALE
|
2017-06-03 04:52:52 +08:00
|
|
|
if ( mConvertContext ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
sws_freeContext(mConvertContext);
|
2020-08-26 07:45:48 +08:00
|
|
|
mConvertContext = nullptr;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2014-04-26 04:57:29 +08:00
|
|
|
#endif
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2019-04-05 02:11:56 +08:00
|
|
|
if ( videoStore ) {
|
|
|
|
delete videoStore;
|
2020-08-26 07:45:48 +08:00
|
|
|
videoStore = nullptr;
|
2019-04-05 02:11:56 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( mVideoCodecContext ) {
|
2017-05-17 00:04:56 +08:00
|
|
|
avcodec_close(mVideoCodecContext);
|
2017-11-28 22:50:09 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
2019-07-02 23:14:24 +08:00
|
|
|
// avcodec_free_context(&mVideoCodecContext);
|
2017-11-28 22:50:09 +08:00
|
|
|
#endif
|
2020-08-26 07:45:48 +08:00
|
|
|
mVideoCodecContext = nullptr; // Freed by av_close_input_file
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( mAudioCodecContext ) {
|
2017-05-17 00:04:56 +08:00
|
|
|
avcodec_close(mAudioCodecContext);
|
2017-11-28 22:50:09 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
2017-11-29 00:11:41 +08:00
|
|
|
avcodec_free_context(&mAudioCodecContext);
|
2017-11-28 22:50:09 +08:00
|
|
|
#endif
|
2020-08-26 07:45:48 +08:00
|
|
|
mAudioCodecContext = nullptr; // Freed by av_close_input_file
|
2017-05-17 00:04:56 +08:00
|
|
|
}
|
2019-07-20 00:51:31 +08:00
|
|
|
|
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-07-17 22:06:30 +08:00
|
|
|
if ( hw_device_ctx ) {
|
2019-07-20 00:51:31 +08:00
|
|
|
av_buffer_unref(&hw_device_ctx);
|
2019-07-17 22:06:30 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( mFormatContext ) {
|
2015-05-29 23:38:02 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0)
|
2019-06-26 03:33:54 +08:00
|
|
|
av_close_input_file(mFormatContext);
|
2014-03-22 00:50:49 +08:00
|
|
|
#else
|
2019-06-26 03:33:54 +08:00
|
|
|
avformat_close_input(&mFormatContext);
|
2014-03-22 00:50:49 +08:00
|
|
|
#endif
|
2020-08-26 07:45:48 +08:00
|
|
|
mFormatContext = nullptr;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2018-10-15 22:51:56 +08:00
|
|
|
if ( packetqueue ) {
|
|
|
|
delete packetqueue;
|
2020-08-26 07:45:48 +08:00
|
|
|
packetqueue = nullptr;
|
2018-10-15 22:51:56 +08:00
|
|
|
}
|
2018-04-19 03:30:42 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return 0;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end FfmpegCamera::Close
|
|
|
|
|
|
|
|
// Function to handle capture and store
|
|
|
|
int FfmpegCamera::CaptureAndRecord(
|
|
|
|
Image &image,
|
|
|
|
timeval recording,
|
|
|
|
char* event_file
|
|
|
|
) {
|
2018-07-10 01:07:49 +08:00
|
|
|
if ( !mCanCapture ) {
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
int ret;
|
2019-07-02 23:14:24 +08:00
|
|
|
|
2019-11-02 05:29:55 +08:00
|
|
|
struct timeval video_buffer_duration = monitor->GetVideoBufferDuration();
|
|
|
|
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
int frameComplete = false;
|
2018-07-10 01:07:49 +08:00
|
|
|
while ( !frameComplete ) {
|
2018-05-08 01:13:36 +08:00
|
|
|
av_init_packet(&packet);
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2018-03-22 21:25:35 +08:00
|
|
|
ret = av_read_frame(mFormatContext, &packet);
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( ret < 0 ) {
|
2018-03-22 21:25:35 +08:00
|
|
|
if (
|
|
|
|
// Check if EOF.
|
2019-07-02 23:14:24 +08:00
|
|
|
(
|
|
|
|
(ret == AVERROR_EOF) ||
|
|
|
|
(mFormatContext->pb && mFormatContext->pb->eof_reached)
|
|
|
|
) ||
|
2018-03-22 21:25:35 +08:00
|
|
|
// Check for Connection failure.
|
|
|
|
(ret == -110)
|
|
|
|
) {
|
2019-06-26 03:33:54 +08:00
|
|
|
Info("Unable to read packet from stream %d: error %d \"%s\".",
|
|
|
|
packet.stream_index, ret, av_make_error_string(ret).c_str());
|
2018-03-22 21:25:35 +08:00
|
|
|
} else {
|
2019-06-26 03:33:54 +08:00
|
|
|
Error("Unable to read packet from stream %d: error %d \"%s\".",
|
|
|
|
packet.stream_index, ret, av_make_error_string(ret).c_str());
|
2018-03-22 21:25:35 +08:00
|
|
|
}
|
2018-02-18 00:07:06 +08:00
|
|
|
return -1;
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
|
|
|
|
2020-10-09 03:50:52 +08:00
|
|
|
#if 0
|
2019-04-03 02:23:49 +08:00
|
|
|
if ( (packet.pts != AV_NOPTS_VALUE) && (packet.pts < -100000) ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
// Ignore packets that have crazy negative pts.
|
|
|
|
// They aren't supposed to happen.
|
|
|
|
Warning("Ignore packet because pts %" PRId64 " is massively negative."
|
|
|
|
" Error count is %d", packet.pts, error_count);
|
|
|
|
dumpPacket(
|
|
|
|
mFormatContext->streams[packet.stream_index],
|
|
|
|
&packet,
|
|
|
|
"Ignored packet");
|
2018-11-30 02:09:29 +08:00
|
|
|
if ( error_count > 100 ) {
|
|
|
|
Error("Bad packet count over 100, going to close and re-open stream");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
error_count += 1;
|
2018-09-29 02:19:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-12-28 02:52:41 +08:00
|
|
|
// If we get a good frame, decrease the error count.. We could zero it...
|
|
|
|
if ( error_count > 0 ) error_count -= 1;
|
2020-10-09 03:50:52 +08:00
|
|
|
#endif
|
2018-11-30 02:09:29 +08:00
|
|
|
|
2017-08-14 23:15:09 +08:00
|
|
|
int keyframe = packet.flags & AV_PKT_FLAG_KEY;
|
2018-04-25 02:11:27 +08:00
|
|
|
bytes += packet.size;
|
2019-07-02 23:14:24 +08:00
|
|
|
dumpPacket(
|
|
|
|
mFormatContext->streams[packet.stream_index],
|
|
|
|
&packet,
|
|
|
|
"Captured Packet");
|
2019-06-21 03:14:20 +08:00
|
|
|
if ( packet.dts == AV_NOPTS_VALUE ) {
|
|
|
|
packet.dts = packet.pts;
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-01-16 00:32:44 +08:00
|
|
|
// Video recording
|
|
|
|
if ( recording.tv_sec ) {
|
2019-01-15 03:00:45 +08:00
|
|
|
uint32_t last_event_id = monitor->GetLastEventId();
|
2017-11-29 00:11:41 +08:00
|
|
|
uint32_t video_writer_event_id = monitor->GetVideoWriterEventId();
|
2017-06-14 05:06:50 +08:00
|
|
|
|
2017-11-29 00:11:41 +08:00
|
|
|
if ( last_event_id != video_writer_event_id ) {
|
2018-09-27 03:33:29 +08:00
|
|
|
Debug(2, "Have change of event. last_event(%d), our current (%d)",
|
2019-01-16 00:32:44 +08:00
|
|
|
last_event_id, video_writer_event_id);
|
2017-06-14 05:06:50 +08:00
|
|
|
|
|
|
|
if ( videoStore ) {
|
|
|
|
Info("Re-starting video storage module");
|
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
// I don't know if this is important or not... but I figure we might
|
|
|
|
// as well write this last packet out to the store before closing it.
|
2017-06-14 05:06:50 +08:00
|
|
|
// Also don't know how much it matters for audio.
|
|
|
|
if ( packet.stream_index == mVideoStreamId ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
// Write the packet to our video store
|
2019-06-24 23:27:47 +08:00
|
|
|
int ret = videoStore->writeVideoFramePacket(&packet);
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( ret < 0 ) { // Less than zero and we skipped a frame
|
2017-06-14 05:06:50 +08:00
|
|
|
Warning("Error writing last packet to videostore.");
|
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if video
|
2017-06-14 05:06:50 +08:00
|
|
|
|
|
|
|
delete videoStore;
|
2020-08-26 07:45:48 +08:00
|
|
|
videoStore = nullptr;
|
2017-08-10 00:50:46 +08:00
|
|
|
have_video_keyframe = false;
|
2017-06-14 05:06:50 +08:00
|
|
|
|
2018-05-08 01:13:36 +08:00
|
|
|
monitor->SetVideoWriterEventId(0);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if videoStore
|
|
|
|
} // end if end of recording
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( last_event_id && !videoStore ) {
|
|
|
|
// Instantiate the video storage module
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-06-21 03:14:20 +08:00
|
|
|
packetqueue->dumpQueue();
|
2017-08-04 00:41:26 +08:00
|
|
|
if ( record_audio ) {
|
|
|
|
if ( mAudioStreamId == -1 ) {
|
2017-05-17 00:04:56 +08:00
|
|
|
Debug(3, "Record Audio on but no audio stream found");
|
|
|
|
videoStore = new VideoStore((const char *) event_file, "mp4",
|
|
|
|
mFormatContext->streams[mVideoStreamId],
|
2020-08-26 07:45:48 +08:00
|
|
|
nullptr,
|
2017-05-17 00:04:56 +08:00
|
|
|
this->getMonitor());
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
|
|
|
|
} else {
|
2017-05-17 00:04:56 +08:00
|
|
|
Debug(3, "Video module initiated with audio stream");
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
videoStore = new VideoStore((const char *) event_file, "mp4",
|
2017-05-17 00:04:56 +08:00
|
|
|
mFormatContext->streams[mVideoStreamId],
|
|
|
|
mFormatContext->streams[mAudioStreamId],
|
|
|
|
this->getMonitor());
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
} else {
|
2018-01-17 22:53:03 +08:00
|
|
|
if ( mAudioStreamId >= 0 ) {
|
|
|
|
Debug(3, "Record_audio is false so exclude audio stream");
|
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
videoStore = new VideoStore((const char *) event_file, "mp4",
|
|
|
|
mFormatContext->streams[mVideoStreamId],
|
2020-08-26 07:45:48 +08:00
|
|
|
nullptr,
|
2017-05-17 00:04:56 +08:00
|
|
|
this->getMonitor());
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if record_audio
|
2018-01-25 00:51:11 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( !videoStore->open() ) {
|
2017-09-26 03:28:14 +08:00
|
|
|
delete videoStore;
|
2020-08-26 07:45:48 +08:00
|
|
|
videoStore = nullptr;
|
2017-09-26 03:28:14 +08:00
|
|
|
|
|
|
|
} else {
|
2019-06-27 23:11:14 +08:00
|
|
|
monitor->SetVideoWriterEventId(last_event_id);
|
2017-09-26 03:28:14 +08:00
|
|
|
|
|
|
|
// Need to write out all the frames from the last keyframe?
|
2019-07-02 23:14:24 +08:00
|
|
|
// No... need to write out all frames from when the event began.
|
|
|
|
// Due to PreEventFrames, this could be more than
|
|
|
|
// since the last keyframe.
|
2017-09-26 03:28:14 +08:00
|
|
|
unsigned int packet_count = 0;
|
|
|
|
ZMPacket *queued_packet;
|
2019-11-02 05:30:57 +08:00
|
|
|
struct timeval video_offset = {0};
|
2017-09-26 03:28:14 +08:00
|
|
|
|
|
|
|
// Clear all packets that predate the moment when the recording began
|
2019-07-02 23:14:24 +08:00
|
|
|
packetqueue->clear_unwanted_packets(
|
2019-11-04 07:11:55 +08:00
|
|
|
&recording, 0, mVideoStreamId);
|
2017-09-26 03:28:14 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
while ( (queued_packet = packetqueue->popPacket()) ) {
|
2017-09-26 03:28:14 +08:00
|
|
|
AVPacket *avp = queued_packet->av_packet();
|
|
|
|
|
2019-11-02 05:30:57 +08:00
|
|
|
// compute time offset between event start and first frame in video
|
2020-12-11 01:09:58 +08:00
|
|
|
if ( packet_count == 0 ) {
|
2019-11-02 05:30:57 +08:00
|
|
|
monitor->SetVideoWriterStartTime(queued_packet->timestamp);
|
|
|
|
timersub(&queued_packet->timestamp, &recording, &video_offset);
|
|
|
|
Info("Event video offset is %.3f sec (<0 means video starts early)",
|
|
|
|
video_offset.tv_sec + video_offset.tv_usec*1e-6);
|
|
|
|
}
|
|
|
|
|
2017-09-26 03:28:14 +08:00
|
|
|
packet_count += 1;
|
2019-07-02 23:14:24 +08:00
|
|
|
// Write the packet to our video store
|
2019-01-16 00:32:44 +08:00
|
|
|
Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)",
|
2019-07-02 23:14:24 +08:00
|
|
|
avp->stream_index,
|
|
|
|
avp->flags & AV_PKT_FLAG_KEY,
|
|
|
|
packetqueue->size());
|
2017-09-26 03:28:14 +08:00
|
|
|
if ( avp->stream_index == mVideoStreamId ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
ret = videoStore->writeVideoFramePacket(avp);
|
2017-09-26 03:28:14 +08:00
|
|
|
have_video_keyframe = true;
|
|
|
|
} else if ( avp->stream_index == mAudioStreamId ) {
|
2019-06-26 03:33:54 +08:00
|
|
|
ret = videoStore->writeAudioFramePacket(avp);
|
2017-09-26 03:28:14 +08:00
|
|
|
} else {
|
2019-07-02 23:14:24 +08:00
|
|
|
Warning("Unknown stream id in queued packet (%d)",
|
|
|
|
avp->stream_index);
|
2017-09-26 03:28:14 +08:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
if ( ret < 0 ) {
|
2019-01-05 23:15:22 +08:00
|
|
|
// Less than zero and we skipped a frame
|
2017-09-26 03:28:14 +08:00
|
|
|
}
|
|
|
|
delete queued_packet;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end while packets in the packetqueue
|
2019-01-05 23:15:22 +08:00
|
|
|
Debug(2, "Wrote %d queued packets", packet_count);
|
2020-12-11 01:09:58 +08:00
|
|
|
} // end if videostore is open or not
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if ! was recording
|
2017-05-17 00:04:56 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Not recording
|
2019-07-02 23:14:24 +08:00
|
|
|
|
2019-01-16 00:32:44 +08:00
|
|
|
if ( videoStore ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(1, "Deleting videoStore instance");
|
2017-05-17 00:04:56 +08:00
|
|
|
delete videoStore;
|
2020-08-26 07:45:48 +08:00
|
|
|
videoStore = nullptr;
|
2017-08-10 00:50:46 +08:00
|
|
|
have_video_keyframe = false;
|
2018-05-08 01:13:36 +08:00
|
|
|
monitor->SetVideoWriterEventId(0);
|
2017-05-17 00:04:56 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if recording or not
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-01-17 04:20:17 +08:00
|
|
|
// Buffer video packets, since we are not recording.
|
2019-01-16 00:32:44 +08:00
|
|
|
// All audio packets are keyframes, so only if it's a video keyframe
|
|
|
|
if ( packet.stream_index == mVideoStreamId ) {
|
|
|
|
if ( keyframe ) {
|
2019-01-17 04:20:17 +08:00
|
|
|
Debug(3, "Clearing queue");
|
2019-11-02 05:29:55 +08:00
|
|
|
if (video_buffer_duration.tv_sec > 0 || video_buffer_duration.tv_usec > 0) {
|
|
|
|
packetqueue->clearQueue(&video_buffer_duration, mVideoStreamId);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
packetqueue->clearQueue(monitor->GetPreEventCount(), mVideoStreamId);
|
|
|
|
}
|
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
if (
|
|
|
|
packetqueue->packet_count(mVideoStreamId)
|
|
|
|
>=
|
|
|
|
monitor->GetImageBufferCount()
|
|
|
|
) {
|
|
|
|
Warning(
|
|
|
|
"ImageBufferCount %d is too small. "
|
|
|
|
"Needs to be at least %d. "
|
|
|
|
"Either increase it or decrease time between keyframes",
|
2019-01-17 04:20:17 +08:00
|
|
|
monitor->GetImageBufferCount(),
|
2019-07-02 23:14:24 +08:00
|
|
|
packetqueue->packet_count(mVideoStreamId)+1);
|
2019-01-17 04:20:17 +08:00
|
|
|
}
|
2018-10-15 23:33:58 +08:00
|
|
|
|
2019-06-24 23:27:47 +08:00
|
|
|
packetqueue->queuePacket(&packet);
|
2019-01-17 04:20:17 +08:00
|
|
|
} else if ( packetqueue->size() ) {
|
2019-01-16 00:32:44 +08:00
|
|
|
// it's a keyframe or we already have something in the queue
|
2019-06-24 23:27:47 +08:00
|
|
|
packetqueue->queuePacket(&packet);
|
2019-07-02 23:14:24 +08:00
|
|
|
}
|
2019-01-16 00:32:44 +08:00
|
|
|
} else if ( packet.stream_index == mAudioStreamId ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
// Ensure that the queue always begins with a video keyframe
|
|
|
|
if ( record_audio && packetqueue->size() ) {
|
2019-06-24 23:27:47 +08:00
|
|
|
packetqueue->queuePacket(&packet);
|
2019-01-16 00:32:44 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if packet type
|
2019-01-16 00:32:44 +08:00
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( packet.stream_index == mVideoStreamId ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
if ( (have_video_keyframe || keyframe) && videoStore ) {
|
|
|
|
int ret = videoStore->writeVideoFramePacket(&packet);
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
// Less than zero and we skipped a frame
|
2019-10-19 01:52:07 +08:00
|
|
|
Error("Unable to write video packet code: %d, framecount %d: %s",
|
|
|
|
ret, frameCount, av_make_error_string(ret).c_str());
|
2019-07-02 23:14:24 +08:00
|
|
|
} else {
|
2017-08-14 23:15:09 +08:00
|
|
|
have_video_keyframe = true;
|
2017-05-17 00:04:56 +08:00
|
|
|
}
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if keyframe or have_video_keyframe
|
2017-08-14 23:15:09 +08:00
|
|
|
|
2020-12-11 03:05:57 +08:00
|
|
|
if ( monitor->DecodingEnabled() ) {
|
2020-12-11 01:09:58 +08:00
|
|
|
ret = zm_send_packet_receive_frame(mVideoCodecContext, mRawFrame, packet);
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
if ( AVERROR(EAGAIN) != ret ) {
|
|
|
|
Warning("Unable to receive frame %d: code %d %s. error count is %d",
|
|
|
|
frameCount, ret, av_make_error_string(ret).c_str(), error_count);
|
|
|
|
error_count += 1;
|
|
|
|
if ( error_count > 100 ) {
|
|
|
|
Error("Error count over 100, going to close and re-open stream");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-05-15 00:01:03 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2020-06-24 02:43:11 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
2020-12-11 01:09:58 +08:00
|
|
|
if ( (ret == AVERROR_INVALIDDATA ) && (hw_pix_fmt != AV_PIX_FMT_NONE) ) {
|
|
|
|
use_hwaccel = false;
|
|
|
|
return -1;
|
|
|
|
}
|
2020-06-24 02:43:11 +08:00
|
|
|
#endif
|
2020-05-15 00:01:03 +08:00
|
|
|
#endif
|
2020-12-11 01:09:58 +08:00
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
2017-08-14 23:15:09 +08:00
|
|
|
continue;
|
2019-07-02 23:14:24 +08:00
|
|
|
}
|
2020-12-11 01:09:58 +08:00
|
|
|
if ( error_count > 0 ) error_count--;
|
|
|
|
zm_dump_video_frame(mRawFrame, "raw frame from decoder");
|
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
|
|
|
if (
|
|
|
|
(hw_pix_fmt != AV_PIX_FMT_NONE)
|
|
|
|
&&
|
|
|
|
(mRawFrame->format == hw_pix_fmt)
|
|
|
|
) {
|
|
|
|
/* retrieve data from GPU to CPU */
|
|
|
|
ret = av_hwframe_transfer_data(hwFrame, mRawFrame, 0);
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
Error("Unable to transfer frame at frame %d: %s, continuing",
|
|
|
|
frameCount, av_make_error_string(ret).c_str());
|
|
|
|
zm_av_packet_unref(&packet);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
zm_dump_video_frame(hwFrame, "After hwtransfer");
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2020-12-11 01:09:58 +08:00
|
|
|
hwFrame->pts = mRawFrame->pts;
|
|
|
|
input_frame = hwFrame;
|
|
|
|
} else {
|
2019-08-08 21:26:40 +08:00
|
|
|
#endif
|
2019-06-26 02:11:59 +08:00
|
|
|
#endif
|
2020-12-11 01:09:58 +08:00
|
|
|
input_frame = mRawFrame;
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2019-08-08 21:26:40 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(57, 89, 0, 89, 0)
|
2020-12-11 01:09:58 +08:00
|
|
|
}
|
2019-08-08 21:26:40 +08:00
|
|
|
#endif
|
2017-05-17 00:04:56 +08:00
|
|
|
#endif
|
2020-12-11 01:09:58 +08:00
|
|
|
if ( transfer_to_image(image, mFrame, input_frame) < 0 ) {
|
|
|
|
Error("Failed to transfer from frame to image");
|
|
|
|
zm_av_packet_unref(&packet);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} // end if don't need to do decode
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
frameComplete = 1;
|
|
|
|
frameCount++;
|
2019-07-02 23:14:24 +08:00
|
|
|
} else if ( packet.stream_index == mAudioStreamId ) {
|
|
|
|
// FIXME best way to copy all other streams
|
2017-11-04 01:49:42 +08:00
|
|
|
frameComplete = 1;
|
2017-05-17 00:04:56 +08:00
|
|
|
if ( videoStore ) {
|
|
|
|
if ( record_audio ) {
|
2017-08-10 00:50:46 +08:00
|
|
|
if ( have_video_keyframe ) {
|
2019-07-02 23:14:24 +08:00
|
|
|
// Write the packet to our video store
|
|
|
|
// FIXME no relevance of last key frame
|
|
|
|
int ret = videoStore->writeAudioFramePacket(&packet);
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
// Less than zero and we skipped a frame
|
|
|
|
Warning("Failure to write audio packet.");
|
|
|
|
zm_av_packet_unref(&packet);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-10 00:50:46 +08:00
|
|
|
} else {
|
2019-07-02 23:14:24 +08:00
|
|
|
Debug(3, "Not recording audio because no video keyframe");
|
2017-08-10 00:50:46 +08:00
|
|
|
}
|
2017-05-17 00:04:56 +08:00
|
|
|
} else {
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(4, "Not doing recording of audio packet");
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2017-06-03 04:52:52 +08:00
|
|
|
} else {
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(4, "Have audio packet, but not recording atm");
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
2017-11-04 01:49:42 +08:00
|
|
|
return 0;
|
2017-05-17 00:04:56 +08:00
|
|
|
} else {
|
|
|
|
#if LIBAVUTIL_VERSION_CHECK(56, 23, 0, 23, 0)
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(3, "Some other stream index %d, %s",
|
|
|
|
packet.stream_index,
|
2019-07-02 23:14:24 +08:00
|
|
|
av_get_media_type_string(
|
|
|
|
mFormatContext->streams[packet.stream_index]->codecpar->codec_type)
|
2019-06-26 02:11:59 +08:00
|
|
|
);
|
2017-05-17 00:04:56 +08:00
|
|
|
#else
|
2019-06-26 02:11:59 +08:00
|
|
|
Debug(3, "Some other stream index %d", packet.stream_index);
|
2017-05-17 00:04:56 +08:00
|
|
|
#endif
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end if is video or audio or something else
|
|
|
|
|
|
|
|
// the packet contents are ref counted... when queuing, we allocate another
|
|
|
|
// packet and reference it with that one, so we should always need to unref
|
|
|
|
// here, which should not affect the queued version.
|
2019-06-26 02:11:59 +08:00
|
|
|
zm_av_packet_unref(&packet);
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end while ! frameComplete
|
2017-11-04 01:49:42 +08:00
|
|
|
return frameCount;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end FfmpegCamera::CaptureAndRecord
|
2017-05-17 00:04:56 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
int FfmpegCamera::transfer_to_image(
|
|
|
|
Image &image,
|
|
|
|
AVFrame *output_frame,
|
|
|
|
AVFrame *input_frame
|
|
|
|
) {
|
2020-07-25 00:37:24 +08:00
|
|
|
uint8_t* image_buffer; // pointer to buffer in image
|
|
|
|
uint8_t* buffer; // pointer to either image_buffer or frame_buffer
|
2019-06-26 02:11:59 +08:00
|
|
|
|
|
|
|
/* Request a writeable buffer of the target image */
|
2020-07-25 00:37:24 +08:00
|
|
|
image_buffer = image.WriteBuffer(width, height, colours, subpixelorder);
|
2020-08-26 07:45:48 +08:00
|
|
|
if ( image_buffer == nullptr ) {
|
2019-06-26 02:11:59 +08:00
|
|
|
Error("Failed requesting writeable buffer for the captured image.");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-07-25 00:37:24 +08:00
|
|
|
// if image_buffer was allocated then use it.
|
|
|
|
buffer = frame_buffer ? frame_buffer : image_buffer;
|
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
2019-12-30 01:52:34 +08:00
|
|
|
// From what I've read, we should align the linesizes to 32bit so that ffmpeg can use SIMD instructions too.
|
2019-08-12 08:21:37 +08:00
|
|
|
int size = av_image_fill_arrays(
|
|
|
|
output_frame->data, output_frame->linesize,
|
2020-07-25 00:37:24 +08:00
|
|
|
buffer, imagePixFormat, width, height,
|
2020-07-08 04:12:14 +08:00
|
|
|
alignment
|
2020-02-24 07:14:17 +08:00
|
|
|
);
|
2019-08-12 08:21:37 +08:00
|
|
|
if ( size < 0 ) {
|
|
|
|
Error("Problem setting up data pointers into image %s",
|
|
|
|
av_make_error_string(size).c_str());
|
2020-07-08 04:12:14 +08:00
|
|
|
} else {
|
|
|
|
Debug(4, "av_image_fill_array %dx%d alignment: %d = %d, buffer size is %d",
|
|
|
|
width, height, alignment, size, image.Size());
|
|
|
|
}
|
|
|
|
Debug(1, "ffmpegcamera: width %d height %d linesize %d colours %d imagesize %d", width, height, linesize, colours, imagesize);
|
|
|
|
if ( linesize != (unsigned int)output_frame->linesize[0] ) {
|
|
|
|
Error("Bad linesize expected %d got %d", linesize, output_frame->linesize[0]);
|
2019-08-12 08:21:37 +08:00
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
#else
|
2020-07-25 00:37:24 +08:00
|
|
|
avpicture_fill((AVPicture *)output_frame, buffer,
|
2019-06-26 02:11:59 +08:00
|
|
|
imagePixFormat, width, height);
|
|
|
|
#endif
|
2020-07-25 00:37:24 +08:00
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBSWSCALE
|
2019-06-27 15:40:18 +08:00
|
|
|
if ( !mConvertContext ) {
|
2019-06-26 02:11:59 +08:00
|
|
|
mConvertContext = sws_getContext(
|
|
|
|
input_frame->width,
|
|
|
|
input_frame->height,
|
|
|
|
(AVPixelFormat)input_frame->format,
|
|
|
|
width, height,
|
2020-08-26 07:45:48 +08:00
|
|
|
imagePixFormat, SWS_BICUBIC, nullptr,
|
|
|
|
nullptr, nullptr);
|
|
|
|
if ( mConvertContext == nullptr ) {
|
2019-06-27 15:40:18 +08:00
|
|
|
Error("Unable to create conversion context for %s from %s to %s",
|
2019-07-02 23:14:24 +08:00
|
|
|
mPath.c_str(),
|
|
|
|
av_get_pix_fmt_name((AVPixelFormat)input_frame->format),
|
|
|
|
av_get_pix_fmt_name(imagePixFormat)
|
|
|
|
);
|
|
|
|
return -1;
|
2019-06-26 02:11:59 +08:00
|
|
|
}
|
2019-08-12 08:21:37 +08:00
|
|
|
Debug(1, "Setup conversion context for %dx%d %s to %dx%d %s",
|
|
|
|
input_frame->width, input_frame->height,
|
|
|
|
av_get_pix_fmt_name((AVPixelFormat)input_frame->format),
|
|
|
|
width, height,
|
|
|
|
av_get_pix_fmt_name(imagePixFormat)
|
|
|
|
);
|
2019-06-26 02:11:59 +08:00
|
|
|
}
|
|
|
|
|
2019-11-01 21:24:22 +08:00
|
|
|
int ret =
|
|
|
|
sws_scale(
|
2019-07-02 23:14:24 +08:00
|
|
|
mConvertContext, input_frame->data, input_frame->linesize,
|
|
|
|
0, mVideoCodecContext->height,
|
2019-11-01 21:24:22 +08:00
|
|
|
output_frame->data, output_frame->linesize);
|
2019-12-30 01:44:59 +08:00
|
|
|
if ( ret < 0 ) {
|
2020-02-24 07:14:17 +08:00
|
|
|
Error("Unable to convert format %u %s linesize %d,%d height %d to format %u %s linesize %d,%d at frame %d codec %u %s lines %d: code: %d",
|
2019-08-28 21:19:57 +08:00
|
|
|
input_frame->format, av_get_pix_fmt_name((AVPixelFormat)input_frame->format),
|
2020-02-24 07:14:17 +08:00
|
|
|
input_frame->linesize[0], input_frame->linesize[1], mVideoCodecContext->height,
|
2019-11-01 21:24:22 +08:00
|
|
|
imagePixFormat,
|
2019-08-28 21:19:57 +08:00
|
|
|
av_get_pix_fmt_name(imagePixFormat),
|
2020-02-24 07:14:17 +08:00
|
|
|
output_frame->linesize[0], output_frame->linesize[1],
|
2019-08-28 21:19:57 +08:00
|
|
|
frameCount,
|
2019-11-01 21:24:22 +08:00
|
|
|
mVideoCodecContext->pix_fmt, av_get_pix_fmt_name(mVideoCodecContext->pix_fmt),
|
2019-12-30 01:44:59 +08:00
|
|
|
mVideoCodecContext->height,
|
2019-11-01 21:24:22 +08:00
|
|
|
ret
|
2019-06-26 02:11:59 +08:00
|
|
|
);
|
|
|
|
return -1;
|
|
|
|
}
|
2020-07-25 00:37:24 +08:00
|
|
|
Debug(4, "Able to convert format %u %s linesize %d,%d height %d to format %u %s linesize %d,%d at frame %d codec %u %s %dx%d ",
|
|
|
|
input_frame->format, av_get_pix_fmt_name((AVPixelFormat)input_frame->format),
|
|
|
|
input_frame->linesize[0], input_frame->linesize[1], mVideoCodecContext->height,
|
|
|
|
imagePixFormat,
|
|
|
|
av_get_pix_fmt_name(imagePixFormat),
|
|
|
|
output_frame->linesize[0], output_frame->linesize[1],
|
|
|
|
frameCount,
|
|
|
|
mVideoCodecContext->pix_fmt, av_get_pix_fmt_name(mVideoCodecContext->pix_fmt),
|
|
|
|
output_frame->width,
|
|
|
|
output_frame->height
|
|
|
|
);
|
2019-07-02 23:14:24 +08:00
|
|
|
#else // HAVE_LIBSWSCALE
|
|
|
|
Fatal("You must compile ffmpeg with the --enable-swscale "
|
|
|
|
"option to use ffmpeg cameras");
|
|
|
|
#endif // HAVE_LIBSWSCALE
|
2020-07-25 00:37:24 +08:00
|
|
|
if ( buffer != image_buffer ) {
|
|
|
|
Debug(1, "Copying image-buffer to buffer");
|
|
|
|
// Have to copy contents of image_buffer to directbuffer.
|
|
|
|
// Since linesize isn't the same have to copy line by line
|
|
|
|
uint8_t *image_buffer_ptr = image_buffer;
|
|
|
|
int row_size = output_frame->width * colours;
|
|
|
|
for ( int i = 0; i < output_frame->height; i++ ) {
|
|
|
|
memcpy(image_buffer_ptr, buffer, row_size);
|
|
|
|
image_buffer_ptr += row_size;
|
2020-08-05 23:33:22 +08:00
|
|
|
buffer += output_frame->linesize[0];
|
2020-07-25 00:37:24 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 02:11:59 +08:00
|
|
|
return 0;
|
2019-07-02 23:14:24 +08:00
|
|
|
} // end int FfmpegCamera::transfer_to_image
|
2019-06-26 02:11:59 +08:00
|
|
|
|
2018-05-09 00:02:08 +08:00
|
|
|
int FfmpegCamera::FfmpegInterruptCallback(void *ctx) {
|
2019-07-02 23:14:24 +08:00
|
|
|
// FfmpegCamera* camera = reinterpret_cast<FfmpegCamera*>(ctx);
|
|
|
|
// Debug(4, "FfmpegInterruptCallback");
|
2018-05-09 00:02:08 +08:00
|
|
|
return zm_terminate;
|
|
|
|
}
|
2017-08-16 23:31:47 +08:00
|
|
|
|
2019-07-02 23:14:24 +08:00
|
|
|
#endif // HAVE_LIBAVFORMAT
|