在过去的两周里,我一直在尝试FFMpeg,但我遇到了一些麻烦……首先,我一直在使用Galaxy S3,它工作得非常好,给我提供了有史以来最好的图片,但我最近切换到Galaxy NEXUS,这给我带来了一堆问题……
我在做什么:我只是从一段视频中提取帧
我做得怎么样:
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...
好了,现在pFrame
正在拿着我的帧的YUV表示。所以,为了检查我从avcodec_decode_video2(...)
函数中得到了什么,我只是将pFrame
写到一个文件中,这样我就可以在web上的任何YUV阅读器上看到它。
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);
好了,现在我在我的Galaxy Nexus根内存上的文件存储@ /storage/sdcard0/blabla.YUV
上有了我的结果。
但是如果我用(例如XnView,这意味着要正确地显示YUV类型)打开文件,我在图片上只看到深绿色。
令我困扰的是,在Galaxy S3上一切正常,但在GNexus上却有问题……
所以我的问题是:为什么它不能在Galaxy Nexus上工作?
Gnexus和armeabiv7之间的兼容性问题?
我不知道!
致敬,Cehm
发布于 2012-12-05 08:25:25
可能你的帧没有被很好的解码,因为解码器还没有得到关键帧。这发生在我处理实时流的时候。因此,在保存生成的帧之前,请等待第一个关键帧。并使用pFrame->width而不是gVideoCodecCtx->width
https://stackoverflow.com/questions/12953979
复制