OpenCV Android(Java) --- Extract frames from MP4 file - android

I am trying to read an MP4 file in OpenCV Java on Android Studio but having no success. I create a VideoCapture object and pass the video as the argument to it but the videoCapture.read() method always returns false. I know that the file exists at that path because I am able to use FFmpeg and MediaExtractor libraries to read the video at that path but IDK why OpenCV never succeeds. Also, I am able to process the same video file using OpenCV in Python.
Here's a code snippet:
VideoCapture camera = new VideoCapture(filePath);
if(camera.read(imageMat)){
System.out.println("read");
}
else{
System.out.println("not read");
}
ImageMat is the matrix I want to read my video frames into.
I would really appreciate if anyone has any suggestions/ resources on how to read a video file using OpenCV in Java/Android Studio.

OpenCV doesn't support .mp4 video format. If you want to use OpenCV then please use the .avi video format.
For more information you can refer to this medium post :
blog

Related

I am confused what ffmpeg file is in android

Please can anyone tell me the usages of ffmpeg file in android. Though I tried to browse but none of them satisfied me.
FFMPEG is library,it will used to decode and encode audio,video file , if you are streaming a video from your android application it will be used.

how to use Lame library in android to convert .Pcm file to Mp3

I am using Lame library to convert pcm file to mp3 in android.
using this link I compiled it and every thing is ok.
but I don't know how to use this library to convert .Pcm file to .Mp3 in android studio.
any sample code or any hint would be appreciated
This is an example: https://github.com/intervigilium/Lame4Android/blob/master/src/com/intervigil/lame/Main.java
It seems that you need to do a Lame object and onActivityResult do the conversion of the file or see this as a possible duplicated question: https://stackoverflow.com/a/34322713/6848782

how to extract audio from video

I am working on an android app that can download videos in different formats.It done perfectly.
Now i want to extract audio from downloaded video file or available video link.
Is there any way to extract audio from video by any of the following methods
1.extract audio directly from a video file link
or
2.is there any library that suitable for android to extract audio from a video files
Thanks for your time!
You can use a library called JAVE (Java Audio Video Encoder) to encode a video into an audio file.
Download JAVE from here.
Refer to the below snippet to encode from MP4 to MP3
Code:
File source = new File("source.mp4");
File target = new File("target.mp3");
AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setCodec("libmp3lame")
.setBitRate(new Integer(128000))
.setChannels(new Integer(2))
.setSamplingRate(new Integer(44100));
EncodingAttributes encodingAttributes = new EncodingAttributes();
encodingAttributes.setFormat("mp3")
.setAudioAttributes(audioAttributes);
Encoder encoder = new Encoder();
encoder.encode(source, target, encodingAttributes);
JAVE is basically a wrapper over FFMPEG, for this simple FFMPEG is a very big framework to use which also increase the app size. I can check a gist of mine performing the thing by using Android native API's (MediaExtractor & MediaMuxer). From the attached URL:
https://gist.github.com/ArsalRaza/132a6e99d59aa80b9861ae368bc786d0

How to compress a video file in android?

i have list of video files in my sdcard.when i click the selected video in gridview,i want to compress the selected video file in android.How to compress a video file in android.is there any sample code availavble?
I think the best solution for video compression is using ffmpeg library.
Here you can find a sample android app that used that library:
https://github.com/umeshbsa/ffmpeg-video-compresion-with-progress-android
another lovely library is silicompressor you can find that here:
https://github.com/Tourenathan-G5organisation/SiliCompressor
Video Compression can be done by MediaCodec (From JB) and FFMPEG. Please refer documents of FFMPEG for more information on compression.
Refer:
ffmpeg: compress video?
https://www.virag.si/2012/01/web-video-encoding-tutorial-with-ffmpeg-0-9/

How to play audio file from URI using ffmpeg files in android

HI all,
I am working on playing audio from URI using ffmpeg shared library in android.
I configured android-ndk and added ffmpeg shared library to project and able to compile the project using cygwin.
In ffmpeg library i see ffmpeg.c file, i donot know how i can use this file to implement audio player in my activity.
Please help me on this issue.
Thank you in advance
First, Use ffmpeg to open the URI and read frames and decode to raw PCM data, you can take a look at ffplay.c about the decoding part.
Next, using the Android AudioTrack class to play the raw PCM data, there is a tutorial: fun with audiotrack
Good luck!

Categories

Resources