ios Cra sh при конвертации yuvj420p в CVPixelBufferRef использовать ffmpeg - PullRequest
0 голосов
/ 20 марта 2020

Мне нужно получить rtsp steam с ip-камеры и преобразовать данные AVFrame в CVPixelBufferRef, чтобы отправить данные другим sdk

Сначала я использую avcodec_decode_video2 для декодирования видеоданных

После декодирования видео я конвертирую данные в CVPixelBufferRef, это мой код

size_t srcPlaneSize = pVideoFrame_->linesize[1]*pVideoFrame_->height;
size_t dstPlaneSize = srcPlaneSize *2;
uint8_t *dstPlane = malloc(dstPlaneSize);
void *planeBaseAddress[2] = { pVideoFrame_->data[0], dstPlane };

// This loop is very naive and assumes that the line sizes are the same.
// It also copies padding bytes.
assert(pVideoFrame_->linesize[1] == pVideoFrame_->linesize[2]);
for(size_t i = 0; i<srcPlaneSize; i++){
    // These might be the wrong way round.
    dstPlane[2*i  ]=pVideoFrame_->data[2][i];
    dstPlane[2*i+1]=pVideoFrame_->data[1][i];
}

// This assumes the width and height are even (it's 420 after all).
assert(!pVideoFrame_->width%2 && !pVideoFrame_->height%2);
size_t planeWidth[2] = {pVideoFrame_->width, pVideoFrame_->width/2};
size_t planeHeight[2] = {pVideoFrame_->height, pVideoFrame_->height/2};
// I'm not sure where you'd get this.
size_t planeBytesPerRow[2] = {pVideoFrame_->linesize[0], pVideoFrame_->linesize[1]*2};
int ret = CVPixelBufferCreateWithPlanarBytes(
        NULL,
        pVideoFrame_->width,
        pVideoFrame_->height,
        kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
        NULL,
        0,
        2,
        planeBaseAddress,
        planeWidth,
        planeHeight,
        planeBytesPerRow,
        NULL,
        NULL,
        NULL,
        &pixelBuf);

После запуска приложения приложение обработает sh на

dstPlane[2*i ]=pVideoFrame_->data[2][i];

Как восстановить этот вопрос?

это консоль в xcode

All info found
Setting avg frame rate based on r frame rate
stream 0: start_time: 0.080 duration: -102481911520608.625
format: start_time: 0.080 duration: -9223372036854.775 bitrate=0 kb/s
nal_unit_type: 0, nal_ref_idc: 0
nal_unit_type: 7, nal_ref_idc: 3
nal_unit_type: 0, nal_ref_idc: 0
nal_unit_type: 8, nal_ref_idc: 3
Ignoring NAL type 0 in extradata
Ignoring NAL type 0 in extradata
nal_unit_type: 7, nal_ref_idc: 3
nal_unit_type: 8, nal_ref_idc: 3
nal_unit_type: 6, nal_ref_idc: 0
nal_unit_type: 5, nal_ref_idc: 3
unknown SEI type 229
Reinit context to 800x608, pix_fmt: yuvj420p
(lldb) 

enter image description here

...