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,

相关推荐
xmode1 天前
centos7.9安装ffmpeg6.1和NASM、Yasm、x264、x265、fdk-aac、lame、opus解码器
ffmpeg·centos
王江奎1 天前
FFmpeg 升级指北
ffmpeg
雨夜和阳晨2 天前
FFmpeg录制屏幕及声音
ffmpeg
吴声子夜歌2 天前
FFmpeg——基础知识及FFmpeg框架
ffmpeg
aqi002 天前
FFmpeg开发笔记(七十二)Linux给FFmpeg集成MPEG-5视频编解码器EVC
android·ffmpeg·音视频·流媒体
不太会编程的IT男3 天前
在 Jetson Orin 开发套件上使用 Hardware Encoder / Decoder 构建 FFmpeg
ffmpeg·视频编解码·h.264
m0_687399843 天前
写一个Ununtu C++ 程序,调用ffmpeg API, 来判断一个数字电影的视频文件mxf 是不是Jpeg2000?
开发语言·c++·ffmpeg
aqi003 天前
FFmpeg开发笔记(七十一)使用国产的QPlayer2实现双播放器观看视频
android·ffmpeg·音视频·流媒体
Java患者·3 天前
【小白】linux安装ffmpeg | java转码 【超详细】
ffmpeg
suifen_3 天前
RK平台ffmpeg支持硬件编解码
ffmpeg