android - 使用 FFMPEG 以毫秒为单位的无损视频修剪
问题描述
我已经花了几周的时间来测试这里的所有答案,以便在 Android 上使用 FFMPEG 进行无损切割。无论我尝试什么,我总是会失败。在我们正在构建的应用程序中,我们需要精确到毫秒。
我已经尝试了很多命令的变体,其中很多变体超过半秒。这适用于复制和重新编码。有了这个,我在这两个位置之前和之后都尝试了 -ss,但我没有看到任何区别。这些是效果最好的两个命令,但仍然不够接近:
//copy
"-ss $startTime -t $endTime -i $input -f segment -c copy $output"
//encode
"-i $input -ss $startTime -c:v libx264 -crf 12 -preset ultrafast -t $endTime $output"
有没有人使用过给出更准确结果的命令甚至其他库?
解决方案
在寻找了几天后,我在 FFMPEG 中最接近毫秒精确修剪的是使用以下命令:
"-ss $startCutTime -i $inputFilePath -ss 0 -c copy -to $endCutTime -avoid_negative_ts make_zero $outputFilePath"
对于 30fps 剪辑,此命令精确到大约 20 毫秒,但这完全取决于视频的帧速率。我希望这可以帮助其他人。以下是每个组件的作用的解释:
/**
* FFMPEG Cmd Structure
* -i: Input file
* -ss: If this is placed before the input file it seeks to this position in the input file. If it's after the input it will split from that exact position.
* -to: The position of where the command is going to cut to.
* -c copy: This copies the video and audio codecs as they are for speed.
* -avoid_negative_ts make_zero: Sets the first timestamp as 0
* The times are passed in parsed eg 00:00:10.456
* The output file is the last part of the command
*/
推荐阅读
- flutter - Flutter - 删除 Slider 中的默认填充
- sql-server - 如何在存储过程 SQL Server 中向用户授予权限
- javascript - VSCode 调试器不会在 Typescript 断点处停止
- python - 仅在 3 维数组的二维上的 Kronnecker 乘积
- javascript - 如何使用矩找到两次的差异?
- python - 无法在 TensorFlow v2 中创建不可训练的变量
- ruby-on-rails - 有两个同名的按钮,但只有一个按钮可以激活?
- r - 在 R 中合并数据框 - 结果数据框太大
- mysql - MYSQL 在 2021 第一周的 7 天删除记录时出现错误 #1292
- c# - ImmutableArray如何正确使用