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