Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JAVA for Video File

KkusApr 24 2017 — edited Jun 22 2017

Dear All Community Member,

I want to asking the question is that when i write a program in java to split video file like(.mp4,.wmv,.flv,etc.) after split one part is running video but rest part not shown anything ..... and after merging file it runs complete videos.... how it is possible...

my code is here.....

import java.io.*;

public class SplitVideoFile {

    public static void main(String[] args) {

        try {

            File file = new File("F:/kri.jpg");//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("F:"+ 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 = 2;// 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();

    }

}

}

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 20 2017
Added on Apr 24 2017
4 comments
3,213 views