首页 > 解决方案 > 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 秒

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

标签: androidvideoffmpegtrimcut

解决方案


使用段复用器

您可以使用段 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在此示例中)。


推荐阅读