The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(android): an export whose phone chip stops taking frames goes again on Android's software encoder (#491)
Jareer0c86f62bed90
diff --git a/src/crates/concat-api/src/message.rs b/src/crates/concat-api/src/message.rsindex 44518e0e..6f7eefb5 100644--- a/src/crates/concat-api/src/message.rs+++ b/src/crates/concat-api/src/message.rs@@ -427,7 +427,9 @@ pub struct JobStatus {/// Running, or how it ended.pub state: JobState,/// What it is doing: "cutout" while masks are found, "stabilize" while- /// shake is measured, then "rendering", "mixing audio" and "muxing".+ /// shake is measured, then "rendering", "mixing audio" and "muxing";+ /// "rendering in software" when the hardware encoder stopped part way+ /// and the video is rendered again from its first frame on the CPU./// Absent until it has said.#[serde(default, skip_serializing_if = "Option::is_none")]pub stage: Option<String>,diff --git a/src/crates/concat-export/src/lib.rs b/src/crates/concat-export/src/lib.rsindex 8d35f468..1b2af9ee 100644--- a/src/crates/concat-export/src/lib.rs+++ b/src/crates/concat-export/src/lib.rs@@ -1696,7 +1696,7 @@ fn render_picture(backdrops,} = build_timeline(request, rate, visible, transitions);- let options = EncodeOptions {+ let mut options = EncodeOptions {crf: request.crf,preset: request.preset.clone(),codec: request.codec,@@ -1706,198 +1706,203 @@ fn render_picture(color_range: request.color_range,hardware: true,threads: 0,+ software_only: false,};// An HDR file comes out of the compositor as its signal, sixteen bits a// channel; anything else, SDR - an HDR timeline's tone-mapped.let signal = output_of(request.color_space);let hdr = request.hdr && signal != Signal::Sdr;compositor.deliver_hdr(hdr);- let mut encoder = if hdr {- Encoder::create_hdr(- destination,- request.width,- request.height,- rate,- &options,- signal,- )- } else {- Encoder::create(destination, request.width, request.height, rate, &options)- }- .map_err(|error| error.to_string())?;// How many devices have died under this export so far; see `recovered`.let mut losses = 0;- // When progress was last said; see `progress_due`.- let mut said = std::time::Instant::now();-- // One decoder per clip, opened at its in-point the first time the clip is- // needed and dropped the moment it leaves the playhead. Every decoder is- // opened at `output rate / clip speed`, so pulling exactly one frame per- // output frame keeps each of them in step with the plan's source times- // without any seeking - including retimed clips.- let mut decoders: HashMap<ClipId, Decoder> = HashMap::new();// A clip whose speed changes, or runs backwards, cannot be followed by a// paced decoder: each of its frames is sought by its own source time,// through a pool that keeps the reader rolling where it can.let sought = concat_media::ReaderPool::with_defaults();- for index in 0..total_frames {- reporter.cancelled()?;-- let time = rate.time_of_frame(index);- let plan = plan_frame(&timeline, time);-- let mut layers: Vec<PlannedLayer> = Vec::with_capacity(plan.layers.len());- for layer in &plan.layers {- if !layer.paced {- let (decode_width, decode_height) = decode_sizes- .get(&layer.clip)- .copied()- .unwrap_or((request.width, request.height));- // A frame that cannot be read ends the export with the- // reason, as it does on the paced path below. A time past- // the media's end is not that: the pool answers it with the- // last frame. This path used to drop a failed frame on the- // floor, so a reversed or retimed clip whose file had gone- // bad exported as a missing layer and nobody was told.- let frame = sought- .frame_at(- &layer.media,- layer.source_time,- decode_width,- decode_height,- stills.contains(&layer.clip),- None,- None,- ranges.get(&layer.clip).copied(),- // Deep where the frame goes to the GPU as it is: a- // cutout cuts eight bits.- !cutouts.contains_key(&layer.clip),- )- .map_err(|error| error.to_string())?;- let frame = cutouts- .get(&layer.clip)- .and_then(|job| job.cut(&frame, layer.source_time))- .map_or(frame, std::sync::Arc::new);- layers.push(filled(- layer,- frame,- tracks.get(&layer.clip).copied().unwrap_or(0),- passes_at(&chains, &reveal_maps, &timeline, layer.clip, time),- geometry.get(&layer.clip),- shapes_at(&shapes, layer, time, rate),- stabilized.get(&layer.clip),- ));- continue;+ // Each pass renders the whole cut from its first frame. There is a+ // second only when the first one's hardware encoder stopped taking+ // frames part way through (#491): what it took is in a file it will+ // never finish, so the file is started again on the CPU's encoder -+ // slower, but it takes every frame - and the progress says so.+ 'pass: loop {+ let stage = if options.software_only {+ RENDERING_IN_SOFTWARE+ } else {+ "rendering"+ };+ let mut encoder = if hdr {+ Encoder::create_hdr(+ destination,+ request.width,+ request.height,+ rate,+ &options,+ signal,+ )+ } else {+ Encoder::create(destination, request.width, request.height, rate, &options)+ }+ .map_err(|error| failed_encoding(&error, &options))?;+ log::info!(+ "export: encoding with {} ({})",+ encoder.encoder_name(),+ if encoder.on_hardware() {+ "hardware"+ } else {+ "software"}- let decoder = match decoders.entry(layer.clip) {- std::collections::hash_map::Entry::Occupied(entry) => entry.into_mut(),- std::collections::hash_map::Entry::Vacant(entry) => {- // Aspect-correct: decode at the source's fitted size and- // let the compositor place it, rather than stretching to- // the frame and losing the picture's shape.+ );++ // When progress was last said; see `progress_due`.+ let mut said = std::time::Instant::now();++ // One decoder per clip, opened at its in-point the first time the clip is+ // needed and dropped the moment it leaves the playhead. Every decoder is+ // opened at `output rate / clip speed`, so pulling exactly one frame per+ // output frame keeps each of them in step with the plan's source times+ // without any seeking - including retimed clips.+ let mut decoders: HashMap<ClipId, Decoder> = HashMap::new();++ for index in 0..total_frames {+ reporter.cancelled()?;++ let time = rate.time_of_frame(index);+ let plan = plan_frame(&timeline, time);++ let mut layers: Vec<PlannedLayer> = Vec::with_capacity(plan.layers.len());+ for layer in &plan.layers {+ if !layer.paced {let (decode_width, decode_height) = decode_sizes.get(&layer.clip).copied().unwrap_or((request.width, request.height));-- // A retimed clip advances the source by `speed / fps`- // seconds per output frame, so the decoder must emit- // frames exactly that far apart: a rate of `fps / speed`.- // (At 2x, 300 output frames cover 20s of source - the- // decoder emits 15 frames per source second, not 60.)- let decode_rate = if layer.speed == Rational::ONE {- rate- } else {- FrameRate::new(rate.fps() / layer.speed)- };-- // Deep - an HDR clip in its own signal, converted on- // the GPU - unless a cutout has to cut it in eight bits;- // the decoder keeps eight bits for a chain itself.- let mut options = DecodeOptions::default()- .starting_at(layer.source_time)- .scaled_to(decode_width, decode_height)- .at_rate(decode_rate)- .in_range(ranges.get(&layer.clip).copied())- .deep(!cutouts.contains_key(&layer.clip));-- // A still is a one-frame stream. Without looping it would- // contribute a single frame and then disappear.- if stills.contains(&layer.clip) {- options = options.repeating().starting_at(Rational::ZERO);+ // A frame that cannot be read ends the export with the+ // reason, as it does on the paced path below. A time past+ // the media's end is not that: the pool answers it with the+ // last frame. This path used to drop a failed frame on the+ // floor, so a reversed or retimed clip whose file had gone+ // bad exported as a missing layer and nobody was told.+ let frame = sought+ .frame_at(+ &layer.media,+ layer.source_time,+ decode_width,+ decode_height,+ stills.contains(&layer.clip),+ None,+ None,+ ranges.get(&layer.clip).copied(),+ // Deep where the frame goes to the GPU as it is: a+ // cutout cuts eight bits.+ !cutouts.contains_key(&layer.clip),+ )+ .map_err(|error| error.to_string())?;+ let frame = cutouts+ .get(&layer.clip)+ .and_then(|job| job.cut(&frame, layer.source_time))+ .map_or(frame, std::sync::Arc::new);+ layers.push(filled(+ layer,+ frame,+ tracks.get(&layer.clip).copied().unwrap_or(0),+ passes_at(&chains, &reveal_maps, &timeline, layer.clip, time),+ geometry.get(&layer.clip),+ shapes_at(&shapes, layer, time, rate),+ stabilized.get(&layer.clip),+ ));+ continue;+ }+ let decoder = match decoders.entry(layer.clip) {+ std::collections::hash_map::Entry::Occupied(entry) => entry.into_mut(),+ std::collections::hash_map::Entry::Vacant(entry) => {+ // Aspect-correct: decode at the source's fitted size and+ // let the compositor place it, rather than stretching to+ // the frame and losing the picture's shape.+ let (decode_width, decode_height) = decode_sizes+ .get(&layer.clip)+ .copied()+ .unwrap_or((request.width, request.height));++ // A retimed clip advances the source by `speed / fps`+ // seconds per output frame, so the decoder must emit+ // frames exactly that far apart: a rate of `fps / speed`.+ // (At 2x, 300 output frames cover 20s of source - the+ // decoder emits 15 frames per source second, not 60.)+ let decode_rate = if layer.speed == Rational::ONE {+ rate+ } else {+ FrameRate::new(rate.fps() / layer.speed)+ };++ // Deep - an HDR clip in its own signal, converted on+ // the GPU - unless a cutout has to cut it in eight bits;+ // the decoder keeps eight bits for a chain itself.+ let mut options = DecodeOptions::default()+ .starting_at(layer.source_time)+ .scaled_to(decode_width, decode_height)+ .at_rate(decode_rate)+ .in_range(ranges.get(&layer.clip).copied())+ .deep(!cutouts.contains_key(&layer.clip));++ // A still is a one-frame stream. Without looping it would+ // contribute a single frame and then disappear.+ if stills.contains(&layer.clip) {+ options = options.repeating().starting_at(Rational::ZERO);+ }++ entry.insert(+ Decoder::open(&layer.media, &options)+ .map_err(|error| error.to_string())?,+ )}+ };- entry.insert(- Decoder::open(&layer.media, &options).map_err(|error| error.to_string())?,- )+ // A source that has run out contributes nothing rather than+ // aborting the export - a clip trimmed past its media's end is a+ // mistake in the edit, not a failure of the renderer.+ if let Some(frame) = decoder.next_frame().map_err(|error| error.to_string())? {+ // The cutout, on the decoded picture before it is placed:+ // the same frame both compositors then draw.+ let frame = match cutouts+ .get(&layer.clip)+ .and_then(|job| job.cut(&frame, layer.source_time))+ {+ Some(cut) => cut,+ None => frame,+ };+ layers.push(filled(+ layer,+ std::sync::Arc::new(frame),+ tracks.get(&layer.clip).copied().unwrap_or(0),+ passes_at(&chains, &reveal_maps, &timeline, layer.clip, time),+ geometry.get(&layer.clip),+ shapes_at(&shapes, layer, time, rate),+ stabilized.get(&layer.clip),+ ));}- };-- // A source that has run out contributes nothing rather than- // aborting the export - a clip trimmed past its media's end is a- // mistake in the edit, not a failure of the renderer.- if let Some(frame) = decoder.next_frame().map_err(|error| error.to_string())? {- // The cutout, on the decoded picture before it is placed:- // the same frame both compositors then draw.- let frame = match cutouts- .get(&layer.clip)- .and_then(|job| job.cut(&frame, layer.source_time))- {- Some(cut) => cut,- None => frame,- };- layers.push(filled(- layer,- std::sync::Arc::new(frame),- tracks.get(&layer.clip).copied().unwrap_or(0),- passes_at(&chains, &reveal_maps, &timeline, layer.clip, time),- geometry.get(&layer.clip),- shapes_at(&shapes, layer, time, rate),- stabilized.get(&layer.clip),- ));}- }- let frame_plan = FramePlan {- time,- width: request.width,- height: request.height,- layers: with_backdrops(- layers,- &backdrops,- |clip| !stills.contains(&clip) && !cutouts.contains_key(&clip),- &sought,- (request.width, request.height),- ),- treatments: Vec::new(),- output: output_of(request.color_space),- };- // The plan is kept for a second drawing: a frame drawn on a device- // that died under it is black, and is drawn again on the device- // that takes over. Both drawings borrow it - the layers' pictures- // were never copied, and now their passes are not either.- let mut composed = composite_treated(- &mut EffectClock {- inner: &mut compositor,- offset: effect_offset,- },- &frame_plan,- &treatments,- &transitions,- );- while compositor.lost() {- losses += 1;- let adapter = compositor.adapter_info();- log::error!(- "export: the GPU device on {} was lost drawing frame {index} of {total_frames} \- ({:.3}s into the cut); the frame is drawn again on the next device",- adapter.name,- time.as_f64(),- );- compositor = recovered(losses, hdr)?;- composed = composite_treated(+ let frame_plan = FramePlan {+ time,+ width: request.width,+ height: request.height,+ layers: with_backdrops(+ layers,+ &backdrops,+ |clip| !stills.contains(&clip) && !cutouts.contains_key(&clip),+ &sought,+ (request.width, request.height),+ ),+ treatments: Vec::new(),+ output: output_of(request.color_space),+ };+ // The plan is kept for a second drawing: a frame drawn on a device+ // that died under it is black, and is drawn again on the device+ // that takes over. Both drawings borrow it - the layers' pictures+ // were never copied, and now their passes are not either.+ let mut composed = composite_treated(&mut EffectClock {inner: &mut compositor,offset: effect_offset,@@ -1906,23 +1911,96 @@ fn render_picture(&treatments,&transitions,);+ while compositor.lost() {+ losses += 1;+ let adapter = compositor.adapter_info();+ log::error!(+ "export: the GPU device on {} was lost drawing frame {index} of {total_frames} \+ ({:.3}s into the cut); the frame is drawn again on the next device",+ adapter.name,+ time.as_f64(),+ );+ compositor = recovered(losses, hdr)?;+ composed = composite_treated(+ &mut EffectClock {+ inner: &mut compositor,+ offset: effect_offset,+ },+ &frame_plan,+ &treatments,+ &transitions,+ );+ }+ if let Err(error) = encoder.write_frame(&composed) {+ // The stopped encoder is closed before the file is opened+ // again, so the chip has its session back.+ drop(encoder);+ again_in_software(&error, &mut options, index, total_frames)?;+ reporter.emit(0, total_frames, RENDERING_IN_SOFTWARE);+ continue 'pass;+ }++ // Retire decoders whose clip has finished, so a long timeline does not+ // hold an ffmpeg process open for every clip it has ever passed.+ let live: Vec<ClipId> = plan.layers.iter().map(|layer| layer.clip).collect();+ decoders.retain(|clip, _| live.contains(clip));++ if progress_due(index, said.elapsed()) {+ reporter.emit(index, total_frames, stage);+ said = std::time::Instant::now();+ }}- encoder- .write_frame(&composed)- .map_err(|error| error.to_string())?;-- // Retire decoders whose clip has finished, so a long timeline does not- // hold an ffmpeg process open for every clip it has ever passed.- let live: Vec<ClipId> = plan.layers.iter().map(|layer| layer.clip).collect();- decoders.retain(|clip, _| live.contains(clip));-- if progress_due(index, said.elapsed()) {- reporter.emit(index, total_frames, "rendering");- said = std::time::Instant::now();++ match encoder.finish() {+ Ok(()) => return Ok(()),+ Err(error) => {+ drop(encoder);+ again_in_software(&error, &mut options, total_frames, total_frames)?;+ reporter.emit(0, total_frames, RENDERING_IN_SOFTWARE);+ }}}+}- encoder.finish().map_err(|error| error.to_string())+/// The stage an export reports while it renders again on the CPU's+/// encoder, its hardware one having stopped taking frames part way+/// through: from the first frame, once, the count back at nothing.+pub const RENDERING_IN_SOFTWARE: &str = "rendering in software";++/// Whether an export goes again after its encoder failed with `error`,+/// `frame` frames of `total` in, having opened it with `options`: once,+/// and only when it was the platform's hardware encoder that stopped+/// taking frames (#491) - a phone's chip that took the export's settings+/// and then went quiet. `options` is then set to the CPU's encoder alone,+/// and the export starts again from its first frame. Anything else ends+/// the export with its reason.+fn again_in_software(+ error: &concat_media::Error,+ options: &mut EncodeOptions,+ frame: i64,+ total: i64,+) -> Result<(), String> {+ if options.software_only || !error.stalled_on_hardware() {+ return Err(failed_encoding(error, options));+ }+ log::warn!(+ "export: {error}, {frame} frames of {total} in; starting again on the software encoder"+ );+ options.software_only = true;+ Ok(())+}++/// What an export says when its encoder failed with `error`: the reason,+/// and on the CPU's encoder, that this was the second try.+fn failed_encoding(error: &concat_media::Error, options: &EncodeOptions) -> String {+ if options.software_only {+ format!(+ "the hardware encoder stopped taking frames part way through, and the slower \+ software encoder the export went on with failed too: {error}"+ )+ } else {+ error.to_string()+ }}/// How many frames apart an export says how far it has got, at most.@@ -3546,6 +3624,50 @@ mod tests {assert!(progress_due(7, PROGRESS_INTERVAL));}+ /// A phone's chip that stops taking frames part way through an export+ /// sends the export round once more on the CPU's encoder; a second+ /// stall, or any other failure, ends it with words that say what was+ /// tried (#491).+ #[test]+ fn a_stalled_hardware_encoder_is_given_one_more_go_in_software() {+ let stall = |hardware| concat_media::Error::Stalled {+ operation: "encode",+ path: "out.mp4".into(),+ detail: "the encoder took no frame for 10 seconds".to_owned(),+ hardware,+ };+ let mut options = EncodeOptions::default();+ again_in_software(&stall(true), &mut options, 120, 480)+ .expect("the first stall on hardware goes again");+ assert!(options.software_only, "and goes again on the CPU");++ // Once: a stall on the CPU, or anything else, then fails.+ let error = again_in_software(&stall(false), &mut options, 30, 480)+ .expect_err("the CPU stalling too ends the export");+ assert!(error.contains("software encoder"), "{error}");+ assert!(error.contains("took no frame for 10 seconds"), "{error}");+ assert!(options.software_only);+ let error = again_in_software(&stall(true), &mut options, 30, 480)+ .expect_err("never a third pass, whatever the encoder says");+ assert!(error.contains("failed too"), "{error}");++ // A stall on the CPU first, or a failure that is not a stall, is+ // said as it always was.+ let mut cpu_first = EncodeOptions::default();+ assert_eq!(+ again_in_software(&stall(false), &mut cpu_first, 30, 480),+ Err("encode failed for out.mp4: the encoder took no frame for 10 seconds".to_owned())+ );+ let refused = concat_media::Error::Ffi {+ operation: "write packet",+ path: "out.mp4".into(),+ detail: "No space left on device".to_owned(),+ };+ let mut options = EncodeOptions::default();+ assert!(again_in_software(&refused, &mut options, 30, 480).is_err());+ assert!(!cpu_first.software_only && !options.software_only);+ }+/// Only Linux is told to install a software renderer: a phone has/// nothing to install, and Windows and macOS have theirs built in.#[test]diff --git a/src/crates/concat-host/src/enhance.rs b/src/crates/concat-host/src/enhance.rsindex 617a8767..8d0e9396 100644--- a/src/crates/concat-host/src/enhance.rs+++ b/src/crates/concat-host/src/enhance.rs@@ -398,6 +398,7 @@ fn footage(color_range: concat_media::ColorRange::Limited,hardware: false,threads: 2,+ software_only: false,},).map_err(|error| error.to_string())?;diff --git a/src/crates/concat-host/src/export.rs b/src/crates/concat-host/src/export.rsindex e9c06a5c..67aae9d9 100644--- a/src/crates/concat-host/src/export.rs+++ b/src/crates/concat-host/src/export.rs@@ -54,7 +54,11 @@ pub struct Progress {pub frame: i64,/// Frames in total.pub total: i64,- /// What the exporter is doing: "rendering", "mixing audio", "muxing".+ /// What the exporter is doing: "rendering", "mixing audio", "muxing";+ /// "rendering in software" ([`concat_export::RENDERING_IN_SOFTWARE`])+ /// when the hardware encoder stopped part way and the video is being+ /// rendered again from its first frame on the CPU, the frame count+ /// back at nothing.pub stage: &'static str,}diff --git a/src/crates/concat-host/src/proxy.rs b/src/crates/concat-host/src/proxy.rsindex ae46a06d..f0572770 100644--- a/src/crates/concat-host/src/proxy.rs+++ b/src/crates/concat-host/src/proxy.rs@@ -238,6 +238,7 @@ pub fn write(// media engine does it for nothing where there is one.hardware: hdr,threads: 2,+ software_only: false,};let mut encoder = if hdr {Encoder::create_hdr(&partial, width, height, rate, &encoding, signal)diff --git a/src/crates/concat-host/src/reverse.rs b/src/crates/concat-host/src/reverse.rsindex 1d3b58a8..d8a27c29 100644--- a/src/crates/concat-host/src/reverse.rs+++ b/src/crates/concat-host/src/reverse.rs@@ -361,6 +361,7 @@ fn segment_options() -> EncodeOptions {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 2,+ software_only: false,}}@@ -377,6 +378,7 @@ fn copy_options() -> EncodeOptions {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 2,+ software_only: false,}}diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rsindex 61f64d26..92b9320d 100644--- a/src/crates/concat-host/tests/export.rs+++ b/src/crates/concat-host/tests/export.rs@@ -94,6 +94,7 @@ fn picture(path: &Path, rate: FrameRate, seconds: u32, codec: VideoCodec) {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder =Encoder::create(path, WIDTH, HEIGHT, rate, &options).expect("the linked FFmpeg encodes");@@ -126,6 +127,7 @@ fn quadrants(path: &Path) {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder = Encoder::create(path, WIDTH, HEIGHT, FrameRate::THIRTY, &options).expect("the linked FFmpeg encodes");@@ -1022,6 +1024,7 @@ fn solid(path: &Path, colour: [u8; 3]) {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder = Encoder::create(path, WIDTH, HEIGHT, FrameRate::THIRTY, &options).expect("the linked FFmpeg encodes");@@ -1152,6 +1155,7 @@ fn an_hlg_clip_exports_through_the_gpu_conversion() {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder = Encoder::create_mislabelled_hdr(&path,@@ -1211,6 +1215,7 @@ fn an_hlg_timeline_exports_as_hdr_or_sdr() {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};{let mut encoder = Encoder::create_hdr(diff --git a/src/crates/concat-host/tests/stabilize.rs b/src/crates/concat-host/tests/stabilize.rsindex a5ae0207..3cb02c08 100644--- a/src/crates/concat-host/tests/stabilize.rs+++ b/src/crates/concat-host/tests/stabilize.rs@@ -75,6 +75,7 @@ fn shoot(path: &Path) {color_range: concat_media::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder = Encoder::create(path, WIDTH, HEIGHT, FrameRate::THIRTY, &options).expect("the linked FFmpeg encodes");diff --git a/src/crates/concat-mcp/src/tools.rs b/src/crates/concat-mcp/src/tools.rsindex 074b8c73..b9eb7ca4 100644--- a/src/crates/concat-mcp/src/tools.rs+++ b/src/crates/concat-mcp/src/tools.rs@@ -36,14 +36,15 @@ const WAIT_LONGEST: f64 = 600.0;const STAGES: usize = 5;/// Where a stage comes in an export, from 0. A job's status names the-/// stage the exporter reports - "rendering", "mixing audio", "muxing" --/// and the API's documentation names them "video", "audio" and "mux"; both+/// stage the exporter reports - "rendering" (or "rendering in software",+/// going again after the hardware encoder stopped), "mixing audio",+/// "muxing" - and the API's documentation names them "video", "audio" and "mux"; both/// are known here, and one this does not know counts as the first.fn stage_place(stage: &str) -> usize {match stage {"cutout" => 0,"stabilize" => 1,- "video" | "rendering" => 2,+ "video" | "rendering" | "rendering in software" => 2,"audio" | "mixing audio" => 3,"mux" | "muxing" => 4,_ => 0,diff --git a/src/crates/concat-media/src/decode.rs b/src/crates/concat-media/src/decode.rsindex 15ce2106..80fbce5a 100644--- a/src/crates/concat-media/src/decode.rs+++ b/src/crates/concat-media/src/decode.rs@@ -1667,6 +1667,7 @@ mod tests {color_range: ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let mut encoder = Encoder::create_tagged(&path,diff --git a/src/crates/concat-media/src/encode.rs b/src/crates/concat-media/src/encode.rsindex 10753c70..db84e25f 100644--- a/src/crates/concat-media/src/encode.rs+++ b/src/crates/concat-media/src/encode.rs@@ -286,6 +286,11 @@ pub struct EncodeOptions {/// Zero for an export; a few for a proxy written while the editor is/// in use.pub threads: u16,+ /// The CPU and nothing else: no hardware encoder is opened, and on a+ /// phone its chip is passed over for Android's own software component.+ /// For an export going again after the hardware encoder stopped taking+ /// frames part way through (see [`Error::Stalled`]); off otherwise.+ pub software_only: bool,}impl Default for EncodeOptions {@@ -300,6 +305,7 @@ impl Default for EncodeOptions {color_range: ColorRange::Limited,hardware: true,threads: 0,+ software_only: false,}}}@@ -628,6 +634,33 @@ fn attempts(encoder_name: &str) -> &'static [Attempt] {}}+impl Attempt {+ /// Whether `encoder_name` asked this way encodes on the CPU: one of+ /// Android's own components, or an encoder that is software already.+ fn in_software(self, encoder_name: &str) -> bool {+ match self {+ Attempt::Component(_) => true,+ Attempt::AsAsked | Attempt::Plain => !Family::of(encoder_name).hardware(),+ }+ }+}++/// The ways to ask `encoder_name`, in order, that `options` allows: every+/// one, or with [`EncodeOptions::software_only`] those on the CPU alone - on+/// a phone straight to Android's software component, past a chip that+/// stopped part way through the last try, and on a desktop the software+/// encoders, with NVENC, Quick Sync, AMF and the rest passed over.+fn allowed_attempts(+ encoder_name: &'static str,+ options: &EncodeOptions,+) -> impl Iterator<Item = Attempt> {+ let software_only = options.software_only;+ attempts(encoder_name)+ .iter()+ .copied()+ .filter(move |attempt| !software_only || attempt.in_software(encoder_name))+}+/// The most a plain ask puts on a phone's chip, in kb/s: room for a clean/// 1080p, and twice that above it.fn plain_kbps(width: u32, height: u32) -> u32 {@@ -985,6 +1018,10 @@ pub struct Encoder {finished: bool,/// Which FFmpeg encoder took the job.encoder_name: &'static str,+ /// Whether it is the platform's hardware doing the work. Not the same+ /// as the name's family: `h264_mediacodec` asked for Android's own+ /// component by name encodes on the CPU.+ hardware: bool,/// The range every converted frame is stamped with, matching the/// stream's tag and the scaler's conversion.color_range: ffmpeg::color::Range,@@ -1283,7 +1320,7 @@ impl Encoder {let mut failure = None;let mut opened = None;'encoders: for (name, codec) in candidates {- for &attempt in attempts(name) {+ for attempt in allowed_attempts(name, options) {match open_video(name,codec,@@ -1306,7 +1343,8 @@ impl Encoder {if attempt != Attempt::AsAsked {log::warn!("{name} opened only when asked {attempt:?}");}- opened = Some((name, codec, encoder, pixel_format));+ let hardware = !attempt.in_software(name);+ opened = Some((name, codec, encoder, pixel_format, hardware));break 'encoders;}Err(error) => {@@ -1316,8 +1354,13 @@ impl Encoder {}}}- let Some((encoder_name, codec, encoder, pixel_format)) = opened else {- return Err(failure.expect("at least one encoder was tried"));+ let Some((encoder_name, codec, encoder, pixel_format, hardware)) = opened else {+ // Nothing was even tried when the CPU alone was asked for and+ // every linked encoder is hardware.+ return Err(failure.unwrap_or_else(|| Error::Missing {+ what: "software encoder",+ name: options.codec.label().to_owned(),+ }));};{@@ -1414,6 +1457,7 @@ impl Encoder {written: 0,finished: false,encoder_name,+ hardware,color_range: options.color_range.as_ffmpeg(),deep,light: pq.then(LightLevel::new),@@ -1425,6 +1469,13 @@ impl Encoder {self.encoder_name}+ /// Whether the platform's hardware is doing the work rather than the+ /// CPU - false for a phone's export on Android's own software+ /// component, whatever the encoder's name.+ pub fn on_hardware(&self) -> bool {+ self.hardware+ }+/// How many frames have been accepted so far.pub const fn written(&self) -> u64 {self.written@@ -1437,7 +1488,8 @@ impl Encoder {/// whenever their input buffers are full, which on a phone is most/// exports; treated as a failure, it ended every H.264 export there/// a fraction of a second in. An encoder that keeps saying it for- /// [`ENCODER_PATIENCE`] is stuck, and the export fails saying so.+ /// [`ENCODER_PATIENCE`] is stuck, and says so as [`Error::Stalled`]:+ /// an export whose hardware it was goes again on the CPU.fn send(&mut self, frame: Option<&Video>) -> Result<()> {let sent = patiently(self,@@ -1451,22 +1503,29 @@ impl Encoder {)?;sent.map_err(|refused| match refused {Refused::Error(error) => ffi::fail("encode", &self.path, error),- Refused::Stalled => Error::Ffi {- operation: "encode",- path: self.path.clone(),- detail: format!(- "the encoder took no {} for {} seconds",- if frame.is_some() {- "frame"- } else {- "end of the stream"- },- ENCODER_PATIENCE.as_secs()- ),- },+ Refused::Stalled => self.stalled(format!(+ "the encoder took no {} for {} seconds",+ if frame.is_some() {+ "frame"+ } else {+ "end of the stream"+ },+ ENCODER_PATIENCE.as_secs()+ )),})}+ /// The failure of an encoder that stopped, saying `detail` and whether+ /// it was the hardware that stopped.+ fn stalled(&self, detail: String) -> Error {+ Error::Stalled {+ operation: "encode",+ path: self.path.clone(),+ detail,+ hardware: self.hardware,+ }+ }+/// Reads out what the encoder still holds once it has been told the/// stream ended, until it says it has handed back the last packet./// FFmpeg's contract has no "try again" here, but its MediaCodec@@ -1479,14 +1538,10 @@ impl Encoder {if until_ended(self, Self::read_out, ENCODER_PATIENCE)? {return Ok(());}- Err(Error::Ffi {- operation: "encode",- path: self.path.clone(),- detail: format!(- "the encoder held its last frames for {} seconds",- ENCODER_PATIENCE.as_secs()- ),- })+ Err(self.stalled(format!(+ "the encoder held its last frames for {} seconds",+ ENCODER_PATIENCE.as_secs()+ )))}/// Writes every packet the encoder has ready.@@ -2028,6 +2083,7 @@ mod tests {color_range: ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let rate = FrameRate::new(concat_core::time::Rational::new(25, 1));const FRAMES: u32 = 150;@@ -2168,6 +2224,101 @@ mod tests {assert_eq!(plain_kbps(3840, 2160), 32_000);}+ /// An export going again on the CPU after a phone's chip stopped part+ /// way through asks Android's own software components only, never the+ /// chip again; on a desktop, the software encoders only (#491).+ #[test]+ fn a_stalled_chip_is_passed_over_for_the_cpu() {+ let cpu = EncodeOptions {+ software_only: true,+ ..EncodeOptions::default()+ };+ let asked = |name: &'static str, options: &EncodeOptions| -> Vec<Attempt> {+ allowed_attempts(name, options).collect()+ };+ assert_eq!(+ asked("h264_mediacodec", &cpu),+ [+ Attempt::Component("c2.android.avc.encoder"),+ Attempt::Component("OMX.google.h264.encoder"),+ ]+ );+ assert_eq!(+ asked("hevc_mediacodec", &cpu),+ [Attempt::Component("c2.android.hevc.encoder")]+ );+ assert_eq!(asked("libx264", &cpu), [Attempt::AsAsked]);+ assert_eq!(asked("libsvtav1", &cpu), [Attempt::AsAsked]);+ for hardware in ["hevc_nvenc", "h264_videotoolbox", "av1_qsv", "h264_mf"] {+ assert!(asked(hardware, &cpu).is_empty(), "{hardware} is hardware");+ }+ // Not asked for, every way is tried, as before.+ let mut every = EncodeOptions::default();+ assert_eq!(+ asked("h264_mediacodec", &every),+ attempts("h264_mediacodec")+ );+ every.hardware = false;+ assert_eq!(asked("hevc_nvenc", &every), [Attempt::AsAsked]);+ // What each way comes to: the chip, or the CPU.+ assert!(!Attempt::AsAsked.in_software("h264_mediacodec"));+ assert!(!Attempt::Plain.in_software("h264_mediacodec"));+ assert!(Attempt::Component("c2.android.avc.encoder").in_software("h264_mediacodec"));+ assert!(Attempt::AsAsked.in_software("libx265"));+ }++ /// Only the hardware stopping is one an export goes again for: the CPU+ /// stopping, or anything else failing, would fail again.+ #[test]+ fn a_hardware_stall_is_told_apart() {+ let stall = |hardware| Error::Stalled {+ operation: "encode",+ path: PathBuf::from("out.mp4"),+ detail: "the encoder took no frame for 10 seconds".to_owned(),+ hardware,+ };+ assert!(stall(true).stalled_on_hardware());+ assert!(!stall(false).stalled_on_hardware());+ let other = Error::Ffi {+ operation: "encode",+ path: PathBuf::from("out.mp4"),+ detail: "Generic error in an external library".to_owned(),+ };+ assert!(!other.stalled_on_hardware());+ // Said as every other failure to encode is, so the words a person+ // reads are the same ones they reported.+ assert_eq!(+ stall(true).to_string(),+ "encode failed for out.mp4: the encoder took no frame for 10 seconds"+ );+ }++ /// Asked for the CPU alone, an export opens on a software encoder and+ /// says so, and still writes a file.+ #[test]+ fn a_software_only_encoder_opens_on_the_cpu() {+ let dir =+ std::env::temp_dir().join(format!("concat-media-cpu-test-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(&dir).expect("scratch dir");+ let path = dir.join("cpu.mp4");+ let options = EncodeOptions {+ preset: "ultrafast".to_owned(),+ software_only: true,+ ..EncodeOptions::default()+ };+ let mut encoder = Encoder::create(&path, 64, 64, FrameRate::THIRTY, &options)+ .expect("a software H.264 encoder is linked");+ assert!(!encoder.on_hardware(), "{}", encoder.encoder_name());+ assert_eq!(Family::of(encoder.encoder_name()), Family::Software);+ for _ in 0..5 {+ encoder.write_frame(&Frame::black(64, 64)).expect("writes");+ }+ encoder.finish().expect("finishes");+ assert!(std::fs::metadata(&path).expect("written").len() > 0);+ let _ = std::fs::remove_dir_all(&dir);+ }+#[test]fn each_encoder_family_takes_its_own_pictures() {assert_eq!(Family::of("libx264").pixel_format(false), Pixel::YUV420P);@@ -2426,6 +2577,7 @@ mod tests {color_range: ColorRange::Limited,hardware: true,threads: 0,+ software_only: false,};let mut encoder = Encoder::create(&path, 64, 64, FrameRate::THIRTY, &options).unwrap_or_else(|error| panic!("{} {ten_bit}: {error}", codec.label()));@@ -2470,6 +2622,7 @@ mod tests {color_range: ColorRange::Limited,hardware: true,threads: 0,+ software_only: false,};let refused = std::env::temp_dir().join("concat-encode-hdr-h264.mp4");assert!(diff --git a/src/crates/concat-media/src/error.rs b/src/crates/concat-media/src/error.rsindex 72e0d495..780de539 100644--- a/src/crates/concat-media/src/error.rs+++ b/src/crates/concat-media/src/error.rs@@ -25,6 +25,23 @@ pub enum Error {detail: String,},+ /// An encoder that kept saying "try again" to a frame, or held its+ /// last frames, for longer than a working one ever takes. Said in the+ /// same words as any other failure to encode; told apart so an export+ /// whose phone chip stopped part way through can go again on the CPU.+ #[error("{operation} failed for {path}: {detail}")]+ Stalled {+ /// The step that stopped: "encode".+ operation: &'static str,+ /// The file being written.+ path: PathBuf,+ /// What the encoder stopped taking, and for how long.+ detail: String,+ /// Whether the encoder that stopped was the platform's hardware+ /// rather than the CPU.+ hardware: bool,+ },+/// An IO error on a file this crate reads or writes itself.#[error("io error on {path}")]Io {@@ -98,3 +115,13 @@ pub enum Error {name: String,},}++impl Error {+ /// Whether this is the platform's hardware encoder having stopped part+ /// way through: an export can go again on the CPU, which takes every+ /// frame however slowly. A stall on the CPU, or any other failure, is+ /// not one that going again would mend.+ pub fn stalled_on_hardware(&self) -> bool {+ matches!(self, Error::Stalled { hardware: true, .. })+ }+}diff --git a/src/crates/concat-media/src/probe.rs b/src/crates/concat-media/src/probe.rsindex 175f5ed2..38544ee4 100644--- a/src/crates/concat-media/src/probe.rs+++ b/src/crates/concat-media/src/probe.rs@@ -353,6 +353,7 @@ mod tests {color_range: crate::ColorRange::Limited,hardware: false,threads: 0,+ software_only: false,};let rate = FrameRate::from_int(25);for (name, hdr, want) in [diff --git a/src/crates/concat/locales/ar.json b/src/crates/concat/locales/ar.jsonindex 62efee28..161926c6 100644--- a/src/crates/concat/locales/ar.json+++ b/src/crates/concat/locales/ar.json@@ -255,6 +255,7 @@"export.output": "الإخراج","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "يعمل في كل مكان",+ "export.renderingInSoftware": "إعادة تصيير الفيديو بالمرمّز الأبطأ","export.renderingVideo": "جارٍ تصيير الفيديو","export.replace": "استبدال","export.replaceFileMessage": "{0} موجود بالفعل. سيستبدله التصدير.",diff --git a/src/crates/concat/locales/az.json b/src/crates/concat/locales/az.jsonindex ff79013d..d6f1ee2b 100644--- a/src/crates/concat/locales/az.json+++ b/src/crates/concat/locales/az.json@@ -255,6 +255,7 @@"export.output": "Çıxış","export.photosNotAllowed": "Concat-ın Şəkillər tətbiqinə fayl əlavə etməyə icazəsi yoxdur; icazəni Parametrlər › Concat › Şəkillər bölməsindən verin","export.playsEverywhere": "Hər yerdə oynayır",+ "export.renderingInSoftware": "Daha yavaş kodlayıcı ilə yenidən render olunur","export.renderingVideo": "Video render olunur","export.replace": "Əvəz et","export.replaceFileMessage": "{0} artıq mövcuddur. İxrac onu əvəz edəcək.",diff --git a/src/crates/concat/locales/bn.json b/src/crates/concat/locales/bn.jsonindex d3d82d37..b33ce3d3 100644--- a/src/crates/concat/locales/bn.json+++ b/src/crates/concat/locales/bn.json@@ -255,6 +255,7 @@"export.output": "আউটপুট","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "সব জায়গায় চলে",+ "export.renderingInSoftware": "ধীরগতির এনকোডারে আবার রেন্ডার হচ্ছে","export.renderingVideo": "ভিডিও রেন্ডার হচ্ছে","export.replace": "প্রতিস্থাপন করুন","export.replaceFileMessage": "{0} ইতিমধ্যে বিদ্যমান। এক্সপোর্ট করলে এটি প্রতিস্থাপিত হবে।",diff --git a/src/crates/concat/locales/de.json b/src/crates/concat/locales/de.jsonindex 0f55d518..6f0bc352 100644--- a/src/crates/concat/locales/de.json+++ b/src/crates/concat/locales/de.json@@ -255,6 +255,7 @@"export.output": "Ausgabe","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Läuft überall",+ "export.renderingInSoftware": "Wird mit dem langsameren Encoder neu gerendert","export.renderingVideo": "Video wird gerendert","export.replace": "Ersetzen","export.replaceFileMessage": "{0} ist schon da. Der Export ersetzt sie.",diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.jsonindex e6ddec07..e2a37993 100644--- a/src/crates/concat/locales/en.json+++ b/src/crates/concat/locales/en.json@@ -255,6 +255,7 @@"export.output": "Output","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Plays everywhere",+ "export.renderingInSoftware": "Rendering again on the slower encoder","export.renderingVideo": "Rendering video","export.replace": "Replace","export.replaceFileMessage": "{0} is already there. Exporting replaces it.",diff --git a/src/crates/concat/locales/es.json b/src/crates/concat/locales/es.jsonindex 525ce670..d252f973 100644--- a/src/crates/concat/locales/es.json+++ b/src/crates/concat/locales/es.json@@ -255,6 +255,7 @@"export.output": "Salida","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Se reproduce en todas partes",+ "export.renderingInSoftware": "Renderizando de nuevo con el codificador más lento","export.renderingVideo": "Renderizando el vídeo","export.replace": "Reemplazar","export.replaceFileMessage": "{0} ya existe. Exportar lo reemplaza.",diff --git a/src/crates/concat/locales/fa.json b/src/crates/concat/locales/fa.jsonindex f4b431a0..9a164c17 100644--- a/src/crates/concat/locales/fa.json+++ b/src/crates/concat/locales/fa.json@@ -255,6 +255,7 @@"export.output": "خروجی","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "همهجا قابل پخش است",+ "export.renderingInSoftware": "رندر دوباره با رمزگذار کندتر","export.renderingVideo": "در حال رندر کردن ویدئو","export.replace": "جایگزینی","export.replaceFileMessage": "{0} از قبل وجود دارد. خروجی گرفتن آن را جایگزین میکند.",diff --git a/src/crates/concat/locales/fr.json b/src/crates/concat/locales/fr.jsonindex fe0ff22b..c27d59a4 100644--- a/src/crates/concat/locales/fr.json+++ b/src/crates/concat/locales/fr.json@@ -255,6 +255,7 @@"export.output": "Sortie","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Lisible partout",+ "export.renderingInSoftware": "Nouveau rendu avec l'encodeur plus lent","export.renderingVideo": "Rendu de la vidéo","export.replace": "Remplacer","export.replaceFileMessage": "{0} existe déjà. L’export le remplace.",diff --git a/src/crates/concat/locales/he.json b/src/crates/concat/locales/he.jsonindex 87ee3548..6a91df33 100644--- a/src/crates/concat/locales/he.json+++ b/src/crates/concat/locales/he.json@@ -255,6 +255,7 @@"export.output": "פלט","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "מתנגן בכל מקום",+ "export.renderingInSoftware": "מרנדר שוב עם המקודד האיטי יותר","export.renderingVideo": "מרנדר וידאו","export.replace": "החלפה","export.replaceFileMessage": "{0} כבר קיים. הייצוא יחליף אותו.",diff --git a/src/crates/concat/locales/hi.json b/src/crates/concat/locales/hi.jsonindex 1b209dab..58a6599f 100644--- a/src/crates/concat/locales/hi.json+++ b/src/crates/concat/locales/hi.json@@ -255,6 +255,7 @@"export.output": "आउटपुट","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "हर जगह चलता है",+ "export.renderingInSoftware": "धीमे एन्कोडर पर फिर से रेंडर हो रहा है","export.renderingVideo": "वीडियो रेंडर हो रहा है","export.replace": "बदलें","export.replaceFileMessage": "{0} पहले से मौजूद है। एक्सपोर्ट करने पर यह बदल जाएगी।",diff --git a/src/crates/concat/locales/hr.json b/src/crates/concat/locales/hr.jsonindex 62baa3a6..e6dad334 100644--- a/src/crates/concat/locales/hr.json+++ b/src/crates/concat/locales/hr.json@@ -255,6 +255,7 @@"export.output": "Izlaz","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Radi svugdje",+ "export.renderingInSoftware": "Ponovno renderiranje sporijim koderom","export.renderingVideo": "Renderiranje videa","export.replace": "Zamijeni","export.replaceFileMessage": "{0} već postoji. Izvoz će je zamijeniti.",diff --git a/src/crates/concat/locales/id.json b/src/crates/concat/locales/id.jsonindex 001ad840..bf628424 100644--- a/src/crates/concat/locales/id.json+++ b/src/crates/concat/locales/id.json@@ -255,6 +255,7 @@"export.output": "Keluaran","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Dapat diputar di mana saja",+ "export.renderingInSoftware": "Merender ulang dengan encoder yang lebih lambat","export.renderingVideo": "Merender video","export.replace": "Ganti","export.replaceFileMessage": "{0} sudah ada. Mengekspor akan menggantinya.",diff --git a/src/crates/concat/locales/it.json b/src/crates/concat/locales/it.jsonindex 5222708e..861615a7 100644--- a/src/crates/concat/locales/it.json+++ b/src/crates/concat/locales/it.json@@ -255,6 +255,7 @@"export.output": "Uscita","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Si riproduce ovunque",+ "export.renderingInSoftware": "Nuovo rendering con l'encoder più lento","export.renderingVideo": "Rendering del video","export.replace": "Sostituisci","export.replaceFileMessage": "{0} esiste già. L’esportazione lo sostituisce.",diff --git a/src/crates/concat/locales/ja.json b/src/crates/concat/locales/ja.jsonindex 7f0c553d..570147dd 100644--- a/src/crates/concat/locales/ja.json+++ b/src/crates/concat/locales/ja.json@@ -255,6 +255,7 @@"export.output": "出力","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "どこでも再生可能",+ "export.renderingInSoftware": "低速なエンコーダーで再レンダリング中","export.renderingVideo": "映像をレンダリング中","export.replace": "置き換える","export.replaceFileMessage": "{0} はすでにあります。書き出すと置き換えられます。",diff --git a/src/crates/concat/locales/ko.json b/src/crates/concat/locales/ko.jsonindex fe09b37e..25b2d5a6 100644--- a/src/crates/concat/locales/ko.json+++ b/src/crates/concat/locales/ko.json@@ -255,6 +255,7 @@"export.output": "출력","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "어디서나 재생",+ "export.renderingInSoftware": "더 느린 인코더로 다시 렌더링 중","export.renderingVideo": "영상 렌더링 중","export.replace": "바꾸기","export.replaceFileMessage": "{0} 이(가) 이미 있습니다. 내보내면 바뀝니다.",diff --git a/src/crates/concat/locales/nl.json b/src/crates/concat/locales/nl.jsonindex 519f66f1..a61f0689 100644--- a/src/crates/concat/locales/nl.json+++ b/src/crates/concat/locales/nl.json@@ -255,6 +255,7 @@"export.output": "Uitvoer","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Speelt overal af",+ "export.renderingInSoftware": "Opnieuw renderen met de langzamere encoder","export.renderingVideo": "Video renderen","export.replace": "Vervangen","export.replaceFileMessage": "{0} bestaat al. Exporteren vervangt het.",diff --git a/src/crates/concat/locales/pl.json b/src/crates/concat/locales/pl.jsonindex 23cff4b5..e895b7c2 100644--- a/src/crates/concat/locales/pl.json+++ b/src/crates/concat/locales/pl.json@@ -255,6 +255,7 @@"export.output": "Wyjście","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Odtwarza się wszędzie",+ "export.renderingInSoftware": "Ponowne renderowanie wolniejszym koderem","export.renderingVideo": "Renderowanie wideo","export.replace": "Zastąp","export.replaceFileMessage": "{0} już istnieje. Eksport go zastąpi.",diff --git a/src/crates/concat/locales/pt-BR.json b/src/crates/concat/locales/pt-BR.jsonindex d52fd83f..1b899f84 100644--- a/src/crates/concat/locales/pt-BR.json+++ b/src/crates/concat/locales/pt-BR.json@@ -255,6 +255,7 @@"export.output": "Saída","export.photosNotAllowed": "O Concat não tem permissão para adicionar em Fotos; permita em Ajustes, Concat, Fotos","export.playsEverywhere": "Reproduz em qualquer lugar",+ "export.renderingInSoftware": "Renderizando de novo com o codificador mais lento","export.renderingVideo": "Renderizando o vídeo","export.replace": "Substituir","export.replaceFileMessage": "{0} já existe. Exportar o substitui.",diff --git a/src/crates/concat/locales/ru.json b/src/crates/concat/locales/ru.jsonindex f1831b64..cbcfa2f5 100644--- a/src/crates/concat/locales/ru.json+++ b/src/crates/concat/locales/ru.json@@ -255,6 +255,7 @@"export.output": "Вывод","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Воспроизводится везде",+ "export.renderingInSoftware": "Повторный рендеринг на более медленном кодировщике","export.renderingVideo": "Рендеринг видео","export.replace": "Заменить","export.replaceFileMessage": "{0} уже есть. Экспорт заменит его.",diff --git a/src/crates/concat/locales/th.json b/src/crates/concat/locales/th.jsonindex a4de4a71..e466663a 100644--- a/src/crates/concat/locales/th.json+++ b/src/crates/concat/locales/th.json@@ -255,6 +255,7 @@"export.output": "เอาต์พุต","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "เล่นได้ทุกที่",+ "export.renderingInSoftware": "กำลังเรนเดอร์ใหม่ด้วยตัวเข้ารหัสที่ช้ากว่า","export.renderingVideo": "กำลังเรนเดอร์วิดีโอ","export.replace": "แทนที่","export.replaceFileMessage": "มี {0} อยู่แล้ว การส่งออกจะแทนที่ไฟล์นี้",diff --git a/src/crates/concat/locales/tr.json b/src/crates/concat/locales/tr.jsonindex 3be1d4dd..d1abb4f1 100644--- a/src/crates/concat/locales/tr.json+++ b/src/crates/concat/locales/tr.json@@ -255,6 +255,7 @@"export.output": "Çıktı","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Her yerde oynatılır",+ "export.renderingInSoftware": "Daha yavaş kodlayıcıyla yeniden işleniyor","export.renderingVideo": "Video işleniyor","export.replace": "Değiştir","export.replaceFileMessage": "{0} zaten var. Dışa aktarma onu değiştirir.",diff --git a/src/crates/concat/locales/uk.json b/src/crates/concat/locales/uk.jsonindex 673a0165..436e2f62 100644--- a/src/crates/concat/locales/uk.json+++ b/src/crates/concat/locales/uk.json@@ -255,6 +255,7 @@"export.output": "Вихід","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Відтворюється всюди",+ "export.renderingInSoftware": "Повторний рендеринг повільнішим кодувальником","export.renderingVideo": "Рендеринг відео","export.replace": "Замінити","export.replaceFileMessage": "{0} уже існує. Експорт замінить його.",diff --git a/src/crates/concat/locales/ur.json b/src/crates/concat/locales/ur.jsonindex 67b5bdf1..0af2b197 100644--- a/src/crates/concat/locales/ur.json+++ b/src/crates/concat/locales/ur.json@@ -255,6 +255,7 @@"export.output": "آؤٹ پٹ","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "ہر جگہ چلتا ہے",+ "export.renderingInSoftware": "سست انکوڈر پر دوبارہ رینڈر ہو رہی ہے","export.renderingVideo": "ویڈیو رینڈر ہو رہی ہے","export.replace": "تبدیل کریں","export.replaceFileMessage": "{0} پہلے سے موجود ہے۔ ایکسپورٹ اسے تبدیل کر دے گا۔",diff --git a/src/crates/concat/locales/vi.json b/src/crates/concat/locales/vi.jsonindex d5fee0d5..d4057903 100644--- a/src/crates/concat/locales/vi.json+++ b/src/crates/concat/locales/vi.json@@ -255,6 +255,7 @@"export.output": "Đầu ra","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "Phát được trên mọi thiết bị",+ "export.renderingInSoftware": "Đang kết xuất lại bằng bộ mã hóa chậm hơn","export.renderingVideo": "Đang kết xuất video","export.replace": "Thay thế","export.replaceFileMessage": "{0} đã tồn tại. Khi xuất, tệp này sẽ bị thay thế.",diff --git a/src/crates/concat/locales/zh-Hans.json b/src/crates/concat/locales/zh-Hans.jsonindex 58194c88..66494af0 100644--- a/src/crates/concat/locales/zh-Hans.json+++ b/src/crates/concat/locales/zh-Hans.json@@ -255,6 +255,7 @@"export.output": "输出","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "随处可播",+ "export.renderingInSoftware": "正在用较慢的编码器重新渲染","export.renderingVideo": "正在渲染视频","export.replace": "替换","export.replaceFileMessage": "{0} 已经存在。导出会将其替换。",diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.jsonindex f4bf715f..f5266035 100644--- a/src/crates/concat/locales/zh-TW.json+++ b/src/crates/concat/locales/zh-TW.json@@ -255,6 +255,7 @@"export.output": "輸出","export.photosNotAllowed": "Concat may not add to Photos; allow it under Settings, Concat, Photos","export.playsEverywhere": "隨處可播",+ "export.renderingInSoftware": "正在以較慢的編碼器重新渲染","export.renderingVideo": "正在渲染影片","export.replace": "取代","export.replaceFileMessage": "{0} 已經存在。匯出會將其取代。",diff --git a/src/crates/concat/src/panes/export.rs b/src/crates/concat/src/panes/export.rsindex cea8b388..0222aff4 100644--- a/src/crates/concat/src/panes/export.rs+++ b/src/crates/concat/src/panes/export.rs@@ -195,6 +195,12 @@ impl ExportPane {}ExportMsg::Progress { fraction, stage } => {if self.phase == ExportPhase::Running {+ // Gone back: the export started again from its first+ // frame on the slower encoder, and the time left is+ // reckoned from there.+ if fraction < self.progress {+ self.started_at = Some(std::time::Instant::now());+ }self.progress = fraction.clamp(0.0, 1.0);self.stage = stage;}@@ -471,6 +477,17 @@ impl ExportPane {request.rate_den = den;studio.pause();+ // The monitor's readers that sit idle are closed now rather than+ // ten seconds on by the sweep: on a phone up to three of them hold+ // MediaCodec decoder sessions, which the chip has few of and its+ // encoder and the export's own decoders need. A reader comes back+ // on the next frame the monitor asks of it; the cached frames stay.+ let closed = concat_host::scheduler()+ .pool()+ .close_idle(std::time::Duration::ZERO);+ if closed > 0 {+ log::info!("export: closed {closed} idle preview decoder(s) before starting");+ }self.phase = ExportPhase::Running;self.progress = 0.0;self.stage = t("export.renderingVideo");@@ -498,6 +515,7 @@ impl ExportPane {};let stage = match progress.stage {"rendering" => t("export.renderingVideo"),+ concat_export::RENDERING_IN_SOFTWARE => t("export.renderingInSoftware"),"mixing audio" => t("export.mixingAudio"),"muxing" => t("export.finalisingFile"),other => other.to_owned(),diff --git a/src/crates/concat/src/studio/consolidate.rs b/src/crates/concat/src/studio/consolidate.rsindex caa119cf..809a52cf 100644--- a/src/crates/concat/src/studio/consolidate.rs+++ b/src/crates/concat/src/studio/consolidate.rs@@ -131,7 +131,9 @@ impl Studio {|progress| {let fraction =(progress.frame as f32 / progress.total.max(1) as f32).clamp(0.0, 1.0);- if fraction - last >= 0.02 {+ // Down as well as up: an export whose hardware+ // encoder stopped starts again from nothing.+ if fraction - last >= 0.02 || fraction < last {last = fraction;on_ui_in_project(epoch, move |studio, _, _| {if let Some(job) = studio.merge_job.as_mut() {