FFMPEG 未按预期在 Android 中“剪切”

问题描述

我提到 FFMPEG not "cutting" as expected 以以下格式将视频分成块:

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:02.000",outputPath};

String[] cmd3 = new String []{"-ss","00:00:03.000",outputPath};

String[] cmd4 = new String []{"-ss","00:00:04.000",outputPath};

String[] cmd5 = new String []{"-ss","00:00:05.000",outputPath};

我使用这个库: https://github.com/teanersener/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 秒

稍后我会将这些拆分视频提供给播放器播放列表。

解决方法

使用段复用器

您可以使用 segment 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)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...