ffmpeg分割视频的方法

news/2024/7/10 20:59:44 标签: ffmpeg

ffmpeg可以说是一个比较全能的编解码器,但我在分割视频的时候视频被他重新编码了,明明是copy却变成了encode。

我使用的命令是这样的:

1
ffmpeg -vcodec copy -acodec copy -ss 01:00:00 -t 00:00:30 -i input_file_h264.mp4 output_file.mp4

本来只是想分割出一段视频的,但却把分离出来的视频重新编码了,画质也变得惨不忍睹。

查了一些国外资料后发现了问题所在。

ffmpeg的手册中对于codec是这样写的:

‘-c[:stream_specifier] codec (input/output,per-stream)’
‘-codec[:stream_specifier] codec (input/output,per-stream)’
Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

意思就是如果把-codec放到输出文件的前面就当做编码器(encoder),在输入文件前面就当做解码器(decoder)。再看看我用的命令,-codec是在最前面的,也就是在输入文件的前面,copy被当做了解码器,这也是很多人遇到 Unknown decoder ‘copy’ 的原因。copy是一种特殊的编码器,因此-codec必须放在输出文件的前面。

还有就是关于-s选项的解释:

‘-ss position (input/output)’
When used as an input option (before -i), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate.

position may be either in seconds or in hh:mm:ss[.xxx] form.

意思就是如果要把-ss作为输入选项的话要放在-i之前,当做输出选项的话放在输出文件之前。我们这是要截取一段视频,应该当做输入选项,所以-ss要在-i之前才有效,不然会花费很长一段时间来寻找-ss。

最后分割视频的命令就变成了:

1
ffmpeg -ss 01:00:00 -i input_file_h264.mp4 -vcodec copy -acodec copy -t 00:06:00 output_file.mp4

果然,用最新版的ffmpeg也能成功分割。从上面我们可以发现一些选项的顺序是非常重要的,错误的顺序有时会造成截然不同的结果,不止ffmpeg,x264、mencoder等这些编码器也是如此。


http://www.niftyadmin.cn/n/652308.html

相关文章

SLAM技术

SALM是什么 SLAM的全称是Simultaneous Localization and Mapping,即定位与制图。SLAM和SFM有这千丝万缕的联系。 SFM(Structure From Motion),称之为传统三维重建,这是一门计算机视觉学科的分支,特点是把…

linux,在后台执行脚本/程序,并屏蔽输出

./xxx.sh >/dev/null 2>&1 & 在后台执行xxx.sh,并将回响重定向输出到空设备文件 /dev/null :空设备文件,将该文件换成具体的文件,输出将会输出到这个文件 2>&1 :表示错误输出重定向,重定向结果等…

写在前面 在编程界,自己还是名小学生,需要不断地学习,才能不断的成长。 常学常用 新的编程语言层出不穷,作为一枚程序猿,我们唯有不断地挣扎不断的求索,方能不被这滚滚的时代潮流所抛弃。其实&#xff0…

Cognos/Sql Server安装文件

cognos8.3安装文件.part1.rarcognos8.3安装文件.part2.rarcognos8.3安装文件.part3.rarCognos8.3 Aix安装文件.part1.rarCognos8.3 Aix安装文件.part2.rarCognos8.3 Aix安装文件.part3.rarcognos8.4.1安装文件.part1.rarcognos8.4.1安装文件.part2.rarcognos8.4.1安装文件.part…

Module build failed: TypeError: this.getResolve is not a function at Object.loader

Vue项目中安装了node-sass 安装过程: //安装node-sass npm install node-sass --save-dev //安装sass-loader npm install sass-loader --save-dev //安装style-loader npm install style-loader --save-dev 运行时,发生如下报错信息: Mo…

To install it, you can run: npm install --save !!vue-style-loader!css-loader?{sourceMap :true}!..

Vue项目,运行时,出现以下错误 ERROR Failed to compile with 1 errors 18:14:44This dependency was not found:* !!vue-style-loader!css-loader?{"sourceMap":true}!../../node_modules/vue-lo…

mysql with docker

Docker 安装mysql Docker mysql 把数据存储在本地目录

Vue三方框架的安装

写在前面: 以下安装,如果在安装过程中因为网络原因导致无法安装成功,建议更换执行命令npm为cnpm(前提是有安装过淘宝镜像) 一、axios 网络请求 安装 npm install axios —save引入 // main.js 导入 axios 来处理网…