本文介绍了使用 IMFSourceReader 编码来自麦克风的音频和视频流中的延迟时会出现噪音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,用于在使用 SourceReader 的视频流期间捕获.MP4 文件(视频(USB 摄像头)和音频(任何麦克风)).

I'm developing an application to capture.MP4 file (video(USB Camera)and audio(Any Microphone) together )during video streaming using SourceReader.

我的代码为所有 API 返回成功并能够保存视频.我面临以下 3 个问题.

My code is returning success for all API's and able to save the video. I'm facing below 3 issues.

  1. 录制 10 秒后,fps 变为 0 并恢复到 1fps(注意:将视频保存为 1080p 60fps).FPS 没有恢复到 60fps.
  2. 在播放录制的文件时,噪音音频只播放整个文件.录制的音频文件未播放.
  3. 为了停止记录,我使用了 sinkwriter finalize 方法.我的应用程序没有响应调用这个方法,这个方法需要时间来释放它(释放时间大约需要 3-5 分钟).

请在以下保管箱链接中找到我的代码:https://www.dropbox.com/s/eddwdc1z9wsoh04/VideoRecord.txt?dl=0

Please find my code in the following dropbox link:https://www.dropbox.com/s/eddwdc1z9wsoh04/VideoRecord.txt?dl=0

没有任何问题,我可以使用捕获引擎技术捕获音频和视频,但该技术支持 Windows 8.我的应用程序必须支持 Windows 7.

Without any problem, I'm able to capture audio and video using capture engine technique but this technique supports from Windows 8. My application has to support from Windows 7.

请告诉我是否缺少配置音频和视频的任何内容?帮我解决这个问题.

Please let me know whether am missing anything to configure audio and video? Help me to solve this issue.

提前致谢

推荐答案

我看到的错误很少.首先,您使用 MF_SOURCE_READER_FIRST_VIDEO_STREAM 调用 ReadSample.这将只读取视频样本.您应该使用 MF_SOURCE_READER_ANY_STREAM 调用 ReadSample(第一次在 OnReadSample 内部),以使其读取视频和音频样本.

I see few mistakes.First, you call ReadSample with MF_SOURCE_READER_FIRST_VIDEO_STREAM. Which will read only the video samples. You should call ReadSample (first time and inside OnReadSample) with MF_SOURCE_READER_ANY_STREAM instead, in order to make it read both video and audio samples.

其次,以下两行错误:

hr = m_pWriter->WriteSample(0, pSample);
hr = m_pWriter->WriteSample(1, pSample);

您应该根据 OnReadSample 中的 dwStreamIndex 值调用具有相应流索引的 WriteSample.例如在您的情况下:

You should call WriteSample with corresponding stream index according to the dwStreamIndex value in OnReadSample. For example in your case:

if(dwStreamIndex == 0)
    hr = m_pWriter->WriteSample(m_dwVideoStreamIndex, pSample);
else if(dwStreamIndex == 1)
    hr = m_pWriter->WriteSample(m_dwAudioStreamIndex, pSample);

这篇关于使用 IMFSourceReader 编码来自麦克风的音频和视频流中的延迟时会出现噪音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 22:50