Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate walkdir;
- use std::fs;
- use std::env;
- use std::io;
- use std::string::ToString;
- use std::process::Command;
- use std::path::Path;
- use walkdir::WalkDir;
- fn parse_dir(dir: &Path) {
- let paths = WalkDir::new(dir);
- for path in paths {
- let file = path.unwrap().path().display().to_string(); //convert std::path to string
- if file.contains(".mp4") {
- let new_file = file.clone() + ".encoded";
- encode(&file, &new_file);
- }
- }
- }
- fn encode(file: &str, new_file: &str) {
- let encoding = Command::new("ffmpeg").arg("-i").arg(file).arg("-f").arg("mp4").arg(new_file).output().unwrap_or_else(|e| {
- panic!("failed to execute process: {}", e);
- });
- println!("{}", String::from_utf8_lossy(&encoding.stdout));
- let new_name = file.clone().to_string() + ".old";
- rename_files(file, &new_name);
- rename_files(new_file, file);
- }
- fn rename_files(file: &str, new_name: &str) -> io::Result<()> {
- try!(fs::rename(file, new_name));
- Ok(())
- }
- fn check_dir(dir: &Path) -> io::Result<()> {
- if try!(fs::metadata(dir)).is_dir() {
- parse_dir(dir);
- }
- Ok(())
- }
- fn main() {
- let args: Vec<String> = env::args().collect();
- if args.len() > 1 {
- let dir = Path::new(&args[1]);
- check_dir(dir);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement