There is a code on the client side:

try { socket = new Socket(InetAddress.getByName(hostname), port); pfd = ParcelFileDescriptor.fromSocket(socket); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } recorder.setOutputFile(pfd.getFileDescriptor()); // String filename = String.format("/sdcard/%d.mp4", System.currentTimeMillis()); // // recorder.setOutputFile(filename); try { recorder.prepare(); recorder.start(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } 

and the code of the server itself:

 try { System.out.println("create sock"); ServerSocket svsock = new ServerSocket(1935); System.out.println("accept"); Socket sock = svsock.accept(); System.out.println("buffer read"); FileOutputStream outFile = null; String filename = String.format("%d.mp4", System.currentTimeMillis()); try { outFile = new FileOutputStream(filename); System.out.println(filename); } catch (IOException e1) { e1.printStackTrace(); } InputStream is = new DataInputStream(sock.getInputStream()); byte[] byteBuffer = new byte[1024]; int allsize = 0; while(sock.isConnected()) { int size = is.read(byteBuffer); if (size == -1){ break; } else { outFile.write(byteBuffer, 0, size); } allsize += size; } System.out.println("close size=" + allsize); outFile.close(); sock.close(); } catch(Exception e) { e.printStackTrace(); } System.out.println("endmain"); } } 

When you run the application on Android 2.2.2 (HTC quiet brilliant) everything works fine. I press the button opens a socket on the server, which writes data to a file. And this file is then successfully played by the same VLC player.

However, when I test on Android 4.0.4 (Galaxy S2), the server also creates a file and writes data to it, but when I try to play the VLC file, I get an error

mp4 error: no moov, foov, moof box avcodec error for example file for: file /: / //C:/1345461283455.mp4 '

Other players also refuse to play it. (I even tried downloading on youtube, but he also gave me a file format error). Moreover, if I do not write to the server and write to the phone's sdcard, then everything is perfectly created and played.

There may be an error on the server side, as well as some new API 15 (4.0.4). Maybe something needs to be added to getFileDescriptor (), etc.

Help advice please. I googled a long time and unsuccessfully before rolling such a huge question :)

    1 answer 1

    The log correctly diagnosed the problem for you - the device does not have the correct codec. Install the desired codec and everything.

    There is a certain minimum set of codecs that must be supported according to the standard , and everything else is at the discretion of the vendor of a particular device.

    • So the fact is that I use the standard ones: recorder.setVideoSource (MediaRecorder.VideoSource.CAMERA); recorder.setOutputFormat (MediaRecorder.OutputFormat.MPEG_4); recorder.setVideoEncoder (MediaRecorder.VideoEncoder.DEFAULT); (I tried all the available methods OutputFormat.THREE_GPP, VideoEncoder.H264, H263, etc.) But it gives the same error. while I'm sure that there is a codec (on sdcard, it also records and loses everywhere) - Sever