Package videoconverter

Source Code of videoconverter.Video

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package videoconverter;

import java.io.IOException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
*
* @author daniel
*/
public class Video implements Archivos{
    String ruta;
   
    public Video(String ruta){
        this.ruta   = ruta;
    }

    @Override
    public void convertir(String destino) {
       
        System.out.println("Vamos a convertir: " + ruta);
        ProcessBuilder pb    = new ProcessBuilder("ffmpeg","-i","PELICULAS/" + ruta,"-y","prueba.webm");
        Process pro = null;
        try {
            pro   = pb.start();
        } catch (IOException ex) {
            Logger.getLogger(Video.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        pb.redirectErrorStream(true);
        Scanner sc    = new Scanner(pro.getErrorStream());
       
        System.out.println("Empezamos");
       
        Pattern durPattern = Pattern.compile("(?<=Duration: )[^,]*");
        String dur = sc.findWithinHorizon(durPattern, 0);
       
        if (dur == null)
                throw new RuntimeException("No se puede parsear la duración");
        String[] hms = dur.split(":");
       
        double totalSecs = Integer.parseInt(hms[0]) * 3600
                + Integer.parseInt(hms[1]) * 60
                + Double.parseDouble(hms[2]);
       
        System.out.println("Duración total: " + totalSecs + " segundos");
       
        Pattern timePattern = Pattern.compile("(?<=time=)[\\d.]*");
        String match;
        while (null != (match = sc.findWithinHorizon(timePattern, 0))) {
            double progress = Double.parseDouble(match) / totalSecs;
            System.out.printf("Progreso: %.2f%%%n", progress * 100);
        }
       
        System.out.println("Terminamos");

        return;
    }

    @Override
    public void mover(String destino) {
        /*
        Aquí el código para mover el fichero
        */
    }

    @Override
    public String getNombre() {
        return ruta;
    }
}
TOP

Related Classes of videoconverter.Video

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.