android-Camera2Video icon indicating copy to clipboard operation
android-Camera2Video copied to clipboard

Saved video file only has one video frame

Open tom-wisnowski opened this issue 10 years ago • 39 comments

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.

tom-wisnowski avatar Mar 06 '16 18:03 tom-wisnowski

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.

tom-wisnowski avatar Mar 06 '16 20:03 tom-wisnowski

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.

tom-wisnowski avatar Mar 07 '16 05:03 tom-wisnowski

I am having the same issue. @twisnowski did you manage to fix this?

saurabharora90 avatar May 03 '16 04:05 saurabharora90

@saurabharora90 Sorry, no fix. Do you still see the issue?

tom-wisnowski avatar May 06 '16 19:05 tom-wisnowski

@twisnowski yes I still see it

saurabharora90 avatar May 07 '16 03:05 saurabharora90

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.

zeebone avatar Jun 02 '16 14:06 zeebone

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.

screen shot 2016-06-02 at 7 32 06 am screen shot 2016-06-02 at 7 51 37 am

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.

cybaker avatar Jun 02 '16 20:06 cybaker

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!

zeebone avatar Jun 02 '16 20:06 zeebone

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");
        } 

cybaker avatar Jun 03 '16 21:06 cybaker

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?

OptimusDan avatar Jun 22 '16 10:06 OptimusDan

I am having the same issue too..so sad!!,ony on Samsung S6

time007 avatar Jun 24 '16 06:06 time007

Any update on this issue?

yurii-diachenko avatar Aug 08 '16 08:08 yurii-diachenko

@cybaker getting NPA function getMovieBox() on line

List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);

kishorejethava avatar Oct 20 '16 08:10 kishorejethava

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.

jaydeep82 avatar Oct 26 '16 06:10 jaydeep82

@cybaker Can you tell me what tool you using to parser MP4.

PeakerChen avatar Nov 22 '16 07:11 PeakerChen

I am also getting the same issue, is there are any fix for this, getting this on my production application.

blackvirus18 avatar Dec 27 '16 09:12 blackvirus18

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 )

  1. Extracted audio track from video
  2. Extracted video track from video
  3. Merged Video And Audio

If anyone can get solutions please post it.

Thanks

adneerav avatar Jan 24 '17 05:01 adneerav

My Verizon Galaxy S7 Edge on 7.0 has the same issue.

luca992 avatar Apr 05 '17 01:04 luca992

Has anyone been able to find a solution?

maxchehab avatar Apr 12 '17 06:04 maxchehab

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.