ffmpeg-android-java icon indicating copy to clipboard operation
ffmpeg-android-java copied to clipboard

Slow compression

Open wuxiaoqiang625 opened this issue 6 years ago • 9 comments

1 minutes and 45 seconds, about 253M video, compression time more than 2 minutes, how to solve the shorter compression time.

wuxiaoqiang625 avatar Jan 17 '18 05:01 wuxiaoqiang625

This one command,Can it be improved。

String cmd = "-y -i " + currentInputVideoPath + " -strict experimental -vcodec libx264 -preset ultrafast " + "-crf 24 -acodec aac -ar 44100 -ac 2 -r 10 -b:a 96k -s 640x480 -aspect 16:9 " + currentOutputVideoPath;

Thanks。

wuxiaoqiang625 avatar Jan 17 '18 05:01 wuxiaoqiang625

@wuxiaoqiang625 have you found a solution?

FranciscoNin avatar Feb 09 '18 19:02 FranciscoNin

No, the hard solution I'm using now has no soft solution. @FranciscoNin

wuxiaoqiang625 avatar Feb 13 '18 05:02 wuxiaoqiang625

@wuxiaoqiang625 What's hard solution?

CoXier avatar Oct 13 '18 13:10 CoXier

Tell me guys if you find any solution

samyakjain avatar Oct 25 '18 09:10 samyakjain

Well guys, after a lot of trial and error, I came up with 2 methods, one to compress videos that are below 250mb and those above.

public static String[] getCompressCommandBelow250(String path, String newFileName) {
        return new String[]{"-y", "-i", path, "-c:v", "libx264",
                "-bufsize", "3968k", "-ac", "1", "-g", "60", "-c:a", "aac", "-b:a", "128k",
                "-level", "3.0", "-crf", "28", "-preset", "ultrafast",
                "-strict", "-2", newFileName};
    }
public static String[] getCompressCommandOver250(String path, String newFileName) {
    return new String[]{"-y", "-i", path, "-c:v", "libx264",
            "-bufsize", "3968k", "-ac", "1", "-g", "60", "-c:a", "aac", "-b:a", "128k",
            "-level", "3.0", "-crf", "22", "-preset", "ultrafast",
            "-strict", "-2", newFileName};
}

It still didn't work well, and as for my research, it's quite impossible for the Android to reach an optimal compress time. With both commands it took me between 30 seconds and 1:30 minutes in any video length, from 3 seconds to a minute. So, what I did was to build my own camera to record videos inside the app, instead of relying on the device's camera to compress later. Doing that I was able to setup the resolution before it's even recorded, so doing that I wouldn't have the need to compress. And it worked very well!

I used this library to make my own camera: https://github.com/natario1/CameraView

And the configs I made:

<com.otaliastudios.cameraview.CameraView
                 android:id="@+id/camera"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:keepScreenOn="true"
                 app:cameraPlaySounds="true"
                 app:cameraSessionType="video"
                 app:cameraVideoCodec="h264"
                 app:cameraVideoMaxDuration="100000"
                 app:cameraVideoQuality="max480p" />

Worked like a charm. Now I have good quality videos with very low file sizes, without compression.

Hope it helps.

FranciscoNin avatar Nov 23 '18 14:11 FranciscoNin

Hi @FranciscoNin I am using this command for compressing video file , String[] mcpress={"-i","/storage/emulated/0/ffmpegTest/vtv_status.mp4","-c:v h264 -acodec mp3","/storage/emulated/0/ffmpegTest/mout.mp4"};

but i am getting following error in Onfailure. could you please tell how did you compress the video?

ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Trailing options were found on the commandline. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/ffmpegTest/vtv_status.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.71.100 Duration: 00:00:15.25, start: 0.046440, bitrate: 890 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x272 [SAR 1:1 DAR 40:17], 757 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default) Metadata: handler_name : SoundHandler At least one output file must be specified

DroidCraftsmanKK avatar Feb 02 '19 12:02 DroidCraftsmanKK

Hi everyone. Any success?

DavitVosk avatar Oct 18 '19 08:10 DavitVosk

I still need help in 2020 !

huynguyennovem avatar Apr 06 '20 10:04 huynguyennovem