fix broken mp3/aac export
This commit is contained in:
@@ -196,26 +196,13 @@ fn export_audio_ffmpeg_mp3<P: AsRef<Path>>(
|
||||
frame.set_rate(settings.sample_rate);
|
||||
|
||||
// Copy planar samples to frame
|
||||
// Use plane_mut::<i16> instead of data_mut — data_mut(ch) is buggy for planar audio:
|
||||
// FFmpeg only sets linesize[0], so data_mut returns 0-length slices for ch > 0.
|
||||
// plane_mut uses self.samples() for the length, which is correct for all planes.
|
||||
for ch in 0..settings.channels as usize {
|
||||
let plane = frame.data_mut(ch);
|
||||
let plane = frame.plane_mut::<i16>(ch);
|
||||
let offset = samples_encoded;
|
||||
let src = &planar_samples[ch][offset..offset + chunk_size];
|
||||
|
||||
// Convert i16 samples to bytes and copy
|
||||
let byte_size = chunk_size * std::mem::size_of::<i16>();
|
||||
if plane.len() < byte_size {
|
||||
return Err(format!(
|
||||
"FFmpeg frame buffer too small: {} bytes, need {} bytes",
|
||||
plane.len(), byte_size
|
||||
));
|
||||
}
|
||||
|
||||
// Safe byte-level copy using slice operations
|
||||
for (i, &sample) in src.iter().enumerate() {
|
||||
let bytes = sample.to_ne_bytes();
|
||||
let offset = i * 2;
|
||||
plane[offset..offset + 2].copy_from_slice(&bytes);
|
||||
}
|
||||
plane.copy_from_slice(&planar_samples[ch][offset..offset + chunk_size]);
|
||||
}
|
||||
|
||||
// Send frame to encoder
|
||||
|
||||
@@ -88,21 +88,19 @@ impl ExportDialog {
|
||||
|
||||
let mut should_export = false;
|
||||
let mut should_close = false;
|
||||
let mut open = self.open;
|
||||
|
||||
let window_title = match self.export_type {
|
||||
ExportType::Audio => "Export Audio",
|
||||
ExportType::Video => "Export Video",
|
||||
};
|
||||
|
||||
egui::Window::new(window_title)
|
||||
.open(&mut open)
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
|
||||
let modal_response = egui::Modal::new(egui::Id::new("export_dialog_modal"))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(500.0);
|
||||
|
||||
ui.heading(window_title);
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Error message (if any)
|
||||
if let Some(error) = &self.error_message {
|
||||
ui.colored_label(egui::Color32::RED, error);
|
||||
@@ -151,8 +149,10 @@ impl ExportDialog {
|
||||
});
|
||||
});
|
||||
|
||||
// Update open state (in case user clicked X button)
|
||||
self.open = open;
|
||||
// Close on backdrop click or escape
|
||||
if modal_response.backdrop_response.clicked() {
|
||||
should_close = true;
|
||||
}
|
||||
|
||||
if should_close {
|
||||
self.close();
|
||||
@@ -529,14 +529,13 @@ impl ExportProgressDialog {
|
||||
|
||||
let mut should_cancel = false;
|
||||
|
||||
egui::Window::new("Exporting...")
|
||||
.open(&mut self.open)
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
|
||||
egui::Modal::new(egui::Id::new("export_progress_modal"))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(400.0);
|
||||
|
||||
ui.heading("Exporting...");
|
||||
ui.add_space(8.0);
|
||||
|
||||
// Status message
|
||||
ui.label(&self.message);
|
||||
ui.add_space(8.0);
|
||||
|
||||
@@ -479,9 +479,11 @@ impl ExportOrchestrator {
|
||||
) {
|
||||
println!("🧵 [EXPORT THREAD] run_audio_export started");
|
||||
|
||||
// Send start notification
|
||||
// Send start notification with calculated total frames
|
||||
let duration = settings.end_time - settings.start_time;
|
||||
let total_frames = (duration * settings.sample_rate as f64).round() as usize;
|
||||
progress_tx
|
||||
.send(ExportProgress::Started { total_frames: 0 })
|
||||
.send(ExportProgress::Started { total_frames })
|
||||
.ok();
|
||||
println!("🧵 [EXPORT THREAD] Sent Started progress");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user