使用ffmpeg根据开始和结束时间剪切视频

2023-11-14

本文翻译自:Cutting the videos based on start and end time using ffmpeg

I tried to cut the video using the start and end time of the video by using the following command 我尝试通过使用以下命令使用视频的开始和结束时间剪切视频

ffmpeg -ss 00:00:03 -t 00:00:08 -i movie.mp4 -acodec copy -vcodec copy -async 1 cut.mp4

By using the above command i want to cut the video from 00:00:03 to 00:00:08 . 通过使用以上命令,我想将视频从00:00:0300:00:08 But it is not cutting the video between those times instead of that it is cutting the video with first 11 seconds. 但是,这并不是在这段时间之间剪切视频,而是在前11秒内剪切视频。 can anyone help me how resolve this? 谁能帮我解决这个问题?

Edit 1: 编辑1:

I have tried to cut by using the following command which is suggested by mark4o 我试图通过使用mark4o建议的以下命令进行剪切

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

But it was shown the following error. 但是显示以下错误。

the encoder 'aac' is experimental but experimental codecs are not enabled 编码器“ aac”是实验性的,但未启用实验性编解码器

so i added the -strict -2 into the command ie, 所以我在命令中添加-strict -2

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -strict -2 cut.mp4

Now it is working fine. 现在工作正常。


#1楼

参考:https://stackoom.com/question/1FOB0/使用ffmpeg根据开始和结束时间剪切视频


#2楼

You probably do not have a keyframe at the 3 second mark. 您可能在3秒标记处没有关键帧。 Because non-keyframes encode differences from other frames, they require all of the data starting with the previous keyframe. 由于非关键帧编码与其他帧的差异,因此它们需要从前一个关键帧开始的所有数据。

With the mp4 container it is possible to cut at a non-keyframe without re-encoding using an edit list. 使用mp4容器,可以在非关键帧处进行剪切,而无需使用编辑列表进行重新编码。 In other words, if the closest keyframe before 3s is at 0s then it will copy the video starting at 0s and use an edit list to tell the player to start playing 3 seconds in. 换句话说,如果最接近3s的关键帧位于0s,则它将复制从0s开始的视频,并使用编辑列表告诉播放器开始播放3秒。

If you are using the latest ffmpeg from git master it will do this using an edit list when invoked using the command that you provided. 如果您使用的是git master中的最新ffmpeg ,则在使用提供的命令调用该列表时,将使用编辑列表来执行此操作。 If this is not working for you then you are probably either using an older version of ffmpeg, or your player does not support edit lists. 如果这不适合您,则可能是您使用的是较旧版本的ffmpeg,或者您的播放器不支持编辑列表。 Some players will ignore the edit list and always play all of the media in the file from beginning to end. 一些播放器将忽略编辑列表,并始终从头到尾播放文件中的所有媒体。

If you want to cut precisely starting at a non-keyframe and want it to play starting at the desired point on a player that does not support edit lists, or want to ensure that the cut portion is not actually in the output file (for example if it contains confidential information), then you can do that by re-encoding so that there will be a keyframe precisely at the desired start time. 如果要从非关键帧开始精确剪切,并且希望它在不支持编辑列表的播放器上从所需点开始播放,或者要确保剪切部分实际上不在输出文件中(例如, (如果其中包含机密信息),则可以通过重新编码来实现,这样就可以在所需的开始时间准确显示关键帧。 Re-encoding is the default if you do not specify copy . 如果不指定copy则默认为重新编码。 For example: 例如:

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

When re-encoding you may also wish to include additional quality-related options or a particular AAC encoder. 重新编码时,您可能还希望包括其他与质量相关的选项或特定的AAC编码器。 For details, see ffmpeg's x264 Encoding Guide for video and AAC Encoding Guide for audio. 有关详细信息,请参阅ffmpeg的x264视频编码指南AAC音频编码指南

Also, the -t option specifies a duration, not an end time. 另外, -t选项指定持续时间,而不是结束时间。 The above command will encode 8s of video starting at 3s. 上面的命令将从3s开始对8s的视频进行编码。 To start at 3s and end at 8s use -t 5 . 要以3s开始并以8s结束,请使用-t 5 If you are using a current version of ffmpeg you can also replace -t with -to in the above command to end at the specified time. 如果您使用的是ffmpeg的当前版本,则还可以在上述命令中将-t替换为-to在指定时间结束。


#3楼

    ffmpeg -i movie.mp4 -vf trim=3:8 cut.mp4

将所有内容从秒3减至秒8。


#4楼

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 -c copy cut.mp4 

Use -c copy for make in instantly. 使用-c复制即可即时制作。 In that case ffmpeg will not re-encode video, just will cut to according size. 在这种情况下,ffmpeg不会重新编码视频,只会切成适当的大小。


#5楼

Try using this. 尝试使用这个。 It is the fastest and best ffmpeg-way I have figure it out: 这是我弄清楚的最快最好的ffmpeg方式:

 ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -c copy output.mp4

This command trims your video in seconds! 此命令可在几秒钟内修剪您的视频!

I have explained it on my blog here : 我已经解释它在我的博客在这里

-i: This specifies the input file. -i:这指定输入文件。 In that case, it is (input.mp4). 在这种情况下,它是(input.mp4)。
-ss: Used with -i, this seeks in the input file (input.mp4) to position. -ss:与-i一起使用,它在输入文件(input.mp4)中查找位置。
00:01:00: This is the time your trimmed video will start with. 00:01:00:这是您修剪的视频开始的时间。
-to: This specifies duration from start (00:01:40) to end (00:02:12). -至:这指定从开始(00:01:40)到结束(00:02:12)的持续时间。
00:02:00: This is the time your trimmed video will end with. 00:02:00:这是您修剪的视频结束的时间。
-c copy: This is an option to trim via stream copy. -c复制:这是通过流复制修剪的选项。 (NB: Very fast) (注:非常快)

The timing format is: hh:mm:ss 计时格式为: hh:mm:ss

Please note that the current highly upvoted answer is outdated and the trim would be extremely slow. 请注意,当前高度评价的答案已过时,修剪将非常慢。 For more information, look at this official ffmpeg article . 有关更多信息,请参见ffmpeg官方文章


#6楼

To cut based on start and end time from the source video and avoid having to do math, specify the end time as the input option and the start time as the output option. 要基于源视频的开始时间和结束时间进行剪切并避免进行数学运算,请指定结束时间作为输入选项,并指定开始时间作为输出选项。

ffmpeg -t 1:00 -i input.mpg -ss 45 output.mpg

This will produce a 15 second cut from 0:45 to 1:00. 这将在0:45到1:00之间产生15秒的切换。

This is because when -ss is given as an output option, the discarded time is still included in the total time read from the input, which -t uses to know when to stop. 这是因为当-ss作为输出选项给出时,丢弃的时间仍包含在从输入中读取的总时间中, -t用于了解何时停止。 Whereas if -ss is given as an input option, the start time is seeked and not counted , which is where the confusion comes from. 而如果将-ss作为输入选项,则会查找开始时间, 而不计算开始时间,这是造成混乱的原因。

It's slower than seeking since the omitted segment is still processed before being discarded, but this is the only way to do it as far as I know. 这比查找要慢,因为省略的段在丢弃之前仍会进行处理,但是据我所知,这是唯一的方法。 If you're clipping from deep within a large file, it's more prudent to just do the math and use -ss for the input. 如果要从一个大文件中深切,则最好进行数学运算,并使用-ss作为输入。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用ffmpeg根据开始和结束时间剪切视频 的相关文章

  • Unix 中的访问时间是多少

    我想知道访问时间是多少 我在网上搜索但得到了相同的定义 读 被改变 我知道与touch我们可以改变它 谁能用一个例子来解释一下它是如何改变的 有没有办法在unix中获取创建日期 时间 stat结构 The stat 2 结构跟踪所有文件日期
  • FFMPEG 帧到 DirectX 表面

    给定一个指向 FFMPEG 的 AVFrame 的指针avcodec decode video 函数如何将图像复制到 DirectX 表面 假设我有一个指向适当大小的 DX X8R8G8B8 表面的指针 Thanks John 您可以使用
  • Linux >2.6.33:可以使用 sendfile() 来实现更快的“猫”吗?

    必须将大量大文件连接成一个更大的单个文件 我们目前使用 cat file1 file2 output file but are wondering whether it could be done faster than with that
  • 如何将命令输出作为多个参数传递给另一个命令

    我想将命令的每个输出作为多个参数传递给第二个命令 例如 grep pattern input returns file1 file2 file3 我想复制这些输出 例如 cp file1 file1 bac cp file2 file2 b
  • 安装 JDK 时出错:keytool 命令需要已安装的 proc fs (/proc)。 Linux 的 Windows 子系统

    我尝试在 Linux 的 Windows 子系统 Ubuntu 14 04 上安装 Oracle JDK 1 7 但出现以下错误 the keytool command requires a mounted proc fs proc Jav
  • 当我的应用程序最小化时,在 Android 中使用 Youtube API 播放音乐视频中的音频

    我正在开发一个使用 Youtube API 的应用程序 因为我主要集中于MUSIC VIDEOS 来自 Youtube 当我离开应用程序时 我需要在后台播放视频的音频 但每次我导航到另一个应用程序时 视频都会暂停 我该怎么做才能解决这个问题
  • 如何在 Ubuntu/Linux 发行版中安装 Tesseract-OCR 3.03?

    我和一个朋友有兴趣为 CV 项目训练 tesseract OCR 引擎 我们尝试使用一些包装器 例如 PyTesser 和 pyocr 但结果目前不如我们需要的那么准确 因此 我们希望尝试训练超立方体以更好地实现我们的目的 即识别食品标签上
  • 打印 STDOUT/STDERR 并将它们写入 Bash 中的文件?

    有没有办法让 Bash 将 STDOUT STDERR 重定向到文件 但仍然将它们打印到终端 这会将 STDOUT 和 STDERR 重定向到同一个文件 some command 2 gt 1 tee file log Example to
  • 在 Linux 服务器上创建和编辑 MS-Word 文档?

    希望开发处理文档的服务器端应用程序 源文档大多是MS Word 2003 2007 即MS版本的Docx 希望服务器应用程序能够在linux或windows上运行 想知道在linux下读写MS Word文件最好的工具或库是什么 兼容性是最重
  • 如何使用 PyAudio 选择特定的输入设备

    通过 PyAudio 录制音频时 如何指定要使用的确切输入设备 我的电脑有两个麦克风 一个内置 一个通过 USB 我想使用 USB 麦克风进行录音 这流类 https people csail mit edu hubert pyaudio
  • swscaler 警告:使用了已弃用的像素格式

    我想先对视频帧执行颜色空间转换 然后使用以下代码将其转换为 opengl 纹理 struct SwsContext pSwsCtx sws getCachedContext NULL width height codec gt pix fm
  • 使用 .htaccess 启用 PHP 短标签

    我在自己的 Centos 服务器上设置了 Apache 并具有多个虚拟 Web 服务器 并且我希望仅为位于以下位置的其中一个 Web 服务器启用 PHP 短标记 var www ostickets html 我可以通过添加成功启用短标签sh
  • 在 Windows / Linux 中创建 Mac 包

    我自己努力制作一个 r 包 我按照 stackoverflow 中上一个问题的说明进行操作如何为外行开发软件包 http cran r project org bin windows Rtools 以下是我根据上一个问题采取的步骤 在新的
  • 如何在C程序中直接改变显存映射来绘制像素(无需库函数)

    是否可以通过使用 C 程序更改 RAM 中屏幕 视频即监视器 内存映射中的值来显示黑点 我不想使用任何库函数 因为我的主要目标是学习如何开发简单的操作系统 我尝试访问起始屏幕内存映射 即 0xA0000 在 C 中 我尝试运行该程序 但由于
  • 进程如何知道它已收到信号

    如果我错了 请纠正我 以下是我对信号的理解 据我所知 信号生成 和信号传递有2个不同 事物 为了产生信号 操作系统只是在位数组中设置一个位 在过程控制中维护 工艺块 PCB 每一位 对应于特定信号 当设置一个位时 这意味着 该位对应的信号为
  • 将rtsp视频流转换为http流

    我有一个实时视频流的 rtsp URL 我想将其作为 HTTP 流进行访问 有人可以告诉我是否有任何组件可以放在我的服务器上来执行此操作 我不知道如何实现这一点 请注意 Thanks 我想说你最好的选择是使用 FFmpeg 或 VLC 两者
  • tar.gz 和 tgz 是同一个东西吗? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我创建了 tgz 文件tar czvf filecommand then 我最终得到了一个 tgz 文件 我想知道它和tar gz 之间的
  • PHP 日志文件颜色

    我正在编写一个 PHP 日志文件类 但我想为写入文件的行添加颜色 我遇到的问题是颜色也会改变终端的颜色 我想要实现的是仅更改写入日志文件的行的颜色 class logClass extends Singleton private funct
  • 在Linux中创建可执行文件

    我计划做的一件事是编写 非常简单的 Perl 脚本 并且我希望能够在不从终端显式调用 Perl 的情况下运行它们 我明白 要做到这一点 我需要授予他们执行权限 使用 chmod 执行此操作非常简单 但它似乎也是一个稍微费力的额外步骤 我想要
  • php56 - CentOS - Remi 仓库

    我刚刚在测试盒上安装了 php 5 6 正常的 cli php 解释器似乎不存在 gt php v bash php command not found gt php56 v PHP 5 6 13 cli built Sep 3 2015

随机推荐

  • 【Python搞搞轻量Blog】第一发 Flask入门

    我发现很多小伙伴一直想着有自己的一个博客 而且还想自己写一个 你们都这么爱折腾 我就给你们搞一个轻量级级别的Blog 准备 我们要用Python来写一套轻量级的博客 那么必须要有Python方面的基础 如果有HTML和CSS的基础食用更佳
  • Ren'Py引擎源代码解读(1)——脚本文件加载

    因为想要尝试把Ren Py移植到Cocos上 尽可能的使用原来的rpy文件 这就难免要解析rpy文件 因此就参考了一下Ren Py自己是怎么解析脚本的 文件加载 那么从哪里看起呢 先简要看一下Ren Py的启动过程 启动脚本肯定是根目录下的
  • 1.1.3 Hadoop生态系统

    1 1 3 Hadoop生态系统 2013 05 08 09 38 16 我来说两句 收藏 我要投稿 本文所属图书 gt Hadoop技术内幕 深入解析Hadoop Common和HDFS架构设计与实现原理 Hadoop技术内幕共两册 分别
  • CDMA 猫用AT命令发中文短信(C#)

    CDMA猫连PDU都不支持 只能发文本短信 而且发中文短信居然是UNICODE 无法在超级终端里输入 只能写程序 网上这个问题谈论地比较多 做起来比较累 还偶尔会出乱码 还是将C 的成功代码帖一下吧 void SendCHNSms stri
  • 力扣 - 1、俩数之和

    题目 给定一个整数数组 nums 和一个整数目标值 target 请你在该数组中找出 和为目标值 的那 两个 整数 并返回它们的数组下标 你可以假设每种输入只会对应一个答案 但是 数组中同一个元素在答案里不能重复出现 你可以按任意顺序返回答
  • 清华梦的粉碎-写给清华大学的退学申请

    作者 王垠 清华梦的诞生 小时候 妈妈给我一个梦 她指着一个大哥哥的照片对我说 这是爸爸的学生 他考上了清华 大学 他是我们中学的骄傲 长大后 你也要进入清华大学读书 为我们家争光 我不知道清华是什么样子 但是我知道爱迪生和 牛顿 的故事
  • 2.3安装工业相机SDK及测试

    不同工业相机的sdk不同 可以到相应的官网下载 我使用的是大华相机 文中提到的例程的Camera和src的代码在文尾 有兴趣可以参考 下载 官方下载地址 http download huaraytech com pub sdk 我使用的是2
  • 自动化测试,软件测试面试题

    这是 2021 博客之星 竞选 https bbs csdn net topics 603958359 麻烦大家帮忙五星 谢谢大家了 性能自动化会给大家整理一套 投票地址 https bbs csdn net topics 60395835
  • Mysql清除字段中的中文,只保留数字、字母等非中文符号

    原理 使用convert函数 将字段类型转换为其他数据类型即ASCII类型 然后再配合用replace函数 清除中文 即可达到效果 根据自身需要也可以用replace清除更多字符 SELECT distinct 字段1 as 原数据 con
  • 接入微信电子发票java_接入微信电子发票流程步骤

    一 流程图 电子发票流程涉及用户 商户 报销方 发票平台和公众平台五个角色 对于自建发票平台的商户 发票平台即为商户自身的开票系统 承担着制作发票卡券 将发 票卡券插入用户卡包以及报销状态更新的关键作用 二 步骤及页面 步骤1 检查是否微信
  • TikTok听证会后:走不出的隐私风暴和出不了的海

    TikTok听证会结束一周 这场来自大洋彼岸的漩涡紧扣着中国科技圈的心弦 这不是一场稀松平常的热点 而是一次样本实例的演绎 每一个企图出海 扩展生意版图的中国企业们 都在密切关注 希望在TikTok身上找到可以参照的出路和回旋的可能性 Ti
  • Python单元测试unittest——及天坑

    python 的单元测试框架是unittest 但我只想说 想放弃 python unitest的重要特性 测试类继承自unittest TestCase 测试函数须以test开头 每个测试函数之间是都是平行的 不可共享数据 平行宇宙 关于
  • awk使用shell变量及shell使用awk中的变量

    在写shell脚本时 经常会使用到awk程序 但是有些复杂的逻辑 可能需要在awk中使用在shell中定义的变量 而且awk程序处理之后 产生的中间变量 还需要在shell中继续处理 一 那如何在awk中使用在shell中定义的变量呢 方法
  • 【踩坑记录】Method oracle/jdbc/driver/OracleResultSetImpl.getObject is abstract 错误

    版本 oralce 10g springboot2 2 2 mybatisplus 3 4 1 异常堆栈 java lang AbstractMethodError Method oracle jdbc driver OracleResul
  • MongoDB是一个介于关系数据库和非关系数据库之间的产品

    MongoDB是一个介于关系数据库和非关系数据库之间的产品 是非关系数据库当中功能最丰富 最像关系数据库的 他支持的数据结构非常松散 是类似json的bjson格式 因此可以存储比较复杂的数据类型 Mongo最大的特点是他支持的查询语言非常
  • (最新版)Java开发,飞机大战3.0版游戏项目,Java实战游戏项目

    Java开发的精品小游戏 飞机大战3 0 飞机大战是不少90后的童年经典回忆 这个游戏具有紧张刺激的画面和操作感 令人回味无穷 如果你是Java编程爱好者 想要锻炼自己的实战能力 那么飞机大战3 0就是一个很好的练手项目 这个项目只要稍微有
  • 删除Pods

    通过删除job删除Pods 否者pods会重启 def cmd kubectl command try r os system kubectl command if r 0 print f Fail kubectl command retu
  • C#接口

    C 接口提供了一个公共方法的集合包 继承该接口的类需要实现接口中的方法 接口中只有申明 没有实现 这点很重要 接口中可以包含4种成员 1 函数 2 属性 3 索引器 4 事件 这里就要提到上面说的很重要的地方了 也就是 这四种成员都不能有实
  • Flex经典等分布局

    CSS 书写规范 布局 宽高 对齐 水平 垂直 颜色 字体 背景色 display block flex width xxx xxx px height xxx px line height xxx px 字体 样式 背景色 div cla
  • 使用ffmpeg根据开始和结束时间剪切视频

    本文翻译自 Cutting the videos based on start and end time using ffmpeg I tried to cut the video using the start and end time