i am trying to compress videos in project therefore using silicompressor. but when i pass it the destination path my application gets and hang and does nothing. But it does create a folder in my storage and stores a video file but when i try to play it, it gives error "Failed to play video". And this file has size of 24 bytes. so take a look and tell what i have done wrong.
Here is my code.
File destinationPath = new File("/storage/emulated/0/DCIM/Camera/myvideo");
destinationPath.mkdir();
File file = new File(destinationPath.getAbsolutePath());
Toast.makeText(Post.this, "folder: " + file, Toast.LENGTH_SHORT).show();
try {
filePath = SiliCompressor.with(Post.this).compressVideo(videouri, file.toString());
video.setVideoURI(Uri.parse(filePath));
Toast.makeText(Post.this, "Completed", Toast.LENGTH_SHORT).show();
} catch (URISyntaxException e) {
Log.d("EXCEPTION", e.toString());
Toast.makeText(Post.this, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
Try running compression code using AsyncTask
Here you can find demo app code for video compression.
I tried this SiliCompressor for video compressor, which is very well, and in this version, Audio and Video work well but not maintaining the resolution.
https://github.com/Tourenathan-G5organisation/SiliCompressor/tree/v2.2.2
Note: In the latest version(2.2.3) of SiliCompressor audio is not working after video compressor
OR
I made this and working well
https://github.com/iamkdblue/CompressVideo
I hope it helps you.
Related
I am trying to load couple of AVI files from phone storage. Sample paths -
/storage/emulated/0/Download/received_files/video1.avi
/storage/emulated/0/Download/received_files/video2.avi
VideoCapture vc1 = new VideoCapture();
VideoCapture vc2 = new VideoCapture();
if (!vc1.open(video1)) {
Log.e(TAG, "Could not open the video file1");
} else {
Log.i(TAG, "Video1 loaded");
}
if (!vc2.open(video1)) {
Log.e(TAG, "Could not open the video file1");
} else {
Log.i(TAG, "Video2 loaded");
}
Needless to say it always returns "Could not open ..." message.
File paths are correct, I am able to create File object using above paths and File.exists() returns true.
I am using OpenCV 3.2.0. Am I missing something?
Thanks
OpenCV for Android supports only MJPEG codec in AVI container hence it will not open any video encoded with any other codec. (source opencv.org)
FFMPEG may be used to support other codecs.
I am trying to pass a video to the OpenCV VideoCapture class. However when I call the VideoCapture.isOpened() method it always returns false. I have tried two methods:
Saving the video file to the internal memory, context.getFilesDir() => /data/data/package_name/files/VideoToAnalyze/Recording.mp4
and also one to environment.getExternalStorageDirectory() => sdcard/appName/Recording.mp4.
Nothing seems to work here. My question is how do I pass a video file (or what is the correct file path) to a VideoCapture OpenCV object? I've posted some code below as an example. Note that I don't get an error. The file is always found/exists, but when I call isOpened() I always get false.
UPDATE:
So it looks like everyone on the web is saying that OpenCV (I'm using 3.10) is lacking a ffmpeg backend and thus cannot process videos. I'm wondering does anyone know this as a fact ?? And is there a work around. Almost all other alternatives to process videos frame by frame is deathly slow.
String x = getApplicationContext().getFilesDir().getAbsolutePath();
File dir = new File(x + "/VideoToAnalyze");
if(dir.isDirectory()) {
videoFile = new File(dir.getAbsolutePath() + "/Recording1.mp4");
} else {
// handle error
}
if(videoFile.exits(){
String absPath = videoFile.getAbsolutePath();
VideoCapture vc = new VideoCapture();
try{
vc.open(absPath);
} catch (Exception e) {
/// handle error
}
if(!vc.isOpened(){
// this code is always hit
Log.v("VideoCapture", "failed");
} else {
Log.v("VideoCapture", "opened");
.....
Its an old question but nevertheless I had same issue.
Opencv for Android only supports MJPEG codec in AVI container. See this
Just to close this .. I downloaded JavaCV .. included .so files into the android project and then used FFMPEGFrameGrabber.
I have an Android app with an expansion file already attached. This is all working fine.
The file is: main.2.com.mydomain.myapp.obb
I want to update some assets in my app so I planned on adding a patch expansion file. Going by the next version iteration this file was: patch.10.com.mydomain.myapp.obb
I've uploaded an alpha build and I can see the files are downloading successfully. The assets in question are videos so I have the following code to access them:
ZipResourceFile expansionFile= null;
AssetFileDescriptor fd= null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),2,10);
fd = expansionFile.getAssetFileDescriptor("myvideo.mp4");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
My understanding is that the getAPKExpansionZipFile call will merge the two expansion files but my questions are:
If my patch file contains a file of the same name as the original main expansion, will the patch file version take precedent or should I have new filenames in my patch file (e.g. patch_myvideo.mp4)
How do I know the video will be correctly loaded from the patch file? I tried checking the AssetFileDescriptor offsets (start, length etc..) but it was the same with and without the patch file call.
Would love to know if I'm on the right track here!
Thanks for any help.
I have a set of videos stored in a folder on the android file system.
I would like to read each frame by frame so that i can perform some OpenCv functions on them and then display them in a Bitmap.
I'm not sure how to do this correctly, any help would be appreciated.
You can take a look at Javacv.
"JavaCV first provides wrappers to commonly used libraries by researchers in the field of computer vision: OpenCV, FFmpeg, libdc1394, PGR FlyCapture, OpenKinect, videoInput, and ARToolKitPlus"
To read each frame by frame you'd have to do something like below
FrameGrabber videoGrabber = new FFmpegFrameGrabber(videoFilePath);
try
{
videoGrabber.setFormat("video format goes here");//mp4 for example
videoGrabber.start();
} catch (com.googlecode.javacv.FrameGrabber.Exception e)
{
Log.e("javacv", "Failed to start grabber" + e);
return -1;
}
Frame vFrame = null;
do
{
try
{
vFrame = videoGrabber.grabFrame();
if(vFrame != null)
//do your magic here
} catch (com.googlecode.javacv.FrameGrabber.Exception e)
{
Log.e("javacv", "video grabFrame failed: "+ e);
}
}while(vFrame != null);
try
{
videoGrabber.stop();
}catch (com.googlecode.javacv.FrameGrabber.Exception e)
{
Log.e("javacv", "failed to stop video grabber", e);
return -1;
}
Hope that helps. Goodluck
i know it's to late but any one can use it if he need it
so you can use #Pawan Kumar code and you need to add read permession to your manifest file <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
and you will get it working.
I donĀ“t know about Android but generally you would have to use VideoCapture::open to open your video and then use VideoCapture::grab to get the next frame. See the Documentation of OpenCV for more information on this.
Update:
It seems like camera access is not officially supported for Android at the moment, see this issue on the OpenCV Github: https://github.com/opencv/opencv/issues/11952
You can either try the unofficial branch linked in the issue: https://github.com/komakai/opencv/tree/android-ndk-camera
or use another library to read in the frames and then create an OpenCV image from the data buffer like in this question.
I create developing app in android which have about 500 mb video i use for uploading apk expansion files method i upload expansion and download it but now i cant play videos from it http://blogmobile.itude.com/2012/11/22/expanding-your-horizons-using-expansion-files-for-android/ i follow this example for playing video but it's not working with me http://ktakeda47.blogspot.com/2012/04/apk-expansion-files.html i followed this link for expansion file downloading .Now plz help me how to play videos from expansion file Dir="/sdcard/Android/obb" ?
I'm using the following code to play mp4 from obb APKexpansion file using APKExpansionSupport lib:
ZipResourceFile expansionFile = null;
AssetFileDescriptor mAFD= null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, 1, 0);
mAFD = expansionFile.getAssetFileDescriptor(strVideoFile);
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
if (expansionFile==null || mAFD == null){
Toast.makeText(this, "obb is not here or doesn't contain file: "+strVideoFile, Toast.LENGTH_LONG).show();
return false;
}
mMediaPlayer.setDataSource(mAFD.getFileDescriptor(), mAFD.getStartOffset(), mAFD.getLength());
Remember - you have to pack obb zip archive without any compression level. This is very important. It must be a zip archive with no compression (level=0).
However there is a URI mentioned in APKES docs (speaking of VideoView) but I cant get a glue how to get the URI from APKES. Finally I found how to do it here
So to use URI you has to extend com.android.vending.expansion.zipfile.APEZProvider like in his example and make changes to Manifest and it should work.