如何在Android中使用FFMPEG降低默认摄像头拍摄的视频尺寸? [英] How do I reduce the video size captured by the default camera using FFMPEG in Android?

查看:412
本文介绍了如何在Android中使用FFMPEG降低默认摄像头拍摄的视频尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试降低Android中默认摄像头(它产生高分辨率视频)所捕获的视频大小。 FFMPEG 是否具有为给定分辨率编码视频的属性?我试过Google,但所有示例都使用命令行模式进行FFMPEG。

I am trying to reduce the video size captured by the default camera (it's generating high resolution video) in Android. Does FFMPEG have a property to encode a video with given resolution? I tried to Google, but all examples are using command line mode for FFMPEG.

我的问题是:


  1. 我们可以在Android中使用ffmpeg命令行吗?

  2. 如果不是,我们将如何实现?

  3. 在Android中直接使用ffmpeg录制视频?

  4. 是否有其他解决方案?

  1. Can we use ffmpeg command line in Android?
  2. If not then how we will achieve it?
  3. Can we able record a video directly using ffmpeg in Android?
  4. Is there any other solution for this?


推荐答案

p>编译ffmpeg为android是可能的,以及从命令行运行ffmpeg。没有必要深入本地代码和jni调用,除非您需要比命令行提供更高级的使用。

Compiling ffmpeg for android is possible, as well as running ffmpeg from command line. There's no need to delve into native code and jni calls unless you need more advanced usage than what the command line provides.

为了引用,这是我运行的shell脚本编译ffmpeg(在Ubuntu下运行,它使事情比Windows容易得多)

For reference, this is the shell script I run to compile ffmpeg (run under Ubuntu, it makes things a lot easier than windows)

#!/bin/bash


ANDROID_API=android-3
export ANDROID_NDK=${HOME}/android-ndk
export ANDROID_SDK=${HOME}/android-sdk
SYSROOT=$ANDROID_NDK/platforms/$ANDROID_API/arch-arm
ANDROID_BIN=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86/bin/
CROSS_COMPILE=${ANDROID_BIN}/arm-linux-androideabi-
export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools

export ARM_ROOT=${HOME}android-ndk
export ARM_INC=$ARM_ROOT/platforms/android-5/arch-arm/usr/include
export ARM_LIB=$ARM_ROOT/platforms/android-5/arch-arm/usr/lib
export LIB_INC=${HOME}/include
export LIB_LIB=${HOME}/lib
CFLAGS=" -I$ARM_INC -fPIC -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID  -Wa,--noexecstack -MMD -MP "
LDFLAGS=" -nostdlib -Bdynamic  -Wl,--no-undefined -Wl,-z,noexecstack  -Wl,-z,nocopyreloc -Wl,-soname,/system/lib/libz.so -Wl,-rpath-link=$ARM_LIB,-dynamic-linker=/system/bin/linker -L$ARM_LIB -nostdlib $ARM_LIB/crtbegin_dynamic.o $ARM_LIB/crtend_android.o -lc -lm -ldl -lgcc "

FLAGS="--target-os=linux --enable-cross-compile --cross-prefix=$CROSS_COMPILE --arch=arm --prefix=$HOME --disable-shared --enable-static --extra-libs=-static --extra-cflags=--static --enable-small --disable-asm --disable-yasm --disable-amd3dnow --disable-amd3dnowext --disable-mmx --disable-mmx2 --disable-sse --disable-ssse3 --disable-indevs"
export CFLAGS=$EXTRA_CFLAGS
export LDFLAGS=$EXTRA_LDFLAGS
./configure $FLAGS --extra-cflags="$CFLAGS" --extra-ldflags="$LDFLAGS" \
--cc="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}" --extra-ldflags="$LDFLAGS" \
--cxx="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}" \
--nm="${CROSS_COMPILE}nm" \
--ar="${CROSS_COMPILE}ar"
make clean
make -j4 || exit 1
make install || exit 1

至于运行ffmpeg,首先需要将ffmpeg复制到应用程序的文件目录中,chmod 755它使用getRuntime.exec()如下所示,然后运行ffmpeg与以下行:

As for running ffmpeg, first you need to copy ffmpeg into your application's files directory, chmod 755 it using getRuntime.exec() as shown below, then run ffmpeg with the following line:

Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/files/ffmpeg -i in.mp4 out.mp4")

现在,以相对于ffmpeg输入的格式可以理解,这是一个很难的,我还在试图找出。我有一个stackoverflow问题的主题:使用ffmpeg实时解码Android的硬件编码的H264相机进纸

Now, getting the camera's input to ffmpeg in a format it can understand is the tough bit, which I'm still trying to figure out. I've got a stackoverflow question going on the topic: Decode android's hardware encoded H264 camera feed using ffmpeg in real time

这篇关于如何在Android中使用FFMPEG降低默认摄像头拍摄的视频尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆