这是我第一次使用 Windows 应用程序,我有点沮丧。我只有一个简单的代码来创建一个 Win32(Visual C++) GUI 应用程序,但是一旦我启动可执行文件,我的 CPU 就会上升到 30%(在应用程序上),在我寻找解决这个问题的过程中,我发现有人说在消息循环(GetMessage 或 PeekMessage)中睡眠 10 毫秒可以解决这个问题,而且确实如此。但由于我真的不喜欢突然休眠我的代码,而且事实上这是一个事件处理程序循环,我希望得到有关如何解决此问题的解释。
一瞥“麻烦地区”。
while (TRUE) {
if (PeekMessage(&g_Msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&g_Msg); // translate keystroke messages into the right format
DispatchMessage(&g_Msg); //Send the message to the WindowProc function
if (g_Msg.message == WM_QUIT)
break;
} else {
// Run d3d code here
}
// Sleep(1); REDUCES CPU!
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
卡约·盖德斯
我正在尝试使用 ffmpeg 从 Roland USB 设备捕获 pcm 流并用 wav 包装它。我正在使用的命令行如下:
ffmpeg -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i hw:2,0 out.wav
Run Code Online (Sandbox Code Playgroud)
符合硬件的设置。我还可以使用 Audacity 捕获流。问题是 FFMPEG 抛出“无法设置样本格式错误”。知道可能发生什么以及如何解决这个问题吗?
提前致谢。
FFMPEG 输出
user@user:~$ ffmpeg -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i hw:2,0 out.wav
ffmpeg version N-85548-g3390a2b Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --enable-gpl --enable-libx264 --enable-libx265 --enable-libvpx --enable-libvorbis --enable-libopus --enable-ffplay
libavutil 55. 61.100 / 55. 61.100
libavcodec 57. 92.100 / 57. …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将VPX(VP8/VP9)视频转码为mpeg2视频,并使用mpegts通过UDP进行流式传输.
我已经初始化了所有上下文和流,只要我将其流式传输到ffplay它就可以工作,如果我将流发送到VLC或其他播放器,接收器只显示第一帧而不执行任何其他操作.如果我通过命令行执行相同的操作,它可以完美地工作 - ffmpeg -re -i video.webm -an -f mpegts udp://127.0.0.1:8080
我的输出背景:
this->output_codec_ctx_->codec_type = AVMEDIA_TYPE_VIDEO; // Set media type
this->output_codec_ctx_->pix_fmt = AV_PIX_FMT_YUV420P; // Set stream pixel format
this->output_codec_ctx_->time_base.den = ceil(av_q2d(input_stream->r_frame_rate)); // Add the real video framerate. Eg.: 29.9
this->output_codec_ctx_->time_base.num = 1; // Numerator of the framerate. Eg.: num/29.9
this->output_codec_ctx_->width = input_stream->codecpar->width; // Video width
this->output_codec_ctx_->height = input_stream->codecpar->height; // Video height
this->output_codec_ctx_->bit_rate = 400000; // Video quality
this->output_codec_ctx_->gop_size = 12;
this->output_codec_ctx_->max_b_frames = 2;
this->output_codec_ctx_->framerate = this->input_codec_ctx_->framerate;
this->output_codec_ctx_->sample_aspect_ratio = this->input_codec_ctx_->sample_aspect_ratio;
Run Code Online (Sandbox Code Playgroud)
我的av_dump:
Output …Run Code Online (Sandbox Code Playgroud) ffmpeg ×2
alsa ×1
c ×1
c++ ×1
libavcodec ×1
libavformat ×1
linux ×1
visual-c++ ×1
winapi ×1
windows ×1