【问题标题】:Compress video with ffmpeg4android library使用 ffmpeg4android 库压缩视频
【发布时间】:2023-04-10 19:45:01
【问题描述】:

我尝试关注ffmpeg4android library,但在压缩视频时遇到问题,如下图所示。

我使用意图转移到压缩媒体类,

Intent intent = new Intent(this, CompressingMedia.class);
intent.putExtra("file_path", mLlItems.get(0).getPath());
startActivity(intent);

这是被转移到的班级:

public class CompressingMedia extends BaseWizard {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    Log.d(Prefs.TAG, "path " + intent.getExtras().getString("file_path"));
    // /storage/emulated/0/DCIM/Camera/VID_20140312_090612.mp4

    String command = "ffmpeg -y -i " + intent.getExtras().getString("file_path") + 
            " -strict experimental -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 /sdcard/out.mp4";

    // if you want to change the default work location (/sdcard/videokit/) use the uncomment the below method.
    // It must be defined before calling the copyLicenseAndDemoFilesFromAssetsToSDIfNeeded method,
    // in order for this method to copy the assets to the correct location.
            //      setWorkingFolder("/sdcard/videokit/");

    // this will copy the license file and the demo video file.
    // to the videokit work folder location.
    // without the license file the library will not work.
    copyLicenseAndDemoFilesFromAssetsToSDIfNeeded();

    commandStr = command;
    setCommand(commandStr);

    runTranscoing();
    }
}

虽然收到了转码成功的提示,但是看起来文件压缩后的容量总是为0。(图片底部的日志)

我不知道下图效果好不好,我无法得到预期的结果 - 视频完全压缩成功。

有人知道为什么压缩后文件总是为0,请告诉我。谢谢。

这是原木猫:

03-13 14:49:45.655:I/ActivityManager(6065):时间线: Activity_launch_request id:app.cloudstringers 时间:38212359

03-13 14:49:45.665: V/Home(6065): Global ID 是 000400010007;Sell 是 3

03-13 14:49:45.770: D/ffmpeg4android(6065): 路径 /storage/emulated/0/videokit/out.mp4

03-13 14:49:45.770: I/ffmpeg4android(6065): workingFolderPath: /sdcard/videokit/

03-13 14:49:45.775: D/ffmpeg4android(6065): 工作目录存在, 不应对资产(许可证文件和演示视频)

03-13 14:49:45.785: D/ffmpeg4android(6065): 输出目录存在。

03-13 14:49:45.785: I/ffmpeg4android(6065): 命令已设置

03-13 14:49:45.785: I/ffmpeg4android(6065): 设置 remoteNotificationIconId: 0

03-13 14:49:45.785: D/ffmpeg4android(6065): 客户端无法解除绑定 - 服务未绑定

03-13 14:49:45.785: D/ffmpeg4android(6065): 客户端 stopService()

03-13 14:49:45.790:W/ContextImpl(6065):隐式意图 startService 不安全:Intent { act=com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge } android.content.ContextWrapper.stopService:499 com.netcompss.ffmpeg4android_client.BaseWizard.stopService:451 com.netcompss.ffmpeg4android_client.BaseWizard.runTranscoing:285

03-13 14:49:45.795: I/ffmpeg4android(6065): !!!!!!!!!!!!!!!!!!services.size(): 1

03-13 14:49:45.795: I/ffmpeg4android(6065): 放置基类

03-13 14:49:45.810: D/ffmpeg4android(6065): 开始: com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge

03-13 14:49:45.810: D/ffmpeg4android(6065): 客户端 startService()

03-13 14:49:45.810: D/ffmpeg4android(6065): bindService() 调用

03-13 14:49:45.815:W/ContextImpl(6065):隐式意图 startService 不安全:Intent { act=com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge } android.content.ContextWrapper.bindService:517 com.netcompss.ffmpeg4android_client.BaseWizard.bindService:462 com.netcompss.ffmpeg4android_client.BaseWizard.runTranscoing:288

03-13 14:49:45.820: D/ffmpeg4android(6065): 客户端 bindService()

03-13 14:49:45.935: I/ffmpeg4android(6616): =======service onCreate(): 停止前台(克服 2.3.x 错误)

03-13 14:49:45.935: I/ffmpeg4android(6616): =======服务 onBind()=======

03-13 14:49:45.940: I/ffmpeg4android(6616): ===onStartCommand 调用

03-13 14:49:45.940: I/ffmpeg4android(6616): ===onStartCommand 猫: 基地

03-13 14:49:45.940: D/ffmpeg4android(6616): onStartCommand, START_STICKY,基本命令

03-13 14:49:45.955: I/ffmpeg4android(6616): 获取 remoteNotificationIconId: 0

03-13 14:49:45.955:I/ffmpeg4android(6616):notifIcon 已设置

03-13 14:49:45.955: I/ffmpeg4android(6616): 启动 RemoteService 通知 ID:5326

03-13 14:49:45.965: I/ffmpeg4android(6616): 运行调用。

03-13 14:49:45.965: D/ffmpeg4android(6616): 睡觉,等待 命令

03-13 14:49:45.970: D/ffmpeg4android(6065): 客户端 onServiceConnected()

03-13 14:49:45.970: I/ffmpeg4android(6065): invokeService 调用

03-13 14:49:45.970: I/Videokit(6065): licenseCheck in path: /sdcard/videokit

03-13 14:49:45.970: I/Videokit(6065): isLicExistsComplex...

03-13 14:49:45.970: I/Videokit(6065): 试图打开 /sdcard/videokit/ffmpeglicense.lic

03-13 14:49:45.970:I/Videokit(6065):找到许可文件...

03-13 14:49:45.970:I/Videokit(6065):时间解码:1394535283

03-13 14:49:45.970: I/Videokit(6065): timeStrDec 1394535283 是有效的 数字。

03-13 14:49:45.970:I/Videokit(6065):时间差异:161702

03-13 14:49:45.970:I/Videokit(6065):您使用了 15 个试用版中的 1 个 天。

03-13 14:49:45.970: I/ffmpeg4android(6065): 设置远程 通知信息

03-13 14:49:45.970: D/ffmpeg4android(6616): 命令项数: 21

03-13 14:49:45.970: D/ffmpeg4android(6616): 命令: ffmpeg -y -i /storage/emulated/0/videokit/out.mp4 -strict experimental -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 /sdcard/out.mp4

03-13 14:49:45.970:D/ffmpeg4android(6616):远程工作文件夹: /sdcard/videokit

03-13 14:49:45.970: D/ffmpeg4android(6065): 删除: /sdcard/videokit/vk.log 已删除:true

03-13 14:49:45.975: D/ffmpeg4android(6065): 删除: /sdcard/videokit/ffmpeg4android.log 被删除:false

03-13 14:49:45.975: D/ffmpeg4android(6065): 删除: /sdcard/videokit/videokit.log 已删除:true

03-13 14:49:45.980: D/ffmpeg4android(6065): 客户端 invokeService()

03-13 14:49:45.980: D/ffmpeg4android(6065): 获取唤醒锁

03-13 14:49:46.265: D/ffmpeg4android(6616): 睡觉,等待 命令

03-13 14:49:46.295: D/ffmpeg4android(6065): TranscodeBackground doInBackground 开始

03-13 14:49:46.295: I/ffmpeg4android(6616): =======远程服务 运行转码 ======

03-13 14:49:46.340: V/HomeAsync(6065): TOTAL_SPACE 是 1;AVAILABLE_SPACE 为 0.451

03-13 14:49:46.345:I/ActivityManager(6065):时间线:Activity_idle id:android.os.BinderProxy@423deed8 时间:38213045

03-13 14:49:46.345:I/ActivityManager(6065):时间线:Activity_idle id:android.os.BinderProxy@420323a0 时间:38213045

03-13 14:49:46.565: D/dalvikvm(6616): 试图加载 lib /data/app-lib/app.cloudstringers-2/libvideokit.so 0x41b285f0

03-13 14:49:46.570:D/dalvikvm(6616):添加了共享库 /data/app-lib/app.cloudstringers-2/libvideokit.so 0x41b285f0

03-13 14:49:46.570:I/Videokit(6616):加载已编译的本机库 2013 年 10 月 23 日 21:59:53

03-13 14:49:46.575: I/ffmpeg4android(6616): ===============正在运行 来自线程路径的命令:/sdcard/videokit

03-13 14:49:46.575: I/Videokit(6616): vk ffmpeg sdcardPath: /sdcard/videokit

03-13 14:49:46.575: I/Videokit(6616): licenseCheck in path: /sdcard/videokit

03-13 14:49:46.575: I/Videokit(6616): isLicExistsComplex...

03-13 14:49:46.575: I/Videokit(6616): 试图打开 /sdcard/videokit/ffmpeglicense.lic

03-13 14:49:46.575:I/Videokit(6616):找到许可文件...

03-13 14:49:46.575: I/ffmpeg4android(6616): =======ProgressBackgroundRemote doInBackground=========

03-13 14:49:46.575:I/Videokit(6616):时间解码:1394535283

03-13 14:49:46.575: I/Videokit(6616): timeStrDec 1394535283 是有效的 数字。

03-13 14:49:46.575:I/Videokit(6616):时间差异:161703

03-13 14:49:46.575:I/Videokit(6616):您使用了 15 个试用版中的 1 个 天。

03-13 14:49:46.575: D/Videokit(6616): 许可证检查 rc: 0

03-13 14:49:46.575: D/Videokit(6616): run() 称为版本 2.0

03-13 14:49:46.575: D/Videokit(6616): run pass off to main()

03-13 14:49:46.800: D/ffmpeg4android(6065): onServiceDisconnected

03-13 14:49:48.640: I/ffmpeg4android(6065): 得到实际持续时间: 00:00:07.78

03-13 14:49:48.640: I/ffmpeg4android(6065): ==== 获取 来自 VK 的 currentVkLogSize

03-13 14:49:48.640: D/ffmpeg4android(6065): currentVkLogSize: 5751

03-13 14:49:48.645: I/ffmpeg4android(6065): 没有 ffmpeg4android_log 文件,使用 vk 日志

03-13 14:49:48.645: I/line(6065): _rate, rate, width or height

03-13 14:49:48.650:I/line(6065):统计:0 次搜索,0 次写入

03-13 14:49:48.650:I/line(6065):统计:读取 72873 字节,2 寻求

03-13 14:49:48.650: D/ffmpeg4android(6065): currentTimeStr: 退出

03-13 14:49:48.650: D/ffmpeg4android(6065): ============找到其中之一 日志中的退出标记============

03-13 14:49:48.650: I/ffmpeg4android(6065): onProgressUpdate: 100

03-13 14:49:48.650: D/ffmpeg4android(6065): 释放唤醒锁

03-13 14:49:48.650: D/ffmpeg4android(6065): TranscodeBackground onPostExecute

03-13 14:49:48.700: D/ffmpeg4android(6065): /sdcard/videokit/null 字节长度:0

03-13 14:49:48.700: D/ffmpeg4android(6065): showNotifications

03-13 14:49:48.700: W/ffmpeg4android(6065): 输出文件未设置使用 setOutputFilePath 方法设置完整的输出文件路径

03-13 14:49:48.705: I/ffmpeg4android(6065): FFMPEG 完成。

03-13 14:49:48.710: D/ffmpeg4android(6065): releaseService()

03-13 14:49:48.710: D/ffmpeg4android(6065): 客户端 stopService()

03-13 14:49:48.710: W/ContextImpl(6065): 隐式意图 startService 不安全:Intent { act=com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge } android.content.ContextWrapper.stopService:499 com.netcompss.ffmpeg4android_client.BaseWizard.stopService:451 com.netcompss.ffmpeg4android_client.BaseWizard.handleServiceFinished:513

【问题讨论】:

  • 能否将代码和输出作为文本而不是图像发布?
  • 谢谢,我已经把编码改成文字了。日志这么长。我认为将它们复制/粘贴到这个问题中并不容易,对吧?
  • 您附加的图像不仅不点击就无法阅读,而且还无法搜索那里的任何内容 - 这就是日志通常的用途。还要查看您的代码,如果您的路径中有任何空格或 shell 符号,它将无法正常工作(您也可能会在那里遇到一个很好的安全漏洞)
  • 啊,非常感谢您的建议 George Y. 已编辑。

标签: android video ffmpeg compression


【解决方案1】:

您也可以考虑使用来自原始来源(http://trac.ffmpeg.org/wiki/How%20to%20compile%20FFmpeg%20for%20Android)的真正(免费!)Android FFmpeg,而不是使用似乎违反 FFmpeg LGPL 许可的人提供的一些第三方编译。

【讨论】:

  • 你好,我试过用真正的ffmpeg。但它看起来很难与之集成。你想告诉我怎么做吗?我可以在 C 文件中调用 C 函数。我也可以构建 ffmpeg so 文件。谢谢
  • 请注意,您回答的问题已经超过一年了。当时还没有 FFmpeg4Android 的源代码可用,也没有满足其他 FFMpeg 要求,所以当被问到这个问题时,该项目确实违反了 LGPL。
【解决方案2】:

根据您的日志,您使用的命令不正确。您的视频文件可能与您使用的大小和纵横比参数不符。

在此处查看您的日志行: 03-13 14:49:48.645: I/line(6065): _rate, rate, width or height

最好的方法是发布输入视频文件的链接,以便我查看。

【讨论】:

  • 你好,我不再使用这个库了,它不是很好用,我需要手动使用 ffmpeg 库。应该比这个好,谢谢。
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-10
  • 1970-01-01
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多