From 8fd08bd36ec879b9767b284170697901f87c7c80 Mon Sep 17 00:00:00 2001 From: Rushi Gandhi Date: Tue, 24 Dec 2024 00:27:36 +0530 Subject: [PATCH 1/3] check if the stream contains mjpeg as codec_name, then treat media as audio --- MediaProcessor/src/Engine.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MediaProcessor/src/Engine.cpp b/MediaProcessor/src/Engine.cpp index 68ed419..ad72708 100644 --- a/MediaProcessor/src/Engine.cpp +++ b/MediaProcessor/src/Engine.cpp @@ -76,6 +76,22 @@ MediaType Engine::getMediaType() const { std::string_view result = *output; if (result.find("video") != std::string_view::npos) { + // Check if the video is real video stream, not static image which is treated as video + const std::string command = + "ffprobe -v error -show_entries stream=code7c_name " + "-of default=noprint_wrappers=1:nokey=1 \"" + + m_mediaPath.string() + "\""; + + std::optional output = Utils::runCommand(command, true); + if (!output || output->empty()) { + throw std::runtime_error("Failed to detect codec name."); + } + + std::string_view result = *output; + if (result.find("mjpeg") != std::string_view::npos) { + return MediaType::Audio; + } + return MediaType::Video; } else if (result.find("audio") != std::string_view::npos) { return MediaType::Audio; From 2408253ff15796b1ce88bfb9fcb38b84856c9bf0 Mon Sep 17 00:00:00 2001 From: Rushi Gandhi Date: Tue, 24 Dec 2024 00:39:29 +0530 Subject: [PATCH 2/3] fix typo in codec_name --- MediaProcessor/src/Engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaProcessor/src/Engine.cpp b/MediaProcessor/src/Engine.cpp index ad72708..71eae82 100644 --- a/MediaProcessor/src/Engine.cpp +++ b/MediaProcessor/src/Engine.cpp @@ -78,7 +78,7 @@ MediaType Engine::getMediaType() const { if (result.find("video") != std::string_view::npos) { // Check if the video is real video stream, not static image which is treated as video const std::string command = - "ffprobe -v error -show_entries stream=code7c_name " + "ffprobe -v error -show_entries stream=codec_name " "-of default=noprint_wrappers=1:nokey=1 \"" + m_mediaPath.string() + "\""; From 0fcceb5fb7da0df1373fa7ce0ab919ddd8c3f72c Mon Sep 17 00:00:00 2001 From: Rushi Gandhi Date: Tue, 24 Dec 2024 12:48:17 +0530 Subject: [PATCH 3/3] used avg_frame_rate of video stream to detect if it is a static image --- MediaProcessor/src/Engine.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/MediaProcessor/src/Engine.cpp b/MediaProcessor/src/Engine.cpp index 71eae82..cd56b93 100644 --- a/MediaProcessor/src/Engine.cpp +++ b/MediaProcessor/src/Engine.cpp @@ -65,9 +65,10 @@ bool Engine::processVideo() { MediaType Engine::getMediaType() const { const std::string command = - "ffprobe -loglevel error -show_entries stream=codec_type " - "-of default=noprint_wrappers=1:nokey=1 \"" + - m_mediaPath.string() + "\""; + "ffprobe -loglevel error -show_entries stream=codec_type,avg_frame_rate " + "-of default=noprint_wrappers=1:nokey=1 \"" + + m_mediaPath.string() + + "\" | awk 'BEGIN {last=\"\"} /audio/ {print; last=\"audio\"} /video/ {print; last=\"video\"} /^[0-9]+\\/[0-9]+$/ && last==\"video\" {print}'"; std::optional output = Utils::runCommand(command, true); if (!output || output->empty()) { @@ -76,23 +77,8 @@ MediaType Engine::getMediaType() const { std::string_view result = *output; if (result.find("video") != std::string_view::npos) { - // Check if the video is real video stream, not static image which is treated as video - const std::string command = - "ffprobe -v error -show_entries stream=codec_name " - "-of default=noprint_wrappers=1:nokey=1 \"" + - m_mediaPath.string() + "\""; - - std::optional output = Utils::runCommand(command, true); - if (!output || output->empty()) { - throw std::runtime_error("Failed to detect codec name."); - } - - std::string_view result = *output; - if (result.find("mjpeg") != std::string_view::npos) { - return MediaType::Audio; - } - - return MediaType::Video; + // check if the video stream avg_frame_rate is 0/0, which is actually a static image + return (result.find("0/0") != std::string_view::npos) ? MediaType::Audio : MediaType::Video; } else if (result.find("audio") != std::string_view::npos) { return MediaType::Audio; } else {