keke77 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

FFmpegFrameGrabber doesn't grab upto the end of the video on Android #491

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Write down following code in your activity 

File file = new File(Environment.getExternalStorageDirectory() + File.separator 
+ "test7.mp4");
        FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(file.getAbsolutePath());
        FFmpegFrameRecorder recorder = null;
        try {
            frameGrabber.start();
            Log.d("javaCv", "frame count " + frameGrabber.getLengthInFrames() + "");
            recorder = new FFmpegFrameRecorder("/mnt/sdcard/streaml_tt.mp4", frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), 2);
            recorder.setVideoCodec(AV_CODEC_ID_H264);
            recorder.setFormat("mp4");
            recorder.setFrameRate(frameGrabber.getFrameRate());
            recorder.setSampleFormat(frameGrabber.getSampleFormat());
            recorder.setSampleRate(frameGrabber.getSampleRate());
            recorder.setAudioCodec(AV_CODEC_ID_AAC);
            recorder.start();

            long currentTimeMillis = System.currentTimeMillis();
            String filePath = Environment.getExternalStorageDirectory() + File.separator + "kk";
            Log.d("bharat", "video bitrate before = " + frameGrabber.getVideoBitrate() + " time:" + currentTimeMillis);
            int count = 0;
            int totalcount = 0;
            int soundCount = 0;
            while (true) {
                try {
                    totalcount++;
                    Frame grabFrame = frameGrabber.grabFrame();

                    if (grabFrame == null) {
                        System.out.println("!!! Failed cvQueryFrame");
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(RecordActivity.this, "Done !!!", Toast.LENGTH_SHORT).show();
                            }
                        });
                        break;
                    }
                    recorder.record(grabFrame);

                } catch (Exception e) {
                    Log.d("javaCv", "exception " + e);
                    e.printStackTrace();
                }
            }
            long secCurrentMillisec = System.currentTimeMillis();
            long timetaken = secCurrentMillisec - currentTimeMillis;

            Log.d("javaCv", "frame done, time taken:" + timetaken + " " + soundCount + " " + count + " " + totalcount);
            recorder.stop();
            recorder.release();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

2.  Put a video named "test7.mp4" in the root directory of your android device.

3.   Run this code [ dont forget to provide Write and Read permissions in 
manifest file] 

What is the expected output? What do you see instead?

I am just taking frame from a video and recording them to make another video 
from it.  But I noticed that in  last 2-3 seconds of new video, Sound is ok but 
frames are not present. it is like the video frames stops 2-3 second before the 
end of the video  and sound keeps playing. 

What version of the product are you using? On what operating system?
 JavaCv 0.9.1 
JavaCPP Presets for FFmpeg 2.3-0.9
JavaCPP Presets for OpenCV 2.4.9-0.9
JavaCPP 0.9

and various .so files from ffmpeg-android-arm.jar opencv-android-arm.jar etc.

Please provide any additional information below.

In a perticular test case, frameGrabber.getLengthInFrames() is returning 416  
and framegrabber grabs 406 frames that has images data (grabFrame.image != null 
) and 806 frames that has audio data ( grabFrame.samples != null ). 

Let me know if any other info is required

Original issue reported on code.google.com by bharat2...@gmail.com on 6 Nov 2014 at 12:01

GoogleCodeExporter commented 9 years ago
Does the same thing happen on Java SE?

And could you please report issues on GitHub if possible, not here? thank you

Original comment by samuel.a...@gmail.com on 6 Nov 2014 at 12:50

GoogleCodeExporter commented 9 years ago
Hi for me, the getLengthInFrames return around 300+ frames, but the counter for 
grabFrame() is 900+ frames! 

http://stackoverflow.com/questions/27291794/javacv-read-video-and-record

Original comment by jack.che...@gmail.com on 4 Dec 2014 at 1:46

GoogleCodeExporter commented 9 years ago
@jack If you know the cause of the trouble, please let us know so we can fix 
it! Thanks

Original comment by samuel.a...@gmail.com on 6 Dec 2014 at 1:03

GoogleCodeExporter commented 9 years ago
Can you try again with JavaCV 0.10 and let me know if the problem still occurs?

And please post future issues on GitHub, if possible, not here, thank you!

Original comment by samuel.a...@gmail.com on 27 Dec 2014 at 3:54

GoogleCodeExporter commented 9 years ago
I think I've found the cause of this issue. I've committed some changes here 
that should fix this:
https://github.com/bytedeco/javacv/commit/fb2206de652e2777b3e0c6621dc3c7d47fc16b
df

Original comment by samuel.a...@gmail.com on 12 May 2015 at 1:32

GoogleCodeExporter commented 9 years ago
Should be fixed in version 1.0. But please let me know if it isn't fixed for 
some reason. Thanks!!

Original comment by samuel.a...@gmail.com on 17 Jul 2015 at 2:15