How to convert wav file to mp4 using ffmpeg in android? - android

I am having a wav file.How to convert wav file into mp4 file container format with AAC as audio stream using FFmpeg in android.I know how compile and port ffmpeg for android.Can anybody give me right direction
thanks,

you'll need to compile libfaac if you want to have a decent quality encoder. Then, something like ffmpeg -i foo.wav -vn -acodec libfaac -ab BITRATE output.mp4 should do the trick.

Related

Need to Compress(reduce size) of Animated WEBP file - FFmpeg, libwebp

I want to reduce WEBP file size. I'm using https://github.com/tanersener/ffmpeg-kit library to convert my video .mp4 to .webp
Input File MP4 Size - 800kb
Output File WEBP size - 5.22 MB
Commands which i used
ffmpeg.exe -i outputbitrate.mp4 -vcodec libwebp -filter:v fps=fps=20 -lossless 1 -loop 0 -preset default -an -vsync 0 -vf scale=512:512:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:-1:-1:color=#00000000 finalout.webp
I tried with compress_level,quality also. which is not reducing the output size.
in mycase, the output should be less then 512kb. how to achieve this.
Any articles or sample code will be very helpful. Thanks

Compress Video with FFmpeg

I want to compress a 1 minute video in less than a minute on Android using ffmpeg in the best possible quality. But when the time is short, the quality is low and when the quality is good, it takes a long time to compress.
Do you know the right command?
For "best quality" at fastest encoding speed:
ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset veryfast output.mp4
This assumes you want H.264 + AAC in MP4.
If input audio is AAC add -c:a copy.
If -preset veryfast is too slow use -preset ultrafast.
See FFmpeg Wiki: H.264 for more info and examples.
FFMPEG cannot do any magic....Low quality takes less time than better quality, so you have to choose right compromise between compression speed and video quality.
You didn't tell us what are size dimensions (WxH and Size in bytes) and neither current Audio and Video Codec (H264 or others).
For example 1 minute of 8K video takes more than 1 minute to be converted using HEVC codec using 10Mbps as bitrate, and cannot be reduced.....so.....
Compress video using FFMPEG:
ffmpeg -i videoPath -s 1280x720 -vf transpose=2 -metadata:s:v:0 rotate=90 -b:v 150k -vcodec mpeg4 -acodec copy outputFile
i solved problem with this command
ffmpeg -i innerPath -c:v libx264 -preset superfast -b:a 256k -vf -b:v 1.5M -c:a aac targetFilePath

Android - Concat 2 videos using com.netcompss.loader.LoadJNI

I'm using com.netcompss.loader.LoadJNI (FFmpeg4Android) and it was working fine until I try to concat 1 video with audio track and other video without audio track.
I was using this command line:
ffmpeg -y -i /storage/emulated/0/app/1.mp4 -i /storage/emulated/0/DCIM/2.mp4 -strict experimental -filter_complex [0:v]scale=640x360,setsar=1:1[v0];[1:v]scale=1280x720,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1 -ab 48000 -ac 2 -ar 22050 -s 640x360 -r 30 -vcodec libx264 -acodec aac -crf 18 /storage/emulated/0/app/out.mp4
1.mp4 has resolution at 640x360 and has audio track.
2.mp4 has resolution at 1280x720 and has no audio track.
On vk.log it was showing this:
Setting 'n' to value '2'
Setting 'v' to value '1'
Setting 'a' to value '1'
Stream specifier ':a' in filtergraph description [0:v]scale=1280x720,setsar=1:1[v0];[1:v]scale=1280x720,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1 matches no streams.
exit_program: 1
Cannot find a matching stream for unlabeled input pad 3 on filter Parsed_concat_4
I'm not good with ffmpeg, so I did some changes to the command line without success.
When all video being concatenated have audio track, there's no problem. But when one of the videos has no audio track, it fails.
What would be the correct command line in this case?
The concat filter requires all segments to have the same number of (matching) streams, and in this case, since you only have two files, where the first one has the audio, you can skip the audio concat.
ffmpeg -y -i /storage/emulated/0/app/1.mp4 -i /storage/emulated/0/DCIM/2.mp4 \
-strict experimental -filter_complex \
[0:v]scale=640x360,setsar=1[v0];[1:v]scale=640x360,setsar=1[v1]; \
[v0][v1]concat=n=2[v] -map "[v]" -r 30 -vcodec libx264 -crf 18 \
-map 0:a -acodec aac -ab 48000 -ac 2 -ar 22050 /storage/emulated/0/app/out.mp4
Since you are scaling the final video to 640x360, there's no point scaling the 2nd video to 1280x720; just scale it directly to final size. And once you do that, there's no need to insert another scaler using the -s option.
The answer from Mulvya works fine and answer what I asked. But it will keep only the first audio from first video. In my case a user may want to concat, for example, 4 videos and only one of it has no audio track. The user want to keep other videos audio.
My solution was to check each video before concat. If a video has no audio track, I add a silent audio track. Then, when running my concat command line it won't face any problem.

Convert aac to mp3 using ffmpeg binary command in android

I'm trying to use ffmpeg binary to convert aac format to mp3 format in andorid
I am too referring to a example here: https://github.com/sjitech/ffmpeg-android
What I tried with failure is
p = Runtime.getRuntime().exec("/data/data/myapp/app_bin/ffmpeg -i /sdcard/chua.aac -acodec libmp3lame -ac 2 -ab 160 /sdcard/chua.mp3");
I make sure that "/sdcard/chua.aac" exists on my phone
I guess the problem may come from libmp3lame in the command which is disabled in ffmpeg binary when building before with the example but I'm not very sure
Please someone reveal what my problem is and how to fix it.

How to Compress video file in android

I want to compress video file before uploading to server.I gone through this link
How to compress a video to maximum level android, but i did not get an answer. Can anyone help me ??
Give this a try
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setVideoEncodingBitRate(690000 );
We can compress video using ffmpeg in android.
For integrating FFmpeg in android we can use precompiled libraries like ffmpeg-android.
You can use below command to compress video
String[] command = {"-y", "-i", inputFileAbsolutePath, "-s", "160x120", "-r", "25", "-vcodec", "mpeg4", "-b:v", "150k", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};
Here,
-y
Overwrite output files without asking.
-i
ffmpeg reads from an arbitrary number of input “files” specified by the -i option
-s
video output size
-r
Set frame rate
-vcodec
Set the video codec.
-b:v
Set the video bitrate
-b:a
Set the audio bitrate
-ac
Set the number of audio channels.
-ar
sets the sampling rate for audio streams if encoded
For detailed explanation and code on using ffmpeg in android to edit videos,check out below ffmpeg video editor tutorial link on my blog which includes compressing video using ffmpeg-
https://androidlearnersite.wordpress.com/2017/03/17/ffmpeg-video-editor/
You have to use ffmpeg lib to compress your video:-
ffmpeg -i input.mp4 -acodec mp2 output.mp4

Categories

Resources