how to extract audio from video - android

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

Related

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

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

Android HLS support using Media Codec, Media Extractor API

Hi I am writing a media player with the help of Media Codec and Media Extractor API. It is working fine, when I tested with some HTTP links. Then I tested it with HTTP live stream URL, it is not working.
ex: "http://mediamotiononline.ios.internapcdn.net/mediamotiononline/inapcms/CMS16042/flash/16042_adaptive2.mp4.m3u8"
I have tried to parse m3u8 file, but it is giving info of Bandwidth, resolution only. With VideoView widget these Http live stream URLs works fine. But I am using Surface to show decoded data. Anyone has any idea how to solve this problem?
this might be help you.
Download m3u8 parser from http://sourceforge.net/projects/m3u8parser/
Add it to your project either jar file or source files.
By using this parser you can get PlaylistInfo, elements.
Explore for playable .ts files in elements. Pass those ts files to your MediaExtractor. It worked for me. Hope it will work for you
too..

streaming a mp4 file using RTSP?

I am developing an app. that will stream the video recorded from camera and stored as mp4 in sdcard...
I know there something called as RTSP which is used for that...
Please tell me where to start . .and is there any library that will do this for me...
I do not understand why you want to stream a local mp4 file, but maybe I misunderstood you problem. RTSP is used for live streaming, but you want to play a local mp4 file.
If you want to capture video and save it as mp4 onto a SD card, you need to use the Android MediaRecorder. Here a link to a simple example.
If you just want to playback a local mp4 file. Have a look at the Android API Demos.
These are part of the Android SDK installation and contain a good example of how to playback local media files.

Android change audio of any video file

I am trying to apply new audio pitch for my video file.
I want to replace audio of my existing video by android code. Is it possible in android. can any one help me to do this
Is there any Android library support this facility to change audio for video file?
Any Help is appreciated...!!!
Thanks in Advance
This is not the exact solution but you can try it:
When you play the video file set its volume to zero.
At the same time use the service in which you can play any audio you want.
As service runs at background it has no effect on your video streaming.
When your video end,end your service.
And remember to set volume of your audio file.
You can change video pitch easily by following these steps :-
Add this library in your android project : https://gitlab.com/soundtouch/soundtouch.
follow this link for integrate this library process : https://stackoverflow.com/a/52425255/7899427.
After successfully integrate this library first of all extract audio file in WAV audio format. You can use ffmpeg library for do this.
Than using the soundtouch library you can change the audio file pitch and tempo rate and export new audio file in WAV format.
After complete these steps merge that converted audio file with video file.
Now will get the converted audio file with same video file.
Happy coding.

Play .ts video file on Android?

I am pretty new at streaming video, so please bear with me. :)
I am trying to port an m3u8 stream over from iPhone to Android. Looking in the m3u8 feed, I found some .ts files. From what I can tell, .ts files are, themselves, wrappers that contain the video stream (Elementary Stream).
Is it possible to play a .ts file in Android? (The docs only list 3gp and mp4 as supported formats.)
Is there a way to extract the Elementary Stream and just process the video feed? If that is in 3gp or mp4, I should be ok.
Will Stagefright handle .ts? Is Stagefright even available? I read that there are/were some problems with it.
(As a further caveat, I am not getting much help from my server guys. They are pushing for a Flash player solution, including a proprietary player. They will not provide me with a 3gp or an mp4 feed, but I'm hoping I can find that in the .ts file.)
I'm open to other suggestions. Thanks for your patience with this newbie. :)
There is a standard for that called HTTP Live Streaming. Android 3.0 supports this protocol to some extent which means you can pass the URL of the m3u8 playlist to the MediaPlayer and the player should be able to stream it over HTTP. Stagefright is bundled with Android 3.0.
You can browse its source code here.
Also, this thread might interest you: it summarizes support for HTTP Live Streaming.
Android stagefright in Gingerbread and prior versions does not support playback of .ts (transport stream) or elementary stream. As you have rightly pointed out, it only supports MP4/3GP/MP3 file formats.
You can play .ts video file in android by using NDK based project. Dolphine player is best open source player for android and also supports various formats of video.
You got the .ts link from m3u file. Now you can fetch binary data from .ts file and store this binary data in file, then play this file by using video player.

Categories

Resources