使用 ffmpeg 合并视频和音频.在音频未结束时循环播放视频 [英] Merge video and audio with ffmpeg. Loop the video while audio is not over

查看:40
本文介绍了使用 ffmpeg 合并视频和音频.在音频未结束时循环播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将音频文件与视频文件合并.

I'm trying to merge an audio file with a video file.

我有两个选择:

  • 有一个很小的视频文件(例如 10 秒),在音频文件没有结束时循环播放.

  • Have a very small video file (e.g., 10 seconds) that loop while the audio file is not over.

有一个很长的视频文件(比我的任何音频文件都长),我可以在上面附加音频文件.我想在音频完成后剪切视频.

Have a very long video file (longer than any of my audio file) on which I can attach the audio file. I would like to cut the video when the audio is finished.

我将后者与 ffmpeg 的 -t 选项一起使用.这意味着我必须获得音频文件的持续时间才能将其输入 ffmpeg.是否可以避免这一步?

I'm using the latter with the -t <duration in second> option of ffmpeg. It means I have to get the duration of the audio file to feed it into ffmpeg. Is it possible to avoid this step?

第一个解决方案的任何指针?

Any pointer for the first solution?

推荐答案

如果你想合并新的音频和视频重复视频直到音频结束,你可以试试这个:

If you want to merge new Audio with video repeat video until the audio finishes, you can try this:

ffmpeg  -stream_loop -1 -i input.mp4 -i input.mp3 -shortest -map 0:v:0 -map 1:a:0 -y out.mp4

使用 -stream_loop -1 表示无限循环 input.mp4,-shortest 表示在最短输入流结束时完成编码.这里最短的输入流将是 input.mp3.

Using -stream_loop -1 means infinite loop input.mp4, -shortest means finish encoding when the shortest input stream ends. Here the shortest input stream will be the input.mp3.

如果您想将新音频与视频重复音频合并,直到视频播放完毕,您可以试试这个:

And if you want to merge new Audio with video repeat audio until the video finishes, you can try this:

ffmpeg  -i input.mp4 -stream_loop -1 -i input.mp3 -shortest -map 0:v:0 -map 1:a:0 -y out.mp4

使用 -y 选项将不经询问就覆盖输出文件.

use -y option will overwrite output files without asking.

这篇关于使用 ffmpeg 合并视频和音频.在音频未结束时循环播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆