关闭

嵌入式 获取I帧并存储且转换为jpg图片

962人阅读 评论(0) 收藏 举报

获取I帧并存储且转换为jpg图片

kj.sh

root@u12d32:/opt/qy_test/avserver# cat kj.sh 
#!/usr/local/env sh

gcc -o i_frame_to_jpg i_frame_to_jpg.c
./i_frame_to_jpg $1
ls


i_frame_to_jpg.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int i = 0;
    char cmd[128] = {0};
    if(argc != 2)
    {

	printf("%s %d The param must be two ,please !\n",__FUNCTION__,__LINE__);
	return -1;
    }
    for(i = 0; i <= atoi(argv[1]);i++)
    {
	memset(cmd,0,128);
	sprintf(cmd,"ffmpeg -i joseph_%dth_i_frame -y -ss 00:00:00 -vframes 1 joseph_%dth_jclient.jpg >/dev/null",i,i);
	printf("%s %d The sys has tranform %dth i_frame to %dth jclient jpg !\n",__FUNCTION__,__LINE__,i,i);
	system(cmd);
    }
    return 0;
}


 

get_i_frame_save_to_file

 

save_to_file_function



void ipnc_i_frame_save(char *i_buf_addr, int i_buf_size,int transfer_time_in)
{

	FILE *fp_video;
	char i_frame_name[32] = {0};
	memset(i_frame_name,0,32);
	sprintf(i_frame_name,"joseph_%dth_i_frame",transfer_time_in);
	printf("%s %d %s \n",__FUNCTION__,__LINE__,i_frame_name);
	fp_video = fopen(i_frame_name, "wb");

#if 1

	fwrite(i_buf_addr,i_buf_size,1,fp_video);
	fflush(fp_video);	
	fclose(fp_video);
#endif
	
}

get_i_frame_from_enc

    int sub_stream_i_frame_size = 0;
    int sub_stream_i_frame_times = 0;
    int sub_stream_i_frame_buf_size = 0;
    int sub_stream_i_frame_position = 0;
    char *sub_stream_i_frame_buf = NULL;
    if((i == 1) && (stStream.u32PackCount == 4))
    {

	sub_stream_i_frame_times++;
	sub_stream_i_frame_position = 0;
	sub_stream_i_frame_buf_size = 0;
	for (iv_temp = 0; iv_temp < stStream.u32PackCount; iv_temp++)
	    sub_stream_i_frame_buf_size+=stStream.pstPack[iv_temp].u32Len[0];

            sub_stream_i_frame_buf = (char *)malloc(sub_stream_i_frame_buf_size);

	    memset(sub_stream_i_frame_buf,0,sub_stream_i_frame_buf_size);
            for (iv_temp = 0; iv_temp< stStream.u32PackCount; iv_temp++)
	    {
	       memcpy(sub_stream_i_frame_buf+sub_stream_i_frame_position,stStream.pstPack[iv_temp].pu8Addr[0],stStream.pstPack[iv_temp].u32Len[0]);
	       sub_stream_i_frame_position += stStream.pstPack[iv_temp].u32Len[0];

	    }
	    ipnc_i_frame_save(sub_stream_i_frame_buf, sub_stream_i_frame_buf_size, sub_stream_i_frame_times);	

     }



 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:986850次
    • 积分:17703
    • 等级:
    • 排名:第540名
    • 原创:741篇
    • 转载:522篇
    • 译文:0篇
    • 评论:105条
    最新评论