How to increase compression speed for FFmpeg? - android

I have used following command for compress video in android.
ffmpeg -y -i /sdcard/DCIM/Camera/VID_20150326_125017.mp4 -strict experimental -s 640x360 -r 25 -vcodec mpeg4 -b 1000k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4
Above command is a work properly, but it's taking too much time for compression.
An 80MB video file takes around 3 minutes to compress to an 8MB file. Is there any way I can reduce this time.

Try this.
-y -i $sourceFile -s ${width}x${height} -r 5 -c:v libx264 -b:v 600k -b:a 44100 -ac 2 -ar 22050 -tune fastdecode -preset ultrafast $destPath
This command uses libx264 codec and -r 5 reduces the time taken.
-tune fastdecode -preset ultrafast this is also used for faster compression.
Reference ffmpeg preset
Result :
SOURCE SIZE : 63.7 MB DEST SIZE : 5.06MB
Time Taken : 15 Secs

Try the command mentioned below to compress videos. In my situation, 52 MB of video was compressed to 12 MB in about 19 seconds.
function command(input, output, bitrate) {
return new Promise((resolve, reject) => {
ffmpeg(input)
.outputOptions(['-c:v libx264', `-b:v ${bitrate}k`, '-c:a aac', '-b:a 58k','-crf 35'])
.output(output)
.on('start', (command) => {
console.log('TCL: command -> command', command)
})
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done');
})
.on('error', (error) => reject(error))
.on('end', () => resolve())
.run()
})
}

Try the below command for video compression
In my case, i had video of 82mb and compressed to 5mb within around 50secs.
String[] command = new String[]{"-i", videoPath, "-vcodec", "h264", "-b:v", "1000k", "-acodec", "mp3" ,"-preset", "ultrafast", outputPath};
Hope it works!

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

FFmpeg stucks for few seconds on start

I'm trying to cut and resize video on Android(but it is similar on MacOS) , but when I run the ffmpeg command it returns me
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
It repeats for about 20 sec (I have 4K video with 3 sec duration).
Is there any way to improve process speed? Here is example of my ffmpeg command
ffmpeg -y -i input.mp4 -ss 00:01.82 -to 00:02.94 -vf scale=500:1024 -c:v libx264 -c:a aac -b:v 500k -b:a 96k output.mp4
Use of -ss after the input performs a decoded frame seek, which is slower. Switch to demuxer seek
ffmpeg -y -ss 00:01.82 -to 00:02.94 -i input.mp4 -vf scale=500:1024 -c:v libx264 -c:a aac -b:v 500k -b:a 96k output.mp4
-to for demuxer was only recently added, so get a current git version. Else, use -t with the calculated duration.

FFmpeg converting two videos with dynamic frame rates - dup/drop frames

I have problems with converting two videos using ffmpeg. Those videos have dynamic frame rate. I'm using this ffmpeg command:
ffmpeg -y -i /storage/emulated/0/Movies/RMR/RMR_camera_2017-10-04-20-42-56.mp4 -i /storage/emulated/0/Movies/RMR/RMR_screen_2017-10-04-20-42-56.mp4 -strict experimental -preset ultrafast -filter_complex [0]scale=iw/4:ih/4[pip];[pip]transpose=2[rotate];[1][rotate]overlay=main_w-overlay_w-30:main_h-overlay_h-10 -profile:v main -level 3.1 -ar 44100 -b:a 160k -crf 20 -s 720x1280 -vcodec h264 -vsync 2 -acodec aac -movflags +faststart /storage/emulated/0/Movies/RMR/out.mp4
I'm using -vsync to drop duplicated frames. This is not good enough, video is with freezing frames. How can I prevent freezing?
Setting a constant frame rate for the two would do
ffmpeg -i ... -i ... -lavfi '[0:v]fps=24000/1001[v1];[1:v]fps=24000/1001[v2];other_filters...' ...

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

Android ffmpeg apply video effects take log time

I am using below command to apply effect,its take 6-8 minutes to apply effect for 2 min video. Please help me to improve effective time for ffmpeg commands.
String commandStr = "ffmpeg -y -i "
+ mVideoData.getPath()
+ " -strict experimental -vf curves=vintage -s 640x480 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k -vcodec mpeg4 /sdcard/videokit/curve.mp4";

Categories

Resources