weixin_39944638
2021-01-08 00:14 阅读 1

Slow compression

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

该提问来源于开源项目:WritingMinds/ffmpeg-android-java

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

9条回答 默认 最新

  • weixin_39944638 weixin_39944638 2021-01-08 00:14

    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。

    点赞 评论 复制链接分享
  • weixin_39740737 weixin_39740737 2021-01-08 00:14

    have you found a solution?

    点赞 评论 复制链接分享
  • weixin_39944638 weixin_39944638 2021-01-08 00:14

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

    点赞 评论 复制链接分享
  • weixin_39716043 weixin_39716043 2021-01-08 00:14

    What's hard solution?

    点赞 评论 复制链接分享
  • weixin_39638086 weixin_39638086 2021-01-08 00:14

    Tell me guys if you find any solution

    点赞 评论 复制链接分享
  • weixin_39740737 weixin_39740737 2021-01-08 00:14

    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"></com.otaliastudios.cameraview.cameraview>
    

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

    Hope it helps.

    点赞 评论 复制链接分享
  • weixin_39664998 weixin_39664998 2021-01-08 00:14

    Hi
    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

    点赞 评论 复制链接分享
  • weixin_39520880 weixin_39520880 2021-01-08 00:14

    Hi everyone. Any success?

    点赞 评论 复制链接分享
  • weixin_39566593 weixin_39566593 2021-01-08 00:14

    I still need help in 2020 !

    点赞 评论 复制链接分享

相关推荐