static int write_video_frame (struct ALL_DATA *all_data, void *jpeg_struct, struct lavcData *lavc_data, VidBuff *proc_buff) { struct GLOBAL *global = all_data->global; //struct GWIDGET *gwidget = all_data->gwidget; int ret=0; switch (global->VidFormat) { case AVI_FORMAT: ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; case WEBM_FORMAT: case MKV_FORMAT: //global->framecount++; ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; default: break; } return (ret); }
void encode_frame(uint8_t *yuv_frame, size_t yuv_length) { int h264_length = 0; //这里有一个问题,通过测试发现前6帧都是0,所以这里我跳过了为0的帧 if (yuv_frame[0] == '\0') return; h264_length = compress_frame(&en, -1, yuv_frame, h264_buf); if (h264_length > 0) { //写h264文件 fwrite(h264_buf, h264_length, 1, h264_fp); } //写yuv文件 fwrite(yuv_frame, yuv_length, 1, yuv_fp); }
void *video_Encode_Thread(void *arg) { int i=-1; while(1) { if((flag[1]==0 && flag[0]==0) || (flag[i]==-1)) continue; if(flag[0]==1) i=0; if(flag[1]==1) i=1; pthread_mutex_lock(&(Buff[i].lock)); /*获取互斥锁*/ if(i) printf("-------------video_Encode_Thread Buff 1\n"); if(!i) printf("-------------video_Encode_Thread Buff 0\n"); /*H.264压缩视频*/ //encode_frame(Buff[i].cam_mbuf + Buff[i].rpos,0); int h264_length = 0; h264_length = compress_frame(&en, -1, Buff[i].cam_mbuf + Buff[i].rpos, h264_buf); if (h264_length > 0) { printf("%s%d\n","-----------h264_length=",h264_length); //写h264文件 fwrite(h264_buf, h264_length, 1, h264_fp); //memcpy(fTo, h264_buf, h264_length); } Buff[i].rpos+=framelength; if(Buff[i].rpos>=BUF_SIZE) { Buff[i].rpos=0;Buff[!i].rpos=0;flag[i]=-1;} /*H.264压缩视频*/ pthread_cond_signal(&(Buff[i].encodeOK)); pthread_mutex_unlock(&(Buff[i].lock));/*释放互斥锁*/ } }
static int write_video_frame (struct ALL_DATA *all_data, void *jpeg_struct, void *lavc_data, VidBuff *proc_buff) { struct GLOBAL *global = all_data->global; struct GWIDGET *gwidget = all_data->gwidget; __THREAD_TYPE press_butt_thread; int ret=0; switch (global->VidFormat) { case AVI_FORMAT: /*all video controls are now disabled so related values cannot be changed*/ if(!(global->VidButtPress)) //if this is set AVI reached it's limit size ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); if (ret) { if (AVI_getErrno () == AVI_ERR_SIZELIM) { if (!(global->VidButtPress)) { global->VidButtPress = TRUE; /*avi file limit reached - must end capture close file and start new one*/ if( __THREAD_CREATE(&press_butt_thread, split_avi, all_data)) //should be created detachable { /*thread failed to start - stop video capture */ /*can't restart since we need IO thread to stop */ g_printerr("split avi: thread creation failed\n"); printf("stoping video capture\n"); if(!(global->no_display)) { gdk_threads_enter(); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gwidget->CapVidButt), FALSE); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } g_print("AVI file size limit reached - restarted capture on new file\n"); } } else { g_printerr ("write error on avi out \n"); } } break; case MKV_FORMAT: //global->framecount++; ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; case WEBM_FORMAT: //global->framecount++; ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; default: break; } return (0); }