linux下视频采集服务器Word文档格式.docx
- 文档编号:7482502
- 上传时间:2023-05-08
- 格式:DOCX
- 页数:25
- 大小:23.37KB
linux下视频采集服务器Word文档格式.docx
《linux下视频采集服务器Word文档格式.docx》由会员分享,可在线阅读,更多相关《linux下视频采集服务器Word文档格式.docx(25页珍藏版)》请在冰点文库上搜索。
5000
34.#define
RTP_HDR_SZ
12
35.#define
VIDEO_PALETTE_JPEG
21
36.
37.unsigned
char
buf[BUFSIZE+2][DATA];
38.int
head,tail;
39.
40.sem_t
writen;
41.sem_t
readn;
42.
43.struct
ARG{int
sockfd;
44.
int
sin_size;
45.
struct
sockaddr_in
client;
46.};
47.
48.struct
FDG{
49.int
video_fd;
50.};
51.
52.typedef
unsigned
u_int8;
53.typedef
short
u_int16;
54.
55.int
get_jpegsize
(unsigned
*buf,
insize);
56.double
tdbl(struct
timeval
*a);
57.pthread_mutex_t
buffer_mutex=PTHREAD_MUTEX_INITIALIZER;
58.
59.static
void
*producer(void
*fdg)
60.{
61.
FDG
*vd;
62.
63.
64.
if(sizeof(fdg)!
=sizeof(struct
FDG))
65.
{
66.
perror("
producer
arg
error"
);
67.
exit
(1);
68.
}
69.
else
70.
{
71.
vd=(struct
*)fdg;
72.
video_fd=vd->
73.
free(fdg);
74.
fdg=NULL;
75.
76.
77.
78.
for(
;
)
79.
80.
sem_wait(&
writen);
//减少可读的资源数
81.
pthread_mutex_lock(&
buffer_mutex);
//进入互斥区
82.
//
memset(buf[head],
'
s'
20);
83.
read(video_fd,
buf[head],
DATA);
84.
head=(head+1)
%
BUFSIZE;
85.
86.
pthread_mutex_unlock(&
//离开互斥区
87.
sem_post(&
readn);
//增加可读资源数
88.
sleep(0.0001);
89.
90.}
91.static
*consumer(void
*arg)
92.{
93.
94.
95.
jpegsize;
96.
97.
ARG
*info;
98.
typedef
99.
version:
2;
/*
protocol
version
*/
100.
p:
1;
padding
flag
101.
x:
header
extension
102.
cc:
4;
CSRC
count
103.
m:
marker
bit
104.
pt:
7;
payload
type
105.
seq:
16;
sequence
number
106.
ts;
timestamp
107.
ssrc;
synchronization
source
108.
}
rtp_hdr_t;
109.
start;
110.
rtp_hdr_t
rtphdr;
111.
u_int8
*jpeg_data;
112.
*packet_buf;
113.
114.
115.
*ptr;
116.
frame,bframe;
117.
bytes_left
//jpeg数据总长度
118.
data_len,packetsize;
//packetsize变量
119.
info=(
*)arg;
120.
if(info->
sockfd<
0)
121.
122.
error
123.
124.
125.
126.
sin_size!
=16)
127.
128.
err
129.
130.
131.
sockfd=info->
132.
sin_size=info->
133.
memcpy(&
client,&
info->
client,sizeof(info->
client));
134.
free(arg);
135.
arg=NULL;
136.
137.
packetsize=RTP_HDR_SZ+2050;
138.
packet_buf
=
(u_int8
*)calloc(packetsize,
sizeof(u_int8));
139.
jpeg_data=
*)
malloc(DATA);
140.
141.
for(;
142.
143.
frame=0;
144.
gettimeofday(&
start,
0);
145.
ts
int)(tdbl(&
start)*1000);
146.
ssrc
125;
147.
Initialize
RTP
header*/
148.
149.
rtphdr.version
150.
rtphdr.p
0;
151.
rtphdr.x
152.
rtphdr.cc
153.
rtphdr.m
154.
rtphdr.pt
40;
155.
rtphdr.seq
156.
rtphdr.ts
htonl(ts);
157.
rtphdr.ssrc
htonl(ssrc);
158.
159.
//减少可读的资源数
160.
161.
162.
163.
jpegsize=get_jpegsize(buf[tail],DATA);
164.
165.
if(jpegsize!
=-1)
166.
167.
memcpy(jpeg_data,buf[tail],jpegsize);
168.
169.
170.
tail=(tail+1)
171.
172.
//离开互斥区
173.
174.
//增加可读资源数
175.
176.
177.
178.
while
(bytes_left
>
0)
179.
180.
ptr
+
RTP_HDR_SZ;
181.
182.
bframe=frame;
183.
184.
data_len
packetsize
-
(ptr
packet_buf)-2;
//每一分片大小
185.
186.
if
(data_len
bytes_left)
//当为最后一个分片时
187.
188.
bytes_left;
189.
190.
bframe=255;
191.
data_len=jpegsize%2048;
192.
193.
194.
*ptr=bframe;
ptr++;
195.
*ptr=frame;
196.
197.
htons(rtphdr.seq);
198.
memcpy(packet_buf,
&
rtphdr,
RTP_HDR_SZ);
199.
memcpy(ptr,
jpeg_data
frame*2048,
data_len);
200.
201.
if(sendto(sockfd,packet_buf,(ptr
packet_buf)
data_len,
202.0,(struct
sockaddr
*)&
client,sin_size)<
203.
204.
sendto
205.
206.
207.
frame++;
208.
-=
2048;
209.
ntohs(rtphdr.seq);
210.
rtphdr.seq++;
211.
212.
213.
214.
215.
free(packet_buf);
216.
free(jpeg_data);
217.
pthread_exit(NULL);
218.}
219.
220.
221.int
main()
222.{
223.
clock_t
oldtick,newtick;
224.
float
time1
225.
static
vf=0;
226.
i;
227.
totalold,totalnew;
228.
229.
video_capability
grab_cap;
230.
231.
width
320;
232.
height
240;
233.
234.
235.
video_picture
grab_pic;
236.
video_mmap
grab_map;
237.
video_mbuf
grab_buf;
238.
239.
240.
241.
242.
243.
server;
244.
msg[100];
245.
*arg;
246.
*fdg;
247.
pthread_t
p_tid;
248.
c_tid;
249.
head=0;
250.
tail=0;
251.
for(i=0;
i<
BUFSIZE+2;
i++)
252.
253.
bzero(buf[i],DATA);
254.
255.
256.
sem_init(&
writen,0,BUFSIZE);
257.
readn,0,0);
258.
259.//数据采集………………………………………………
260.loop:
261.
totalold
clock();
262.
video_fd
open("
/dev/video0"
O_RDWR);
263.
(video_fd
==
-1)
264.
{
265.//\u6253\u5f00\u6444\u50cf\u5934
266.
fprintf(stderr,
"
can
not
open
video0"
267.
268.
}
269.
oldtick
270.
((ioctl(video_fd,
VIDIOCGCAP,
grab_cap))
0)
271.
272.
ioctl
VIDEOCGCAP
failed."
273.
274.
275.
newtick
276.
(double)(newtick
oldtick)/
CLOCKS_PER_SEC;
277.
printf("
\n%f
second
is
take
to
\n"
time1);
278.
279.printf("
The
VideoCap
Name:
%s\n"
grab_cap.name);
280.printf("
hannels:
%d\n"
grab_cap.channels);
281.printf("
Audios:
grab_cap.audios);
282.printf("
maxwidth:
%d,
maxheight:
minwidth
minheight:
283.grab_cap.maxwidth,
grab_cap.maxheight,
284.grab_cap.minwidth,
grab_cap.minheight);
285.
286.
287.
288.if
VIDIOCGPICT,
grab_pic))
289.{
290.
VIDIOCGPICT
291.
292.}
293.
294.
295.
296.
297.printf("
brightness:
%d\nThe
hue:
colour:
%d\n
298.The
contrast:
whiteness:
depth:
palette:
299.grab_pic.brightness,
grab_pic.hue,
grab_pic.colour,
grab_pic.contrast,
300.grab_pic.whiteness,
grab_pic.depth,
grab_pic.palette);
301.
302.
303.
304.if
VIDIOCGMBUF,
grab_buf))
305.{
306.
307.
308.}
309.
310.
311.
VIDIOCGMBUF
312.
313.printf("
mapping
size:
frames:
offset
314.grab_buf.size,
grab_buf.frames,
grab_buf.offsets);
315.printf("
%d
nihao\n"
grab_buf.size);
316.grab_map.width
width;
317.grab_map.height
height;
318.grab_map.format
VIDEO_PALETTE_JPEG;
319.grab_map.frame
320.if(vf==0)
321.{
322.
vf=vf+1;
323.
close(video_fd);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- linux 视频 采集 服务器