Mercurial > mplayer.hg
annotate libmpdemux/demux_rawvideo.c @ 10217:1f3935c55e6f
10l
author | alex |
---|---|
date | Fri, 30 May 2003 18:48:44 +0000 |
parents | a37708f0b574 |
children | 3e40b8f879c8 |
rev | line source |
---|---|
9065 | 1 |
2 #include "config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <unistd.h> | |
7 #include <string.h> | |
8 | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
9 #include "../m_option.h" |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
10 #include "../m_config.h" |
9065 | 11 |
12 #include "stream.h" | |
13 #include "demuxer.h" | |
14 #include "stheader.h" | |
15 | |
16 #include "../libmpcodecs/img_format.h" | |
17 | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
18 extern int demuxer_type; |
9065 | 19 static int format = IMGFMT_I420; |
20 static int size_id = 0; | |
21 static int width = 0; | |
22 static int height = 0; | |
23 static float fps = 25; | |
24 static int imgsize=0; | |
25 | |
26 config_t demux_rawvideo_opts[] = { | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
27 { "on", &demuxer_type, CONF_TYPE_FLAG, 0,0, DEMUXER_TYPE_RAWVIDEO, NULL }, |
9065 | 28 // size: |
29 { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL }, | |
30 { "h", &height, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL }, | |
31 { "sqcif", &size_id, CONF_TYPE_FLAG,0,0,1, NULL }, | |
32 { "qcif", &size_id, CONF_TYPE_FLAG,0,0,2, NULL }, | |
33 { "cif", &size_id, CONF_TYPE_FLAG,0,0,3, NULL }, | |
34 { "4cif", &size_id, CONF_TYPE_FLAG,0,0,4, NULL }, | |
35 { "pal", &size_id, CONF_TYPE_FLAG,0,0,5, NULL }, | |
36 { "ntsc", &size_id, CONF_TYPE_FLAG,0,0,6, NULL }, | |
9068 | 37 { "16cif", &size_id, CONF_TYPE_FLAG,0,0,7, NULL }, |
38 { "sif", &size_id, CONF_TYPE_FLAG,0,0,8, NULL }, | |
9065 | 39 // format: |
40 { "format", &format, CONF_TYPE_INT, 0, 0 , 0, NULL }, | |
41 { "y420", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_I420, NULL }, | |
42 { "yv12", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YV12, NULL }, | |
43 { "yuy2", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_YUY2, NULL }, | |
9068 | 44 { "uyvy", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_UYVY, NULL }, |
9065 | 45 { "y8", &format, CONF_TYPE_FLAG, 0, 0 , IMGFMT_Y8, NULL }, |
46 // misc: | |
47 { "fps", &fps, CONF_TYPE_FLOAT,CONF_RANGE,0.001,1000, NULL }, | |
48 { "size", &imgsize, CONF_TYPE_INT, CONF_RANGE, 1 , 8192*8192*4, NULL }, | |
49 | |
50 {NULL, NULL, 0, 0, 0, 0, NULL} | |
51 }; | |
52 | |
53 | |
54 int demux_rawvideo_open(demuxer_t* demuxer) { | |
55 sh_video_t* sh_video; | |
56 | |
57 switch(size_id){ | |
58 case 1: width=128; height=96; break; | |
59 case 2: width=176; height=144; break; | |
60 case 3: width=352; height=288; break; | |
61 case 4: width=704; height=576; break; | |
62 case 5: width=720; height=576; break; | |
63 case 6: width=720; height=480; break; | |
9068 | 64 case 7: width=1408;height=1152;break; |
65 case 8: width=352; height=240; break; | |
9065 | 66 } |
67 if(!width || !height){ | |
68 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: width or height not specified!\n"); | |
69 return 0; | |
70 } | |
9068 | 71 |
9065 | 72 if(!imgsize) |
73 switch(format){ | |
74 case IMGFMT_I420: | |
75 case IMGFMT_IYUV: | |
76 case IMGFMT_YV12: imgsize=width*height+2*(width>>1)*(height>>1);break; | |
77 case IMGFMT_YUY2: imgsize=width*height*2;break; | |
9068 | 78 case IMGFMT_UYVY: imgsize=width*height*2;break; |
9065 | 79 case IMGFMT_Y8: imgsize=width*height;break; |
80 default: | |
81 mp_msg(MSGT_DEMUX,MSGL_ERR,"rawvideo: img size not specified and unknown format!\n"); | |
82 return 0; | |
83 } | |
84 | |
85 sh_video = new_sh_video(demuxer,0); | |
86 sh_video->format=format; | |
87 sh_video->fps=fps; | |
88 sh_video->frametime=1.0/fps; | |
89 sh_video->disp_w=width; | |
90 sh_video->disp_h=height; | |
91 sh_video->i_bps=fps*imgsize; | |
92 | |
93 demuxer->movi_start = demuxer->stream->start_pos; | |
94 demuxer->movi_end = demuxer->stream->end_pos; | |
95 | |
96 demuxer->video->sh = sh_video; | |
97 sh_video->ds = demuxer->video; | |
98 | |
99 return 1; | |
100 } | |
101 | |
102 int demux_rawvideo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) { | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
103 sh_video_t* sh = demuxer->video->sh; |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
104 off_t pos; |
9065 | 105 if(demuxer->stream->eof) return 0; |
106 if(ds!=demuxer->video) return 0; | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
107 pos = stream_tell(demuxer->stream); |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
108 ds_read_packet(ds,demuxer->stream,imgsize,(pos/imgsize)*sh->frametime,pos,0x10); |
9065 | 109 return 1; |
110 } | |
111 | |
112 void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ | |
113 stream_t* s = demuxer->stream; | |
114 sh_video_t* sh_video = demuxer->video->sh; | |
115 off_t pos; | |
116 | |
117 pos = (flags & 1) ? demuxer->movi_start : stream_tell(s); | |
118 if(flags & 2) | |
119 pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
120 else | |
121 pos += (rel_seek_secs*sh_video->i_bps); | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
122 if(pos < 0) pos = 0; |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
123 if(demuxer->movi_end && pos > demuxer->movi_end) pos = (demuxer->movi_end-imgsize); |
9065 | 124 pos/=imgsize; |
125 stream_seek(s,pos*imgsize); | |
9708
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
126 //sh_video->timer=pos * sh_video->frametime; |
a37708f0b574
on now set the demuxer type some we can use rawvideo with -audiofile
albeu
parents:
9068
diff
changeset
|
127 demuxer->video->pts = pos * sh_video->frametime; |
9065 | 128 // printf("demux_rawvideo: streamtell=%d\n",(int)stream_tell(demuxer->stream)); |
129 } |