Mercurial > mplayer.hg
annotate libmpcodecs/vf_lavc.c @ 30918:be200e917ae1
Remove unused OPTFLAGS variable from config.mak.
author | diego |
---|---|
date | Thu, 25 Mar 2010 19:53:05 +0000 |
parents | a972c1a4a012 |
children | f957f330aa6d |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
18 |
5873 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 | |
17012 | 24 #include "config.h" |
25 #include "mp_msg.h" | |
26 #include "help_mp.h" | |
5873 | 27 |
28 #include "img_format.h" | |
29 #include "mp_image.h" | |
30 #include "vf.h" | |
31 #include "libavcodec/avcodec.h" | |
32 | |
25962 | 33 extern int avcodec_initialized; |
5873 | 34 |
35 struct vf_priv_s { | |
36 unsigned char* outbuf; | |
37 int outbuf_size; | |
7852 | 38 AVCodecContext* context; |
8413 | 39 AVFrame* pic; |
7852 | 40 AVCodec* codec; |
5873 | 41 vo_mpegpes_t pes; |
42 }; | |
43 | |
7852 | 44 #define lavc_venc_context (*vf->priv->context) |
5873 | 45 |
46 //===========================================================================// | |
47 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
48 static int config(struct vf_instance *vf, |
5873 | 49 int width, int height, int d_width, int d_height, |
50 unsigned int flags, unsigned int outfmt){ | |
51 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0; | |
52 | |
53 lavc_venc_context.width = width; | |
54 lavc_venc_context.height = height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
55 |
15843 | 56 if(!lavc_venc_context.time_base.num || !lavc_venc_context.time_base.den){ |
6019 | 57 // guess FPS: |
58 switch(height){ | |
59 case 240: | |
60 case 480: | |
15307 | 61 lavc_venc_context.time_base= (AVRational){1001,30000}; |
6019 | 62 break; |
63 case 576: | |
64 case 288: | |
65 default: | |
15307 | 66 lavc_venc_context.time_base= (AVRational){1,25}; |
6019 | 67 break; |
68 // lavc_venc_context.frame_rate=vo_fps*FRAME_RATE_BASE; // same as src | |
69 } | |
70 } | |
5873 | 71 |
72 if(vf->priv->outbuf) free(vf->priv->outbuf); | |
73 | |
74 vf->priv->outbuf_size=10000+width*height; // must be enough! | |
75 vf->priv->outbuf = malloc(vf->priv->outbuf_size); | |
76 | |
77 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { | |
78 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); | |
79 return 0; | |
80 } | |
81 | |
82 if (lavc_venc_context.codec->encode == NULL) { | |
83 mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); | |
84 return 0; | |
85 } | |
86 | |
87 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES); | |
88 } | |
89 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
90 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
5873 | 91 mp_image_t* dmpi; |
92 int out_size; | |
8413 | 93 AVFrame *pic= vf->priv->pic; |
5873 | 94 |
8339 | 95 pic->data[0]=mpi->planes[0]; |
96 pic->data[1]=mpi->planes[1]; | |
97 pic->data[2]=mpi->planes[2]; | |
98 pic->linesize[0]=mpi->stride[0]; | |
99 pic->linesize[1]=mpi->stride[1]; | |
100 pic->linesize[2]=mpi->stride[2]; | |
5873 | 101 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
102 out_size = avcodec_encode_video(&lavc_venc_context, |
8339 | 103 vf->priv->outbuf, vf->priv->outbuf_size, pic); |
5873 | 104 |
7368 | 105 if(out_size<=0) return 1; |
5873 | 106 |
107 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES, | |
108 MP_IMGTYPE_EXPORT, 0, | |
109 mpi->w, mpi->h); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
110 |
5873 | 111 vf->priv->pes.data=vf->priv->outbuf; |
112 vf->priv->pes.size=out_size; | |
113 vf->priv->pes.id=0x1E0; | |
114 vf->priv->pes.timestamp=-1; // dunno | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
115 |
7127 | 116 dmpi->planes[0]=(unsigned char*)&vf->priv->pes; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
117 |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
118 return vf_next_put_image(vf,dmpi, MP_NOPTS_VALUE); |
5873 | 119 } |
120 | |
121 //===========================================================================// | |
122 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
123 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
5873 | 124 switch(fmt){ |
125 case IMGFMT_YV12: | |
126 case IMGFMT_I420: | |
127 case IMGFMT_IYUV: | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26069
diff
changeset
|
128 return vf_next_query_format(vf, IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_ACCEPT_STRIDE)); |
5873 | 129 } |
130 return 0; | |
131 } | |
132 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
133 static int vf_open(vf_instance_t *vf, char *args){ |
6019 | 134 int p_quality=0; |
135 float p_fps=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
136 |
5873 | 137 vf->config=config; |
138 vf->put_image=put_image; | |
139 vf->query_format=query_format; | |
140 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
141 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
142 | |
25962 | 143 if (!avcodec_initialized){ |
5873 | 144 avcodec_init(); |
145 avcodec_register_all(); | |
25962 | 146 avcodec_initialized=1; |
5873 | 147 } |
148 | |
149 vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name("mpeg1video"); | |
150 if (!vf->priv->codec) { | |
151 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video"); | |
152 return 0; | |
153 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
154 |
7852 | 155 vf->priv->context=avcodec_alloc_context(); |
8413 | 156 vf->priv->pic = avcodec_alloc_frame(); |
5873 | 157 |
158 // TODO: parse args -> | |
6019 | 159 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps); |
160 | |
161 if(p_quality<32){ | |
162 // fixed qscale | |
163 lavc_venc_context.flags = CODEC_FLAG_QSCALE; | |
11257
837bca3ae69f
constant qscale was broken due to libavcodec changes, fix taken from ve_lavc.c
ranma
parents:
11000
diff
changeset
|
164 lavc_venc_context.global_quality = |
837bca3ae69f
constant qscale was broken due to libavcodec changes, fix taken from ve_lavc.c
ranma
parents:
11000
diff
changeset
|
165 vf->priv->pic->quality = (int)(FF_QP2LAMBDA * ((p_quality<1) ? 1 : p_quality) + 0.5); |
6019 | 166 } else { |
167 // fixed bitrate (in kbits) | |
168 lavc_venc_context.bit_rate = 1000*p_quality; | |
169 } | |
15307 | 170 lavc_venc_context.time_base.num = 1000*1001; |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
171 lavc_venc_context.time_base.den = (p_fps<1.0) ? 1000*1001*25 : (p_fps * lavc_venc_context.time_base.num); |
5873 | 172 lavc_venc_context.gop_size = 0; // I-only |
15349 | 173 lavc_venc_context.pix_fmt= PIX_FMT_YUV420P; |
5873 | 174 |
175 return 1; | |
176 } | |
177 | |
25221 | 178 const vf_info_t vf_info_lavc = { |
5873 | 179 "realtime mpeg1 encoding with libavcodec", |
180 "lavc", | |
181 "A'rpi", | |
182 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
183 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9577
diff
changeset
|
184 NULL |
5873 | 185 }; |
186 | |
187 //===========================================================================// |