mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
Merge pull request #5492 from AJ0070/5491-passthrough-codec-tag
fix: drop input codec tags the output muxer rejects when copying video
This commit is contained in:
5 files changed
+54
No files matched your search
@@ -684,6 +684,14 @@ void zm_dump_codecpar(const AVCodecParameters *par) {
|
||||
);
|
||||
}
|
||||
|
||||
void zm_clear_incompatible_codec_tag(const AVOutputFormat *format, AVCodecParameters *par) {
|
||||
unsigned int tag;
|
||||
if (format->codec_tag
|
||||
and av_codec_get_id(format->codec_tag, par->codec_tag) != par->codec_id
|
||||
and av_codec_get_tag2(format->codec_tag, par->codec_id, &tag))
|
||||
par->codec_tag = 0;
|
||||
}
|
||||
|
||||
void zm_dump_codec(const AVCodecContext *codec) {
|
||||
Debug(1, "Dumping codec_context codec_type %d %s codec_id %d %s tag %c%c%c%c width %d height %d timebase %d/%d format %s profile %d level %d "
|
||||
"gop_size %d has_b_frames %d max_b_frames %d me_cmp %d me_range %d qmin %d qmax %d bit_rate %" PRId64 " qcompress %f extradata:%d:%s",
|
||||
|
||||
@@ -150,6 +150,7 @@ void zm_dump_stream(AVStream *st);
|
||||
void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output);
|
||||
void zm_dump_codec(const AVCodecContext *codec);
|
||||
void zm_dump_codecpar(const AVCodecParameters *par);
|
||||
void zm_clear_incompatible_codec_tag(const AVOutputFormat *format, AVCodecParameters *par);
|
||||
|
||||
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
|
||||
#define zm_dump_frame(frame, text) Debug(1, "%s: format %d %s sample_rate %" PRIu32 " nb_samples %d" \
|
||||
|
||||
@@ -175,6 +175,7 @@ bool VideoStore::open() {
|
||||
return false;
|
||||
}
|
||||
avcodec_parameters_copy(video_out_stream->codecpar, video_in_stream->codecpar);
|
||||
zm_clear_incompatible_codec_tag(oc->oformat, video_out_stream->codecpar);
|
||||
zm_dump_codecpar(video_out_stream->codecpar);
|
||||
|
||||
video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
|
||||
@@ -505,6 +506,7 @@ bool VideoStore::open() {
|
||||
return false;
|
||||
}
|
||||
avcodec_parameters_copy(video_out_stream->codecpar, video_in_stream->codecpar);
|
||||
zm_clear_incompatible_codec_tag(oc->oformat, video_out_stream->codecpar);
|
||||
video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
|
||||
zm_dump_codecpar(video_out_stream->codecpar);
|
||||
} else {
|
||||
|
||||
@@ -78,6 +78,7 @@ set(TEST_SOURCES
|
||||
zm_logger_rotate.cpp
|
||||
zm_logger_reload.cpp
|
||||
zm_ffmpeg_camera.cpp
|
||||
zm_ffmpeg_codec_tag.cpp
|
||||
zm_ffmpeg_fallback.cpp)
|
||||
|
||||
add_executable(tests ${TEST_SOURCES})
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "zm_catch2.h"
|
||||
|
||||
#include "zm_ffmpeg.h"
|
||||
|
||||
static unsigned int codec_tag_for(const char *format_name, unsigned int tag) {
|
||||
AVCodecParameters *par = avcodec_parameters_alloc();
|
||||
par->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||
par->codec_id = AV_CODEC_ID_H264;
|
||||
par->codec_tag = tag;
|
||||
const AVOutputFormat *format = av_guess_format(format_name, nullptr, nullptr);
|
||||
REQUIRE(format != nullptr);
|
||||
zm_clear_incompatible_codec_tag(format, par);
|
||||
tag = par->codec_tag;
|
||||
avcodec_parameters_free(&par);
|
||||
return tag;
|
||||
}
|
||||
|
||||
TEST_CASE("zm_clear_incompatible_codec_tag", "[ffmpeg]") {
|
||||
FFMPEGInit();
|
||||
// 0x1b is the mpegts stream type for H.264
|
||||
REQUIRE(codec_tag_for("mp4", 0x1b) == 0);
|
||||
REQUIRE(codec_tag_for("mp4", MKTAG('a', 'v', 'c', '1')) == MKTAG('a', 'v', 'c', '1'));
|
||||
REQUIRE(codec_tag_for("mp4", MKTAG('h', 'e', 'v', '1')) == 0);
|
||||
REQUIRE(codec_tag_for("mpegts", 0x1b) == 0x1b);
|
||||
}
|
||||
Reference in new issue
Block a user