⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video_jpeg.c

📁 sample on embedded linux
💻 C
字号:
#include <stdio.h>#include <time.h>#include "hi_common_api.h"#include <pthread.h>#include "video_comm.h"/*config system parameter*/HI_U16 mode = D1;HI_U16 normal = PAL;VENC_FORMAT_E format = VENC_FORMAT_H264;HI_VOID jpegsnap (VENC_CHN *arg){    HI_U32 u32Len;    HI_S32 u32Qval;    FILE* pFile;    HI_S8 *pResultPic;    HI_S8 filename[255];    HI_S32 hiRet = HI_SUCCESS;    HI_S32 venc_chn;    VENC_INIT_S    venc_init;    HI_S32 loop = 0;    u32Qval = 70;    venc_chn = *arg;    /*malloc memory for snapshot*/    pResultPic = (HI_S8 *)malloc(MAX_JPEG_BUFFER);    if (HI_NULL_PTR == pResultPic)    {        return ;    }    /*snapshot loop*/    while (++loop < 20)    {        sprintf(filename, "venc_%d%d.jpeg", venc_chn, u32Qval);        hiRet = HI_JPEG_GetSnapShot(venc_chn, u32Qval++, pResultPic, &u32Len);        if (hiRet != HI_SUCCESS )        {            break;        }        /*save image to file*/        pFile = fopen(filename,"wr");        if (HI_NULL_PTR == pFile)        {            break;        }                if(-1 == fseek(pFile,0,SEEK_SET))        {            fclose(pFile);            break;        }                if(-1 == fwrite(pResultPic, u32Len, 1, pFile))        {            fclose(pFile);            break;        }                fclose(pFile);        pFile = HI_NULL_PTR;    }        free (pResultPic);    return ;  }HI_S32 main (HI_VOID){    HI_S32 hiRet = HI_SUCCESS;    HI_S32 venc_chn;    HI_S32 vi_chn = 0;     VENC_INIT_S    venc_init;    VENC_STREAM_S  venc_stream;      HI_S32 i, j;    time_t t0, t1;     pthread_t mythread;    	/*config A/D device*/    hiRet = ADconfig(mode, normal);	if (HI_SUCCESS != hiRet)	{	    printf ("ADconfig failed\n");        HI_VENC_Close();	    return hiRet;	}	/*config VI public attribute*/	hiRet = ViPubConfig(mode, normal, format);	if (HI_SUCCESS != hiRet)	{	    printf ("vi public atr config failed\n");        HI_VENC_Close();	    return hiRet;	}	hiRet = ViChnConfig(mode, normal, vi_chn);	if (HI_SUCCESS != hiRet)	{	    printf ("vi chn atr config failed\n");        HI_VENC_Close();	    return hiRet;	}    	    /*create video encode channel*/        hiRet = HI_VENC_CreateCH(vi_chn, &venc_chn);    if ( hiRet != HI_SUCCESS )    {        HI_VENC_Close();        return hiRet;    }    /*create video encode thread*/    if ( pthread_create(&mythread, NULL, (void*)jpegsnap, &venc_chn))    {        printf ("create jpeg thread failed");		return -1;	}    /* start video encode */    hiRet = HI_VENC_StartCH(venc_chn, 0);    if ( hiRet != HI_SUCCESS )    {        HI_VENC_DestroyCH(venc_chn, HI_TRUE);        HI_VENC_Close();        return hiRet;    }    t0 = time(NULL);    do    {         /*get stream*/        HI_VENC_GetStream(venc_chn, &venc_stream, HI_TRUE);        if ( hiRet != HI_SUCCESS )        {                        HI_VENC_DestroyCH(venc_chn, HI_TRUE);             HI_VENC_Close();            return hiRet;        }        /*release stream*/        hiRet = HI_VENC_ReleaseStream(venc_chn, &venc_stream);                    if ( hiRet != HI_SUCCESS )        {            HI_VENC_DestroyCH(venc_chn, HI_TRUE);            HI_VENC_Close();            return hiRet;        }        t1 = time(NULL);    }    while (t0 + 10 > t1);    pthread_join(mythread, NULL);    HI_VENC_StopCH(venc_chn);                HI_VENC_DestroyCH(venc_chn, HI_TRUE);                HI_VENC_Close();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -