[英]Replace the audio stream of a video using NAudio
I have 2 files. 我有2个档案。 Both are the same length (in seconds): 两者的长度相同(以秒为单位):
How do I use the NAudio .NET library in my C# application to overwrite the audio of file #1 with the audio from file #2? 如何在C#应用程序中使用NAudio .NET库用文件#2的音频覆盖文件#1的音频? I want to write the final result to disk as a new video file. 我想将最终结果作为新的视频文件写入磁盘。
I believe this is possible using the Media Foundation capabilities of NAudio 1.7, but I can't figure out how to modify the audio stream of a video file and re-save the video. 我相信使用NAudio 1.7的Media Foundation功能可以做到这一点,但是我不知道如何修改视频文件的音频流并重新保存视频。
I'm afraid this is not possible with NAudio 1.7. 恐怕NAudio 1.7无法做到这一点。 NAudio has interop wrappers for a large percentage of the Media Foundation API, but the focus of the MediaFoundationReader
and MediaFoundationEncoder
classes is just on the audio. NAudio具有用于大部分Media Foundation API的互操作包装,但是MediaFoundationReader
和MediaFoundationEncoder
类的焦点仅在音频上。 It should be possible with Media Foundation, so if you can find a C++ sample that does this with the MF API, you could recreate it in C# using the interop wrappers from NAudio. Media Foundation应该有可能,因此,如果您找到一个使用MF API做到这一点的C ++示例,则可以使用NAudio的互操作包装在C#中重新创建它。 Alternatively you could try using a different managed Media Foundation library, such as Media Foundation .NET 或者,您可以尝试使用其他托管的Media Foundation库,例如Media Foundation .NET。
You can use FFMPEG to do that. 您可以使用FFMPEG来做到这一点。 Call FFMPEG from c# and find the command to merge Video with Audio. 从c#调用FFMPEG,然后找到将视频与音频合并的命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.