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,

相关推荐
肥or胖10 小时前
【FFmpeg 快速入门】本地播放器 项目
开发语言·qt·ffmpeg·音视频
笑虾10 小时前
bat 批处理实现 FFmpeg 命令导出 mov 到 png 序列帧
ffmpeg·png·mov·序列帧
mortimer2 天前
当AI配音遇上视频:实现音画同步的自动化工程实践
python·ffmpeg·ai编程
甲方求你学点技术吧4 天前
8:从USB摄像头把声音拿出来--ALSA大佬登场!
linux·图像处理·ffmpeg·音视频
hjjdebug4 天前
ffmpeg 中 write_option()函数详细注释
ffmpeg·write_option
biubiubiu07065 天前
FFmpeg Windows安装
windows·ffmpeg
Gene_20225 天前
[TOOL] ubuntu 使用 ffmpeg 操作 gif、mp4
linux·ubuntu·ffmpeg
xhBruce5 天前
FFmpeg+javacpp中av_log使用
ffmpeg·ffmpeg+javacpp
DogDaoDao5 天前
Windows下VScode配置FFmpeg开发环境保姆级教程
windows·vscode·ffmpeg·音视频·gcc
1nv1s1ble5 天前
ffmpeg-api记录
ffmpeg