Skip to content

Commit 81ccdd8

Browse files
authored
feat: include stderr along with existing error code when video preview fails (#3383)
1 parent 0b8aaba commit 81ccdd8

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

yazi-plugin/preset/plugins/video.lua

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,35 @@ function M:preload(job)
5252
return false
5353
end
5454

55-
-- stylua: ignore
56-
local cmd = Command("ffmpeg"):arg({
57-
"-v", "quiet", "-threads", 1, "-hwaccel", "auto",
58-
"-skip_frame", "nokey",
59-
"-an", "-sn", "-dn",
60-
})
55+
local cmd = Command("ffmpeg")
56+
:stderr(Command.PIPED)
57+
:arg { "-v", "warning", "-hwaccel", "auto", "-threads", 1, "-an", "-sn", "-dn" }
6158

6259
if percent ~= 0 then
6360
cmd:arg { "-ss", math.floor(meta.format.duration * percent / 100) }
6461
end
65-
cmd:arg { "-i", tostring(job.file.url) }
62+
cmd:arg { "-skip_frame", "nokey", "-i", tostring(job.file.url) }
6663
if percent == 0 then
6764
cmd:arg { "-map", "disp:attached_pic" }
6865
end
6966

7067
-- stylua: ignore
71-
local status, err = cmd:arg({
68+
local output, err = cmd:arg({
7269
"-vframes", 1,
7370
"-q:v", 31 - math.floor(rt.preview.image_quality * 0.3),
7471
"-vf", string.format("scale='min(%d,iw)':'min(%d,ih)':force_original_aspect_ratio=decrease:flags=fast_bilinear", rt.preview.max_width, rt.preview.max_height),
7572
"-f", "image2",
7673
"-y", tostring(cache),
77-
}):status()
74+
}):output()
7875

79-
if not status then
76+
if not output then
8077
return true, Err("Failed to start `ffmpeg`, error: %s", err)
81-
elseif not status.success then
82-
return false, Err("`ffmpeg` exited with error code: %s", status.code)
83-
else
78+
elseif output.status.success then
8479
return true
80+
elseif output.stderr:find("No filtered frames for output stream", 1, true) then
81+
return true, Err("No more keyframes available")
82+
else
83+
return false, Err("`ffmpeg` exited with error code %s: %s", output.status.code, output.stderr)
8584
end
8685
end
8786

yazi-plugin/src/process/command.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{any::TypeId, ffi::OsStr, io, process::Stdio};
22

3-
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
3+
use mlua::{AnyUserData, ExternalError, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
44
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
55
use yazi_binding::Error;
66
use yazi_shared::wtf8::FromWtf8;
@@ -139,22 +139,21 @@ impl UserData for Command {
139139
)
140140
}
141141

142-
methods.add_function_mut("arg", |_, (ud, arg): (AnyUserData, Value)| {
143-
{
144-
let mut me = ud.borrow_mut::<Self>()?;
145-
match arg {
146-
Value::String(s) => {
147-
me.inner.arg(OsStr::from_wtf8(&s.as_bytes())?);
148-
}
149-
Value::Table(t) => {
150-
for s in t.sequence_values::<mlua::String>() {
151-
me.inner.arg(OsStr::from_wtf8(&s?.as_bytes())?);
152-
}
142+
methods.add_function_mut("arg", |lua, (ud, arg): (AnyUserData, Value)| {
143+
let mut me = ud.borrow_mut::<Self>()?;
144+
match arg {
145+
Value::Nil => return lua.create_sequence_from(me.inner.as_std().get_args())?.into_lua(lua),
146+
Value::String(s) => {
147+
me.inner.arg(OsStr::from_wtf8(&s.as_bytes())?);
148+
}
149+
Value::Table(t) => {
150+
for s in t.sequence_values::<mlua::String>() {
151+
me.inner.arg(OsStr::from_wtf8(&s?.as_bytes())?);
153152
}
154-
_ => return Err("arg must be a string or table of strings".into_lua_err()),
155153
}
154+
_ => Err("arg must be a string or table of strings".into_lua_err())?,
156155
}
157-
Ok(ud)
156+
ud.into_lua(lua)
158157
});
159158
methods.add_function_mut("cwd", |_, (ud, dir): (AnyUserData, mlua::String)| {
160159
ud.borrow_mut::<Self>()?.inner.current_dir(dir.to_str()?.as_ref());

0 commit comments

Comments
 (0)