ffmpeg 从现有视频中截取一段

ffmpeg 从现有视频中截取一段

  • References

    1. ffmpeg -i ./input.mp4 -vcodec copy -acodec copy -ss 00:00:10 -to 00:00:25 ./output.mp4 -y

    strong@foreverstrong:~/ForeverStrong$ ffmpeg -i ./train_video.mp4 -vcodec copy -acodec copy -ss 00:00:10 -to 00:00:25 ./output_train_video.mp4 -y

    input: 输入视频文件名
    output: 输出视频文件名
    -vcodec copy: 使用与原视频一样的视频编解码器
    -acodec copy: 使用与原视频一样的音频编解码器
    -i: input file
    -y: overwrite output files without asking
    -to: 结束时间
    -ss: 起始时间

上述命令从视频的第 10s (-ss 00:00:10) 开始截取,到视频的第 25s (-to 00:00:25) 结束,共计截出视频 15s.

    1. ffmpeg -ss 00:01:20 -t 00:00:30 -accurate_seek -i ./input.mp4 -vcodec copy -acodec copy ./output.mp4 -y

    strong@foreverstrong:~/ForeverStrong$ ffmpeg -ss 00:01:20 -t 00:00:30 -accurate_seek -i ./train_video.mp4 -vcodec copy -acodec copy ./output_train_video.mp4 -y

截取时间段不准确,不建议使用。

input: 输入视频文件名
output: 输出视频文件名
-vcodec copy: 使用与原视频一样的视频编解码器
-acodec copy: 使用与原视频一样的音频编解码器
-i: input file
-y: overwrite output files without asking
-t: 截取时长
-ss: 起始时间

上述命令从视频的第 1 分 20 秒 (-ss 00:01:20) 开始截取,截取 30 秒 (-t 00:00:30) 视频。

截取速度快,因为它不会对视频重新编码,直接截取相关时间,导出视频。但是这种方式会导致:如果视频结尾不是关键帧,那么视频最后就会出现一段空白。

    1. ffmpeg -ss 00:01:20 -t 00:00:30 -accurate_seek -i ./input.mp4 -vcodec copy -acodec copy -avoid_negative_ts 1 ./output.mp4 -y

    strong@foreverstrong:~/ForeverStrong$ ffmpeg -ss 00:01:20 -t 00:00:30 -accurate_seek -i ./train_video.mp4 -vcodec copy -acodec copy -avoid_negative_ts 1 ./output_train_video.mp4 -y

截取时间段不准确,不建议使用。

截取视频之后,空白视频消失,但是时间不会精确截取,它会找到下一个关键帧,补全这个视频,导致连续分割的视频之间存在细微的交集。

    1. ffmpeg -ss 00:01:20 -t 00:00:30 -i ./input.mp4 -c:v libx264 -c:a aac -strict experimental -b:a 98k ./output.mp4

    strong@foreverstrong:~/ForeverStrong$ ffmpeg -ss 00:01:20 -t 00:00:30 -i ./train_video.mp4 -c:v libx264 -c:a aac -strict experimental -b:a 98k ./output_train_video.mp4 -y

截取时间段准确,建议使用。

如果需要精确截取视频,避免关键帧的丢失并精确截取时间,建议重新编码视频。

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

相关推荐
cuijiecheng201817 小时前
音视频入门基础:RTP专题(9)——FFmpeg接收RTP流的原理和内部实现
ffmpeg·音视频
偶是老李头19 小时前
Ubuntu虚拟机NDK编译ffmpeg
linux·ubuntu·ffmpeg·android ndk
lucky-billy1 天前
Qt 中使用 ffmpeg 获取采集卡数据录制视频
qt·ffmpeg·音视频
cuijiecheng20181 天前
FFmpeg源码:url_find_protocol函数分析
ffmpeg
大懒猫软件1 天前
使用 Python 爬虫和 FFmpeg 爬取 B 站高清视频
爬虫·python·ffmpeg
柯木超2 天前
使用 Swift 完成FFmpeg音频录制、播放和视频格式转换应用
ffmpeg
hjjdebug3 天前
ffmpeg configure 研究1-命令行参数的分析
ffmpeg·configure·bash 脚本
SimpleForest3 天前
FFmpeg Audio options
ffmpeg
糯米导航4 天前
foobar2000设置DSP使用教程及软件推荐
android·ffmpeg
SimpleForest4 天前
关于视频去水印的一点尝试
人工智能·ffmpeg·音视频