gpt4 book ai didi

ios - FFmpeg:如何从 OSX CMSampleBufferRef 获取 AVPacket

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:20 25 4
gpt4 key购买 nike

我是 AV 技术的新手,一直在尝试将 FFmpeg 与 Apple 的 CoreVideo 框架结合起来处理网络摄像头捕获。

首先,我有来自 CoreVideo 的网络摄像头捕获(可以从 AVCaptureVideoDataOutputSampleBufferDelegate 中找到),由 CMSampleBuffer

表示
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {}

由此,在没有存储为临时文件的情况下,我想将其放入 FFmpeg 的 AVPacket 以便我可以处理。

有人知道我应该研究哪个 FFmpeg api 吗?

最佳答案

假设您可以访问缓冲区原始数据,您首先需要创建一个 AVPicture 然后用原始数据填充它,然后对帧进行编码。

您可能还需要检查帧的像素格式(即 YUV442、YUV420、ARGB 等)

int result;
AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);
AVCodecContext *codec_context = avcodec_alloc_context3(codec);

uint8_t *frame_bytes; //this should hold the frame raw data
AVFrame *frm = av_frame_alloc();
result = avpicture_fill((AVPicture*) frm, frame_bytes, AV_PIX_FMT_YUV410P, frame_width, frame_height);
assert(!result);

AVPacket pkt;
int got_packet;

av_init_packet(&pkt);
result = avcodec_encode_video2(codec_context, &pkt, frm, &got_packet);
assert(!result);

关于ios - FFmpeg:如何从 OSX CMSampleBufferRef 获取 AVPacket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29289598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com