Skip to content

Commit 7bf2fb8

Browse files
Convert OutputCodec from int to varchar OutputCodecName. ffmpeg has different values for codec_id for different versions of ffmpeg. So just use the codec name instead.
1 parent c191f43 commit 7bf2fb8

File tree

9 files changed

+42
-35
lines changed

9 files changed

+42
-35
lines changed

db/zm_create.sql.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ CREATE TABLE `Monitors` (
559559
`DecoderHWAccelDevice` varchar(255),
560560
`SaveJPEGs` TINYINT NOT NULL DEFAULT '3' ,
561561
`VideoWriter` TINYINT NOT NULL DEFAULT '0',
562-
`OutputCodec` int(10) unsigned NOT NULL default 0,
562+
`OutputCodecName` varchar(32) NOT NULL default 'auto',
563563
`Encoder` varchar(32),
564564
`EncoderHWAccelName` varchar(64),
565565
`EncoderHWAccelDevice` varchar(255),

db/zm_update-1.37.70.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Change OutputCodec from int to varchar(32) */
2+
SELECT 'Checking for OutputCodecName in Monitors';
3+
SET @s = (SELECT IF(
4+
(SELECT COUNT(*)
5+
FROM INFORMATION_SCHEMA.COLUMNS
6+
WHERE table_name = 'Monitors'
7+
AND table_schema = DATABASE()
8+
AND column_name = 'OutputCodecName'
9+
) > 0,
10+
"SELECT 'Column OutputCodecName already exists in Monitors'",
11+
"ALTER TABLE `Monitors` ADD COLUMN `OutputCodecName` varchar(32) NOT NULL default '' AFTER `VideoWriter`"
12+
));
13+
PREPARE stmt FROM @s;
14+
EXECUTE stmt;
15+
16+
UPDATE Monitors SET OutputCodecName='auto' where OutputCodec=0 AND OutputCodecName='';
17+
UPDATE Monitors SET OutputCodecName='h264' where OutputCodec=27 AND OutputCodecName='';
18+
UPDATE Monitors SET OutputCodecName='hevc' where OutputCodec=173 AND OutputCodecName='';
19+
UPDATE Monitors SET OutputCodecName='vp9' where OutputCodec=167 AND OutputCodecName='';
20+
UPDATE Monitors SET OutputCodecName='av1' where OutputCodec=225 or OutputCodec=226 AND OutputCodecName='';
21+

distros/redhat/zoneminder.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
%global zmtargetdistro %{?rhel:el%{rhel}}%{!?rhel:fc%{fedora}}
1919

2020
Name: zoneminder
21-
Version: 1.37.69
21+
Version: 1.37.70
2222
Release: 1%{?dist}
2323
Summary: A camera monitoring and analysis tool
2424
Group: System Environment/Daemons

src/zm_monitor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::string load_monitor_sql =
9494
"`Deinterlacing`, "
9595
"`Decoder`, `DecoderHWAccelName`, `DecoderHWAccelDevice`, `RTSPDescribe`, "
9696
"`SaveJPEGs`, `VideoWriter`, `EncoderParameters`, "
97-
"`OutputCodec`, `Encoder`, `EncoderHWAccelName`, `EncoderHWAccelDevice`, `OutputContainer`, "
97+
"`OutputCodecName`, `Encoder`, `EncoderHWAccelName`, `EncoderHWAccelDevice`, `OutputContainer`, "
9898
"`RecordAudio`, WallClockTimestamps,"
9999
"`Brightness`, `Contrast`, `Hue`, `Colour`, "
100100
"`EventPrefix`, `LabelFormat`, `LabelX`, `LabelY`, `LabelSize`,"
@@ -359,7 +359,7 @@ Monitor::Monitor() :
359359
"Device, Channel, Format, V4LMultiBuffer, V4LCapturesPerFrame, " // V4L Settings
360360
"Protocol, Method, Options, User, Pass, Host, Port, Path, SecondPath, Width, Height, Colours, Palette, Orientation+0, Deinterlacing, RTSPDescribe, "
361361
"SaveJPEGs, VideoWriter, EncoderParameters,"
362-
"OutputCodec, Encoder, OutputContainer, RecordAudio, WallClockTimestamps,"
362+
"OutputCodecName, Encoder, OutputContainer, RecordAudio, WallClockTimestamps,"
363363
"Brightness, Contrast, Hue, Colour, "
364364
"EventPrefix, LabelFormat, LabelX, LabelY, LabelSize,"
365365
"ImageBufferCount, `MaxImageBufferCount`, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, "
@@ -550,8 +550,8 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
550550

551551
Debug(3, "Decoding: %d savejpegs %d videowriter %d", decoding, savejpegs, videowriter);
552552

553-
/*"`OutputCodec`, `Encoder`, `OutputContainer`, " */
554-
output_codec = dbrow[col] ? atoi(dbrow[col]) : 0;
553+
/*"`OutputCodecName`, `Encoder`, `OutputContainer`, " */
554+
output_codec = dbrow[col] ? dbrow[col] : "auto";
555555
col++;
556556
encoder = dbrow[col] ? dbrow[col] : "";
557557
col++;

src/zm_monitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
537537
int colours;
538538
VideoWriter videowriter;
539539
std::string encoderparams;
540-
int output_codec;
540+
std::string output_codec;
541541
std::string encoder;
542542
std::string encoder_hwaccel_name;
543543
std::string encoder_hwaccel_device;
@@ -847,7 +847,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
847847
const std::string &GetEncoderOptions() const { return encoderparams; }
848848
const std::string &EncoderHWAccelName() const { return encoder_hwaccel_name; }
849849
const std::string &EncoderHWAccelDevice() const { return encoder_hwaccel_device; }
850-
int OutputCodec() const { return output_codec; }
850+
const std::string &OutputCodec() const { return output_codec; }
851851
const std::string &Encoder() const { return encoder; }
852852
const std::string &OutputContainer() const { return output_container; }
853853

src/zm_videostore.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,9 @@ bool VideoStore::open() {
298298
}
299299
} // end if extradata_entry
300300
} else if (monitor->GetOptVideoWriter() == Monitor::ENCODE) {
301-
int wanted_codec = monitor->OutputCodec();
302-
if (!wanted_codec) {
303-
// default to h264
304-
//Debug(2, "Defaulting to H264");
305-
//wanted_codec = AV_CODEC_ID_H264;
306-
// FIXME what is the optimal codec? Probably low latency h264 which is effectively mjpeg
307-
} else {
308-
if (AV_CODEC_ID_H264 != 27 and wanted_codec > 3) {
309-
// Older ffmpeg had AV_CODEC_ID_MPEG2VIDEO_XVMC at position 3 has been deprecated
310-
wanted_codec += 1;
311-
}
312-
Debug(2, "Codec wanted %d %s", wanted_codec, avcodec_get_name((AVCodecID)wanted_codec));
301+
std::string wanted_codec = monitor->OutputCodec();
302+
if (wanted_codec.empty() or wanted_codec == "auto") {
303+
Debug(2, "Codec wanted %s", wanted_codec.c_str());
313304
}
314305
std::string wanted_encoder = monitor->Encoder();
315306

@@ -321,13 +312,8 @@ bool VideoStore::open() {
321312
continue;
322313
}
323314
}
324-
if (wanted_codec and (codec_data[i].codec_id != wanted_codec)) {
325-
Debug(1, "Not the right codec %d %s != %d %s",
326-
codec_data[i].codec_id,
327-
avcodec_get_name(codec_data[i].codec_id),
328-
wanted_codec,
329-
avcodec_get_name((AVCodecID)wanted_codec)
330-
);
315+
if ((!wanted_codec.empty() and wanted_codec != "auto") and (codec_data[i].codec_codec != wanted_codec)) {
316+
Debug(1, "Not the right codec %s != %s", codec_data[i].codec_codec, wanted_codec.c_str());
331317
continue;
332318
}
333319

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.37.69
1+
1.37.70

web/includes/Monitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public static function getRTSP2WebStreamOptions() {
275275
'DecoderHWAccelDevice' => null,
276276
'SaveJPEGs' => 0,
277277
'VideoWriter' => '2',
278-
'OutputCodec' => '0',
278+
'OutputCodecName' => 'auto',
279279
'Encoder' => 'auto',
280280
'OutputContainer' => null,
281281
'EncoderParameters' => '',

web/skins/classic/views/monitor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,13 +1145,13 @@ class="nav-link<?php echo ($tab == $name ? ' active' : '') . ' ' . (($name == 'z
11451145
<label><?php echo translate('OutputCodec') ?></label>
11461146
<?php
11471147
$videowriter_codecs = array(
1148-
'0' => translate('Auto'),
1149-
'27' => 'h264',
1150-
'173' => 'h265/hevc',
1151-
'167' => 'vp9',
1152-
'226' => 'av1',
1148+
'auto' => translate('Auto'),
1149+
'h264' => 'h264',
1150+
'hevc' => 'h265/hevc',
1151+
'vp9' => 'vp9',
1152+
'av1' => 'av1',
11531153
);
1154-
echo htmlSelect('newMonitor[OutputCodec]', $videowriter_codecs, $monitor->OutputCodec());
1154+
echo htmlSelect('newMonitor[OutputCodecName]', $videowriter_codecs, $monitor->OutputCodecName());
11551155
?>
11561156
</li>
11571157
<li class="Encoder">

0 commit comments

Comments
 (0)