- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
vcodec_receive_frame
函数没有接收到其余的帧。我测试了视频总共有 132 帧,它只收到了 125 帧 在视频结尾丢失 7 帧 .如何找回丢失的帧?
但是奇怪的事情发生了。如您所见,我的 MyDecode::receiveFrame()
的输出功能。 block 内的代码if (ret != 0){}
首先执行,但丢失的帧在视频的末尾。那么他们怎么会先出来呢?是什么导致了这种情况发生?
我的解码.cpp
AVFrame* MyDecode::receiveFrame()
{
mux.lock();
if (!codecCtx) {
mux.unlock();
return 0;
}
AVFrame* frame = av_frame_alloc();
int ret = avcodec_receive_frame(codecCtx, frame);
mux.unlock();
if (ret != 0)
{
static int lost_frames = 1;
std::cout << "Lost frames: " << lost_frames << std::endl;
lost_frames += 1;
av_frame_free(&frame);
return nullptr;
}
std::cout << "Received frames: " << received_frame_num << std::endl;
received_frame_num += 1;
return frame;
}
bool MyDecode::sendPacket(AVPacket* packet)
{
if (!packet || !packet->data || packet->size == 0)
return false;
mux.lock();
if (!codecCtx) {
mux.unlock();
return false;
}
int ret = avcodec_send_packet(codecCtx, packet);
mux.unlock();
av_packet_free(&packet);
if (ret != 0) {
return false;
}
return true;
}
Total frames: 132
Lost frames: 1
Lost frames: 2
Lost frames: 3
Lost frames: 4
Lost frames: 5
Lost frames: 6
Lost frames: 7
Received frames: 1
Received frames: 2
Received frames: 3
................
Received frames: 125
AVPacket* MyDemux::readFrame()
{
mux.lock();
if (!formatCtx) {
std::cout << "formaetCtx is null" << std::endl;
mux.unlock();
return nullptr;
}
AVPacket* packet = av_packet_alloc();
if (!packet) {
std::cout << "packet is null" << std::endl;
mux.unlock();
return nullptr;
}
int ret = av_read_frame(formatCtx, packet);
if (ret != 0) {
while (true) {
av_read_frame(formatCtx, nullptr);
}
mux.unlock();
av_packet_free(&packet);
av_packet_unref(packet);
return nullptr;
}
media_type = packet->stream_index;
mux.unlock();
return packet;
}
while (true) {
AVPacket* pkt = demux.readFrame();
if (demux.get_media_type() == 0) {
AVFrame* frame = video_decode.receiveFrame();
videoWidget->paintFrame(frame);
}
else if (demux.get_media_type() == 1) {
}
if (!pkt) {
std::cout << "to break" << std::endl;
break;
}
}
最佳答案
您必须向解码器发送 NULL pkts 以耗尽所有未决帧。
来自 avcodec.h
End of stream situations. These require "flushing" (aka draining) the codec, as the codec might buffer multiple frames or packets internally for performance or out of necessity (consider B-frames).
This is handled as follows:
- Instead of valid input, send NULL to the avcodec_send_packet() (decoding) or avcodec_send_frame() (encoding) functions. This will enter draining mode.
- Call avcodec_receive_frame() (decoding) or avcodec_receive_packet() (encoding) in a loop until AVERROR_EOF is returned. The functions will not return AVERROR(EAGAIN), unless you forgot to enter draining mode. - Before decoding can be resumed again, the codec has to be reset with avcodec_flush_buffers().
关于FFmpeg - avcodec_receive_frame 在接收帧之前不接收所有帧并丢失帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55292212/
vcodec_receive_frame函数没有接收到其余的帧。我测试了视频总共有 132 帧,它只收到了 125 帧 在视频结尾丢失 7 帧 .如何找回丢失的帧? 但是奇怪的事情发生了。如您所见,我
我正在尝试解码帧,但内存使用量随着每一帧(更具体地说,每次调用 avcodec_send_packet)而增长,直到最后代码因 bad_alloc 而崩溃。这是基本的解码循环: int rfret =
我正在使用 ffmpeg 库对 MPEG 传输流中的视频进行解码、缩放和重新编码。我刚刚从源代码重新编译到 v3.3.2,并从旧的 avcodec_decode_video2() API 更改为新的发
我是 FFmpeg 的新手。使用 nice repo(https://github.com/leandromoreira/ffmpeg-libav-tutorial) 学习时,在 hello_worl
我正在使用 QOpenGL 小部件绘制框架。但是,我正在努力使用 avcodec_receive_frame 获取帧。它在 else if (ret == AVERROR(EAGAIN)) block
我正在学习在我的引擎中使用 ffmpeg, 我想解码视频流的第一帧并将其输出到图像文件。 我试过了,就是不知道为什么它返回-11。 我的代码:(最后 5 行代码中的错误,第 70-74 行) Link
我正在关注本教程:http://dranger.com/ffmpeg/tutorial01.html 并试图更改一些已弃用的功能,所以我不得不尝试使用 avcodec_send_packet和 avc
我正在考虑如何设计一个循环,从互联网读取帧,馈送到 ffmpeg 解码器,然后从 ffmpeg 接收以发送到渲染。 考虑这个伪代码循环: while true { auto packet =
我是一名优秀的程序员,十分优秀!