access violation reading 0x0000000000000020

news/2024/11/28 2:35:07/


access violation reading 0x0000000000000020

原因:

再次使用之前应该先释放一下内存:

av_freep(aviobuffer);

//printf("restart 4");

aviobuffer = (unsigned char *)av_malloc(32768);

加上之后继续报错:

OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF

代码:在下面:

int play_file(char* file_name, FrameFunc tcallback(char* a, int size,int num, int height, int width))

{

 

av_log_set_level(AV_LOG_WARNING);

av_register_all();

unsigned version = avcodec_version();

 

printf("FFmpeg version: %d\n", version);

 

AVFormatContext *pFormatCtx;

int            i, videoindex;

AVCodecContext  *pCodecCtx;

AVCodec        *pCodec;

char filepath[] = "video.264";

avformat_network_init();

pFormatCtx = avformat_alloc_context();

//string patha = "C:\\Users\\sbd01\\Videos\\video.264";

//patha = "C:\\Users\\sbd01\\Pictures\\ffmpegtest\\Debug\\video.dat";

FILE *fp_open =  fopen(file_name, "rb+");

unsigned char *aviobuffer = (unsigned char *)av_malloc(32768);

//printf("avio_alloc_context %d\n", cam_no);

AVIOContext *avio = avio_alloc_context(aviobuffer, 32768, 0, (void*)fp_open, file_buffer, NULL, NULL);

 

pFormatCtx->pb = avio;

//if (avformat_open_input(&pFormatCtx, patha.c_str(), NULL, NULL) != 0) {

if (avformat_open_input(&pFormatCtx, NULL, NULL, NULL) != 0) {

printf("Couldn't open input stream.\n");

return -1;

}

//-----

pFormatCtx->probesize = 1000 * 1024;

pFormatCtx->max_analyze_duration = 10 * AV_TIME_BASE;

pCodec = NULL;

while (pCodec == NULL) {

printf("start find stream info \n");

if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {

printf("Couldn't find stream info\n");

goto restart_stream;

continue;

}

videoindex = -1;

for (i = 0; i < pFormatCtx->nb_streams; i++)

if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

if (videoindex == -1) {

videoindex = i;

}

//break;

}

if (videoindex == -1) {

printf("Didn't find a video stream.\n");

goto restart_stream;

}

pCodecCtx = pFormatCtx->streams[videoindex]->codec;

//pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);

 

pCodec = avcodec_find_decoder(pCodecCtx->codec_id);

if (pCodec == NULL) {

printf("Codec not found \n");

goto restart_stream;

//return -1;

}

if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {

printf("Could not open codec.\n");

goto restart_stream;

continue;

//return -1;

}

if (pCodecCtx->width <= 0 || pCodecCtx->height <= 0 || pCodecCtx->height >2000 || pCodecCtx->width >3000) {

printf("pCodecCtx error 1 width %d height %d ", pCodecCtx->width, pCodecCtx->height);

goto restart_stream;

}

goto ok;

restart_stream:

printf("restart 1  ");

avformat_free_context(pFormatCtx);

printf("restart 2  ");

//avformat_close_input(&pFormatCtx);

pFormatCtx = NULL;

pFormatCtx = avformat_alloc_context();

printf("restart 3  ");

av_freep(aviobuffer);

//printf("restart 4");

aviobuffer = (unsigned char *)av_malloc(32768);

printf("restart 4  ");

AVIOContext *avio2 = avio_alloc_context(aviobuffer, 32768, 0, &fp_open, file_buffer, NULL, NULL);

pFormatCtx->pb = avio2;

pFormatCtx->probesize = 1000 * 1024;

pFormatCtx->max_analyze_duration = 10 * AV_TIME_BASE;

if (avformat_open_input(&pFormatCtx, NULL, NULL, NULL) != 0) {

printf("2Couldn't open input stream\n");

//return -1;

}

printf("restart 5\n");

pCodec = NULL;

continue;

ok:

break;

}

//---------

/*if (avformat_find_stream_info(pFormatCtx, NULL)<0) {

printf("Couldn't find stream information.\n");

return -1;

}

videoindex = -1;

for (i = 0; i<pFormatCtx->nb_streams; i++)

if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

videoindex = i;

break;

}

if (videoindex == -1) {

printf("Didn't find a video stream.\n");

return -1;

}

pCodecCtx = pFormatCtx->streams[videoindex]->codec;

pCodec = avcodec_find_decoder(pCodecCtx->codec_id);

if (pCodec == NULL) {

printf("Codec not found.\n");

return -1;

}

if (avcodec_open2(pCodecCtx, pCodec, NULL)<0) {

printf("Could not open codec.\n");

return -1;

}*/

AVFrame *pFrame, *pFrameYUV;

pFrame = av_frame_alloc();

pFrameYUV = av_frame_alloc();

 

/*if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {

printf("Could not initialize SDL - %s\n", SDL_GetError());

return -1;

}*/

 

/*int screen_w = 0, screen_h = 0;

SDL_Surface *screen;

screen_w = pCodecCtx->width;

screen_h = pCodecCtx->height;

screen = SDL_SetVideoMode(screen_w, screen_h, 0, 0);

 

if (!screen) {

printf("SDL: could not set video mode - exiting:%s\n", SDL_GetError());

return -1;

}

SDL_Overlay *bmp;

bmp = SDL_CreateYUVOverlay(pCodecCtx->width, pCodecCtx->height, SDL_YV12_OVERLAY, screen);

SDL_Rect rect;

rect.x = 0;

rect.y = 0;

rect.w = screen_w;

rect.h = screen_h;*/

//SDL End------------------------  

int ret, got_picture;

 

AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket));

 

struct SwsContext *img_convert_ctx;

img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);

 

uint8_t *out_buffer;

 

out_buffer = new uint8_t[avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height)];

avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);

 

int need_decode = 1;

int is_key_frame = 0;

while (av_read_frame(pFormatCtx, packet) >= 0) {

if (packet->stream_index == videoindex) {

 

if (packet->size < 50) {

av_free_packet(packet);

printf("packet is too small %d\n",  packet->size);

continue;

}

 

if (packet->flags &AV_PKT_FLAG_KEY){

is_key_frame = 1;

need_decode = 1;

printf("key frame %d\n", need_decode);

}

else {

is_key_frame = 0;

}

if (!need_decode) {

av_free_packet(packet);

printf("not key frame \n");

continue;

}

 

ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);

if (ret < 0) {

printf("Decode Error %d \n", pCodecCtx->frame_d_flags);

if (is_key_frame) {

need_decode = 0;

}

continue;

}

if (got_picture) {

if (pCodecCtx->frame_d_flags) {

printf("got_picture err %d\n", pCodecCtx->frame_d_flags);

pCodecCtx->frame_d_flags = 0;

need_decode = 0;

av_free_packet(packet);

continue;

}

printf("decode ok %d %d\n", pCodecCtx->flags, pCodecCtx->flags2);

sws_scale(img_convert_ctx,pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);

 

/*fwrite(pFrameYUV->data[0], (pCodecCtx->width)*(pCodecCtx->height) * 3, 1, output);*/

 

tcallback((char*)pFrameYUV->data[0], pCodecCtx->height * pCodecCtx->width * 3, 1, pCodecCtx->height, pCodecCtx->width);

}

else {

printf("got_picture:%d %d %d\n", got_picture, pCodecCtx->flags, pCodecCtx->flags2);

}

}

av_free_packet(packet);

}

sws_freeContext(img_convert_ctx);

 

//fclose(fp_open);

 

//SDL_Quit();

 

//av_free(out_buffer);  

av_free(pFrameYUV);

avcodec_close(pCodecCtx);

avformat_close_input(&pFormatCtx);

return 0;

}



http://www.ppmy.cn/news/346459.html

相关文章

jffs2_scan_eraseblock()问题解决办法

原文地址&#xff1a;https://blog.csdn.net/xin289379297/article/details/40923655 这个问题搞了我三天&#xff0c;尝试了网上的所有办法&#xff0c;均不奏效&#xff0c;只是偶尔能mount上jffs2系统&#xff1b; Old JFFS2 bitmask found at 0x02476c3cYou cannot use old…

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0064ffe4: 0x0011 in

jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x0064ffe4: 0x0011 in ./mkfs.jffs2 -s 0x1000 -e 0x40000 -p 0x500000 -d rootfs/ -o rootfs.jffs2 说明&#xff1a; 页大小0x1000 4k 块大小0x40000 64k jffs2分区总空间0x500000即5M 当然生成的…

zynq linux内核出错,Zynq-Linux移植学习笔记(二十五)——新内核JFFS2文件系统CRC错误解决...

1、背景介绍 最近为了使用PCIe驱动,对Linux内核进行了升级,目前ZYNQ发布的最新版内核为2017.4(对应内核版本4.9),升级虽然解决了PCIe驱动问题,但却引入了另一个奇怪的问题-挂载JFFS2文件系统时会出现如下错误: jffs2: jffs2_scan_eraseblock(): Node at 0x0000225c {0x198…

linux提取文件关键字命令,Linux 中awk 提取包含某个关键字的段落

前提 AWK是一种处理文本文件的语言,是一个强大的文本分析工具。 本文将使用命令awk将具有某个关键字的段落提取出来。 准备数据 "Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007fb2dc1aa800 nid=0x63f6 in Object.wait() [0x00007fb2be61f000] java.lang.Threa…

c#上位机plc通讯读位

1、 var result McNet2.Read("D6000", 200); saveData["Barcode"] BitConverter.ToString(result.Content, (6100-6000)*2,80); 先一次性读取200个&#xff0c;result为一个字节数组。(6100-6000)*2为字节数组的位置【一个…

golang切片slice

切片不是数组,他是指向底层的数组 创建一般用make方法,第一个参数是指向的数组类型,第二个是存放元素的个数,第三个是存放容量,如果存放的个数超过容量,那么他就会从分配内存地址(容量在原来的基础上*2),len方法获取长度,cap获取容量 如果是简洁声明,不声明数组长度就是切片,譬…

android 8 奕骆,为耐而生的手机 Innos奕骆D6000评测

说道手机续航能力真是让人头疼的问题,当然也是老生常谈的问题,随着快速充电技术广泛应用到手机上,续航问题才在一定程度上得了缓解,但一天多充仍然不可避免,虽然市面上也出现了许多超续航手机,大电池容量+快速充电续航能力显著,但说道超续航手机比较优秀手机的当属Innos…

HP D6000 盘柜配置

基础设施 HP DL380 Gen8 服务器 System:Centos_6.3 HP Smart Array P431/2G Controller HP D6000 盘柜 P431卡插入服务器PCI-E插槽&#xff0c;通过 SAS线 把盘柜与服务器连接 配置RAID6 重启服务器&#xff0c;按F5进入P431卡配置界面 开始配置&#xff0c;配置RAID6 缓存配置…