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

Better error & download url if ffmpeg is missing #7991

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 25 additions & 11 deletions crates/store/re_video/src/decode/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ use super::{AsyncDecoder, Chunk, Frame, OutputCallback};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to start ffmppeg: {0}")]
#[error("Couldn't find an installation of the FFmpeg executable.")]
FfmpegNotInstalled {
/// Download URL for the latest version of `FFmpeg` on the current platform.
/// None if the platform is not supported.
// TODO(andreas): as of writing, ffmpeg-sidecar doesn't define a download URL for linux arm.
download_url: Option<&'static str>,
},

#[error("Failed to start FFmpeg: {0}")]
FailedToStartFfmpeg(std::io::Error),

#[error("Failed to get stdin handle")]
Expand All @@ -31,28 +39,28 @@ pub enum Error {
#[error("No frame info received, this is a likely a bug in Rerun")]
NoFrameInfo,

#[error("Failed to write data to ffmpeg: {0}")]
#[error("Failed to write data to FFmpeg: {0}")]
FailedToWriteToFfmpeg(std::io::Error),

#[error("Bad video data: {0}")]
BadVideoData(String),

#[error("FFMPEG error: {0}")]
#[error("FFmpeg error: {0}")]
Ffmpeg(String),

#[error("FFMPEG fatal error: {0}")]
#[error("FFmpeg fatal error: {0}")]
FfmpegFatal(String),

#[error("FFMPEG IPC error: {0}")]
#[error("FFmpeg IPC error: {0}")]
FfmpegSidecar(String),

#[error("FFMPEG exited unexpectedly with code {0:?}")]
#[error("FFmpeg exited unexpectedly with code {0:?}")]
FfmpegUnexpectedExit(Option<std::process::ExitStatus>),

#[error("FFMPEG output a non-image chunk when we expected only images.")]
#[error("FFmpeg output a non-image chunk when we expected only images.")]
UnexpectedFfmpegOutputChunk,

#[error("Failed to send video frame info to the ffmpeg read thread.")]
#[error("Failed to send video frame info to the FFmpeg read thread.")]
BrokenFrameInfoChannel,
}

Expand Down Expand Up @@ -99,6 +107,12 @@ impl FfmpegProcessAndListener {
) -> Result<Self, Error> {
re_tracing::profile_function!();

if !ffmpeg_sidecar::command::ffmpeg_is_installed() {
return Err(Error::FfmpegNotInstalled {
download_url: ffmpeg_sidecar::download::ffmpeg_download_url().ok(),
});
}

let mut ffmpeg = FfmpegCommand::new()
.hide_banner()
// "Reduce the latency introduced by buffering during initial input streams analysis."
Expand Down Expand Up @@ -303,7 +317,7 @@ fn read_ffmpeg_output(
FfmpegEvent::Log(LogLevel::Unknown, msg) => {
if msg.contains("system signals, hard exiting") {
// That was probably us, killing the process.
re_log::debug!("ffmpeg process for {debug_name} was killed");
re_log::debug!("FFmpeg process for {debug_name} was killed");
return;
}
if !should_ignore_log_msg(&msg) {
Expand Down Expand Up @@ -462,12 +476,12 @@ fn read_ffmpeg_output(
}

FfmpegEvent::ParsedVersion(ffmpeg_version) => {
re_log::debug_once!("ffmpeg version is: {}", ffmpeg_version.version);
re_log::debug_once!("FFmpeg version is: {}", ffmpeg_version.version);
}

FfmpegEvent::ParsedConfiguration(ffmpeg_configuration) => {
re_log::debug_once!(
"ffmpeg configuration: {:?}",
"FFmpeg configuration: {:?}",
ffmpeg_configuration.configuration
);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/store/re_video/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ mod webcodecs;

use crate::Time;

pub use ffmpeg::Error as FfmpegError;
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
#[error("Unsupported codec: {0}")]
Expand Down Expand Up @@ -115,7 +117,7 @@ pub enum Error {

#[cfg(with_ffmpeg)]
#[error(transparent)]
Ffmpeg(std::sync::Arc<ffmpeg::Error>),
Ffmpeg(std::sync::Arc<FfmpegError>),

#[error("Unsupported bits per component: {0}")]
BadBitsPerComponent(usize),
Expand Down
12 changes: 12 additions & 0 deletions crates/viewer/re_data_ui/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ pub fn show_video_blob_info(

Err(err) => {
ui.error_label_long(&err.to_string());

if let re_renderer::video::VideoPlayerError::Decoding(
re_video::decode::Error::Ffmpeg(ffmpeg),
) = err
{
if let re_video::decode::FfmpegError::FfmpegNotInstalled {
download_url: Some(url),
} = ffmpeg.as_ref()
{
ui.markdown_ui(&format!("You can download a build of `FFmpeg` [here]({url}). For Rerun to be able to use it, its binaries need to be reachable from `PATH`."));
}
}
}
}
}
Expand Down
Loading