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,

相关推荐
OperateCode2 天前
AutoVideoMerge:让二刷更沉浸的自动化视频处理脚本工具
python·opencv·ffmpeg
胡耀超3 天前
DataOceanAI Dolphin(ffmpeg音频转化教程) 多语言(中国方言)语音识别系统部署与应用指南
python·深度学习·ffmpeg·音视频·语音识别·多模态·asr
byxdaz3 天前
FFmpeg QoS 处理
ffmpeg
codelancera4 天前
ffmpeg-调整视频分辨率
ffmpeg·音视频
chenchao_shenzhen6 天前
RK3568嵌入式音视频硬件编解码4K 60帧 rkmpp FFmpeg7.1 音视频开发
ffmpeg·音视频·rk3588·音视频开发·嵌入式开发·瑞芯微rk3568·硬件编解码
_多拉不懂A梦6 天前
FFmepg源码系列-avformat_open_input()
c++·ffmpeg·音视频
阿飞__10 天前
C++使用FFmpeg进行视频推流
c++·ffmpeg·音视频
mortimer10 天前
pydub下音频处理:跨越wav格式的4GB限制这道坎
python·ffmpeg·numpy
aqi0010 天前
FFmpeg开发笔记(八十)使用百变魔音AiSound实现变声特效
android·ffmpeg·音视频·直播·流媒体