@@ -396,6 +396,9 @@ async fn process_job(job: Job) -> Result<()> {
396396 let mut current_speed: Option < String > = None ;
397397 let mut total_duration: Option < String > = None ;
398398 let mut last_report = std:: time:: Instant :: now ( ) ;
399+ let mut progress_count = 0u32 ;
400+
401+ info ! ( "Starting to read FFmpeg progress from stdout..." ) ;
399402
400403 while let Ok ( Some ( line) ) = lines. next_line ( ) . await {
401404 // Parse FFmpeg progress output format:
@@ -420,9 +423,12 @@ async fn process_job(job: Job) -> Result<()> {
420423 } else if let Some ( value) = line. strip_prefix ( "duration=" ) {
421424 total_duration = Some ( value. trim ( ) . to_string ( ) ) ;
422425 } else if line. starts_with ( "progress=" ) {
426+ progress_count += 1 ;
423427 // End of a progress block - report to server (throttled)
424428 if last_report. elapsed ( ) >= std:: time:: Duration :: from_secs ( 2 ) {
425429 if let Some ( queue_url) = & queue_url_clone {
430+ info ! ( "Sending progress update #{}: frame={:?}, time={:?}, speed={:?}" ,
431+ progress_count, current_frame, current_time, current_speed) ;
426432 let progress = JobProgress {
427433 frame : current_frame,
428434 total_frames : None ,
@@ -432,28 +438,50 @@ async fn process_job(job: Job) -> Result<()> {
432438 percent : None , // Could calculate from time/duration
433439 stage : Some ( "Encoding" . to_string ( ) ) ,
434440 } ;
435- let _ = update_job_progress_remote ( queue_url, & job_id_clone, progress) . await ;
441+ match update_job_progress_remote ( queue_url, & job_id_clone, progress) . await {
442+ Ok ( _) => info ! ( "Progress update sent successfully" ) ,
443+ Err ( e) => error ! ( "Failed to send progress update: {}" , e) ,
444+ }
436445 }
437446 last_report = std:: time:: Instant :: now ( ) ;
438447 }
439448 }
440449 }
450+ info ! ( "Finished reading FFmpeg progress. Total progress blocks: {}" , progress_count) ;
451+ } else {
452+ warn ! ( "No stdout available from FFmpeg process" ) ;
441453 }
442454 } ) ;
443455
456+ // Read stderr in a separate task
457+ let stderr_handle = {
458+ let stderr = child. stderr . take ( ) ;
459+ tokio:: spawn ( async move {
460+ if let Some ( stderr) = stderr {
461+ use tokio:: io:: AsyncReadExt ;
462+ let mut buf = String :: new ( ) ;
463+ let mut reader = tokio:: io:: BufReader :: new ( stderr) ;
464+ let _ = reader. read_to_string ( & mut buf) . await ;
465+ buf
466+ } else {
467+ String :: new ( )
468+ }
469+ } )
470+ } ;
471+
444472 // Wait for FFmpeg to complete
445- let output = child. wait_with_output ( ) . await ?;
473+ let status = child. wait ( ) . await ?;
446474
447- // Wait for progress parsing to finish
475+ // Wait for progress parsing and stderr reading to finish
448476 let _ = progress_handle. await ;
477+ let stderr = stderr_handle. await . unwrap_or_default ( ) ;
449478
450- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
451- info ! ( "FFmpeg exit status: {}" , output. status) ;
479+ info ! ( "FFmpeg exit status: {}" , status) ;
452480 if !stderr. is_empty ( ) {
453481 info ! ( "FFmpeg stderr: {}" , stderr) ;
454482 }
455483
456- if output . status . success ( ) {
484+ if status. success ( ) {
457485 info ! ( "FFmpeg processing successful!" ) ;
458486
459487 // Report upload stage
@@ -512,7 +540,7 @@ async fn process_job(job: Job) -> Result<()> {
512540 }
513541 }
514542 } else {
515- error ! ( "FFmpeg FAILED with exit code: {}" , output . status) ;
543+ error ! ( "FFmpeg FAILED with exit code: {}" , status) ;
516544
517545 if let Some ( queue_url) = & job. webdav_config . queue_url {
518546 let _ = update_job_status_remote ( queue_url, & job. id , JobStatus :: Failed , None ) . await ;
0 commit comments