chrisbatt / AndroidFastImageProcessing

A framework for speeding up image processing on android devices by taking advantage of shaders on the GPU.
MIT License
285 stars 118 forks source link

Store Filtered video in video formated file (like .mp4) #7

Open KamdarV opened 10 years ago

KamdarV commented 10 years ago

First of all, I would like to thank you for giving us a great library similar to GPUImage framework of iOS.

While viewing Library, I could find VideoToImageExample filtering sample. But it storing output as image in .jpg format in JPGFileEndpoint.java class. I wanted to filter video and store filtered video in video formate file (like .mp4). That means VideoToVideoExample. Please help me for the same.

Thanks in advance.

chrisbatt commented 10 years ago

This was one of my goals for the original project. The issue is that Android does not provide any easy way (as far as I know) to create videos from a group of images. I managed to get something working on Android 2.2 using the FFMpeg library. The problem was that it was crashing on all of the Android 4+ devices I tested on making it relatively useless. I believe it the video output code and sample were committed to the project in one of the earlier commits, if you wanted to take a look at it. If not, it is still on my todo list, but I fear it will be a while before I actually get anything working properly.

KamdarV commented 10 years ago

Thanks for reply. I also checked out many libraries like openCV, FFMpeg, Mp4Parser, etc. but couldn't reach to the solution yet. Waiting for your updated project with video filter output.

KamdarV commented 10 years ago

Hello chrisbatt, can I add filter image ( e.g. watereffect.jpg) with video in android. Please let me know if you have any idea about this. Need sample code if possible. Thank u so much.

chrisbatt commented 10 years ago

I am a little bit confused about what you are asking. If you are asking if you can use a JPGFileEndpoint with a video input then the answer is yes. I believe there is an example of this in the examples folder called VideoToImage. If you are asking about something else, would it be possible to clarify what you mean by a filter image with video?

KamdarV commented 10 years ago

My question is, as in FastImageProcessing library you are creating filter classes (e.g. SepiaFilter.java, HueFilter.java,..etc.). I have an image like toastermetal
for filter effect. So I think i need to add this image with every frames of videos. I found this project https://github.com/guardianproject/SSCVideoProto and tried following changes :

String[] ffmpegCommand = {ffmpegBin, "-v", "10", "-y", "-i", inputFile.getPath(), "-vcodec", "libx264", "-b", "3000k", "-vpre", "baseline", "-s", "720x480", "-r", "30", //"-vf", "drawbox=10:20:200:60:red@0.5", "-i" , Environment.getExternalStorageDirectory().getPath() + "/toasterMetal.png", "-filter_complex", "[0:v][1:v]overlay=main_w-overlay_w-10:main_h-overlay_h-10[out]" , "-map", "[out]", "-map", "0:a", "-acodec", "copy", "-f", "mp4", Environment.getExternalStorageDirectory().getPath() + "/output.mp4"};

But it didnt work. Please help me if you have any idea how to implement this or have any other way to do this. Thanks.

leeicmobile commented 10 years ago

Was going to create a new issue but this seems like a sensible place to put it. I attempted to integrate a new Output for video into the library using chris suggestion of JavaCV on his blog. I've forked the latest Here: https://github.com/icmobilelab/AndroidFastImageProcessing

This seems to work fine in Android 4.0.3+ although I have only tested on KitKat so far.

main code is in VideoFileEndpoint.java and VideoFileEndpointListener.java

comments aren't all updated apologies.

KamdarV commented 10 years ago

Thank you very much for all your efforts. Can you please also add VideoToVideoExample as well..?

leeicmobile commented 10 years ago

Can't do all the work kamdar :) You just need to hook it up like you would the screen endpoint and call start and stop recording. Plus the class which owns the videofile end point should implement the videofile endpoint listener.

You should also review the javacv setup requirements if the bundled lib.so files aren't working. You'll need to download javacv.jar and javacpp.jar (part of the javacv setup) On Feb 17, 2014 6:44 AM, "KamdarV" notifications@github.com wrote:

Thank you very much for all your efforts. Can you please also add VideoToVideoExample as well..

Reply to this email directly or view it on GitHubhttps://github.com/chrisbatt/AndroidFastImageProcessing/issues/7#issuecomment-35232215 .

KamdarV commented 10 years ago

OK..Thank you.

stofanakmartin commented 10 years ago

leeicmobile i have tried what you posted here. I hooked videoFileEndpoint just like screenEndPoint included javaCv to my project and recording works but its very slow. Record speed is one frame in half a second so the result video has 2fps. When i attach the screen as endpoint the video is fluid. My device is SGSII, do you have some tips how to enhance performace of recording?

leeicmobile commented 10 years ago

Hi Stofo89,

unfortunately I've also found that performance differs considerably from device to device.

This is dues to the glreadpixels call which can be upto 100ms per call on some GPU architectures.

All I could suggest is perhaps do post-processing of the video, if you are using camera input for instance record just the camera frames to a video then apply the filters and record the output without also displaying to the screen.

Lee

On 15 March 2014 15:12, stofo89 notifications@github.com wrote:

leeicmobile i have tried what you posted here. I hooked videoFileEndpoint just like screenEndPoint included javaCv to my project and recording works but its very slow. Record speed is one frame in half a second so the result video has 2fps. When i attach the screen as endpoint the video is fluid. My device is SGSII, do you have some tips how to enhance performace of recording?

Reply to this email directly or view it on GitHubhttps://github.com/chrisbatt/AndroidFastImageProcessing/issues/7#issuecomment-37728179 .

ompemi commented 9 years ago

Hey @leeicmobile ,

Your VideoFileInput was a great starting point, thank you. I managed to record the video but as @stofo89 points out it is too slow. After some tests the only acceptable preview size that could work with most devices is lower than 800 pixels width (there seems to be a solution for 4.3)

I noticed that the VideoFileInput does not output the video as the ScreenEndpoint while recording. Do you have any quick hint here?

I will post updates if I manage to get the filtered video out while recording, so that I can push to your repo an example of VideoToVideoExample.

Thanks, Omar

justin0814 commented 9 years ago

Hi Lee, @leeicmobile I am very interested in your idea to use this library to do post-processing of a given video without displaying it to the screen. I have tried your VideoFileEndpoint and found the only to get an output video file is to call startRecord() and stopRecord(). That means for a video of 20 seconds, I need to wait for 20 seconds to play it in the background and in the meantime record it to a video file.

I need to only filter it and get the output file. is there a way to get the video file through background post-processing in a shorter period of time?

Waiting for your reply. Thanks for your works.

Justin