Merge branch 'master' of github.com:ZoneMinder/zoneminder
commit
7efbf78260
|
@ -483,7 +483,7 @@ CREATE TABLE `Monitors` (
|
|||
`SaveJPEGs` TINYINT NOT NULL DEFAULT '3' ,
|
||||
`VideoWriter` TINYINT NOT NULL DEFAULT '0',
|
||||
`OutputCodec` int(10) unsigned NOT NULL default 0,
|
||||
`Encoder` enum('auto','h264','libx264','h264_omx','h264_vaapi','mjpeg','mpeg1','mpeg2'),
|
||||
`Encoder` varchar(32),
|
||||
`OutputContainer` enum('auto','mp4','mkv'),
|
||||
`EncoderParameters` TEXT,
|
||||
`RecordAudio` TINYINT NOT NULL DEFAULT '0',
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE `Monitors` MODIFY `Encoder` varchar(32);
|
|
@ -31,7 +31,7 @@
|
|||
%global _hardened_build 1
|
||||
|
||||
Name: zoneminder
|
||||
Version: 1.35.27
|
||||
Version: 1.35.28
|
||||
Release: 1%{?dist}
|
||||
Summary: A camera monitoring and analysis tool
|
||||
Group: System Environment/Daemons
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# ==========================================================================
|
||||
#
|
||||
# ZoneMinder Config Data Module, $Date: 2011-01-20 18:49:42 +0000 (Thu, 20 Jan 2011) $, $Revision: 3230 $
|
||||
# ZoneMinder Config Data Module
|
||||
# Copyright (C) 2001-2008 Philip Coombes
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
|
@ -508,7 +508,7 @@ our @options = (
|
|||
},
|
||||
{
|
||||
name => 'ZM_SYSTEM_SHUTDOWN',
|
||||
default => 'true',
|
||||
default => 'yes',
|
||||
description => 'Allow Admin users to power off or restart the system from the ZoneMinder UI.',
|
||||
help => 'The system will need to have sudo installed and the following added to /etc/sudoers~~
|
||||
~~
|
||||
|
@ -518,6 +518,14 @@ our @options = (
|
|||
type => $types{boolean},
|
||||
category => 'system',
|
||||
},
|
||||
{
|
||||
name => 'ZM_FEATURES_SNAPSHOTS',
|
||||
default => 'no',
|
||||
description => 'Enable snapshot functionality.',
|
||||
help => 'Snapshots are a collection of events. They can be created using the snapshot button in montage view. All visible monitors will have a short event created, archived and added to the Snapshot.',
|
||||
type => $types{boolean},
|
||||
category => 'hidden',
|
||||
},
|
||||
{
|
||||
name => 'ZM_USE_DEEP_STORAGE',
|
||||
default => 'yes',
|
||||
|
|
|
@ -570,7 +570,6 @@ void logInit(const char *name, const Logger::Options &options) {
|
|||
}
|
||||
|
||||
void logTerm() {
|
||||
dbQueue.stop();
|
||||
if (Logger::smInstance) {
|
||||
delete Logger::smInstance;
|
||||
Logger::smInstance = nullptr;
|
||||
|
|
|
@ -1891,6 +1891,24 @@ bool Monitor::Analyse() {
|
|||
|
||||
struct timeval *timestamp = snap->timestamp;
|
||||
|
||||
/* try to stay behind the decoder. */
|
||||
if (decoding_enabled) {
|
||||
while (!snap->image and !snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
|
||||
// Need to wait for the decoder thread.
|
||||
Debug(1, "Waiting for decode");
|
||||
packet_lock->wait();
|
||||
if (!snap->image and snap->decoded) {
|
||||
Debug(1, "No image but was decoded, giving up");
|
||||
delete packet_lock;
|
||||
return false;
|
||||
}
|
||||
} // end while ! decoded
|
||||
if (zm_terminate) {
|
||||
delete packet_lock;
|
||||
return false;
|
||||
}
|
||||
} // end if decoding enabled
|
||||
|
||||
if (Active() and (function == MODECT or function == MOCORD)) {
|
||||
Debug(3, "signal and active and modect");
|
||||
Event::StringSet zoneSet;
|
||||
|
@ -1905,22 +1923,6 @@ bool Monitor::Analyse() {
|
|||
}
|
||||
|
||||
if (!(analysis_image_count % (motion_frame_skip+1))) {
|
||||
if (decoding_enabled) {
|
||||
while (!snap->image and !snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
|
||||
// Need to wait for the decoder thread.
|
||||
Debug(1, "Waiting for decode");
|
||||
packet_lock->wait();
|
||||
if (!snap->image and snap->decoded) {
|
||||
Debug(1, "No image but was decoded, giving up");
|
||||
delete packet_lock;
|
||||
return false;
|
||||
}
|
||||
} // end while ! decoded
|
||||
if (zm_terminate) {
|
||||
delete packet_lock;
|
||||
return false;
|
||||
}
|
||||
} // end if decoding enabled
|
||||
|
||||
if (snap->image) {
|
||||
// decoder may not have been able to provide an image
|
||||
|
@ -2632,6 +2634,7 @@ bool Monitor::Decode() {
|
|||
ZMPacket *packet = packet_lock->packet_;
|
||||
packetqueue.increment_it(decoder_it);
|
||||
if (packet->codec_type != AVMEDIA_TYPE_VIDEO) {
|
||||
Debug(4, "Not video");
|
||||
packetqueue.unlock(packet_lock);
|
||||
return true; // Don't need decode
|
||||
}
|
||||
|
@ -2692,19 +2695,23 @@ bool Monitor::Decode() {
|
|||
capture_image = packet->image;
|
||||
|
||||
/* Deinterlacing */
|
||||
if ( deinterlacing_value ) {
|
||||
if ( deinterlacing_value == 1 ) {
|
||||
if (deinterlacing_value) {
|
||||
Debug(1, "Doing deinterlacing");
|
||||
if (deinterlacing_value == 1) {
|
||||
capture_image->Deinterlace_Discard();
|
||||
} else if ( deinterlacing_value == 2 ) {
|
||||
} else if (deinterlacing_value == 2) {
|
||||
capture_image->Deinterlace_Linear();
|
||||
} else if ( deinterlacing_value == 3 ) {
|
||||
} else if (deinterlacing_value == 3) {
|
||||
capture_image->Deinterlace_Blend();
|
||||
} else if ( deinterlacing_value == 4 ) {
|
||||
} else if (deinterlacing_value == 4) {
|
||||
ZMLockedPacket *deinterlace_packet_lock = nullptr;
|
||||
while (!zm_terminate) {
|
||||
ZMLockedPacket *second_packet_lock = packetqueue.get_packet(decoder_it);
|
||||
if (!second_packet_lock) return false;
|
||||
if ( second_packet_lock->packet_->codec_type == packet->codec_type) {
|
||||
if (!second_packet_lock) {
|
||||
packetqueue.unlock(packet_lock);
|
||||
return false;
|
||||
}
|
||||
if (second_packet_lock->packet_->codec_type == packet->codec_type) {
|
||||
deinterlace_packet_lock = second_packet_lock;
|
||||
break;
|
||||
}
|
||||
|
@ -2713,8 +2720,8 @@ bool Monitor::Decode() {
|
|||
}
|
||||
if (zm_terminate) return false;
|
||||
capture_image->Deinterlace_4Field(deinterlace_packet_lock->packet_->image, (deinterlacing>>8)&0xff);
|
||||
delete deinterlace_packet_lock;
|
||||
} else if ( deinterlacing_value == 5 ) {
|
||||
packetqueue.unlock(deinterlace_packet_lock);
|
||||
} else if (deinterlacing_value == 5) {
|
||||
capture_image->Deinterlace_Blend_CustomRatio((deinterlacing>>8)&0xff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -487,9 +487,9 @@ void MonitorStream::runStream() {
|
|||
|
||||
if (!checkInitialised()) {
|
||||
if (!loadMonitor(monitor_id)) {
|
||||
sendTextFrame("Not connected");
|
||||
if (!sendTextFrame("Not connected")) return;
|
||||
} else {
|
||||
sendTextFrame("Unable to stream");
|
||||
if (!sendTextFrame("Unable to stream")) return;
|
||||
}
|
||||
sleep(1);
|
||||
} else {
|
||||
|
|
|
@ -232,45 +232,50 @@ AVPacket *ZMPacket::set_packet(AVPacket *p) {
|
|||
return &packet;
|
||||
}
|
||||
|
||||
AVFrame *ZMPacket::get_out_frame(const AVCodecContext *ctx) {
|
||||
if ( !out_frame ) {
|
||||
AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
|
||||
if (!out_frame) {
|
||||
out_frame = zm_av_frame_alloc();
|
||||
if ( !out_frame ) {
|
||||
if (!out_frame) {
|
||||
Error("Unable to allocate a frame");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
||||
|
||||
codec_imgsize = av_image_get_buffer_size(
|
||||
ctx->pix_fmt,
|
||||
ctx->width,
|
||||
ctx->height, 32);
|
||||
format, width, height, 32);
|
||||
Debug(1, "buffer size %u from %s %dx%d", codec_imgsize, av_get_pix_fmt_name(format), width, height);
|
||||
buffer = (uint8_t *)av_malloc(codec_imgsize);
|
||||
av_image_fill_arrays(
|
||||
int ret;
|
||||
if ((ret=av_image_fill_arrays(
|
||||
out_frame->data,
|
||||
out_frame->linesize,
|
||||
buffer,
|
||||
ctx->pix_fmt,
|
||||
ctx->width,
|
||||
ctx->height,
|
||||
32);
|
||||
format,
|
||||
width,
|
||||
height,
|
||||
32))<0) {
|
||||
Error("Failed to fill_arrays %s", av_make_error_string(ret).c_str());
|
||||
av_frame_free(&out_frame);
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
codec_imgsize = avpicture_get_size(
|
||||
ctx->pix_fmt,
|
||||
ctx->width,
|
||||
ctx->height);
|
||||
format,
|
||||
width,
|
||||
>height);
|
||||
buffer = (uint8_t *)av_malloc(codec_imgsize);
|
||||
avpicture_fill(
|
||||
(AVPicture *)out_frame,
|
||||
buffer,
|
||||
ctx->pix_fmt,
|
||||
ctx->width,
|
||||
ctx->height
|
||||
format,
|
||||
width,
|
||||
height
|
||||
);
|
||||
#endif
|
||||
out_frame->width = ctx->width;
|
||||
out_frame->height = ctx->height;
|
||||
out_frame->format = ctx->pix_fmt;
|
||||
out_frame->width = width;
|
||||
out_frame->height = height;
|
||||
out_frame->format = format;
|
||||
}
|
||||
return out_frame;
|
||||
} // end AVFrame *ZMPacket::get_out_frame( AVCodecContext *ctx );
|
||||
|
|
|
@ -74,7 +74,8 @@ class ZMPacket {
|
|||
ZMPacket();
|
||||
~ZMPacket();
|
||||
|
||||
AVFrame *get_out_frame(const AVCodecContext *ctx);
|
||||
//AVFrame *get_out_frame(const AVCodecContext *ctx);
|
||||
AVFrame *get_out_frame(int width, int height, AVPixelFormat format);
|
||||
int get_codec_imgsize() { return codec_imgsize; };
|
||||
};
|
||||
|
||||
|
|
|
@ -193,10 +193,11 @@ void PacketQueue::clearPackets(ZMPacket *add_packet) {
|
|||
return;
|
||||
}
|
||||
std::unique_lock<std::mutex> lck(mutex);
|
||||
if (!pktQueue.size()) return;
|
||||
|
||||
// If analysis_it isn't at the end, we need to keep that many additional packets
|
||||
int tail_count = 0;
|
||||
if (pktQueue.size() and (pktQueue.back() != add_packet)) {
|
||||
if (pktQueue.back() != add_packet) {
|
||||
packetqueue_iterator it = pktQueue.end();
|
||||
--it;
|
||||
while (*it != add_packet) {
|
||||
|
@ -205,7 +206,7 @@ void PacketQueue::clearPackets(ZMPacket *add_packet) {
|
|||
--it;
|
||||
}
|
||||
}
|
||||
Debug(1, "Tail count is %d", tail_count);
|
||||
Debug(1, "Tail count is %d, queue size is %lu", tail_count, pktQueue.size());
|
||||
|
||||
if (!keep_keyframes) {
|
||||
// If not doing passthrough, we don't care about starting with a keyframe so logic is simpler
|
||||
|
@ -241,11 +242,17 @@ void PacketQueue::clearPackets(ZMPacket *add_packet) {
|
|||
|
||||
// First packet is special because we know it is a video keyframe and only need to check for lock
|
||||
ZMPacket *zm_packet = *it;
|
||||
Debug(1, "trying lock on first packet");
|
||||
ZMLockedPacket *lp = new ZMLockedPacket(zm_packet);
|
||||
if (lp->trylock()) {
|
||||
Debug(1, "Have lock on first packet");
|
||||
++it;
|
||||
delete lp;
|
||||
|
||||
if (it == pktQueue.end()) {
|
||||
Debug(1, "Hit end already");
|
||||
it = pktQueue.begin();
|
||||
} else {
|
||||
// Since we have many packets in the queue, we should NOT be pointing at end so don't need to test for that
|
||||
while (*it != add_packet) {
|
||||
zm_packet = *it;
|
||||
|
@ -275,6 +282,7 @@ void PacketQueue::clearPackets(ZMPacket *add_packet) {
|
|||
}
|
||||
it++;
|
||||
} // end while
|
||||
}
|
||||
} // end if first packet not locked
|
||||
Debug(1, "Resulting pointing at latest packet? %d, next front points to begin? %d",
|
||||
( *it == add_packet ),
|
||||
|
@ -419,7 +427,7 @@ unsigned int PacketQueue::clear(unsigned int frames_to_keep, int stream_id) {
|
|||
void PacketQueue::clear() {
|
||||
deleting = true;
|
||||
condition.notify_all();
|
||||
|
||||
Debug(1, "Clearing packetqueue");
|
||||
std::unique_lock<std::mutex> lck(mutex);
|
||||
|
||||
while (!pktQueue.empty()) {
|
||||
|
@ -560,13 +568,19 @@ ZMLockedPacket *PacketQueue::get_packet(packetqueue_iterator *it) {
|
|||
ZMLockedPacket *lp = nullptr;
|
||||
while (!lp) {
|
||||
while (*it == pktQueue.end()) {
|
||||
if (deleting or zm_terminate)
|
||||
if (deleting or zm_terminate) {
|
||||
Debug(1, "terminated, leaving");
|
||||
condition.notify_all();
|
||||
return nullptr;
|
||||
}
|
||||
Debug(2, "waiting. Queue size %zu it == end? %d", pktQueue.size(), (*it == pktQueue.end()));
|
||||
condition.wait(lck);
|
||||
}
|
||||
if (deleting or zm_terminate)
|
||||
if (deleting or zm_terminate) {
|
||||
Debug(1, "terminated, leaving");
|
||||
condition.notify_all();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZMPacket *p = *(*it);
|
||||
if (!p) {
|
||||
|
@ -586,6 +600,7 @@ ZMLockedPacket *PacketQueue::get_packet(packetqueue_iterator *it) {
|
|||
}
|
||||
delete lp;
|
||||
lp = nullptr;
|
||||
Debug(2, "waiting. Queue size %zu it == end? %d", pktQueue.size(), (*it == pktQueue.end()));
|
||||
condition.wait(lck);
|
||||
} // end while !lp
|
||||
return nullptr;
|
||||
|
@ -645,51 +660,43 @@ packetqueue_iterator *PacketQueue::get_event_start_packet_it(
|
|||
// Step one count back pre_event_count frames as the minimum
|
||||
// Do not assume that snapshot_it is video
|
||||
// snapshot it might already point to the beginning
|
||||
while (( (*it) != pktQueue.begin() ) and pre_event_count) {
|
||||
packet = *(*it);
|
||||
Debug(1, "Previous packet pre_event_count %d stream_index %d keyframe %d score %d",
|
||||
pre_event_count, packet->packet.stream_index, packet->keyframe, packet->score);
|
||||
ZM_DUMP_PACKET(packet->packet, "");
|
||||
if (packet->packet.stream_index == video_stream_id) {
|
||||
pre_event_count --;
|
||||
if (!pre_event_count)
|
||||
break;
|
||||
if (pre_event_count) {
|
||||
while ((*it) != pktQueue.begin()) {
|
||||
packet = *(*it);
|
||||
Debug(1, "Previous packet pre_event_count %d stream_index %d keyframe %d score %d",
|
||||
pre_event_count, packet->packet.stream_index, packet->keyframe, packet->score);
|
||||
ZM_DUMP_PACKET(packet->packet, "");
|
||||
if (packet->packet.stream_index == video_stream_id) {
|
||||
pre_event_count --;
|
||||
if (!pre_event_count)
|
||||
break;
|
||||
}
|
||||
(*it)--;
|
||||
}
|
||||
(*it)--;
|
||||
}
|
||||
// it either points to beginning or we have seen pre_event_count video packets.
|
||||
|
||||
if ((*it) == pktQueue.begin()) {
|
||||
packet = *(*it);
|
||||
Debug(1, "Hit begin");
|
||||
// hit end, the first packet in the queue should ALWAYS be a video keyframe.
|
||||
// So we should be able to return it.
|
||||
if (pre_event_count) {
|
||||
if (packet->image_index < (int)pre_event_count) {
|
||||
// probably just starting up
|
||||
Debug(1, "Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||
} else {
|
||||
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||
}
|
||||
ZM_DUMP_PACKET(packet->packet, "");
|
||||
packet = *(*it);
|
||||
if (pre_event_count) {
|
||||
if (packet->image_index < (int)pre_event_count) {
|
||||
// probably just starting up
|
||||
Debug(1, "Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||
} else {
|
||||
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||
}
|
||||
ZM_DUMP_PACKET(packet->packet, "");
|
||||
return it;
|
||||
}
|
||||
|
||||
// Not at beginning, so must be pointing at a video keyframe or maybe pre_event_count == 0
|
||||
if (packet->keyframe) {
|
||||
ZM_DUMP_PACKET(packet->packet, "Found video keyframe, Returning");
|
||||
return it;
|
||||
}
|
||||
|
||||
while (--(*it) != pktQueue.begin()) {
|
||||
while ((*it) != pktQueue.begin()) {
|
||||
packet = *(*it);
|
||||
ZM_DUMP_PACKET(packet->packet, "No keyframe");
|
||||
if ((packet->packet.stream_index == video_stream_id) and packet->keyframe)
|
||||
return it; // Success
|
||||
--(*it);
|
||||
}
|
||||
if ( !(*(*it))->keyframe ) {
|
||||
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||
if (!(*(*it))->keyframe) {
|
||||
Warning("Hit beginning of packetqueue and packet is not a keyframe. index is %d", packet->image_index);
|
||||
}
|
||||
return it;
|
||||
} // end packetqueue_iterator *PacketQueue::get_event_start_packet_it
|
||||
|
|
|
@ -27,12 +27,34 @@ extern "C" {
|
|||
#include "libavutil/time.h"
|
||||
}
|
||||
|
||||
/*
|
||||
AVCodecID codec_id;
|
||||
char *codec_codec;
|
||||
char *codec_name;
|
||||
enum AVPixelFormat sw_pix_fmt;
|
||||
enum AVPixelFormat hw_pix_fmt;
|
||||
AVHWDeviceType hwdevice_type;
|
||||
*/
|
||||
|
||||
VideoStore::CodecData VideoStore::codec_data[] = {
|
||||
{ AV_CODEC_ID_H264, "h264", "h264_vaapi", AV_PIX_FMT_NV12 },
|
||||
{ AV_CODEC_ID_H264, "h264", "h264_omx", AV_PIX_FMT_YUV420P },
|
||||
{ AV_CODEC_ID_H264, "h264", "h264", AV_PIX_FMT_YUV420P },
|
||||
{ AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P },
|
||||
{ AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P },
|
||||
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
||||
{ AV_CODEC_ID_H265, "h265", "hevc_vaapi", AV_PIX_FMT_NV12, AV_PIX_FMT_VAAPI, AV_HWDEVICE_TYPE_VAAPI },
|
||||
{ AV_CODEC_ID_H265, "h265", "hevc_nvenc", AV_PIX_FMT_NV12, AV_PIX_FMT_NV12, AV_HWDEVICE_TYPE_NONE },
|
||||
{ AV_CODEC_ID_H265, "h265", "libx265", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
|
||||
|
||||
{ AV_CODEC_ID_H264, "h264", "h264_vaapi", AV_PIX_FMT_NV12, AV_PIX_FMT_VAAPI, AV_HWDEVICE_TYPE_VAAPI },
|
||||
{ AV_CODEC_ID_H264, "h264", "h264_nvenc", AV_PIX_FMT_NV12, AV_PIX_FMT_NV12, AV_HWDEVICE_TYPE_NONE },
|
||||
{ AV_CODEC_ID_H264, "h264", "h264_omx", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
|
||||
{ AV_CODEC_ID_H264, "h264", "h264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
|
||||
{ AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE },
|
||||
{ AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ422P, AV_HWDEVICE_TYPE_NONE },
|
||||
#else
|
||||
{ AV_CODEC_ID_H265, "h265", "libx265", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P },
|
||||
|
||||
{ AV_CODEC_ID_H264, "h264", "h264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P },
|
||||
{ AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P },
|
||||
{ AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ422P },
|
||||
#endif
|
||||
};
|
||||
|
||||
VideoStore::VideoStore(
|
||||
|
@ -44,6 +66,7 @@ VideoStore::VideoStore(
|
|||
AVCodecContext *p_audio_in_ctx,
|
||||
Monitor *p_monitor
|
||||
) :
|
||||
chosen_codec_data(nullptr),
|
||||
monitor(p_monitor),
|
||||
out_format(nullptr),
|
||||
oc(nullptr),
|
||||
|
@ -61,8 +84,10 @@ VideoStore::VideoStore(
|
|||
video_in_frame(nullptr),
|
||||
in_frame(nullptr),
|
||||
out_frame(nullptr),
|
||||
hw_frame(nullptr),
|
||||
packets_written(0),
|
||||
frame_count(0),
|
||||
hw_device_ctx(nullptr),
|
||||
#if defined(HAVE_LIBSWRESAMPLE) || defined(HAVE_LIBAVRESAMPLE)
|
||||
resample_ctx(nullptr),
|
||||
#if defined(HAVE_LIBSWRESAMPLE)
|
||||
|
@ -151,8 +176,8 @@ bool VideoStore::open() {
|
|||
int wanted_codec = monitor->OutputCodec();
|
||||
if ( !wanted_codec ) {
|
||||
// default to h264
|
||||
Debug(2, "Defaulting to H264");
|
||||
wanted_codec = AV_CODEC_ID_H264;
|
||||
//Debug(2, "Defaulting to H264");
|
||||
//wanted_codec = AV_CODEC_ID_H264;
|
||||
// FIXME what is the optimal codec? Probably low latency h264 which is effectively mjpeg
|
||||
} else {
|
||||
if ( AV_CODEC_ID_H264 != 27 and wanted_codec > 3 ) {
|
||||
|
@ -163,14 +188,15 @@ bool VideoStore::open() {
|
|||
}
|
||||
std::string wanted_encoder = monitor->Encoder();
|
||||
|
||||
for ( unsigned int i = 0; i < sizeof(codec_data) / sizeof(*codec_data); i++ ) {
|
||||
if ( wanted_encoder != "" and wanted_encoder != "auto" ) {
|
||||
if ( wanted_encoder != codec_data[i].codec_name ) {
|
||||
for (unsigned int i = 0; i < sizeof(codec_data) / sizeof(*codec_data); i++) {
|
||||
chosen_codec_data = &codec_data[i];
|
||||
if (wanted_encoder != "" and wanted_encoder != "auto") {
|
||||
if (wanted_encoder != codec_data[i].codec_name) {
|
||||
Debug(1, "Not the right codec name %s != %s", codec_data[i].codec_name, wanted_encoder.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( codec_data[i].codec_id != wanted_codec ) {
|
||||
if (wanted_codec and (codec_data[i].codec_id != wanted_codec)) {
|
||||
Debug(1, "Not the right codec %d %s != %d %s",
|
||||
codec_data[i].codec_id,
|
||||
avcodec_get_name(codec_data[i].codec_id),
|
||||
|
@ -181,13 +207,13 @@ bool VideoStore::open() {
|
|||
}
|
||||
|
||||
video_out_codec = avcodec_find_encoder_by_name(codec_data[i].codec_name);
|
||||
if ( !video_out_codec ) {
|
||||
if (!video_out_codec) {
|
||||
Debug(1, "Didn't find encoder for %s", codec_data[i].codec_name);
|
||||
continue;
|
||||
}
|
||||
Debug(1, "Found video codec for %s", codec_data[i].codec_name);
|
||||
video_out_ctx = avcodec_alloc_context3(video_out_codec);
|
||||
if ( oc->oformat->flags & AVFMT_GLOBALHEADER ) {
|
||||
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
||||
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
|
||||
video_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
|
||||
#else
|
||||
|
@ -198,7 +224,8 @@ bool VideoStore::open() {
|
|||
// When encoding, we are going to use the timestamp values instead of packet pts/dts
|
||||
video_out_ctx->time_base = AV_TIME_BASE_Q;
|
||||
video_out_ctx->codec_id = codec_data[i].codec_id;
|
||||
video_out_ctx->pix_fmt = codec_data[i].pix_fmt;
|
||||
video_out_ctx->pix_fmt = codec_data[i].hw_pix_fmt;
|
||||
Debug(1, "Setting pix fmt to %d %s", codec_data[i].hw_pix_fmt, av_get_pix_fmt_name(codec_data[i].hw_pix_fmt));
|
||||
video_out_ctx->level = 32;
|
||||
|
||||
// Don't have an input stream, so need to tell it what we are sending it, or are transcoding
|
||||
|
@ -219,22 +246,55 @@ bool VideoStore::open() {
|
|||
* the motion of the chroma plane does not match the luma plane. */
|
||||
video_out_ctx->mb_decision = 2;
|
||||
}
|
||||
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
||||
if (codec_data[i].hwdevice_type != AV_HWDEVICE_TYPE_NONE) {
|
||||
Debug(1, "Setting up hwdevice");
|
||||
ret = av_hwdevice_ctx_create(&hw_device_ctx,
|
||||
codec_data[i].hwdevice_type,
|
||||
nullptr, nullptr, 0);
|
||||
|
||||
AVBufferRef *hw_frames_ref;
|
||||
AVHWFramesContext *frames_ctx = nullptr;
|
||||
|
||||
if (!(hw_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx))) {
|
||||
Error("Failed to create hwaccel frame context.");
|
||||
return -1;
|
||||
}
|
||||
frames_ctx = (AVHWFramesContext *)(hw_frames_ref->data);
|
||||
frames_ctx->format = codec_data[i].hw_pix_fmt;
|
||||
frames_ctx->sw_format = codec_data[i].sw_pix_fmt;
|
||||
frames_ctx->width = monitor->Width();
|
||||
frames_ctx->height = monitor->Height();
|
||||
frames_ctx->initial_pool_size = 20;
|
||||
if ((ret = av_hwframe_ctx_init(hw_frames_ref)) < 0) {
|
||||
Error("Failed to initialize hwaccel frame context."
|
||||
"Error code: %s",av_err2str(ret));
|
||||
av_buffer_unref(&hw_frames_ref);
|
||||
} else {
|
||||
video_out_ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ref);
|
||||
if (!video_out_ctx->hw_frames_ctx) {
|
||||
Error("Failed to allocate hw_frames_ctx");
|
||||
}
|
||||
}
|
||||
av_buffer_unref(&hw_frames_ref);
|
||||
}
|
||||
#endif
|
||||
|
||||
AVDictionary *opts = 0;
|
||||
std::string Options = monitor->GetEncoderOptions();
|
||||
Debug(2, "Options? %s", Options.c_str());
|
||||
ret = av_dict_parse_string(&opts, Options.c_str(), "=", ",#\n", 0);
|
||||
if ( ret < 0 ) {
|
||||
if (ret < 0) {
|
||||
Warning("Could not parse ffmpeg encoder options list '%s'\n", Options.c_str());
|
||||
} else {
|
||||
AVDictionaryEntry *e = nullptr;
|
||||
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
|
||||
while ((e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr) {
|
||||
Debug(3, "Encoder Option %s=%s", e->key, e->value);
|
||||
}
|
||||
}
|
||||
|
||||
if ( (ret = avcodec_open2(video_out_ctx, video_out_codec, &opts)) < 0 ) {
|
||||
if ( wanted_encoder != "" and wanted_encoder != "auto" ) {
|
||||
if ((ret = avcodec_open2(video_out_ctx, video_out_codec, &opts)) < 0) {
|
||||
if (wanted_encoder != "" and wanted_encoder != "auto") {
|
||||
Warning("Can't open video codec (%s) %s",
|
||||
video_out_codec->name,
|
||||
av_make_error_string(ret).c_str()
|
||||
|
@ -248,27 +308,26 @@ bool VideoStore::open() {
|
|||
video_out_codec = nullptr;
|
||||
}
|
||||
|
||||
Debug(1, "Success");
|
||||
AVDictionaryEntry *e = nullptr;
|
||||
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr ) {
|
||||
while ((e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr) {
|
||||
Warning("Encoder Option %s not recognized by ffmpeg codec", e->key);
|
||||
}
|
||||
//av_dict_free(&opts);
|
||||
if ( video_out_codec ) break;
|
||||
if (video_out_codec) break;
|
||||
avcodec_free_context(&video_out_ctx);
|
||||
} // end foreach codec
|
||||
if (hw_device_ctx) av_buffer_unref(&hw_device_ctx);
|
||||
} // end foreach codec
|
||||
|
||||
if ( !video_out_codec ) {
|
||||
if (!video_out_codec) {
|
||||
Error("Can't open video codec!");
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||
// We allocate and copy in newer ffmpeg, so need to free it
|
||||
avcodec_free_context(&video_out_ctx);
|
||||
#endif
|
||||
//video_out_ctx = nullptr;
|
||||
|
||||
return false;
|
||||
} // end if can't open codec
|
||||
} // end if can't open codec
|
||||
Debug(2, "Success opening codec");
|
||||
} // end if copying or transcoding
|
||||
} // end if copying or transcoding
|
||||
zm_dump_codec(video_out_ctx);
|
||||
} // end if video_in_stream
|
||||
|
||||
|
@ -958,18 +1017,22 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
frame_count += 1;
|
||||
|
||||
// if we have to transcode
|
||||
if ( monitor->GetOptVideoWriter() == Monitor::ENCODE ) {
|
||||
if (monitor->GetOptVideoWriter() == Monitor::ENCODE) {
|
||||
Debug(3, "Have encoding video frame count (%d)", frame_count);
|
||||
|
||||
if ( !zm_packet->out_frame ) {
|
||||
Debug(3, "Have no out frame");
|
||||
AVFrame *out_frame = zm_packet->get_out_frame(video_out_ctx);
|
||||
if ( !out_frame ) {
|
||||
if (!zm_packet->out_frame) {
|
||||
Debug(3, "Have no out frame. codec is %s sw_pf %d %s hw_pf %d %s",
|
||||
chosen_codec_data->codec_name,
|
||||
chosen_codec_data->sw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->sw_pix_fmt),
|
||||
chosen_codec_data->hw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->hw_pix_fmt)
|
||||
);
|
||||
AVFrame *out_frame = zm_packet->get_out_frame(video_out_ctx->width, video_out_ctx->height, chosen_codec_data->sw_pix_fmt);
|
||||
if (!out_frame) {
|
||||
Error("Unable to allocate a frame");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( zm_packet->image ) {
|
||||
if (zm_packet->image) {
|
||||
Debug(2, "Have an image, convert it");
|
||||
//Go straight to out frame
|
||||
swscale.Convert(
|
||||
|
@ -977,7 +1040,7 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
zm_packet->buffer,
|
||||
zm_packet->codec_imgsize,
|
||||
zm_packet->image->AVPixFormat(),
|
||||
video_out_ctx->pix_fmt,
|
||||
chosen_codec_data->sw_pix_fmt,
|
||||
video_out_ctx->width,
|
||||
video_out_ctx->height
|
||||
);
|
||||
|
@ -1003,6 +1066,34 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
} // end if no in_frame
|
||||
} // end if no out_frame
|
||||
|
||||
AVFrame *frame = zm_packet->out_frame;
|
||||
|
||||
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
||||
if (video_out_ctx->hw_frames_ctx) {
|
||||
if (!(hw_frame = av_frame_alloc())) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
return ret;
|
||||
}
|
||||
if ((ret = av_hwframe_get_buffer(video_out_ctx->hw_frames_ctx, hw_frame, 0)) < 0) {
|
||||
Error("Error code: %s", av_err2str(ret));
|
||||
av_frame_free(&hw_frame);
|
||||
return ret;
|
||||
}
|
||||
if (!hw_frame->hw_frames_ctx) {
|
||||
Error("Outof ram!");
|
||||
av_frame_free(&hw_frame);
|
||||
return 0;
|
||||
}
|
||||
if ((ret = av_hwframe_transfer_data(hw_frame, zm_packet->out_frame, 0)) < 0) {
|
||||
Error("Error while transferring frame data to surface: %s.", av_err2str(ret));
|
||||
av_frame_free(&hw_frame);
|
||||
return ret;
|
||||
}
|
||||
|
||||
frame = hw_frame;
|
||||
} // end if hwaccel
|
||||
#endif
|
||||
|
||||
//zm_packet->out_frame->coded_picture_number = frame_count;
|
||||
//zm_packet->out_frame->display_picture_number = frame_count;
|
||||
//zm_packet->out_frame->sample_aspect_ratio = (AVRational){ 0, 1 };
|
||||
|
@ -1010,7 +1101,7 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
//zm_packet->out_frame->pict_type = AV_PICTURE_TYPE_NONE;
|
||||
//zm_packet->out_frame->key_frame = zm_packet->keyframe;
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||
zm_packet->out_frame->pkt_duration = 0;
|
||||
frame->pkt_duration = 0;
|
||||
#endif
|
||||
|
||||
int64_t in_pts = zm_packet->timestamp->tv_sec * (uint64_t)1000000 + zm_packet->timestamp->tv_usec;
|
||||
|
@ -1020,14 +1111,14 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
video_first_pts,
|
||||
static_cast<int64>(zm_packet->timestamp->tv_sec),
|
||||
static_cast<int64>(zm_packet->timestamp->tv_usec));
|
||||
zm_packet->out_frame->pts = 0;
|
||||
frame->pts = 0;
|
||||
} else {
|
||||
uint64_t useconds = in_pts - video_first_pts;
|
||||
zm_packet->out_frame->pts = av_rescale_q(useconds, AV_TIME_BASE_Q, video_out_ctx->time_base);
|
||||
frame->pts = av_rescale_q(useconds, AV_TIME_BASE_Q, video_out_ctx->time_base);
|
||||
Debug(2,
|
||||
"Setting pts for frame(%d) to (%" PRId64 ") from (start %" PRIu64 " - %" PRIu64 " - secs(%" PRIi64 ") usecs(%" PRIi64 ") @ %d/%d",
|
||||
frame_count,
|
||||
zm_packet->out_frame->pts,
|
||||
frame->pts,
|
||||
video_first_pts,
|
||||
useconds,
|
||||
static_cast<int64>(zm_packet->timestamp->tv_sec),
|
||||
|
@ -1040,9 +1131,9 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
opkt.data = nullptr;
|
||||
opkt.size = 0;
|
||||
|
||||
ret = zm_send_frame_receive_packet(video_out_ctx, zm_packet->out_frame, opkt);
|
||||
if ( ret <= 0 ) {
|
||||
if ( ret < 0 ) {
|
||||
ret = zm_send_frame_receive_packet(video_out_ctx, frame, opkt);
|
||||
if (ret <= 0) {
|
||||
if (ret < 0) {
|
||||
Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str());
|
||||
}
|
||||
return ret;
|
||||
|
@ -1132,6 +1223,7 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) {
|
|||
|
||||
write_packet(&opkt, video_out_stream);
|
||||
zm_av_packet_unref(&opkt);
|
||||
if (hw_frame) av_frame_free(&hw_frame);
|
||||
|
||||
return 1;
|
||||
} // end int VideoStore::writeVideoFramePacket( AVPacket *ipkt )
|
||||
|
|
|
@ -15,6 +15,9 @@ extern "C" {
|
|||
#endif
|
||||
#endif
|
||||
#include "libavutil/audio_fifo.h"
|
||||
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
||||
#include "libavutil/hwcontext.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HAVE_LIBAVCODEC
|
||||
|
@ -30,89 +33,97 @@ class VideoStore {
|
|||
const AVCodecID codec_id;
|
||||
const char *codec_codec;
|
||||
const char *codec_name;
|
||||
const enum AVPixelFormat pix_fmt;
|
||||
const enum AVPixelFormat sw_pix_fmt;
|
||||
const enum AVPixelFormat hw_pix_fmt;
|
||||
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
||||
const AVHWDeviceType hwdevice_type;
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct CodecData codec_data[];
|
||||
CodecData *chosen_codec_data;
|
||||
|
||||
Monitor *monitor;
|
||||
AVOutputFormat *out_format;
|
||||
AVFormatContext *oc;
|
||||
AVStream *video_out_stream;
|
||||
AVStream *audio_out_stream;
|
||||
Monitor *monitor;
|
||||
AVOutputFormat *out_format;
|
||||
AVFormatContext *oc;
|
||||
AVStream *video_out_stream;
|
||||
AVStream *audio_out_stream;
|
||||
|
||||
AVCodec *video_out_codec;
|
||||
AVCodecContext *video_in_ctx;
|
||||
AVCodecContext *video_out_ctx;
|
||||
AVCodec *video_out_codec;
|
||||
AVCodecContext *video_in_ctx;
|
||||
AVCodecContext *video_out_ctx;
|
||||
|
||||
AVStream *video_in_stream;
|
||||
AVStream *audio_in_stream;
|
||||
AVStream *video_in_stream;
|
||||
AVStream *audio_in_stream;
|
||||
|
||||
const AVCodec *audio_in_codec;
|
||||
AVCodecContext *audio_in_ctx;
|
||||
// The following are used when encoding the audio stream to AAC
|
||||
AVCodec *audio_out_codec;
|
||||
AVCodecContext *audio_out_ctx;
|
||||
// Move this into the object so that we aren't constantly allocating/deallocating it on the stack
|
||||
AVPacket opkt;
|
||||
// we are transcoding
|
||||
AVFrame *video_in_frame;
|
||||
AVFrame *in_frame;
|
||||
AVFrame *out_frame;
|
||||
const AVCodec *audio_in_codec;
|
||||
AVCodecContext *audio_in_ctx;
|
||||
// The following are used when encoding the audio stream to AAC
|
||||
AVCodec *audio_out_codec;
|
||||
AVCodecContext *audio_out_ctx;
|
||||
// Move this into the object so that we aren't constantly allocating/deallocating it on the stack
|
||||
AVPacket opkt;
|
||||
// we are transcoding
|
||||
AVFrame *video_in_frame;
|
||||
AVFrame *in_frame;
|
||||
AVFrame *out_frame;
|
||||
AVFrame *hw_frame;
|
||||
|
||||
SWScale swscale;
|
||||
unsigned int packets_written;
|
||||
unsigned int frame_count;
|
||||
SWScale swscale;
|
||||
unsigned int packets_written;
|
||||
unsigned int frame_count;
|
||||
|
||||
AVBufferRef *hw_device_ctx;
|
||||
|
||||
#ifdef HAVE_LIBSWRESAMPLE
|
||||
SwrContext *resample_ctx;
|
||||
AVAudioFifo *fifo;
|
||||
SwrContext *resample_ctx;
|
||||
AVAudioFifo *fifo;
|
||||
#else
|
||||
#ifdef HAVE_LIBAVRESAMPLE
|
||||
AVAudioResampleContext* resample_ctx;
|
||||
AVAudioResampleContext* resample_ctx;
|
||||
#endif
|
||||
#endif
|
||||
uint8_t *converted_in_samples;
|
||||
|
||||
const char *filename;
|
||||
const char *format;
|
||||
|
||||
// These are for in
|
||||
int64_t video_first_pts;
|
||||
int64_t video_first_dts;
|
||||
int64_t audio_first_pts;
|
||||
int64_t audio_first_dts;
|
||||
int64_t video_last_pts;
|
||||
int64_t audio_last_pts;
|
||||
uint8_t *converted_in_samples;
|
||||
|
||||
// These are for out, should start at zero. We assume they do not wrap because we just aren't going to save files that big.
|
||||
int64_t *next_dts;
|
||||
int64_t audio_next_pts;
|
||||
const char *filename;
|
||||
const char *format;
|
||||
|
||||
int max_stream_index;
|
||||
// These are for in
|
||||
int64_t video_first_pts;
|
||||
int64_t video_first_dts;
|
||||
int64_t audio_first_pts;
|
||||
int64_t audio_first_dts;
|
||||
int64_t video_last_pts;
|
||||
int64_t audio_last_pts;
|
||||
|
||||
bool setup_resampler();
|
||||
int write_packet(AVPacket *pkt, AVStream *stream);
|
||||
// These are for out, should start at zero. We assume they do not wrap because we just aren't going to save files that big.
|
||||
int64_t *next_dts;
|
||||
int64_t audio_next_pts;
|
||||
|
||||
public:
|
||||
VideoStore(
|
||||
const char *filename_in,
|
||||
const char *format_in,
|
||||
AVStream *video_in_stream,
|
||||
AVCodecContext *video_in_ctx,
|
||||
AVStream *audio_in_stream,
|
||||
AVCodecContext *audio_in_ctx,
|
||||
Monitor * p_monitor);
|
||||
~VideoStore();
|
||||
bool open();
|
||||
int max_stream_index;
|
||||
|
||||
void write_video_packet(AVPacket &pkt);
|
||||
void write_audio_packet(AVPacket &pkt);
|
||||
int writeVideoFramePacket(ZMPacket *pkt);
|
||||
int writeAudioFramePacket(ZMPacket *pkt);
|
||||
int writePacket(ZMPacket *pkt);
|
||||
int write_packets(PacketQueue &queue);
|
||||
void flush_codecs();
|
||||
bool setup_resampler();
|
||||
int write_packet(AVPacket *pkt, AVStream *stream);
|
||||
|
||||
public:
|
||||
VideoStore(
|
||||
const char *filename_in,
|
||||
const char *format_in,
|
||||
AVStream *video_in_stream,
|
||||
AVCodecContext *video_in_ctx,
|
||||
AVStream *audio_in_stream,
|
||||
AVCodecContext *audio_in_ctx,
|
||||
Monitor * p_monitor);
|
||||
~VideoStore();
|
||||
bool open();
|
||||
|
||||
void write_video_packet(AVPacket &pkt);
|
||||
void write_audio_packet(AVPacket &pkt);
|
||||
int writeVideoFramePacket(ZMPacket *pkt);
|
||||
int writeAudioFramePacket(ZMPacket *pkt);
|
||||
int writePacket(ZMPacket *pkt);
|
||||
int write_packets(PacketQueue &queue);
|
||||
void flush_codecs();
|
||||
};
|
||||
|
||||
#endif //havelibav
|
||||
|
|
|
@ -382,6 +382,7 @@ int main(int argc, char *argv[]) {
|
|||
Image::Deinitialise();
|
||||
Debug(1, "terminating");
|
||||
logTerm();
|
||||
dbQueue.stop();
|
||||
zmDbClose();
|
||||
|
||||
return zm_terminate ? 0 : result;
|
||||
|
|
|
@ -342,6 +342,7 @@ int main(int argc, const char *argv[], char **envp) {
|
|||
Debug(1, "Terminating");
|
||||
Image::Deinitialise();
|
||||
logTerm();
|
||||
dbQueue.stop();
|
||||
zmDbClose();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -178,6 +178,7 @@ $SLANG = array(
|
|||
'BadColours' => 'Target colour must be set to a valid value',
|
||||
'BadPassthrough' => 'Passthrough only works with ffmpeg type monitors.',
|
||||
'BadPath' => 'Path must be set to a valid value',
|
||||
'BadPathNotEncoded' => 'Path must be set to a valid value. We have detected invalid characters !*\'()$ ,#[] that may need to be url percent encoded.',
|
||||
'BadPort' => 'Port must be set to a valid number',
|
||||
'BadPostEventCount' => 'Post event image count must be an integer of zero or more',
|
||||
'BadPreEventCount' => 'Pre event image count must be at least zero, and less than image buffer size',
|
||||
|
|
|
@ -51,3 +51,6 @@ select.chosen {
|
|||
tr td:first-child {
|
||||
min-width: 300px;
|
||||
}
|
||||
.OutputContainer {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -718,7 +718,7 @@ function getMontageReviewHTML($view) {
|
|||
function getSnapshotsHTML($view) {
|
||||
$result = '';
|
||||
|
||||
if ( canView('Snapshots') ) {
|
||||
if (defined('ZM_FEATURES_SNAPSHOTS') and ZM_FEATURES_SNAPSHOTS and canView('Snapshots')) {
|
||||
$class = $view == 'snapshots' ? ' selected' : '';
|
||||
$result .= '<li id="getSnapshotsHTML" class="nav-item dropdown"><a class="nav-link'.$class.'" href="?view=snapshots">' .translate('Snapshots'). '</a></li>'.PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,9 @@ function updateMonitorDimensions(element) {
|
|||
form.elements['newMonitor[Height]'].value = dimensions[1];
|
||||
}
|
||||
}
|
||||
update_estimated_ram_use();
|
||||
return false;
|
||||
}
|
||||
} // function updateMonitorDimensions(element)
|
||||
|
||||
function loadLocations( element ) {
|
||||
var form = element.form;
|
||||
|
@ -139,6 +140,10 @@ function initPage() {
|
|||
form.submit();
|
||||
};
|
||||
});
|
||||
document.querySelectorAll('input[name="newMonitor[ImageBufferCount]"],input[name="newMonitor[MaxImageBufferCount]"],input[name="newMonitor[Width]"],input[name="newMonitor[Height]"]').forEach(function(el) {
|
||||
el.oninput = window['update_estimated_ram_use'].bind(el);
|
||||
});
|
||||
update_estimated_ram_use();
|
||||
|
||||
document.querySelectorAll('select[name="newMonitor[Function]"]').forEach(function(el) {
|
||||
el.onchange = function() {
|
||||
|
@ -158,6 +163,47 @@ function initPage() {
|
|||
el.onchange();
|
||||
});
|
||||
|
||||
document.querySelectorAll('select[name="newMonitor[VideoWriter]"]').forEach(function(el) {
|
||||
el.onchange = function() {
|
||||
if ( this.value == 1 /* Encode */ ) {
|
||||
$j('.OutputCodec').show();
|
||||
$j('.Encoder').show();
|
||||
} else {
|
||||
$j('.OutputCodec').hide();
|
||||
$j('.Encoder').hide();
|
||||
}
|
||||
};
|
||||
el.onchange();
|
||||
});
|
||||
document.querySelectorAll('select[name="newMonitor[OutputCodec]"]').forEach(function(el) {
|
||||
el.onchange = function() {
|
||||
var encoder_dropdown = $j('select[name="newMonitor[Encoder]"]');
|
||||
if (encoder_dropdown) {
|
||||
for (i=0; i<encoder_dropdown[0].options.length; i++) {
|
||||
option = encoder_dropdown[0].options[i];
|
||||
if ( this.value == 27 ) {
|
||||
option.disabled = !option.value.includes('264');
|
||||
if ( option.disabled && option.selected ) {
|
||||
encoder_dropdown[0].options[0].selected = 1;
|
||||
option.selected = false;
|
||||
}
|
||||
} else if ( this.value == 173 /* hevc */ ) {
|
||||
option.disabled = !(option.value.includes('hevc') || option.value.includes('265') );
|
||||
if ( option.disabled && option.selected ) {
|
||||
encoder_dropdown[0].options[0].selected = 1;
|
||||
option.selected = false;
|
||||
}
|
||||
} else {
|
||||
option.disabled = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('No encoder');
|
||||
}
|
||||
};
|
||||
el.onchange();
|
||||
});
|
||||
|
||||
$j('.chosen').chosen();
|
||||
|
||||
// Don't enable the back button if there is no previous zm page to go back to
|
||||
|
@ -265,6 +311,25 @@ function random_WebColour() {
|
|||
);
|
||||
}
|
||||
|
||||
function update_estimated_ram_use() {
|
||||
var width = document.querySelectorAll('input[name="newMonitor[Width]"]')[0].value;
|
||||
var height = document.querySelectorAll('input[name="newMonitor[Height]"]')[0].value;
|
||||
var colours = document.querySelectorAll('select[name="newMonitor[Colours]"]')[0].value;
|
||||
|
||||
var min_buffer_count = parseInt(document.querySelectorAll('input[name="newMonitor[ImageBufferCount]"]')[0].value);
|
||||
var min_buffer_size = min_buffer_count * width * height * colours;
|
||||
document.getElementById('estimated_ram_use').innerHTML = 'Min: ' + human_filesize(min_buffer_size);
|
||||
|
||||
var max_buffer_count = parseInt(document.querySelectorAll('input[name="newMonitor[MaxImageBufferCount]"]')[0].value);
|
||||
if (max_buffer_count) {
|
||||
var max_buffer_size = (min_buffer_count + max_buffer_count) * width * height * colours;
|
||||
console.log(max_buffer_size);
|
||||
document.getElementById('estimated_ram_use').innerHTML += ' Max: ' + human_filesize(max_buffer_size);
|
||||
} else {
|
||||
document.getElementById('estimated_ram_use').innerHTML += ' Max: Unlimited';
|
||||
}
|
||||
}
|
||||
|
||||
function updateLatitudeAndLongitude(latitude, longitude) {
|
||||
var form = document.getElementById('contentForm');
|
||||
form.elements['newMonitor[Latitude]'].value = latitude;
|
||||
|
|
|
@ -72,9 +72,11 @@ function validateForm( form ) {
|
|||
if ( form.elements['newMonitor[VideoWriter]'].value == 2 /* Passthrough */ )
|
||||
errors[errors.length] = "<?php echo translate('BadPassthrough') ?>";
|
||||
} else if ( form.elements['newMonitor[Type]'].value == 'Ffmpeg' ) {
|
||||
if ( !form.elements['newMonitor[Path]'].value )
|
||||
//|| !form.elements['newMonitor[Path]'].value.match( /^\d+$/ ) ) // valid url
|
||||
if ( !form.elements['newMonitor[Path]'].value ) {
|
||||
errors[errors.length] = "<?php echo translate('BadPath') ?>";
|
||||
} else if ( form.elements['newMonitor[Path]'].value.match( /[\!\*'\(\)\$ ,#\[\]]/) ) {
|
||||
warnings[warnings.length] = "<?php echo translate('BadPathNotEncoded') ?>";
|
||||
}
|
||||
|
||||
} else if ( form.elements['newMonitor[Type]'].value == 'File' ) {
|
||||
if ( !form.elements['newMonitor[Path]'].value )
|
||||
|
@ -91,7 +93,7 @@ function validateForm( form ) {
|
|||
if (form.elements['newMonitor[VideoWriter]'].value == '1' /* Encode */) {
|
||||
var parameters = form.elements['newMonitor[EncoderParameters]'].value.replace(/[^#a-zA-Z]/g, "");
|
||||
if (parameters == '' || parameters == '#Linesbeginningwith#areacomment#Forchangingqualityusethecrfoption#isbestisworstquality#crf' ) {
|
||||
errors[errors.length] = '<?php echo translate('BadEncoderParameters') ?>';
|
||||
warnings[warnings.length] = '<?php echo translate('BadEncoderParameters') ?>';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -972,7 +972,7 @@ include('_monitor_source_nvsocket.php');
|
|||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="OutputCodec">
|
||||
<td><?php echo translate('OutputCodec') ?></td>
|
||||
<td>
|
||||
<?php
|
||||
|
@ -980,30 +980,28 @@ $videowriter_codecs = array(
|
|||
'0' => translate('Auto'),
|
||||
'27' => 'h264',
|
||||
'173' => 'h265/hevc',
|
||||
'8' => 'mjpeg',
|
||||
'1' => 'mpeg1',
|
||||
'2' => 'mpeg2',
|
||||
);
|
||||
echo htmlSelect('newMonitor[OutputCodec]', $videowriter_codecs, $monitor->OutputCodec());
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr class="Encoder">
|
||||
<td><?php echo translate('Encoder') ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$videowriter_encoders = array(
|
||||
'auto' => translate('Auto'),
|
||||
'h264_omx' => 'h264_omx',
|
||||
'libx264' => 'libx264',
|
||||
'h264_vaapi' => 'h264_vaapi',
|
||||
'h264' => 'h264',
|
||||
'mjpeg' => 'mjpeg',
|
||||
'mpeg1' => 'mpeg1',
|
||||
'mpeg2' => 'mpeg2',
|
||||
'h264_nvenc' => 'h264_nvenc',
|
||||
'h264_omx' => 'h264_omx',
|
||||
'h264_vaapi' => 'h264_vaapi',
|
||||
'libx265' => 'libx265',
|
||||
'hevc_nvenc' => 'hevc_nvenc',
|
||||
'hevc_vaapi' => 'hevc_vaapi',
|
||||
);
|
||||
echo htmlSelect('newMonitor[Encoder]', $videowriter_encoders, $monitor->Encoder());?></td></tr>
|
||||
<tr>
|
||||
<tr class="OutputContainer">
|
||||
<td><?php echo translate('OutputContainer') ?></td>
|
||||
<td>
|
||||
<?php
|
||||
|
@ -1086,6 +1084,10 @@ echo htmlSelect('newMonitor[OutputContainer]', $videowriter_containers, $monitor
|
|||
<td class="text-right pr-3"><?php echo translate('AlarmFrameCount') ?></td>
|
||||
<td><input type="number" name="newMonitor[AlarmFrameCount]" value="<?php echo validHtmlStr($monitor->AlarmFrameCount()) ?>" min="1"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-right pr-3"><?php echo translate('Estimated Ram Use') ?></td>
|
||||
<td id="estimated_ram_use"></td>
|
||||
</tr>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -200,10 +200,12 @@ if ( canView('System') ) {
|
|||
<button type="button" value="Cancel" data-on-click-this="cancel_layout"><?php echo translate('Cancel') ?></button>
|
||||
</span>
|
||||
|
||||
<?php if (defined('ZM_FEATURES_SNAPSHOTS') and ZM_FEATURES_SNAPSHOTS) { ?>
|
||||
<button type="button" name="snapshotBtn" data-on-click-this="takeSnapshot">
|
||||
<i class="material-icons md-18">camera_enhance</i>
|
||||
<?php echo translate('Snapshot') ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canView('Snapshots') ) {
|
||||
if (!canView('Snapshots')) {
|
||||
$view = 'error';
|
||||
return;
|
||||
} else if (!ZM_FEATURES_SNAPSHOTS) {
|
||||
$view = 'console';
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('includes/Event.php');
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
if (!canView('Snapshots')) {
|
||||
$view = 'error';
|
||||
return;
|
||||
} else if (!ZM_FEATURES_SNAPSHOTS) {
|
||||
$view = 'console';
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('includes/Event.php');
|
||||
|
|
Loading…
Reference in New Issue