bool VaApiPostProcessor::process(const VideoFrame &in, QLinkedList<VideoFrame> &queue) { if (!d->pipeline) return false; auto surface = VaApiSurfacePool::getSurface(in.mpi()); if (!surface) return false; mp_image *out1 = nullptr, *out2 = nullptr; out1 = d->pipeline->render(in, d->setupDeint(in.mpi()->fields, true)); if (d->deint.doubler && d->deint.method != DeintMethod::None) out2 = d->pipeline->render(in, d->setupDeint(in.mpi()->fields, false)); if (out1) queue.push_back(VideoFrame(true, out1, nextPTS(), in.field() & ~VideoFrame::Interlaced)); if (out2) queue.push_back(VideoFrame(true, out2, nextPTS(), in.field() & ~VideoFrame::Interlaced)); return out1 || out2; }
bool MediaConverter::outputFrame() { AVFrame *pFrame = NULL; if (mInputPixFmt != mOutputPixFmt) { mSwsContextPtr = sws_getCachedContext(mSwsContextPtr, mOutputWidth, mOutputHeight, mInputPixFmt, mOutputWidth, mOutputHeight, mOutputPixFmt, SWS_BICUBIC, NULL, NULL, NULL); if (NULL == mSwsContextPtr) { printf("Could not initialize the conversion context.\n"); return false; } int ret = sws_scale(mSwsContextPtr, mInputFramePtr->data, mInputFramePtr->linesize, 0, mOutputHeight, mOutputFramePtr->data, mOutputFramePtr->linesize); assert(ret != 0); pFrame = mOutputFramePtr; } else pFrame = mInputFramePtr; pFrame->pts = nextPTS(); ////////////////////////////////////////////////////////////////////////// int got_packet = 0; AVPacket packet; av_init_packet(&packet); packet.data = mEncodeBuff; packet.size = mEncodeBuffSize; int ret = avcodec_encode_video2(mOutputCodecCtxPtr, &packet, pFrame, &got_packet); //printf("outsize=%d getpacket=%d packetsize=%d stream_index=%d\n", ret, got_packet, packet.size, packet.stream_index); if (got_packet == 1) { if (packet.pts != AV_NOPTS_VALUE) packet.pts = av_rescale_q(packet.pts, mOutputCodecCtxPtr->time_base, mOutputStreamPtr->time_base); if (packet.dts != AV_NOPTS_VALUE) packet.dts = av_rescale_q(packet.dts, mOutputCodecCtxPtr->time_base, mOutputStreamPtr->time_base); if (mOutputCodecCtxPtr->coded_frame->key_frame) packet.pts |= AV_PKT_FLAG_KEY; int ret = av_interleaved_write_frame(mOutputFormatCtxPtr, &packet); //printf("after pts=%d dts=%d ret=%d\n", (int)packet.pts, (int)packet.dts, ret); return 0 == ret; } else isOutputBuffered = true; return true; }