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,

相关推荐
Antonio91542 分钟前
【音视频】⾳频处理基本概念及⾳频重采样
ffmpeg·音视频·aac
Antonio9158 小时前
【音视频】AVIO输入模式
ffmpeg·音视频
hunandede13 小时前
ffmpeg av_buffer_unref的逻辑实现; av_freep 和 av_freep函数的区别
ffmpeg
邪恶的贝利亚1 天前
一些有关ffmpeg 使用(1)
ffmpeg
RenderNow1 天前
深耕ffmpeg系列之AVFrame
ffmpeg
xiaoh_71 天前
解决视频处理中的 HEVC 解码错误:Could not find ref with POC xxx【已解决】
python·ffmpeg·音视频
王江奎1 天前
Android FFmpeg 交叉编译全指南:NDK编译 + CMake 集成
android·ffmpeg
qq_316837752 天前
使用ffmpeg 将图片合成为视频,填充模糊背景,并添加两段音乐
ffmpeg·音视频
林鸿群2 天前
Mediamtx与FFmpeg远程与本地推拉流使用
ffmpeg
unix2linux3 天前
YOLO v5 Series - FFmpeg & (HTML5 + FLV.js ) & ONNX YOLOv5s Integrating
yolo·ffmpeg·html5