Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow compression #265

Open
wuxiaoqiang625 opened this issue Jan 17, 2018 · 9 comments
Open

Slow compression #265

wuxiaoqiang625 opened this issue Jan 17, 2018 · 9 comments

Comments

@wuxiaoqiang625
Copy link

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

@wuxiaoqiang625
Copy link
Author

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。

@FranciscoNin
Copy link

@wuxiaoqiang625 have you found a solution?

@wuxiaoqiang625
Copy link
Author

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

@CoXier
Copy link

CoXier commented Oct 13, 2018

@wuxiaoqiang625 What's hard solution?

@samyakjain
Copy link

Tell me guys if you find any solution

@FranciscoNin
Copy link

FranciscoNin commented Nov 23, 2018

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.

@DroidCraftsmanKK
Copy link

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

@DavitVosk
Copy link

Hi everyone. Any success?

@huynguyennovem
Copy link

I still need help in 2020 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants