1

My objective is to create a named pipe(fifo) in windows(java), write some data(coming from camera) into that and invoke ffmpeg command to make mp4 from that data. But I suspect that it is not opening a fifo pipe, rather it is opening a file. How can I make it open a fifo pipe? Here is the code :

public void run () {
String mp4Folder = "C://Users/user_2/Desktop/streamDestination";            // Where the MP4 is to be kept
VFrame frame = null;
int actualPipeValLen = 0;
FileOutputStream requestStream = null;
long lastProcessedTS = 0;
final String FIFOPATH = "D://FIFO//";
final String PIPE_NAME = FIFOPATH + "myfifo";
final String MKFIFOCOMMAND = "mkfifo -m=rw " + PIPE_NAME;
final String DELFIFOCOMMAND = "rm -r " + PIPE_NAME;
String mp4FileName = mp4Folder + File.separator + "1.mp4";
mp4FileName = mp4FileName.replace("\\", "/");
long firstTimeStamp = 0;
try {
    Runtime.getRuntime().exec(MKFIFOCOMMAND);
} catch (IOException e1) {
    e1.printStackTrace();
}
if(firstTimeStamp == 0) {
    firstTimeStamp = frame.getTimestamp();
}
if((frame.getTimestamp() - firstTimeStamp) > (15 * 1000)) {
    if(requestStream != null) {
        requestStream.close();
        requestStream = null;
    }
    if(actualPipeValLen > 0) {
        String[] ffmpeg = new String[] {"ffmpeg", "-i", PIPE_NAME , "-vcodec", "copy", mp4FileName };
        Process ffmpegProcess = Runtime.getRuntime().exec(ffmpeg);
        actualPipeValLen = 0;
        firstTimeStamp = lastProcessedTS;
        Thread.sleep(2 * 1000);
        try {
            Runtime.getRuntime().exec(DELFIFOCOMMAND);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        System.exit(0);
    }
} else {
    System.out.println("Writing into pipe : " + actualPipeValLen);
    if(requestStream == null) {
        requestStream = new  FileOutputStream(PIPE_NAME);
    }
    requestStream.write(frame.getFrame());
    actualPipeValLen += frame.getFrame().length;
    lastProcessedTS = frame.getTimestamp();
}

}

sourav
  • 113
  • 2
  • 15

0 Answers0