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
Related
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
I am working on a project in which I need to speed up a mute video. I did a little digging around and found the following command.
ffmpeg -i input.mkv -filter:v "setpts=PTS/2" output.mkv
Tried to use it in android as follows.
new String[]{"-y", "-i", inputFileAbsolutePath, "-filter_complex", "setpts=PTS/2", "-map", "[v]", "-map", "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", fileOutput};
It doesn't even show anything in the Logcat.
I have also tried a few other solutions but no luck.
Any help would be appreciated.
Thanks.
If you were to view the log from the ffmpeg process it would provide an error:
Output with label 'v' does not exist in any defined filter graph, or was already used elsewhere.
So either properly label and map the filter output:
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/2[v]" -map "[v]" -b:v 2097k -r 60 -vcodec mpeg4 output.mp4
...or omit the labels and rely on the default stream selection behavior.
ffmpeg -i input.mp4 -filter_complex setpts=PTS/2 -b:v 2097k -r 60 -vcodec mpeg4 output.mp4
I want to make a sample video file into video for 30 seconds to show. But I can not do it because I'm not good enough with FFmpeg.
My code :
String command[]={
"-y",
"-r",
"1/5",
"-i",
src.getAbsolutePath(), // only one image file path
"-c:v",
"libx264",
"-vf",
"fps=25",
"-pix_fmt",
"yuv420p",
imagesvideoOutput
};
Simple command for 30 second video from a single image:
ffmpeg -loop 1 -i image.png -vf format=yuv420p -t 30 output.mp4
Faster, but somewhat more complicated method:
ffmpeg -loop 1 -framerate 1 -i image.png -vf fps=25,format=yuv420p -t 30 output.mp4
I am trying to add text and time stamp on video but not able to print the simple text on it.
String[] complexCommand = {"-f", "3gp", "-i", videoPath, "-s", height + "x" + width, "-r",
"17", "drawtext=fontfile='file://android_asset/font_eight.ttf':fontsize=20:text='test':x=10:y=100",
"-vcodec", "libx264", "-vb", "2000k", "-preset", "fast", "-f", "3gp", dir.getAbsolutePath() + "/out.3gp"};
ffmpeg -f 3gp -i /storage/emulated/0/DCIM/Camera/VID_20171211_105946.3gp -s 1920x1080
-r 17 drawtext='fontfile=file://android_asset/font_eight.ttf:fontsize=20:text=test:x=10:y=100
-vcodec libx264 -vb 2000k -preset fast -f 3gp /storage/emulated/0/Pictures/Video/out.3gp
-- Edited Question ---
Error:
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 # 0xf5ba0730] impossible to init fontconfig
[AVFilterGraph # 0xf5b89040] Error initializing filter 'drawtext' with args 'fontfile=file://android_asset/font_eight.ttf:fontsize=32:text=test:fontcolor=white:x=0:y=0'
Error opening filters!
Same command runs on windows with no error, But when I converted it for mobile device and tested getting error of font-path.
drawtext is a video filter, so it has to be passed as an argument to -vf or -filter_complex (used when filtering multiple streams).
So,
-vf drawtext=fontsize=20:=text='aaa':x=10:y=100
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.