Converting video in remote shell going error

Hi everyone, I hope you are well.

this code works fine on my local machine, but not on remote shell. iterating through each video and converting. why will it be?

// HANDBRAKE CLI
use std::process::{Command, Stdio}; 
use std::{fs, io};
// ==================== CONSTANTS
const DESTINY: &str = "/home/pichi/01_HANDBRAKE/";
const PRESETS: &str = "/home/pichi/01_HANDBRAKE/presets/";

// ==================== FUNCTIONS
fn handbrakecli(preset: &u32, aud: &String, sub: &String, src: &String, dst: &String) {    
    let preset_720 = String::from(PRESETS.to_owned()+"mp4720x480.json");    
    let preset_720_z = String::from("mp4720x480");
    let preset_1280 = String::from(PRESETS.to_owned()+"mp41280x720.json");
    let preset_1280_z = String::from("mp41280x720");
    
    // var store result
    let mut preset_file = String::new();
    let mut preset_z = String::new();
    match preset {
        1 => { preset_file = preset_720;
                 preset_z = preset_720_z;
            },
        2 => { preset_file = preset_1280;
                 preset_z = preset_1280_z;        
            },
        _ => println!("End de presets"),
    };    
    
    let salida = Command::new("HandBrakeCLI")
    .arg("-v")
    .arg("--preset-import-file")
    .arg(&preset_file)
    .arg("-Z")
    .arg(&preset_z)
    .arg("-a")
    .arg(&aud) // audio tracks (ej. 1 or 1,2)
    .arg("-s")
    .arg(&sub) // subtitle tracks (ej. 1 or 1,2)
    .arg("-i")
    .arg(&src) // origin
    .arg("-o")
    .arg(&dst) //destiny    
    .stdout(Stdio::piped())
    .output()
    .expect("Failed to execute command");
}

fn main() {
    println!(" ** HANDBRAKE CLI ** ");
    
    // var to store result for handbrakecli
    //let mut aud_track: &str = ""; // 1 or 1,2
    let mut preset: u32 = 0;
    let mut aud_track = String::new();
    let mut sub_track = String::new();
    
    // reading preset
    loop {
        println!("Give me preset or resolution:
        1 >  720x480
        2 > 1280x720
        ");
        let mut input = String::new();
        let stdin_preset = io::stdin();
        stdin_preset.read_line(&mut input).unwrap();
        match input.trim_end() { // this method kill "\n" at the end
            "1" => { println!("Select 720x480!");
                    preset = 1; break;
                },
            "2" => { println!("Select 1280x720!");
                    preset = 2; break;
                },
            _ => println!("incorrect !. Choose 1 or 2"),                
        }
    }
    
    // reading audio track
    println!("give me audio tracks (Ej. 1 or 1,2):");
    let stdin_audio = io::stdin();
    stdin_audio.read_line(&mut aud_track).unwrap(); // "match" is handle for ".unwrap()"
    println!("Pista de audio: {} ", &aud_track);
    
    // reading subtitle track
    println!("Dame subtitulos (Ej. 1 or 1,2):");
    let stdin_subtitle = io::stdin();
    stdin_subtitle.read_line(&mut sub_track).unwrap();
    println!("Pista de subtitulo: {} ", &sub_track);
    
    // reading video folder
    println!("Get video folder:");
    let mut video_folder = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut video_folder).unwrap();
    println!("Video folder: {} ", video_folder);
    
    // read files in dir    
    for file in fs::read_dir(video_folder.replace("\n", "")).unwrap() {
        let video_src = &file.unwrap().path().display().to_string();
        let video_src_split = video_src.split("/");
        let mut vector = Vec::new();
        for a in video_src_split {                        
            vector.push(a);
        }
        let video_name = vector[vector.len()-1];
        // split extension to take mp4
        let video_split = video_name.split(".");
        let mut video_vector = Vec::new();
        for a in video_split {
            //println!("{}", a);
            video_vector.push(a);
        }
        let video_mp4 = video_vector[0];        
        let destiny = String::from(DESTINY.to_owned() + &video_mp4);
        println!("Video name: {} ", &video_name);
        println!("Video destiny: {} ", &destiny);
        
        handbrakecli(&preset, &aud_track, &sub_track, &video_src, &destiny);
    }
}

OUTPUT ERROR:
thread 'main' panicked at 'Failed to execute command: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:1188:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

Looks like HandBrakeCLI isn't in your path:

1 Like

You could use the fs_err crate to get more helpful and informative error messages, in this case including the exact file name that was not found / is not present.

It can be used as a drop-in-replacement of std::fs (after installing it via cargo add fs_err) like this:

use fs_err as fs;

and then removing the import of std::fs.

1 Like

Thanks, handbrake was missing.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.