2008-07-16 16:35:59 +08:00
|
|
|
/*
|
2008-07-25 17:08:15 +08:00
|
|
|
* ZoneMinder FFMPEG implementation, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
* Copyright (C) 2001-2008 Philip Coombes
|
2008-07-16 16:35:59 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
2008-07-16 16:35:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zm_ffmpeg.h"
|
2013-11-26 22:34:26 +08:00
|
|
|
#include "zm_image.h"
|
|
|
|
#include "zm_rgb.h"
|
|
|
|
|
|
|
|
#if HAVE_LIBAVCODEC || HAVE_LIBAVUTIL || HAVE_LIBSWSCALE
|
|
|
|
|
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
|
|
|
void FFMPEGInit() {
|
|
|
|
static bool bInit = false;
|
|
|
|
|
|
|
|
if(!bInit) {
|
|
|
|
av_register_all();
|
|
|
|
av_log_set_level(AV_LOG_DEBUG);
|
|
|
|
bInit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 22:34:26 +08:00
|
|
|
#if HAVE_LIBAVUTIL
|
2015-11-04 09:46:26 +08:00
|
|
|
enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder) {
|
2016-04-04 22:11:48 +08:00
|
|
|
enum _AVPIXELFORMAT pf;
|
|
|
|
|
|
|
|
Debug(8,"Colours: %d SubpixelOrder: %d",p_colours,p_subpixelorder);
|
|
|
|
|
|
|
|
switch(p_colours) {
|
|
|
|
case ZM_COLOUR_RGB24:
|
|
|
|
{
|
|
|
|
if(p_subpixelorder == ZM_SUBPIX_ORDER_BGR) {
|
|
|
|
/* BGR subpixel order */
|
|
|
|
pf = AV_PIX_FMT_BGR24;
|
|
|
|
} else {
|
|
|
|
/* Assume RGB subpixel order */
|
|
|
|
pf = AV_PIX_FMT_RGB24;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ZM_COLOUR_RGB32:
|
|
|
|
{
|
|
|
|
if(p_subpixelorder == ZM_SUBPIX_ORDER_ARGB) {
|
|
|
|
/* ARGB subpixel order */
|
|
|
|
pf = AV_PIX_FMT_ARGB;
|
|
|
|
} else if(p_subpixelorder == ZM_SUBPIX_ORDER_ABGR) {
|
|
|
|
/* ABGR subpixel order */
|
|
|
|
pf = AV_PIX_FMT_ABGR;
|
|
|
|
} else if(p_subpixelorder == ZM_SUBPIX_ORDER_BGRA) {
|
|
|
|
/* BGRA subpixel order */
|
|
|
|
pf = AV_PIX_FMT_BGRA;
|
|
|
|
} else {
|
|
|
|
/* Assume RGBA subpixel order */
|
|
|
|
pf = AV_PIX_FMT_RGBA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ZM_COLOUR_GRAY8:
|
|
|
|
pf = AV_PIX_FMT_GRAY8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Panic("Unexpected colours: %d",p_colours);
|
|
|
|
pf = AV_PIX_FMT_GRAY8; /* Just to shush gcc variable may be unused warning */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pf;
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
2016-08-07 22:55:19 +08:00
|
|
|
/* The following is copied directly from newer ffmpeg. */
|
2016-08-10 01:14:10 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(52, 7, 0, 17, 100)
|
2016-08-07 22:55:19 +08:00
|
|
|
#else
|
|
|
|
static int parse_key_value_pair(AVDictionary **pm, const char **buf,
|
|
|
|
const char *key_val_sep, const char *pairs_sep,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
char *key = av_get_token(buf, key_val_sep);
|
|
|
|
char *val = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (key && *key && strspn(*buf, key_val_sep)) {
|
|
|
|
(*buf)++;
|
|
|
|
val = av_get_token(buf, pairs_sep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key && *key && val && *val)
|
|
|
|
ret = av_dict_set(pm, key, val, flags);
|
|
|
|
else
|
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
|
|
|
|
av_freep(&key);
|
|
|
|
av_freep(&val);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int av_dict_parse_string(AVDictionary **pm, const char *str,
|
|
|
|
const char *key_val_sep, const char *pairs_sep,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ignore STRDUP flags */
|
|
|
|
flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
|
|
|
|
|
|
|
|
while (*str) {
|
|
|
|
if ((ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (*str)
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-26 22:34:26 +08:00
|
|
|
#endif // HAVE_LIBAVUTIL
|
|
|
|
|
|
|
|
#if HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
|
|
|
|
SWScale::SWScale() : gotdefaults(false), swscale_ctx(NULL), input_avframe(NULL), output_avframe(NULL) {
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug(4,"SWScale object created");
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Allocate AVFrame for the input */
|
2015-05-29 23:38:02 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
|
2016-04-04 22:11:48 +08:00
|
|
|
input_avframe = av_frame_alloc();
|
2015-05-29 23:38:02 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
input_avframe = avcodec_alloc_frame();
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
if(input_avframe == NULL) {
|
|
|
|
Fatal("Failed allocating AVFrame for the input");
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Allocate AVFrame for the output */
|
2015-05-29 23:38:02 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
|
2016-04-04 22:11:48 +08:00
|
|
|
output_avframe = av_frame_alloc();
|
2015-05-29 23:38:02 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
output_avframe = avcodec_alloc_frame();
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
if(output_avframe == NULL) {
|
|
|
|
Fatal("Failed allocating AVFrame for the output");
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SWScale::~SWScale() {
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Free up everything */
|
2015-11-04 12:30:14 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
|
2016-04-04 22:11:48 +08:00
|
|
|
av_frame_free( &input_avframe );
|
2015-11-04 12:30:14 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
av_freep( &input_avframe );
|
2015-11-04 12:30:14 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
//input_avframe = NULL;
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2015-11-04 12:30:14 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
|
2016-04-04 22:11:48 +08:00
|
|
|
av_frame_free( &output_avframe );
|
2015-11-04 12:30:14 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
av_freep( &output_avframe );
|
2015-11-04 12:30:14 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
//output_avframe = NULL;
|
|
|
|
|
|
|
|
if(swscale_ctx) {
|
|
|
|
sws_freeContext(swscale_ctx);
|
|
|
|
swscale_ctx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug(4,"SWScale object destroyed");
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
2015-11-04 09:46:26 +08:00
|
|
|
int SWScale::SetDefaults(enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) {
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Assign the defaults */
|
|
|
|
default_input_pf = in_pf;
|
|
|
|
default_output_pf = out_pf;
|
|
|
|
default_width = width;
|
|
|
|
default_height = height;
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
gotdefaults = true;
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return 0;
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
2015-11-04 09:46:26 +08:00
|
|
|
int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) {
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Parameter checking */
|
|
|
|
if(in_buffer == NULL || out_buffer == NULL) {
|
|
|
|
Error("NULL Input or output buffer");
|
|
|
|
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
|
|
|
// if(in_pf == 0 || out_pf == 0) {
|
|
|
|
// Error("Invalid input or output pixel formats");
|
|
|
|
// return -2;
|
|
|
|
// }
|
|
|
|
if (!width || !height) {
|
2016-04-04 22:11:48 +08:00
|
|
|
Error("Invalid width or height");
|
|
|
|
return -3;
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2015-05-29 23:38:02 +08:00
|
|
|
#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0)
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Warn if the input or output pixelformat is not supported */
|
|
|
|
if(!sws_isSupportedInput(in_pf)) {
|
|
|
|
Warning("swscale does not support the input format: %c%c%c%c",(in_pf)&0xff,((in_pf)&0xff),((in_pf>>16)&0xff),((in_pf>>24)&0xff));
|
|
|
|
}
|
|
|
|
if(!sws_isSupportedOutput(out_pf)) {
|
|
|
|
Warning("swscale does not support the output format: %c%c%c%c",(out_pf)&0xff,((out_pf>>8)&0xff),((out_pf>>16)&0xff),((out_pf>>24)&0xff));
|
|
|
|
}
|
2014-04-26 04:12:58 +08:00
|
|
|
#endif
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
/* Check the buffer sizes */
|
2016-03-02 22:03:55 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
2016-04-29 19:27:28 +08:00
|
|
|
size_t insize = av_image_get_buffer_size(in_pf, width, height,1);
|
2016-03-02 22:03:55 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
size_t insize = avpicture_get_size(in_pf, width, height);
|
2016-03-02 22:03:55 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
if(insize != in_buffer_size) {
|
|
|
|
Error("The input buffer size does not match the expected size for the input format. Required: %d Available: %d", insize, in_buffer_size);
|
|
|
|
return -4;
|
|
|
|
}
|
2016-03-02 22:03:55 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
2016-04-29 19:27:28 +08:00
|
|
|
size_t outsize = av_image_get_buffer_size(out_pf, width, height,1);
|
2016-03-02 22:03:55 +08:00
|
|
|
#else
|
2016-04-04 22:11:48 +08:00
|
|
|
size_t outsize = avpicture_get_size(out_pf, width, height);
|
2016-03-02 22:03:55 +08:00
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
if(outsize < out_buffer_size) {
|
|
|
|
Error("The output buffer is undersized for the output format. Required: %d Available: %d", outsize, out_buffer_size);
|
|
|
|
return -5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the context */
|
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
|
|
|
swscale_ctx = sws_getCachedContext(swscale_ctx, width, height, in_pf, width, height, out_pf, 0, NULL, NULL, NULL);
|
2016-04-04 22:11:48 +08:00
|
|
|
if(swscale_ctx == NULL) {
|
|
|
|
Error("Failed getting swscale context");
|
|
|
|
return -6;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the buffers */
|
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 LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
|
|
|
if (av_image_fill_arrays(input_avframe->data, input_avframe->linesize,
|
|
|
|
(uint8_t*) in_buffer, in_pf, width, height, 1) <= 0) {
|
|
|
|
#else
|
|
|
|
if (avpicture_fill((AVPicture*) input_avframe, (uint8_t*) in_buffer,
|
|
|
|
in_pf, width, height) <= 0) {
|
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
Error("Failed filling input frame with input buffer");
|
|
|
|
return -7;
|
|
|
|
}
|
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 LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
|
|
|
if (av_image_fill_arrays(output_avframe->data, output_avframe->linesize,
|
|
|
|
out_buffer, out_pf, width, height, 1) <= 0) {
|
|
|
|
#else
|
|
|
|
if (avpicture_fill((AVPicture*) output_avframe, out_buffer, out_pf, width,
|
|
|
|
height) <= 0) {
|
|
|
|
#endif
|
2016-04-04 22:11:48 +08:00
|
|
|
Error("Failed filling output frame with output buffer");
|
|
|
|
return -8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the conversion */
|
|
|
|
if(!sws_scale(swscale_ctx, input_avframe->data, input_avframe->linesize, 0, height, output_avframe->data, output_avframe->linesize ) ) {
|
|
|
|
Error("swscale conversion failed");
|
|
|
|
return -10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
2015-11-04 09:46:26 +08:00
|
|
|
int SWScale::Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) {
|
2016-04-04 22:11:48 +08:00
|
|
|
if(img->Width() != width) {
|
|
|
|
Error("Source image width differs. Source: %d Output: %d",img->Width(), width);
|
|
|
|
return -12;
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if(img->Height() != height) {
|
|
|
|
Error("Source image height differs. Source: %d Output: %d",img->Height(), height);
|
|
|
|
return -13;
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return Convert(img->Buffer(),img->Size(),out_buffer,out_buffer_size,in_pf,out_pf,width,height);
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int SWScale::ConvertDefaults(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size) {
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if(!gotdefaults) {
|
|
|
|
Error("Defaults are not set");
|
|
|
|
return -24;
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return Convert(img,out_buffer,out_buffer_size,default_input_pf,default_output_pf,default_width,default_height);
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int SWScale::ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size) {
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if(!gotdefaults) {
|
|
|
|
Error("Defaults are not set");
|
|
|
|
return -24;
|
|
|
|
}
|
2013-11-26 22:34:26 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
return Convert(in_buffer,in_buffer_size,out_buffer,out_buffer_size,default_input_pf,default_output_pf,default_width,default_height);
|
2013-11-26 22:34:26 +08:00
|
|
|
}
|
|
|
|
#endif // HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-08-07 22:55:19 +08:00
|
|
|
|
2013-11-26 22:34:26 +08:00
|
|
|
#endif // HAVE_LIBAVCODEC || HAVE_LIBAVUTIL || HAVE_LIBSWSCALE
|
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 HAVE_LIBAVUTIL
|
|
|
|
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb){
|
|
|
|
int64_t a, b, this_thing;
|
|
|
|
|
|
|
|
av_assert0(in_ts != AV_NOPTS_VALUE);
|
|
|
|
av_assert0(duration >= 0);
|
|
|
|
|
|
|
|
if (*last == AV_NOPTS_VALUE || !duration || in_tb.num*(int64_t)out_tb.den <= out_tb.num*(int64_t)in_tb.den) {
|
|
|
|
simple_round:
|
|
|
|
*last = av_rescale_q(in_ts, in_tb, fs_tb) + duration;
|
|
|
|
return av_rescale_q(in_ts, in_tb, out_tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
a = av_rescale_q_rnd(2*in_ts-1, in_tb, fs_tb, AV_ROUND_DOWN) >>1;
|
|
|
|
b = (av_rescale_q_rnd(2*in_ts+1, in_tb, fs_tb, AV_ROUND_UP )+1)>>1;
|
|
|
|
if (*last < 2*a - b || *last > 2*b - a)
|
|
|
|
goto simple_round;
|
|
|
|
|
|
|
|
this_thing = av_clip64(*last, a, b);
|
|
|
|
*last = this_thing + duration;
|
|
|
|
|
|
|
|
return av_rescale_q(this_thing, fs_tb, out_tb);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename) {
|
|
|
|
AVFormatContext *s = avformat_alloc_context();
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
*avctx = NULL;
|
|
|
|
if (!s) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Out of memory\n");
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!oformat) {
|
|
|
|
if (format) {
|
|
|
|
oformat = av_guess_format(format, NULL, NULL);
|
|
|
|
if (!oformat) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
|
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oformat = av_guess_format(NULL, filename, NULL);
|
|
|
|
if (!oformat) {
|
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n", filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
avformat_free_context(s);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
s->oformat = oformat;
|
|
|
|
if (s->oformat->priv_data_size > 0) {
|
|
|
|
s->priv_data = av_mallocz(s->oformat->priv_data_size);
|
|
|
|
if (s->priv_data) {
|
|
|
|
if (s->oformat->priv_class) {
|
|
|
|
*(const AVClass**)s->priv_data= s->oformat->priv_class;
|
|
|
|
av_opt_set_defaults(s->priv_data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Out of memory\n");
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
s->priv_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename) strncpy(s->filename, filename, sizeof(s->filename));
|
|
|
|
*avctx = s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void zm_log_fps(double d, const char *postfix) {
|
|
|
|
uint64_t v = lrintf(d * 100);
|
|
|
|
if (!v) {
|
|
|
|
Debug(3, "%1.4f %s", d, postfix);
|
|
|
|
} else if (v % 100) {
|
|
|
|
Debug(3, "%3.2f %s", d, postfix);
|
|
|
|
} else if (v % (100 * 1000)) {
|
|
|
|
Debug(3, "%1.0f %s", d, postfix);
|
|
|
|
} else
|
|
|
|
Debug(3, "%1.0fk %s", d / 1000, postfix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "user interface" functions */
|
|
|
|
void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output) {
|
|
|
|
char buf[256];
|
|
|
|
Debug(1, "Dumping stream index i(%d) index(%d)", i, index );
|
|
|
|
int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
|
|
|
|
AVStream *st = ic->streams[i];
|
|
|
|
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
|
|
|
|
|
|
|
|
avcodec_string(buf, sizeof(buf), st->codec, is_output);
|
|
|
|
Debug(3, " Stream #%d:%d", index, i);
|
|
|
|
|
|
|
|
/* the pid is an important information, so we display it */
|
|
|
|
/* XXX: add a generic system */
|
|
|
|
if (flags & AVFMT_SHOW_IDS)
|
|
|
|
Debug(3, "[0x%x]", st->id);
|
|
|
|
if (lang)
|
|
|
|
Debug(3, "(%s)", lang->value);
|
|
|
|
av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
|
|
|
|
st->time_base.num, st->time_base.den);
|
|
|
|
Debug(3, ": %s", buf);
|
|
|
|
|
|
|
|
if (st->sample_aspect_ratio.num && // default
|
|
|
|
av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
|
|
|
|
AVRational display_aspect_ratio;
|
|
|
|
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
|
|
|
|
st->codec->width * (int64_t)st->sample_aspect_ratio.num,
|
|
|
|
st->codec->height * (int64_t)st->sample_aspect_ratio.den,
|
|
|
|
1024 * 1024);
|
|
|
|
Debug(3, ", SAR %d:%d DAR %d:%d",
|
|
|
|
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
|
|
|
|
display_aspect_ratio.num, display_aspect_ratio.den);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
|
|
int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
|
|
|
|
int tbn = st->time_base.den && st->time_base.num;
|
|
|
|
int tbc = st->codec->time_base.den && st->codec->time_base.num;
|
|
|
|
|
|
|
|
if (fps || tbn || tbc)
|
|
|
|
Debug(3, "\n" );
|
|
|
|
|
|
|
|
if (fps)
|
|
|
|
zm_log_fps(av_q2d(st->avg_frame_rate), tbn || tbc ? "fps, " : "fps");
|
|
|
|
if (tbn)
|
|
|
|
zm_log_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
|
|
|
|
if (tbc)
|
|
|
|
zm_log_fps(1 / av_q2d(st->codec->time_base), "tbc");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (st->disposition & AV_DISPOSITION_DEFAULT)
|
|
|
|
Debug(3, " (default)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_DUB)
|
|
|
|
Debug(3, " (dub)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_ORIGINAL)
|
|
|
|
Debug(3, " (original)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_COMMENT)
|
|
|
|
Debug(3, " (comment)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_LYRICS)
|
|
|
|
Debug(3, " (lyrics)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_KARAOKE)
|
|
|
|
Debug(3, " (karaoke)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_FORCED)
|
|
|
|
Debug(3, " (forced)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
|
|
|
|
Debug(3, " (hearing impaired)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
|
|
|
|
Debug(3, " (visual impaired)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
|
|
|
|
Debug(3, " (clean effects)");
|
|
|
|
Debug(3, "\n");
|
|
|
|
|
|
|
|
//dump_metadata(NULL, st->metadata, " ");
|
|
|
|
|
|
|
|
//dump_sidedata(NULL, st, " ");
|
|
|
|
}
|