详细介绍Qt,ffmpeg 和SDL开发
1. SOURCES = *.cpp
1. SOURCES = hello.cpp
2. main.cpp
1. SOURCES+= hello.cpp
2. SOURCES +=main.cpp
1. CONFIG+= qt warn_on release
1. TARGET = filename
1. INTERFACES = filename.ui
1. win32 {
2. SOURCES += hello_win.cpp
3. }
1. !exists( main.cpp ) {
2. error( "No main.cpp file found")
3. }
1. win32 {
2. debug {
3. CONFIG += console
4. }
5. }
1. win32:debug {
2. CONFIG += console
3. }
1. qmake -oMakefile hello.pro
1. qmake -tvcapp -o hello.dsp hello.pro
1. LIBS += -L/usr/local/lib -lmath
1. INCLUDEPATH = c:/msdev/include d:/stl/include
1. INCLUDEPATH = c:/msdev/include \
2. d:/stl/include
1. extern "C" {
2. #include <ffmpeg/avcodec.h>
3. #include <ffmpeg/avformat.h>
4. }
1. INCLUDEPATH += C:\OpenCV\cv\include \
2. C:\OpenCV\cvaux\include \
3. C:\OpenCV\cxcore\include \
4. C:\OpenCV\otherlibs\highgui
5. LIBS += C:\OpenCV\lib\cv.lib \
6. C:\OpenCV\lib\cvaux.lib \
7. C:\OpenCV\lib\cxcore.lib \
8. C:\OpenCV\lib\highgui.lib \
1. INCLUDEPATH +=
2.
3. D:\Qt\2009.05\ffmpeg\include\libavcodec \
4. D:\Qt\2009.05\ffmpeg\include\libavdevice \
5. D:\Qt\2009.05\ffmpeg\include\libavfilter \
6. D:\Qt\2009.05\ffmpeg\include\libavformat \
7. D:\Qt\2009.05\ffmpeg\include\libavutil \
8. D:\Qt\2009.05\ffmpeg\include\libswscale \
9. D:\Qt\2009.05\ffmpeg\include \
10. LIBS +=
11.
12. D:\Qt\2009.05\ffmpeg\lib\avcodec.lib \
13. D:\Qt\2009.05\ffmpeg\lib\avdevice.lib \
14. D:\Qt\2009.05\ffmpeg\lib\avfilter.lib \
15. D:\Qt\2009.05\ffmpeg\lib\avformat.lib \
16. D:\Qt\2009.05\ffmpeg\lib\avutil.lib \
17. D:\Qt\2009.05\ffmpeg\lib\swscale.lib \
1. D:\Qt\2009.05\SDL\include \
2. D:\Qt\2009.05\SDL\lib\SDL.lib \
3. D:\Qt\2009.05\SDL\lib\SDLmain.lib \
1. #include <SDL.h>
2. #include <SDL_thread.h>
1. undefined reference to `qMain(int, char**)'
1. #include <QtGui/QApplication>
2. #include "mainwindow.h"
3. #include <stdio.h>
4. #include <QLabel>
5. #include <QWidget>
6.
7. extern "C"{
8. #include <avcodec.h>
9. #include <avformat.h>
10. #include <swscale.h>
11. #include <SDL.h>
12. #include <SDL_thread.h>
13. }
14.
15. #ifdef __MINGW32__
16. #undef main /* Prevents SDL from overriding main() */
17. #endif
18.
19. int main(int argc, char *argv[])
20. {
21. QApplication a(argc, argv);
22.
23. AVFormatContext *pFormatCtx;
24. int i, videoStream;
25. AVCodecContext *pCodecCtx;
26. AVCodec *pCodec;
27. AVFrame *pFrame;
28. AVPacket packet;
29. int frameFinished;
30. float aspect_ratio;
31. static struct SwsContext *img_convert_ctx;
32. static int sws_flags = SWS_BICUBIC;
33.
34. SDL_Overlay *bmp;
35. SDL_Surface *screen;
36. SDL_Rect rect;
37. SDL_Event event;
38.
39. MainWindow w;
40. QLabel *frame_pre;
41. frame_pre = new QLabel;
42. QWidget *widget_player;
43. widget_player = new QWidget();
44. widget_player->setAttribute(Qt::WA_PaintOnScreen);
45. widget_player->setAttribute(Qt::WA_NoSystemBackground);
46. widget_player->show();
47. w.show();
48. frame_pre->show();
49.
50. av_register_all();
51.
52. /*set sdl env*/
53. char variable[64];
54. #ifdef Q_OS_WIN
55. sprintf(variable, "SDL_WINDOWID=0x%lx", widget_player->winId());
56. #else
57. sprintf(variable, "SDL_WINDOWID=0x%lx", this->winId());
58. #endif
59. putenv(variable);
60.
61. if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
62. fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
63. exit(1);
64. }
65.
66. // Open video file
67. if(av_open_input_file(&pFormatCtx, "D:\\Flyhigh.wmv", NULL, 0, NULL)!=0)
68. return -1; // Couldn't open file
69.
70. // Retrieve stream information
71. if(av_find_stream_info(pFormatCtx)<0)
72. return -1; // Couldn't find stream information
73.
74. // Dump information about file onto standard error
75. dump_format(pFormatCtx, 0, "D:\\Flyhigh.wmv", 0);
76.
77. // Find the first video stream
78. videoStream=-1;
79. for(i=; i<pFormatCtx->nb_streams; i++)
80. if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
81. videoStream=i;
82. break;
83. }
84. if(videoStream==-1)
85. return -1; // Didn't find a video stream
86.
87. // Get a pointer to the codec context for the video stream
88. pCodecCtx=pFormatCtx->streams[videoStream]->codec;
89.
90. // Find the decoder for the video stream
91. pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
92. if(pCodec==NULL) {
93. fprintf(stderr, "Unsupported codec!\n");
94. return -1; // Codec not found
95. }
96.
97. // Open codec
98. if(avcodec_open(pCodecCtx, pCodec)<0)
99. return -1; // Could not open codec
100.
101. // Allocate video frame
102. pFrame=avcodec_alloc_frame();
103.
104. // Make a screen to put our video
105. #ifndef __DARWIN__
106. screen = SDL_SetVideoMode(pCodecCtx->width, pCodecCtx->height, 0, 0);
107. #else
108. screen = SDL_SetVideoMode(pCodecCtx->width, pCodecCtx->height, 24, 0);
109. #endif
110. if(!screen) {
111. fprintf(stderr, "SDL: could not set video mode - exiting\n");
112. exit(1);
113. }
114.
115. // Allocate a place to put our YUV image on that screen
116. bmp = SDL_CreateYUVOverlay(pCodecCtx->width,
117. pCodecCtx->height,
118. SDL_YV12_OVERLAY,
119. screen);
120.
121. // Read frames and save first five frames to disk
122. i=;
123.
124. while(av_read_frame(pFormatCtx, &packet)>=0) {
125. // Is this a packet from the video stream?
126. if(packet.stream_index==videoStream) {
127. // Decode video frame
128. avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
129. packet.data, packet.size);
130. // Did we get a video frame?
131. if(frameFinished) {
132. SDL_LockYUVOverlay(bmp);
133. AVPicture *pict;
134. pict = new AVPicture;
135. pict->data[0] = bmp->pixels[0];
136. pict->data[1] = bmp->pixels[2];
137. pict->data[2] = bmp->pixels[1];
138.
139. pict->linesize[0] = bmp->pitches[0];
140. pict->linesize[1] = bmp->pitches[2];
141. pict->linesize[2] = bmp->pitches[1];
142.
143. // Convert the image into YUV format that SDL uses
144. if (pCodecCtx->pix_fmt == PIX_FMT_YUV420P) {
145. /* as we only generate a YUV420P picture, we must convert it
146. to the codec pixel format if needed */
147. img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
148. pCodecCtx->pix_fmt,
149. pCodecCtx->width, pCodecCtx->height,
150. PIX_FMT_YUV420P,
151. sws_flags, NULL, NULL, NULL);
152. if (img_convert_ctx == NULL) {
153. fprintf(stderr, "Cannot initialize the conversion context\n");
154. exit(1);
155. }
156. sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize,
157. 0, pCodecCtx->height, pict->data, pict->linesize);
158. }
159. // img_convert(&pict, PIX_FMT_YUV420P,
160. // (AVPicture *)pFrame, pCodecCtx->pix_fmt,
161. // pCodecCtx->width, pCodecCtx->height);
162. SDL_UnlockYUVOverlay(bmp);
163. rect.x = ;
164. rect.y = ;
165. rect.w = pCodecCtx->width;
166. rect.h = pCodecCtx->height;
167. SDL_DisplayYUVOverlay(bmp, &rect);
168. }
169. }
170. // Free the packet that was allocated by av_read_frame
171. av_free_packet(&packet);
172. SDL_PollEvent(&event);
173. switch(event.type) {
174. case SDL_QUIT:
175. SDL_Quit();
176. exit(0);
177. break;
178. default:
179. break;
180. }
181. }
182. // Free the YUV frame
183. av_free(pFrame);
184.
185. // Close the codec
186. avcodec_close(pCodecCtx);
187.
188. // Close the video file
189. av_close_input_file(pFormatCtx);
190. return a.exec();
191. }
详细介绍Qt,ffmpeg 和SDL开发的更多相关文章
- SDL开发笔记(二):音频基础介绍、使用SDL播放音频
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- ios开发——实用技术篇&Pist转模型详细介绍
Pist转模型详细介绍 关于Plist转模型在iOS开发中是非常常见的,每开一一个项目或者实现一个功能都要用到它,所以今天就给大家讲讲Plist怎么转成模型数据, 前提:必须有一个Plist文件或者通 ...
- QT中PRO文件写法的详细介绍
学习Qt时,发现有些知识看了不经常用就忘了,以下是书本上写的一些关于qmake的相关知识,自己看后,打算把一些经常用到的记下来,整理整理. Qt程序一般使用Qt提供的qmake工具来编译. qmake ...
- loadrunner 脚本开发-web_custom_request函数详细介绍
脚本开发-web_custom_request函数详细介绍 by:授客 QQ:1033553122 c语言版本: int web_custom_request(const char *RequestN ...
- 安卓app开发-05-Android xml布局详细介绍
安卓app开发-05-Android xml布局详细介绍 虽然说有 墨刀,墨客 这些图形化开发工具来做 Android 的界面设计,但是我们还是离不开要去学习做安卓原生app,学习 xml 布局还是必 ...
- 移植QT5.6到嵌入式开发板(史上最详细的QT移植教程)
目前网上的大多数 QT 移植教程还都停留在 qt4.8 版本,或者还有更老的 Qtopia ,但是目前 Qt 已经发展到最新的 5.7 版本了,我个人也已经使用了很长一段时间的 qt5.6 for w ...
- SpringMVC+Maven开发项目源码详细介绍
代码地址如下:http://www.demodashi.com/demo/11638.html Spring MVC概述 Spring MVC框架是一个开源的Java平台,为开发强大的基于Java的W ...
- Android 蓝牙开发(3)——蓝牙的详细介绍
前面的两篇文章,主要是在 Android 官网关于蓝牙介绍的基础上加上自己的理解完成的.主要针对的是 Android 开发中的一些 API 的使用. 第一篇文章 Android 蓝牙开发(1) 主要是 ...
- iOS开发——实用OC篇&多种定时器详细介绍
多种定时器详细介绍 在软件开发过程中,我们常常需要在某个时间后执行某个方法,或者是按照某个周期一直执行某个方法.在这个时候,我们就需要用到定时器. 然而,在iOS中有很多方法完成以上的任务,到底有 ...
随机推荐
- DirectX 初始化DirectX(手写和红龙书里面的方式)
上次介绍了如何初始化Direct3D,这次手写一次初始化代码,都是一样的方式不过看起来整洁一点. 创建一个Win32空项目添加一个空类增加以下代码即可. #include "CreateDe ...
- python urllib基础学习
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #使用python创建一个简单的WEB客户端 import urll ...
- pthread_t结构的定义
linux下是这样定义的: 在linux的实现中pthread_t被定义为 "unsigned long int",參考这里 Windows下这样定义: /* * Generic ...
- “有箭头的视图”,即程序的Storyboard Entry Point。
设置方法很简单:打开StoryBoard文件,选中要设置为第一视图的ViewController,在右边工具栏勾选Is Initial View Controller就好了,此时你会看到ViewCon ...
- c# 运算符 ?、??、?:
用途:简化代码 说明: ? 是可空类型和运算符 int a; //a<>null int ?b; //b=null int ?c = b+1; //c=null; ?? 是空接合运算符 i ...
- Delphi线程同步
总结一下Windows常用的几种线程同步技术. 1.Critical Sections(临界段),源代码中如果有不能由两个或两个以上线程同时执行的部分,可以用临界段来使这部分的代码执行串行化.它只能在 ...
- Performing Post-Build Event之类的编译错误
如果编译出现Perror PRJ0019: A tool returned an error code from "Performing Post-Build Event..."之 ...
- C++中const
[const] 0.普通const对象定义在栈空间中 { ; ; cout << &a << ' ' << &b; } Result: 0x22ab ...
- 火狐浏览器,hostadmin hosts文件访问权限不足
开始->附件->以管理员身份运行. cacls %windir%\system32\drivers\etc\hosts /E /G Users:W
- 单机/伪分布式Hadoop2.4.1安装文档
转载自官方文档,最新版请见:http://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-common/SingleCluster.h ...