在特定点使用JAVA / JSP或Javascript切割视频

时间:2015-03-08 06:15:25

标签: java jsp video

我正在创建一个用户可以观看视频的网站。我想为用户提供功能,他可以在这里切割视频的一部分并保存到其驱动器(在本地主机上执行)。我设计了由两个按钮(起点和终点)组成的视频播放器。当用户点击开始和终点按钮时,它应该只剪切该特定部分。

问题 -

  1. 当用户点击这些按钮时,如何在变量中存储起点和终点[即时间]?

  2. 是否可以使用javascript进行上述操作?

  3. 鉴于代码将视频分成相等的部分。我想将视频从1.15分钟剪切到2.30分钟。

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    public class SplitVideoFile {
    public static void main(String[] args) {
        try {
            File file = new File("C:/Documents and Settings/Despicable Me 2 - Trailer (HD) - YouTube.mp4");//File read from Source folder to Split.
            if (file.exists()) {
    
            String videoFileName = file.getName().substring(0, file.getName().lastIndexOf(".")); // Name of the videoFile without extension
            File splitFile = new File("C:/Documents and Settings/Videos_Split/"+ videoFileName);//Destination folder to save.
            if (!splitFile.exists()) {
                splitFile.mkdirs();
                System.out.println("Directory Created -> "+ splitFile.getAbsolutePath());
            }
    
            int i = 01;// Files count starts from 1
            InputStream inputStream = new FileInputStream(file);
            String videoFile = splitFile.getAbsolutePath() +"/"+ String.format("%02d", i) +"_"+ file.getName();// Location to save the files which are Split from the original file.
            OutputStream outputStream = new FileOutputStream(videoFile);
            System.out.println("File Created Location: "+ videoFile);
            int totalPartsToSplit = 20;// Total files to split.
            int splitSize = inputStream.available() / totalPartsToSplit;
            int streamSize = 0;
            int read = 0;
            while ((read = inputStream.read()) != -1) {
    
                if (splitSize == streamSize) {
                    if (i != totalPartsToSplit) {
                        i++;
                        String fileCount = String.format("%02d", i); // output will be 1 is 01, 2 is 02
                        videoFile = splitFile.getAbsolutePath() +"/"+ fileCount +"_"+ file.getName();
                        outputStream = new FileOutputStream(videoFile);
                        System.out.println("File Created Location: "+ videoFile);
                        streamSize = 0;
                    }
                }
                outputStream.write(read);
                streamSize++;
            }
    
            inputStream.close();
            outputStream.close();
            System.out.println("Total files Split ->"+ totalPartsToSplit);
        } else {
            System.err.println(file.getAbsolutePath() +" File Not Found.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    }
    }
    

0 个答案:

没有答案