mutaphore / RTSP-Client-Server

Implementation of a streaming video server and client that communicate using the Real-Time Streaming Protocol (RTSP) and send data using the Realtime Transfer Protocol (RTP)
522 stars 191 forks source link

VideoStream.getnextframe() problem #4

Closed ghost closed 7 years ago

ghost commented 7 years ago

Exception in thread "main" java.lang.NumberFormatException: For input string: " at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:569) at java.lang.Integer.parseInt(Integer.java:615) at VideoStream.getnextframe(VideoStream.java:35) at testing.main(testing.java:14)

mutaphore commented 7 years ago

Can you post the code you were running when this exception was thrown?

ghost commented 7 years ago

import java.io.*;

public class VideoStream {

FileInputStream fis;
int frame_nb; 

public VideoStream(String filename) throws Exception{
    fis = new FileInputStream(filename);
    frame_nb = 0;
}

public int getnextframe(byte[] frame) throws Exception
{
    int length = 0;
    String length_string;
    byte[] frame_length = new byte[5];

    fis.read(frame_length,0,5);

    length_string = new String(frame_length);
    length = Integer.parseInt(length_string);   // here's give me  NumberformatException

    return(fis.read(frame,0,length));
}

}

mutaphore commented 7 years ago

The first 5 bytes in the video frame it is expecting an integer which tells it how much to read. Looks like the error was thrown when it can't parse the integer. Are you using a different video than the one provided in this project? If you do a printf on length_string you could see what is the string that is causing the problem.

mutaphore commented 7 years ago

Closing this issue