本文介绍了Android 上的快速视频压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将视频文件上传到服务器并在上传前进行压缩.我正在使用 ffmpeg libx264.我已经看到 viber 可以在一分钟内上传 30 秒大小为 78MB 的视频文件 [减少到 2.3MB].我想知道他们是怎么做到这么快的?

I want to upload video files to server and compress before uploading. I'm using ffmpeg libx264. I have seen viber can upload 30 second video file of size 78MB within a minute [reduce it's down to 2.3MB]. I want to know how do they do it so fast?

到目前为止我尝试过的 -

What I have tried so far -

FFMPEG version :  n2.4.2
Built with gcc 4.8

Build Configuraiton : --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --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/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=

命令:

ffmpeg -y -i /storage/emulated/0/main.mp4 -s 480x320 -r 20 -c:v libx264 -preset ultrafast -c:a copy -me_method zero -tune fastdecode -tune zerolatency -strict -2 -b:v 1000k -pix_fmt yuv420p /storage/emulated/0/output.mp4

到目前为止的结果是,一个 30 秒的 78MB 文件被压缩为 4.3MB,大约需要 1 分 28 秒.这是控制台转储 - http://pastebin.com/rn81acGx.我主要是想减少压缩所需的时间.我怎样才能做到这一点?

The result so far is, a 30second 78MB file gets compressed to 4.3MB which takes around 1min 28seconds. Here is the console dump - http://pastebin.com/rn81acGx . I mainly want to reduce the time it takes to compress. How can I achieve this?

提前致谢.

推荐答案

x264 cpu 能力

您的 ffmpeg 控制台输出/日志显示来自 libx264 的以下消息:

x264 cpu capabilities

Your ffmpeg console output/log shows the following message from libx264:

using cpu capabilities: none!

对于您的设备,我希望是这样的:

For your device I would expect something like:

using cpu capabilities: ARMv7 NEON

您应该重新评估编译 x264 的方式,以便它正确支持 CPU 的功能.使用 none 时,它的编码速度要慢得多.

You should re-evaluate how you compiled x264 so it properly supports the capabilities of your CPU. With none it encodes significantly slower.

  • 不要为 x264 使用 --disable-asm 配置选项.
  • x264 运行 ./configure 后,控制台输出应显示 asm: yes.
  • 使用最近的 x264.我看到许多用户在编译旧版本时可能会错过优化.
  • 然后重新编译ffmpeg,使其使用新的x264.如果您有多个版本,请确保 ffmpeg 不会链接到错误的 x264.
  • Do not use the --disable-asm configure option for x264.
  • After you run ./configure for x264 the console output should show asm: yes.
  • Use a recent x264. I see many users compiling old versions that may miss out on optimizations.
  • Then recompile ffmpeg so it uses the new x264. Make sure ffmpeg does not link to the wrong x264 if you have multiple versions.

ffmpeg 目前通过 Android 中的 MediaCodec API 支持硬件辅助 H.264 和 HEVC 解码,这可能有助于减少整体处理时间.有关更多信息和最新功能列表,请参阅 FFmpeg Wiki:硬件加速.

ffmpeg currently supports hardware assisted H.264 and HEVC decoding via the MediaCodec API in Android which may help decrease the overall processing time. For more info and an up-to-date list of capabilities see FFmpeg Wiki: Hardware Acceleration.

要使用它,请确保您的 ffmpeg 使用 --enable-jni--enable-mediacodec 编译.

To use it ensure your ffmpeg is compiled with --enable-jni and --enable-mediacodec.

这篇关于Android 上的快速视频压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 07:49