Mercurial > mplayer.hg
comparison libmpcodecs/vf_lavc.c @ 5873:74cbaabeaa33
realtime yv12->mpeg1 with libavcodec qscale=1
author | arpi |
---|---|
date | Sat, 27 Apr 2002 23:34:44 +0000 |
parents | |
children | 5ebafc7f5efe |
comparison
equal
deleted
inserted
replaced
5872:02576893af2a | 5873:74cbaabeaa33 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 #include "../help_mp.h" | |
9 | |
10 #ifdef USE_LIBAVCODEC | |
11 | |
12 #include "img_format.h" | |
13 #include "mp_image.h" | |
14 #include "vf.h" | |
15 | |
16 //#include "../libvo/fastmemcpy.h" | |
17 | |
18 #ifdef USE_LIBAVCODEC_SO | |
19 #include <libffmpeg/avcodec.h> | |
20 #else | |
21 #include "libavcodec/avcodec.h" | |
22 #endif | |
23 | |
24 extern int avcodec_inited; | |
25 | |
26 struct vf_priv_s { | |
27 unsigned char* outbuf; | |
28 int outbuf_size; | |
29 AVCodecContext context; | |
30 AVCodec *codec; | |
31 vo_mpegpes_t pes; | |
32 }; | |
33 | |
34 #define lavc_venc_context (vf->priv->context) | |
35 | |
36 //===========================================================================// | |
37 | |
38 static int config(struct vf_instance_s* vf, | |
39 int width, int height, int d_width, int d_height, | |
40 unsigned int flags, unsigned int outfmt){ | |
41 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0; | |
42 | |
43 lavc_venc_context.width = width; | |
44 lavc_venc_context.height = height; | |
45 | |
46 if(vf->priv->outbuf) free(vf->priv->outbuf); | |
47 | |
48 vf->priv->outbuf_size=10000+width*height; // must be enough! | |
49 if(vf->priv->outbuf) free(vf->priv->outbuf); | |
50 vf->priv->outbuf = malloc(vf->priv->outbuf_size); | |
51 | |
52 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { | |
53 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); | |
54 return 0; | |
55 } | |
56 | |
57 if (lavc_venc_context.codec->encode == NULL) { | |
58 mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); | |
59 return 0; | |
60 } | |
61 | |
62 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES); | |
63 } | |
64 | |
65 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
66 mp_image_t* dmpi; | |
67 int out_size; | |
68 AVPicture lavc_venc_picture; | |
69 | |
70 lavc_venc_picture.data[0]=mpi->planes[0]; | |
71 lavc_venc_picture.data[1]=mpi->planes[1]; | |
72 lavc_venc_picture.data[2]=mpi->planes[2]; | |
73 lavc_venc_picture.linesize[0]=mpi->stride[0]; | |
74 lavc_venc_picture.linesize[1]=mpi->stride[1]; | |
75 lavc_venc_picture.linesize[2]=mpi->stride[2]; | |
76 | |
77 out_size = avcodec_encode_video(&lavc_venc_context, | |
78 vf->priv->outbuf, vf->priv->outbuf_size, &lavc_venc_picture); | |
79 | |
80 if(out_size<=0) return; | |
81 | |
82 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES, | |
83 MP_IMGTYPE_EXPORT, 0, | |
84 mpi->w, mpi->h); | |
85 | |
86 vf->priv->pes.data=vf->priv->outbuf; | |
87 vf->priv->pes.size=out_size; | |
88 vf->priv->pes.id=0x1E0; | |
89 vf->priv->pes.timestamp=-1; // dunno | |
90 | |
91 dmpi->planes[0]=&vf->priv->pes; | |
92 | |
93 vf_next_put_image(vf,dmpi); | |
94 } | |
95 | |
96 //===========================================================================// | |
97 | |
98 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
99 switch(fmt){ | |
100 case IMGFMT_YV12: | |
101 case IMGFMT_I420: | |
102 case IMGFMT_IYUV: | |
103 return (vf_next_query_format(vf,fmt) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE))); | |
104 } | |
105 return 0; | |
106 } | |
107 | |
108 static int open(vf_instance_t *vf, char* args){ | |
109 vf->config=config; | |
110 vf->put_image=put_image; | |
111 vf->query_format=query_format; | |
112 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
113 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
114 | |
115 if (!avcodec_inited){ | |
116 avcodec_init(); | |
117 avcodec_register_all(); | |
118 avcodec_inited=1; | |
119 } | |
120 | |
121 vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name("mpeg1video"); | |
122 if (!vf->priv->codec) { | |
123 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video"); | |
124 return 0; | |
125 } | |
126 | |
127 // TODO: parse args -> | |
128 lavc_venc_context.bit_rate = 8000000; | |
129 lavc_venc_context.frame_rate = 25 * FRAME_RATE_BASE; | |
130 lavc_venc_context.qmin= 1; | |
131 lavc_venc_context.gop_size = 0; // I-only | |
132 lavc_venc_context.flags = CODEC_FLAG_QSCALE; | |
133 lavc_venc_context.quality = 1; | |
134 | |
135 return 1; | |
136 } | |
137 | |
138 vf_info_t vf_info_lavc = { | |
139 "realtime mpeg1 encoding with libavcodec", | |
140 "lavc", | |
141 "A'rpi", | |
142 "", | |
143 open | |
144 }; | |
145 | |
146 //===========================================================================// | |
147 #endif |