Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if the stream contains mjpeg as codec_name, then treat media as audio #91

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions MediaProcessor/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> output = Utils::runCommand(command, true);
if (!output || output->empty()) {
Expand All @@ -76,7 +77,8 @@ MediaType Engine::getMediaType() const {

std::string_view result = *output;
if (result.find("video") != std::string_view::npos) {
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 {
Expand Down
Loading