I am working on live device to server streaming in android. I am able to send data in bytes on server but when i play that file during recording on server VLC
Run qt_faststart to move the moov atom to the beginning of the stream.
qt-faststart in.mp4 out.mp4
In my case ffmpeg wouldn't even let me recreate the container using:
ffmpeg -i video.mp4 -c copy out.mp4
It failed with the same corrupted STCO atom
error.
I was able to fix this problem by opening up the video file in avidemux and re-exporting the video without encoding.
Then ffmpeg could read this file without problems.
There is a tool untrunc which claims to repair unfinished (truncated) mp4, m4v, mov, 3gp video. I haven't tested it myself but it may be worth a try.
Add to your gradle this lib: compile 'net.ypresto.qtfaststartjava:qtfaststart:0.1.0' and then
File input = new File(path + "/input.mp4"); // Your input file
File output = new File(path + "/output.mp4"); // Your output file
try{
if(!output.exists()) // if there is no output file we'll create one
output.createNewFile();
}
}catch (IOException e){
Log.e("TAG", e.toString());
}
try{
QtFastStart.fastStart(input, output); // Adds moov to your input
// Now your output file is ready to stream!
}catch (QtFastStart.MalformedFileException m){
Log.e("QT", m.toString());
}catch (QtFastStart.UnsupportedFileException q){
Log.e("QT", q.toString());
}catch (IOException i){
Log.e("QT", i.toString());
}
Here that's all
It is possible to move the moov atom to the begining of the video file using FFMpeg.
ffmpeg -i input_video_file.mp4 -vcodec copy -acodec copy -movflags faststart output_video_file.mp4
the mp4 format needs the moov atom information to play the video, and to generate the moov atom the video must be finished, you can't play a mp4 file while it is recording because you still don't have all the information to create the moov atom part.
What you want to do is some kind of real-time-streaming (play while is recroding) so you need to use another formats. HLS streaming and mpeg-dash stores the video in tiny chunks (2seconds to 10seconds) and send to the users, this way the users plays many finished files one after the other.
as @Sebastian Annies suggested, to create many tiny mp4 files and concatenate is the same approach: to have tiny finished files and play as a list, here you could get more information What exactly is Fragmented mp4(fMP4)? How is it different from normal mp4?