Mercurial > mplayer.hg
annotate libmpcodecs/vf_lavc.c @ 22943:6bfd7e9775bc
Simplify calc_response_string()
author | rtogni |
---|---|
date | Mon, 09 Apr 2007 21:26:49 +0000 |
parents | 8b52dad54b1d |
children | f8d4f8eff72b |
rev | line source |
---|---|
5873 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
17012 | 6 #include "config.h" |
7 #include "mp_msg.h" | |
8 #include "help_mp.h" | |
5873 | 9 |
10 #include "img_format.h" | |
11 #include "mp_image.h" | |
12 #include "vf.h" | |
13 | |
17012 | 14 //#include "libvo/fastmemcpy.h" |
5873 | 15 |
16 #ifdef USE_LIBAVCODEC_SO | |
7004 | 17 #include <ffmpeg/avcodec.h> |
5873 | 18 #else |
19 #include "libavcodec/avcodec.h" | |
20 #endif | |
21 | |
22 extern int avcodec_inited; | |
23 | |
24 struct vf_priv_s { | |
25 unsigned char* outbuf; | |
26 int outbuf_size; | |
7852 | 27 AVCodecContext* context; |
8413 | 28 AVFrame* pic; |
7852 | 29 AVCodec* codec; |
5873 | 30 vo_mpegpes_t pes; |
31 }; | |
32 | |
7852 | 33 #define lavc_venc_context (*vf->priv->context) |
5873 | 34 |
35 //===========================================================================// | |
36 | |
37 static int config(struct vf_instance_s* vf, | |
38 int width, int height, int d_width, int d_height, | |
39 unsigned int flags, unsigned int outfmt){ | |
40 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0; | |
41 | |
42 lavc_venc_context.width = width; | |
43 lavc_venc_context.height = height; | |
6019 | 44 |
15843 | 45 if(!lavc_venc_context.time_base.num || !lavc_venc_context.time_base.den){ |
6019 | 46 // guess FPS: |
47 switch(height){ | |
48 case 240: | |
49 case 480: | |
15307 | 50 lavc_venc_context.time_base= (AVRational){1001,30000}; |
6019 | 51 break; |
52 case 576: | |
53 case 288: | |
54 default: | |
15307 | 55 lavc_venc_context.time_base= (AVRational){1,25}; |
6019 | 56 break; |
57 // lavc_venc_context.frame_rate=vo_fps*FRAME_RATE_BASE; // same as src | |
58 } | |
59 } | |
5873 | 60 |
61 if(vf->priv->outbuf) free(vf->priv->outbuf); | |
62 | |
63 vf->priv->outbuf_size=10000+width*height; // must be enough! | |
64 vf->priv->outbuf = malloc(vf->priv->outbuf_size); | |
65 | |
66 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { | |
67 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); | |
68 return 0; | |
69 } | |
70 | |
71 if (lavc_venc_context.codec->encode == NULL) { | |
72 mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); | |
73 return 0; | |
74 } | |
75 | |
76 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES); | |
77 } | |
78 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
79 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
5873 | 80 mp_image_t* dmpi; |
81 int out_size; | |
8413 | 82 AVFrame *pic= vf->priv->pic; |
5873 | 83 |
8339 | 84 pic->data[0]=mpi->planes[0]; |
85 pic->data[1]=mpi->planes[1]; | |
86 pic->data[2]=mpi->planes[2]; | |
87 pic->linesize[0]=mpi->stride[0]; | |
88 pic->linesize[1]=mpi->stride[1]; | |
89 pic->linesize[2]=mpi->stride[2]; | |
5873 | 90 |
91 out_size = avcodec_encode_video(&lavc_venc_context, | |
8339 | 92 vf->priv->outbuf, vf->priv->outbuf_size, pic); |
5873 | 93 |
7368 | 94 if(out_size<=0) return 1; |
5873 | 95 |
96 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES, | |
97 MP_IMGTYPE_EXPORT, 0, | |
98 mpi->w, mpi->h); | |
99 | |
100 vf->priv->pes.data=vf->priv->outbuf; | |
101 vf->priv->pes.size=out_size; | |
102 vf->priv->pes.id=0x1E0; | |
103 vf->priv->pes.timestamp=-1; // dunno | |
104 | |
7127 | 105 dmpi->planes[0]=(unsigned char*)&vf->priv->pes; |
5873 | 106 |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
107 return vf_next_put_image(vf,dmpi, MP_NOPTS_VALUE); |
5873 | 108 } |
109 | |
110 //===========================================================================// | |
111 | |
112 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
113 switch(fmt){ | |
114 case IMGFMT_YV12: | |
115 case IMGFMT_I420: | |
116 case IMGFMT_IYUV: | |
5876 | 117 return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE))); |
5873 | 118 } |
119 return 0; | |
120 } | |
121 | |
122 static int open(vf_instance_t *vf, char* args){ | |
6019 | 123 int p_quality=0; |
124 float p_fps=0; | |
125 | |
5873 | 126 vf->config=config; |
127 vf->put_image=put_image; | |
128 vf->query_format=query_format; | |
129 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
130 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
131 | |
132 if (!avcodec_inited){ | |
133 avcodec_init(); | |
134 avcodec_register_all(); | |
135 avcodec_inited=1; | |
136 } | |
137 | |
138 vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name("mpeg1video"); | |
139 if (!vf->priv->codec) { | |
140 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video"); | |
141 return 0; | |
142 } | |
7852 | 143 |
144 vf->priv->context=avcodec_alloc_context(); | |
8413 | 145 vf->priv->pic = avcodec_alloc_frame(); |
5873 | 146 |
147 // TODO: parse args -> | |
6019 | 148 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps); |
149 | |
150 if(p_quality<32){ | |
151 // fixed qscale | |
152 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
|
153 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
|
154 vf->priv->pic->quality = (int)(FF_QP2LAMBDA * ((p_quality<1) ? 1 : p_quality) + 0.5); |
6019 | 155 } else { |
156 // fixed bitrate (in kbits) | |
157 lavc_venc_context.bit_rate = 1000*p_quality; | |
158 } | |
15307 | 159 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
|
160 lavc_venc_context.time_base.den = (p_fps<1.0) ? 1000*1001*25 : (p_fps * lavc_venc_context.time_base.num); |
5873 | 161 lavc_venc_context.gop_size = 0; // I-only |
15349 | 162 lavc_venc_context.pix_fmt= PIX_FMT_YUV420P; |
5873 | 163 |
164 return 1; | |
165 } | |
166 | |
167 vf_info_t vf_info_lavc = { | |
168 "realtime mpeg1 encoding with libavcodec", | |
169 "lavc", | |
170 "A'rpi", | |
171 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9577
diff
changeset
|
172 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9577
diff
changeset
|
173 NULL |
5873 | 174 }; |
175 | |
176 //===========================================================================// |