annotate libmpcodecs/vf_lavc.c @ 5887:f684e461f141

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