使用FFmpeg创建静音视频和黑屏视频 [英] Create muted video and black screen video with FFmpeg
问题描述
我正在尝试使用FFmpeg从本地mp4文件生成以下内容:
I'm trying to use FFmpeg to generate the following from a local mp4 file:
- 没有音频的原始视频的副本
- 带有音频但没有视觉效果的原始视频的副本(改为黑屏).此文件还需要为mp4格式.
在阅读了文档之后,我努力使终端命令正确无误.要删除音频,我尝试了此命令,但没有成功:
After reading through the documentation I am struggling to get the terminal commands right. To remove the audio I have tried this command without any success:
ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy
有人可以指导我如何实现这一目标吗?
Could anyone guide me towards how to accomplish this?
推荐答案
创建黑色视频和无声音频
使用 anullsrc 过滤器.产生10秒输出的示例:
Create black video and silent audio
Use the color and anullsrc filters. Example to make 10 second output:
ffmpeg -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 10 output.mp4
从视频文件中删除/忽略音频
您可以使用 -map
选项选择确切的流.这样会禁用默认流选择行为.
流复制仅视频:
ffmpeg -i input.mp4 -map 0:v -c copy output.mp4
流复制除音频外的所有内容:
Stream copy everything except audio:
ffmpeg -i input.mp4 -map 0 -map -0:a -c copy output.mp4
另请参阅如何使用-map
选项?
Also see How to use -map
option?
使用 geq(通用方程式)过滤器.此方法很容易,因为它使用与input.mp4
相同的宽度x高度和帧速率,但速度较慢:
Using the geq (General Equation) filter. This method is easy because it uses the same width x height and frame rate as input.mp4
, but it is somewhat slow:
ffmpeg -i input.mp4 -vf geq=0:128:128 -c:a copy output.mp4
或
您可以添加 scale2ref过滤器来制作颜色源过滤器匹配
You can add the scale2ref filter to make the color source filter match the video size of 这两个示例流复制音频,所以有不重新编码音频.如果需要重新编码或输入音频格式与输出容器格式不兼容,请删除 Both of these examples stream copy the audio, so there is no re-encoding of the audio. If you need to re-encode or if the input audio format is not compatible with the output container format, then remove 请参见如何使用ffmpeg向视频中添加新音频(不混音)?,并参考anullsrc示例. See How to add a new audio (not mixing) into a video using ffmpeg? and refer to the anullsrc example. 这篇关于使用FFmpeg创建静音视频和黑屏视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
input.mp4
的视频大小,然后可以省略size=640x480
.
input.mp4
and then you can omit size=640x480
.-c:a copy
.-c:a copy
.