내 코드의 주된 동기는 FFMPEG의 AVPicture에서 RGB 값을 변경하는 것입니다.AVPicture에서 RGB 값 가져 오기 FFMPEG에서 그레이 스케일로 변경
나는 "데이터 [0]"기사에 따라 이미지 데이터를 얻을 수 있었다 : 내가 좋아하는 것
http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/가 어떻게 pic.data의 3 바이트에 액세스 할 수 있는지 알을 [0]하는 RGB 형식입니다. 나는 for-loop를 통해 2D 매트릭스 방식으로 pic.data [i] [j]에 액세스하려고 시도했지만 j 번째 요소는 3보다 큽니다.
이와 관련하여 도움이 될 것입니다.
코드는 여기에 있습니다 : 내 마음에
AVPicture pic;
avpicture_alloc(&pic, PIX_FMT_RGB24, mpAVFrameInput->width,mpAVFrameInput->height);
auto ctxt = sws_getContext(mpAVFrameInput->width,mpAVFrameInput->height,static_cast<PixelFormat>(mpAVFrameInput->format),
mpAVFrameInput->width, mpAVFrameInput->height, PIX_FMT_RGB24, SWS_BILINEAR, nullptr, nullptr, nullptr);
if (ctxt == nullptr)
throw std::runtime_error("Error while calling sws_getContext");
sws_scale(ctxt, mpAVFrameInput->data, mpAVFrameInput->linesize, 0, mpAVFrameInput->height, pic.data,
pic.linesize);
for (int i = 0; i < (mpAVFrameInput->height-1); i++) {
for (int j = 0; j < (mpAVFrameInput->width-1); j++) {
printf("\n value: %d",pic.data[0][j]);
}
}
의사 코드는 다음과 같습니다
For each pixel in image {
Red = pic.data[i][j].pixel.RED;
Green = pic.data[i][j].pixel.GREEN;
Blue = pic.data[i][j].pixel.BLUE;
GRAY = (Red+Green+Blue)/3;
Red = GRAY;
Green = GRAY;
Blue = GRAY;
Save Frame;}
I 그러므로 어떤지도와 도움이 매우 감지 할 수있을 것입니다 FFMPEG 아주 새로운 오전.
많은 감사합니다.
왜 색 변환을 수행 할 수 swscale를 사용하는 대신 스스로 일을하지 : 여기
샘플입니까? –이 기능을 병렬 방식으로 이식하고 CUDA로 이식 할 계획입니다. –
흠, 그러면 이것을 확인해보십시오. http://stackoverflow.com/questions/16223315/video-decoder-on-cuda-ffmpeg. 그러나 H.264 나 MPEG-4를 해독하는 경우 FFmpeg를 건너 뛰고 이미 NVIDS 또는 다른 GPU 기반의 해독 기술을 사용하는 것이 좋습니다. 이미 CUDA를 사용할 계획이라면. –