android - FFMPEG 在 Android 中没有像预期的那样“切割”
问题描述
我提到FFMPEG 没有像预期的那样“切割”以将视频分成以下格式的块:
00:00:00 - 00:00:01
00:00:01 - 00:00:02
00:00:02 - 00:00:03
00:00:03 - 00:00:04
00:00:04 - 00:00:05
这是我使用的命令:
String[] cmd1 = new String []{"-ss", "00:00:00.000", "-i", inputVideoUrl, "-t", "00:00:01.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd2 = new String []{"-ss", "00:00:01.000", "-i", inputVideoUrl, "-t", "00:00:02.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd3 = new String []{"-ss", "00:00:02.000", "-i", inputVideoUrl, "-t", "00:00:03.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd4 = new String []{"-ss", "00:00:03.000", "-i", inputVideoUrl, "-t", "00:00:04.000", "-c:v", "libx264", "-strict", "-2", outputPath};
String[] cmd5 = new String []{"-ss", "00:00:04.000", "-i", inputVideoUrl, "-t", "00:00:05.000", "-c:v", "libx264", "-strict", "-2", outputPath};
我使用这个库: https ://github.com/teaersener/mobile-ffmpeg
implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.2.2.LTS'
当我执行时,我一直得到从视频开头开始的持续时间。请建议我做错了什么,我搜索并尝试更改命令但没有任何效果。
00:00:00 - 00:00:01
00:00:00 - 00:00:02
00:00:00 - 00:00:03
00:00:00 - 00:00:04
00:00:00 - 00:00:05
让我分享另一个示例来解释我的要求: inputVideoUrl 包含任意长度的视频(例如:5 分钟)我想以 5 个分割视频的形式剪切用户选择的部分(例如前一分钟)。
分割 1: 00 秒 - 12.0 秒
分段 2:12.1 秒 - 24.0 秒
分段 3:24.1 秒 - 36.0 秒
分段 4:36.1 秒 - 48.0 秒
分段 5:48.1 秒 - 60.0 秒
稍后我会将这些拆分视频提供给播放器播放列表。
解决方案
使用段复用器
您可以使用段 muxer的一个命令完成所有操作:
ffmpeg -i input -c:v libx264 -c:a aac -f segment -segment_time 1 -force_key_frames "expr:gte(t,n_forced*1)" -reset_timestamps 1 output_%03d.mp4
中的数值expr:gte(t,n_forced*1)
应等于该-segment_time
值(1
在此示例中)。
推荐阅读
- laravel - MySql phpmyadmin 表到 Laravel 迁移文件
- python - 在声明 range() 时,您是否应该在逗号/s 之后放置一个空格?
- php - WooCommerce 在订单接收端点获取订单 ID 和订单密钥
- angular - 将 Canvas 与 Angular Ionic 一起使用 - 难以保存附加文本的图像
- c++ - 在 while 循环中不被 cin 阻塞
- javascript - 错误域=NSURLErrorDomain 代码=-1001 “请求超时。” UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataPDTask
- java - Spring Boot AuthenticationManagerBean 不起作用
- javascript - 使用 JS ID 作为 html 中的背景图片 url
- typescript - 在 TS 中,为什么 number[][number] === number?
- python - 使用 web3.py 解码智能合约的返回值?