博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多线程解码并保存为yuv
阅读量:4223 次
发布时间:2019-05-26

本文共 8883 字,大约阅读时间需要 29 分钟。

// 开启多线程解码高清视频,并将解码后的原始数据yuv保存到硬盘

#include 
#include "QueryPerformance.h" // time counter#include "windows.h"#include
#include
#include "cudaDecodeInterface.h"#pragma comment(lib,"cudaDecode.lib")typedef unsigned (WINAPI *PBEGINTHREADEX_THREADFUNC) (LPVOID lpThreadParameter);typedef unsigned *PBEGINTHREADEX_THREADID;HANDLE hand_cuda[6] = {NULL, NULL, NULL, NULL,NULL,NULL};bool cuda_decodeEnd[6] = {false, false, false, false,false,false};static int counter[6] = {0, 0, 0, 0,0,0};FILE *fp0 = fopen("../decodePic/cudadecode0.yuv", "wb");FILE *fp1 = fopen("../decodePic/cudadecode1.yuv", "wb");FILE *fp2 = fopen("../decodePic/cudadecode2.yuv", "wb");FILE *fp3 = fopen("../decodePic/cudadecode3.yuv", "wb");FILE *fp4 = fopen("../decodePic/cudadecode4.yuv", "wb");FILE *fp5 = fopen("../decodePic/cudadecode5.yuv", "wb");// front claimint CudaDecodeNotify0(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);int CudaDecodeNotify1(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);int CudaDecodeNotify2(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);int CudaDecodeNotify3(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);int CudaDecodeNotify4(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);int CudaDecodeNotify5(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof);DWORD WINAPI OnCuda0();DWORD WINAPI OnCuda1();DWORD WINAPI OnCuda2();DWORD WINAPI OnCuda3();DWORD WINAPI OnCuda4();DWORD WINAPI OnCuda5();HANDLE handle_video[6] = {NULL, NULL, NULL, NULL,NULL,NULL};int main(int argc, char* argv[]){ printf("Cuda Decoder......\n"); CStopwatch stopwatch; handle_video[0] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda0, NULL, 0, NULL); handle_video[1] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda1, NULL, 0, NULL); handle_video[2] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda2, NULL, 0, NULL); handle_video[3] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda3, NULL, 0, NULL); handle_video[4] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda4, NULL, 0, NULL); handle_video[5] = (HANDLE)_beginthreadex(NULL, 0, (PBEGINTHREADEX_THREADFUNC)OnCuda5, NULL, 0, NULL); WaitForMultipleObjects(6, handle_video, TRUE, INFINITE); __int64 qwElapsedTime = stopwatch.Now(); printf("总用时为:%d
\n", qwElapsedTime); // DWORD end_time = GetTickCount64(); // printf("总用时为:%d
\n", end_time - begin_time); for (int i=0; i<6; i++) { CloseHandle(handle_video[i]); } fflush(stdin); system("pause"); return 0;}// OnCuda函数DWORD WINAPI OnCuda0(){ bool nstate = Cuda_SupportDecode(); hand_cuda[0] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[0], "../data/720P/video0.m2v", CudaDecodeNotify0)==1 ) { StartTime = GetTickCount(); printf("文件<1>打开成功\n"); } else printf("文件<1>打开失败\n"); while ( !cuda_decodeEnd[0] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<1>解码完成 nTime1 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[0]); return 0;}DWORD WINAPI OnCuda1(){ bool nstate = Cuda_SupportDecode(); hand_cuda[1] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[1], "../data/720P/video1.m2v", CudaDecodeNotify1)==1 ) { StartTime = GetTickCount(); printf("文件<2>打开成功\n"); } else printf("文件<2>打开失败\n"); while ( !cuda_decodeEnd[1] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<2>解码完成 nTime2 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[1]); return 0;}DWORD WINAPI OnCuda2(){ bool nstate = Cuda_SupportDecode(); hand_cuda[2] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[2], "../data/720P/video2.m2v", CudaDecodeNotify2)==1 ) { StartTime = GetTickCount(); printf("文件<3>打开成功\n"); } else printf("文件<3>打开失败\n"); while ( !cuda_decodeEnd[2] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<3>解码完成 nTime3 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[2]); return 0;}DWORD WINAPI OnCuda3(){ bool nstate = Cuda_SupportDecode(); hand_cuda[3] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[3], "../data/720P/video3.m2v", CudaDecodeNotify3)==1 ) { StartTime = GetTickCount(); printf("文件<4>打开成功\n"); } else printf("文件<4>打开失败\n"); while ( !cuda_decodeEnd[3] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<4>解码完成 nTime4 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[3]); return 0;}DWORD WINAPI OnCuda4(){ bool nstate = Cuda_SupportDecode(); hand_cuda[4] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[4], "../data/720P/video4.m2v", CudaDecodeNotify4)==1 ) { StartTime = GetTickCount(); printf("文件<5>打开成功\n"); } else printf("文件<5>打开失败\n"); while ( !cuda_decodeEnd[4] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<1>解码完成 nTime1 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[4]); return 0;}DWORD WINAPI OnCuda5(){ bool nstate = Cuda_SupportDecode(); hand_cuda[5] = Cuda_CreateDecoder(); DWORD StartTime = 0; // 起始的时间 DWORD ElapsedTime = 0; //消耗的时间 if( Cuda_OpenFile(hand_cuda[5], "../data/720P/video5.m2v", CudaDecodeNotify5)==1 ) { StartTime = GetTickCount(); printf("文件<6>打开成功\n"); } else printf("文件<6>打开失败\n"); while ( !cuda_decodeEnd[5] ) { Sleep(1); } ElapsedTime = GetTickCount() - StartTime; // printf("文件<1>解码完成 nTime1 = %d
\n", ElapsedTime); Cuda_DestroyDecoder(hand_cuda[5]); return 0;}// cudaDecodeNotify函数,拷贝解码后的数据到硬盘int CudaDecodeNotify0(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[0]++; fwrite(pDecodeData,1,nDataSize,fp0); if(nEof) { OutputDebugString("thread 1 读包结束!!!\n"); printf("====== thread 1 读包结束!!!\n"); fclose(fp0); cuda_decodeEnd[0] = true; }#if 0 printf(" \n------ video 1:%d ------\n", counter[0]); FILE *file = fopen("../order.txt", "at"); fprintf(file, " ------ 视频1:%d ------\n", counter[0]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[1], 1, NULL);// Sleep(1); return 0;}int CudaDecodeNotify1(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[1]++; fwrite(pDecodeData,1,nDataSize,fp1); if(nEof) { OutputDebugString("thread 2 读包结束!!!\n"); printf("====== thread 2 读包结束!!!\n"); fclose(fp1); cuda_decodeEnd[1] = true; }#if 0 printf(" \n------ video 2 : %d ------\n", counter[1]); FILE *file = fopen("../order_new.txt", "at"); fprintf(file, " ------ 视频2:%d ------\n", counter[1]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[2], 1, NULL);// Sleep(1); return 0;}int CudaDecodeNotify2(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[2]++; fwrite(pDecodeData,1,nDataSize,fp2); if(nEof) { OutputDebugString("thread 3 读包结束!!!\n"); printf("====== thread 3 读包结束!!!\n"); fclose(fp2); cuda_decodeEnd[2] = true; }#if 0 printf(" \n------ video 3:%d ------\n", counter[2]); FILE *file = fopen("../order.txt", "at"); fprintf(file, " ------ 视频3:%d ------\n", counter[2]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[3], 1, NULL);// Sleep(1); return 0;}int CudaDecodeNotify3(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[3]++; fwrite(pDecodeData,1,nDataSize,fp3); if(nEof) { OutputDebugString("thread 4 读包结束!!!\n"); printf("====== thread 4 读包结束!!!\n"); fclose(fp3); cuda_decodeEnd[3] = true; }#if 0 printf(" \n------ video 4 :%d ------\n\n", counter[3]); FILE *file = fopen("../order.txt", "at"); fprintf(file, " ------ 视频4:%d ------\n", counter[3]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[4], 1, NULL);// Sleep(1); return 0;}int CudaDecodeNotify4(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[4]++; fwrite(pDecodeData,1,nDataSize,fp4); if(nEof) { OutputDebugString("thread 5 读包结束!!!\n"); printf("====== thread 5 读包结束!!!\n"); fclose(fp4); cuda_decodeEnd[4] = true; }#if 0 printf(" \n------ video 1:%d ------\n", counter[0]); FILE *file = fopen("../order.txt", "at"); fprintf(file, " ------ 视频1:%d ------\n", counter[0]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[5], 1, NULL);// Sleep(1); return 0;}int CudaDecodeNotify5(unsigned char* pDecodeData, int nDataSize, DWORD timestamp, int nEof){// counter[5]++; fwrite(pDecodeData,1,nDataSize,fp5); if(nEof) { OutputDebugString("thread 6 读包结束!!!\n"); printf("====== thread 6 读包结束!!!\n"); fclose(fp5); cuda_decodeEnd[5] = true; }#if 0 printf(" \n------ video 1:%d ------\n", counter[0]); FILE *file = fopen("../order.txt", "at"); fprintf(file, " ------ 视频1:%d ------\n", counter[0]); fclose(file);#endif// ReleaseSemaphore(hand_semaphore[0], 1, NULL);// Sleep(1); return 0;}

转载地址:http://owkqi.baihongyu.com/

你可能感兴趣的文章
Github近期最有趣的10款机器学习开源项目
查看>>
新年伊始,我们共赴数据盛宴,与未来对话!(文末有彩蛋)
查看>>
独家 | 一文带你上手卷积神经网络实战(附数据集&学习资料)
查看>>
开发者必读:计算机科学中的线性代数(附论文)
查看>>
独家 | 这15个最热门的GitHub库你不可错过!
查看>>
新年伊始,我们共赴数据盛宴,与未来对话 !(文末有彩蛋)
查看>>
手把手教你用Pandas透视表处理数据(附学习资料)
查看>>
数据蒋堂 | JOIN延伸 - 维度查询语法
查看>>
教你用一行Python代码实现并行(附代码)
查看>>
收藏!超全机器学习资料合集!(附下载)
查看>>
独家 | 我这样预测了医疗AI的发展,或许你也可以(附论文链接)
查看>>
重磅 | 数据挖掘之父韩家炜:文本语料库的数据挖掘(附视频+PPT下载)
查看>>
数据蒋堂 | JOIN延伸 - 维度其它应用
查看>>
独家 | 一文为你解析神经网络(附实例、公式)
查看>>
盘点近期重大技术成就及其将带给你的影响,与你我息息相关!
查看>>
就凭这些,蕴含清华百年历史的《无问西东》唤起了一片赤子之心
查看>>
手把手教你36小时搭建无人超市系统 !(附代码)
查看>>
一文读懂最近流行的CNN架构(附学习资料)
查看>>
8800个机器学习开源项目为你精选TOP30!
查看>>
《大数据系统基础》实践项目期末答辩顺利举行 校企联手打造精品实践项目见真章
查看>>