Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling recording of longer duration videos #303

Closed
dijilraj opened this issue Jan 7, 2016 · 7 comments
Closed

Handling recording of longer duration videos #303

dijilraj opened this issue Jan 7, 2016 · 7 comments

Comments

@dijilraj
Copy link

dijilraj commented Jan 7, 2016

I am using RecordActivity sample to record a video a video of size 480x480 with duration of 10 seconds. But when recording duration is increased to more than 25 seconds an out of memory exception occurs.

images[i] = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);

Exception occurs at the above line where memory is allocated for frames. So I am now looking at implementing a solution so that short videos are saved in background and then combined later. Do we need to use multiple instances of FFmpegFrameRecorder to handle this?

@saudet
Copy link
Member

saudet commented Jan 7, 2016

I'm not sure I understand your question. Please explain what you are trying to achieve.

@dijilraj
Copy link
Author

dijilraj commented Jan 7, 2016

I am trying to implement a video recording functionality similar to vine. ie, output video should be in 480x480 resolution. I am able to process the frames and obtain video in 480x480 resolution.

This recording functionality works fine when duration of recording is smaller than 10 seconds and when there is enough free memory in phone. But if that is not the case, an exception is thrown. On debugging, the exception was found to be thrown from the section in code where memory is allocated for frames (Line 225 in RecordActivity).

Also please note that out of memory exception was occurring if RecordActivity is used as it is (ie, without the code for processing frames to get video in 480x480 resolution) if variable RECORD_LENGTH is greater than 20 seconds.

As a solution, I am trying to save small video chunks and combining them later. For recording multiple video chunks , it seems multiple instances of FFmpegFrameRecorder are needed. Could you please let me know whether this would be the best approach or is there any better solution for this problem so that small amount of memory need to be allocated.

@Iqra786
Copy link

Iqra786 commented Jan 10, 2016

Which camera API you are using? I am using 320 X 320 on both APIS (Camera1 and 2) it work fine. except it doesn't compile on Marshmallow that is other issue. You can not achieve 480 X 480 just adding raw frames in recorder. You have to write more code.
In last paragraph - are you trying to achieve pause and record functionality?

@saudet
Copy link
Member

saudet commented Jan 10, 2016

@dijil You're going to need to compress the data in memory. This should be pretty easy to achieve once we have support for packets, see issue #93

Please consider making a contribution by implementing support for packets! It's a feature that's being requested by a lot people, so it won't be useful only to you! Thank you

@saudet saudet closed this as completed Jan 10, 2016
@dijilraj
Copy link
Author

@Iqra786 @saudet I am using Camera API. Video is recorded in 640x480 resolution and then each frame is processed to get a frame in 480x480 resolution. This is working fine and I am able to get 480x480 video also. I have used https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java as reference for implementing this functionality.

Issue for me is that I need to record video for longer duration (25 seconds). Frames are allotted memory in initRecorder method (Line 225) in RecordActivity, . When duration of videos recorded is long, more amount of memory need to be allocated. So when it reaches a certain threshold (different for different devices) , app will throw an out of memory exception.

I am trying to combine small video chunks so that only small amount of memory need to be allotted at a time. ie, if I have to record 25 seconds long video, my plan is to have a small size Frame array (for storing 5 seconds of frames). Then after each 5 seconds recording is completed, save the video from those 5 seconds Frame data, empty the array and then start recording the next 5 seconds of data.

An issue for implementing this solution is that location of file to be saved can be specified only at the time of creating FFmpegFrameRecorder object. So for implementing my plan of saving multiple video chunks, there need to be multiple instances of FFmpegFrameRecorder. This in turn require multiple Frame arrays. So memory allotment need to be made for 25 seconds worth of frame data. So this also cause out of memory exception.

As you checked, I am implementing pause and record functionality. But that is implemented by recording only the required frames and it is working fine now. Issue is only for recording longer duration videos.

@saudet
Copy link
Member

saudet commented Jan 13, 2016

@dijil Like I said, this should be something that we can easily implement if we had support for packets. It should be possible to have each packet correspond to a compressed frame. Think of a packet as a JPG file in memory. The JPG codec is probably too slow, but there are codecs that are fast enough for a resolution of 480x480. BTW, Android 4.1+ comes with APIs for that, so if you don't need to support anything else, you might want to check that out:
https://github.com/google/grafika/blob/master/src/com/android/grafika/ContinuousCaptureActivity.java

@ytarek
Copy link

ytarek commented Feb 14, 2016

@dijil @saudet i am running through the same problem , cant record videos longer than 10 seconds on android for any high resolution .
i get outofmemory exception from the line 228
images[i] = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);

any help here , thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants