How to reduce video compression process time? - android

I have used FFMPEG for video compression but it is taking too much time. Is there any solution to reduce video compression process time?
I have used below command,
String cmd = "-i " + inputFile + " -c:v libx264 -crf 23 -c:a aac -b:a 128k -movflags +faststart -preset ultrafast " + outputFile;

Related

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

Add fade effect between video and png image FFMPEG android

By using below command we can merge video and image together. I not an expert to build ffmpeg commands.
String cmd = "-t 5 -i " + videoPath +
" -loop 1 -t 5 -i " + imagePath +
" -f lavfi -t 5 -i anullsrc" +
" -filter_complex [1][0]scale2ref[2nd][ref];[ref][0:a][2nd][2:a]concat=n=2:v=1:a=1[v][a]" +
" -c:v libx264 -c:a aac -strict -2 -map [v] -map [a] -preset veryfast " + outputPath;
Any one who have idea to add a transition effect between video and image.
Please help me.
Thanks in advance.

Video Compression using ffpmeg

I am using ffmeg for video compression. I have used ffpmeg library
Use command "ffmpeg -i " + filein.trim() + " -vcodec h264 -acodec mp2 " + fileout.trim() but i doesn't respond anything.
I have used any ndk library for first time.
Use this command will work for you. This works for me .
String cmd = "-y -i " + currentInputVideoPath + " -strict -2 -vcodec libx264 -preset ultrafast " + "-crf 24 -acodec aac -ar 44100 -ac 2 -b:a 96k -s 320x240 -aspect 4:3 " + currentOutputVideoPath;

ffmpeg video rotation issue

I am using ffmpeg library to compress video and upload it to server.
My problem is :
Video is saved with perfect rotation in storage but when I upload it to server it gets 90degree rotated.
Command is:
setCommand("ffmpeg -y -i /sdcard/videokit/" + NetworkStatus.OrderNo
+ ".mp4 -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -acodec aac -ar 44100 -ac 2 -b:a 96k -s 320x240 /sdcard/videokit/" + NetworkStatus.OrderNo + "out.mp4");
Can you please help me to get out of this. I need to show video in portrait mode only if I have captured video in portrait.
Thanks

Add path to ffmpeg

I am playing with video compression by using ffmpeg. I can compress the video e.g. with this line:
String commandStr = "ffmpeg -y -i /sdcard/videokit3/Dani.mp4 -strict experimental -s 320x240-r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 512k /sdcard/videokit3/Dani2.mp4";
In this line the path is hardcoded, so I did
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "videokit3/Dani.mp4";
which results in /mnt/sdcard/videokit3/Dani.mp4
This seems to be different from /sdcard/videokit3/Dani.mp4 so this line runs to error (I see the difference, I just don't get it):
String commandStr = "ffmpeg -y -i " + path + " -strict experimental -s 320x240 -r 30 -ab 48000 -ac 2 -ar 22050 -b 512k /sdcard/videokit3/Dani4.mp4";
Can you help?
The easiest way to get around would be replace the string and trim "/mnt" out before inserting into the statement. The reason why the external SDcard absolute path returns as "mounted" drive is available here on SO: stackoverflow.com/a/5695129/2777098

Categories

Resources