android - 如何减少 FFmpeg 中的转换/压缩时间以及如何合并命令?

标签 android video command-line ffmpeg

在使用 在原始视频中添加文本后,我想减少创建新视频所需的时间FFmpeg
我试图搜索,我发现下面给出的这段代码可以减少时间。

 -y -i /sdcard/videokit/in.mp4 -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -acodec aac -ar 44100 -ac 2 -b 36000k -s 1280x720 -aspect 16:9 -metadata:s:v:0 rotate=0 /sdcard/videokit/out3.mp4

现在,我想在视频中添加文字,并在 中完成。 FFmpeg ,通过此命令及其 100% 工作。
  String[] addTextCommand = {
            "-i",
            "" + realFilePath,
            "-vf",
            "drawtext=fontsize=50:fontfile=/storage/emulated/0/Download/Cerbetica-regular.ttf:fontcolor=red:text='"
                    + strText +
                    "':x=0:y=0: box=1: boxcolor=black@0.5:boxborderw=10: x=0: y=(h-text_h)/2",
            "-strict",
            "-2",
            outputFilePath};

现在我的问题是我如何合并这两个代码并制作一个命令来制作编辑过的视频,并且花费更少的时间来创建一个新视频。在此,我尝试了此命令,但它不起作用。
   String[] addTextCommand = {
            "-i",
            "" + realVideoPath,
            "-vf",
            "-c:v", "libx264",
            "-preset", "ultrafast",
            "-crf", "24",
            "-acodec", "aac",
            "-ar", "44100",
            "-ac", "2",
            "-b", "36000k",
            "-s", "1280x720",
            "-aspect", "16:9",
            "-metadata:s:v:0 rotate=0",
            "drawtext=fontsize=50:fontfile=/storage/emulated/0/Download/Cerbetica-regular.ttf:fontcolor=red:text='"
                    + strText +
                    "':x=0:y=0: box=1: boxcolor=black@0.5:boxborderw=10: x=0: y=(h-text_h)/2",
            "-strict",
            "-2",
            outputFilePath};

如果有人知道如何指挥 FFmpeg 请描述它并解释如何使用它。

使用@Mulvya 的命令我在控制台中得到了这个。
     D/MainActivity: FAILED with output : WARNING: linker: /data/user/0/com.inheritx.videoprocessing/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
                   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/i686-linux-android- --arch=x86 --cpu=i686 --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/x86 --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --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
                   Unrecognized option '2'.
                   Error splitting the argument list: Option not found
   D/MainActivity: Finished command : ffmpeg -i
   D/MainActivity: Finished command : ffmpeg /storage/emulated/0/Download/spacetestSMALL_512kb.mp4
   D/MainActivity: Finished command : ffmpeg -vf
   D/MainActivity: Finished command : ffmpeg drawtext=fontsize=50:fontfile=/system/fonts/DroidSans.ttf:fontcolor=red:text='Hello':x=0:y=0: box=1: boxcolor=black@0.5:boxborderw=10: x=0: y=(h-text_h)/2
   D/MainActivity: Finished command : ffmpeg -c:v
   D/MainActivity: Finished command : ffmpeg libx264
   D/MainActivity: Finished command : ffmpeg -preset
   D/MainActivity: Finished command : ffmpeg ultrafast
   D/MainActivity: Finished command : ffmpeg -crf
   D/MainActivity: Finished command : ffmpeg 24
   D/MainActivity: Finished command : ffmpeg -acodec
   D/MainActivity: Finished command : ffmpeg aac
   D/MainActivity: Finished command : ffmpeg -ar
   D/MainActivity: Finished command : ffmpeg 44100
   D/MainActivity: Finished command : ffmpeg -s
   D/MainActivity: Finished command : ffmpeg 1280x720
   D/MainActivity: Finished command : ffmpeg -aspect
   D/MainActivity: Finished command : ffmpeg 16:9
   D/MainActivity: Finished command : ffmpeg -metadata:s:v:0 rotate=0
   D/MainActivity: Finished command : ffmpeg -strict
   D/MainActivity: Finished command : ffmpeg -2
   D/MainActivity: Finished command : ffmpeg /storage/emulated/0/Movies/add_text25.mp4

最佳答案

利用

   String[] addTextCommand = {
            "-i",
            "" + realVideoPath,
            "-vf",
            "drawtext=fontsize=50:fontfile=/storage/emulated/0/Download/Cerbetica-regular.ttf:fontcolor=red:text='"
                    + strText +
                    "':x=0:y=0: box=1: boxcolor=black@0.5:boxborderw=10: x=0: y=(h-text_h)/2",
            "-c:v", "libx264",
            "-preset", "ultrafast",
            "-crf", "24",
            "-acodec", "aac",
            "-ar", "44100",
            "-ac", "2",
            "-s", "1280x720",
            "-aspect", "16:9",
            "-metadata:s:v:0 rotate=0",
            "-strict",
            "-2",
            outputFilePath};

drawtext 字符串是视频过滤器选项的参数,但您已将它们分开。

关于android - 如何减少 FFmpeg 中的转换/压缩时间以及如何合并命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44043571/

相关文章:

android - Espresso,点击位置上的一个项目

android - TLS Client Hello 请求在 iOS 或 Android 中包含未知版本

javascript - 视频播放在 setInterval 中不起作用

video - 如何使用 FFmpeg 直播本地视频

android - 特定 Activity 被销毁时释放内存

qt - 如何将 QUdp 数据包放入 AVPacket/FFmpeg

r - 相当于 R 中的 Stata 选项卡命令

command-line - sqlite3 命令行 - 如何显示更少/更多输出

java - 使用 Java exec 的额外 psql 命令行参数

android.database.sqlite.SQLiteException : near "...": syntax error (code 1)