I've been experimenting FFMpeg for the past 2 weeks and I'm having a bit of trouble... First I've been working with a Galaxy S3, which worked super fine, gave me the best pictures ever but I recently switched to a Galaxy NEXUS which gave me a bunch of problems...
What I'm doing : I just extract frame from a video
How I'm doing :
while(av_read_frame(gFormatCtx, &packet)>=0)
{
// Is this a packet from the video stream?
if(packet.stream_index==videoStream)
{
// Decode video frame
avcodec_decode_video2(gVideoCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished)
{//and so on... But our problem is already here...
Ok, now pFrame
is holding a YUV representation of my frame... So, in order to check what I'm getting from the avcodec_decode_video2(...)
function I'm just writing pFrame
to a file so I can see it with any YUV reader on the web.
char yuvFileName[100];
sprintf(yuvFileName,"/storage/sdcard0/yuv%d.yuv",index);
FILE* fp = fopen(yuvFileName, "wb");
int y;
// Write pixel data
for(y=0; y<gVideoCodecCtx->height; y++)
{
fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, gVideoCodecCtx->width, fp);
}
for(y=0; y<gVideoCodecCtx->height/2; y++)
{
fwrite(pFrame->data[1]+y*pFrame->linesize[1], 1, gVideoCodecCtx->width/2, fp);
}
for(y=0; y<gVideoCodecCtx->height/2; y++)
{
fwrite(pFrame->data[2]+y*pFrame->linesize[2], 1, gVideoCodecCtx->width/2, fp);
}
fclose(fp);
Ok so Here I now have my result on a file store @ /storage/sdcard0/blabla.YUV
on my Galaxy Nexus root memory.
But If I open the file with (for example XnView, which is meant to display YUV type properly) I only see Dark green on the picture.
What bothers me is that everything worked properly on Galaxy S3 but something failed on GNexus...
So here's my question : Why doesn't it work on Galaxy Nexus ?
Compatibility problem between Gnexus and armeabiv7 ?
I don't know !
Regards, Cehm
May be your frames was not decoded well, because decodec did not get keyframe yet. That's happened to me when i was processing live streams. So wait for first keyframe before u will save produced frame. And use pFrame->width rather than gVideoCodecCtx->width