0

So, I have this video in .mp4 format and I've converted it into bytes and sent to my server and written the bytes to a file.

When I try to open the new file, it says, 'No Proper Codec found' or something like that.

So, How do I transfer the video to client with the codec so it can play at my server end.

Clinet.java

File file = new File("/Users/Batman/Documents/Eclipse/Record/outo.flv");
    InputStream is = new FileInputStream(file);
    OutputStream os = RTSPSocket.getOutputStream();
    long len = file.length();
    byte[] bytes = new byte[(int) len];
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
        offset += numRead;
    }
    String s = String.valueOf(len);
    RTSPBufferedWriter.write(s);
    RTSPBufferedWriter.flush();
        os.write(bytes);
    os.close();
    is.close();

Server.java

inputStream = socket.getInputStream();
                byte[] bytes = new byte[1415874];
                for (int i = 0; i < bytes.length; i++) {
                    fileOutputStream.write(inputStream.read(bytes));
                }
                fileOutputStream.close();
                inputStream.close();

Thanks

Spark
  • 371
  • 6
  • 15

1 Answers1

0

You're sending the length in ASCII but you're never reading it separately. Instead you are assuming a hardwired length of 1415874. So the length is still there in the input and gets written to the target file.

Sending the length in ASCII without a delimiter won't work anyway, as you don't know at the receiving end how long the length is. You should send the length as a long, using DataOutputStream.writeLong(), and reading it via DataInputStream.readLong(). In fact you should proceed as given in this answer.

Community
  • 1
  • 1
user207421
  • 305,947
  • 44
  • 307
  • 483
  • I've tried it using DataOutput and Input Streams. I'm able to send the bytes to the destination file, but again, unable to play the recorded video – Spark May 04 '16 at 02:21
  • I'm unable to do it for .mp4 but was able to do it for .flv format. But I need this for mp4 video. Any help is appreciated – Spark May 04 '16 at 02:29
  • 1
    It shouldn't make any difference what the format is. It's only bits. Double-check your code against mine in the link, and don't get creative. Copy it. – user207421 May 04 '16 at 08:41