Saved video file only has one video frame
Ran the sample on a Galaxy S6. The video file is saved, but when pulling the video file and playing it on the desktop it only has audio and 1 frame of video. The video appears to be frozen in playback.
Any ideas? Perhaps the surface list is not getting updated correctly by the background handler in the capture session? The preview surface is updated correctly, just not the mediarecorder surface.
update. when I view the files saved on the device something weird happens. The audio plays completely and then the video animates after the audio completes. When you look at the video playback controls the video starts when it looks like the playback is at the end of the video. Could this be an issue with how I have setup the mediarecorder? I have repro'ed this on two devices.
If I do not configure the audio source on the media recorder then the video plays back as expected. Once I add the MIC source to the media encoder the problem appears.
I am having the same issue. @twisnowski did you manage to fix this?
@saurabharora90 Sorry, no fix. Do you still see the issue?
@twisnowski yes I still see it
I'm running into a similar issue with my Galaxy S7 Edge running Marshmallow.
I've got the Galaxy Tab S2 9.7 running Lollipop and it runs on that no problem. I've also tested on my Nexus 7 LTE running Marshmallow and it runs on that as well.
I'm guessing this must be a limitation or some kind of change in the code that Samsung made with Touchwiz on the Marshmallow.
Has anyone had any luck getting this to work on their Samsung? I'm unable to even get the Mediarecorder to run through prepare if I try to omit the setting of the audiosource.
The issue is a deep sleep problem on some devices running Marshmallow. It appears to be CPU related as an S7 on Verizon doesn't have the issue, but an S7 on AT&T does have the issue. I've seen this on an S6 Verizon phone when it updated to Marshmallow.
In order to replicate, reboot a device while connected to USB. Run the sample. All should be ok. Then, disconnect the device, let it go into deep sleep (screen off, no movement for 5? minutes), and try again. The issue will appear once the device has gone into deep sleep.
The root cause is that the first sample of the recorded video has a duration that is ginormous, making the player believe the first frame should be displayed for a very long time, which is the symptom of it looking like just one frame of video. Use mp4parser and look at the video track's decodingTimes. You can see the difference from a good and bad decoding time in the attached files.
I understand this is a known issue in deep sleep but cannot find the issue quickly on google developers. I'm currently trying to use mp4parser to rewrite that one sample's duration, but I'm not an expert mp4parser guy.
Interesting. I tried doing the reboot and you are right, it worked like a charm. Really weird.
I may have to delve a little deeper...
Thanks for the insight!
Here is my workaround. For a 5 minute recording on an S6, it was about a 700MB mp4 file. This processing took about 20 seconds to read and rewrite that file:
DataSource channel = new FileDataSourceImpl(rawFile);
IsoFile isoFile = new IsoFile(channel);
List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);
boolean sampleError = false;
for (TrackBox trackBox : trackBoxes) {
TimeToSampleBox.Entry firstEntry = trackBox.getMediaBox().getMediaInformationBox().getSampleTableBox().getTimeToSampleBox().getEntries().get(0);
// Detect if first sample is a problem and fix it in isoFile
// This is a hack. The audio deltas are 1024 for my files, and video deltas about 3000
// 10000 seems sufficient since for 30 fps the normal delta is about 3000
if(firstEntry.getDelta() > 10000) {
sampleError = true;
firstEntry.setDelta(3000);
}
}
if(sampleError) {
Movie movie = new Movie();
for (TrackBox trackBox : trackBoxes) {
movie.addTrack(new Mp4TrackImpl(channel.toString() + "[" + trackBox.getTrackHeaderBox().getTrackId() + "]" , trackBox));
}
movie.setMatrix(isoFile.getMovieBox().getMovieHeaderBox().getMatrix());
Container out = new DefaultMp4Builder().build(movie);
//delete file first!
FileChannel fc = new RandomAccessFile(rawFile.getName(), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Log.d(TAG, "Finished correcting raw video");
}
I've also come across the same issue, glad to see it's not just me! The fix above worked great for me, however I need the recorded video to be played on some older device's HTML video elements (which don't support the ISO type, just plain old MP4s).
I'm wondering @cybaker , as you mentioned the initial 'deep sleep' problem, if you had any further insight into what's actually causing the problem? How did you come to the conclusion? Is there anything low level that can be accessed to analyse/control this behaviour? i.e, is there a way to "kick" the device and media recorder out of this glitchy state?
I am having the same issue too..so sad!!,ony on Samsung S6
Any update on this issue?
@cybaker getting NPA function getMovieBox() on line
List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);
I'm getting same issue in both S6 and S7. Video has complete audio but 1 frame of video. It appears to be frozen in playback.
Any solution about this ? is google team or other team working on it to fix it ?
thank you.
@cybaker Can you tell me what tool you using to parser MP4.
I am also getting the same issue, is there are any fix for this, getting this on my production application.
Hello
I am also facing the same issue for all samsung devices.
I also tried this given by @cybaker but the same issue which is mentioned in comment .
Apart from the above also tried below things using mp4 parser but still the issue is not resolved.(7 seconds track converted to more thn 30 mnts by trying below things and given by @cybaker )
- Extracted audio track from video
- Extracted video track from video
- Merged Video And Audio
If anyone can get solutions please post it.
Thanks
My Verizon Galaxy S7 Edge on 7.0 has the same issue.
Has anyone been able to find a solution?
I run android-Camera2Video in s6 and s7 video recorded and save in sdcard. but when we preview the saved video then video freeze but sound played. Kindly let me know what is the solution for given devices.