Mercurial > mplayer.hg
annotate libmpcodecs/vf_lavc.c @ 35374:8249c2131cd3
Rename uiGotoTheNext uiProcessNextInPlaylist.
This is a more descriptive (although very long) name for the variable.
author | ib |
---|---|
date | Sat, 24 Nov 2012 15:54:22 +0000 |
parents | a3c178a46634 |
children |
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" | |
33871
30f5e5cd3676
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents:
32537
diff
changeset
|
31 #include "av_helpers.h" |
5873 | 32 #include "libavcodec/avcodec.h" |
33 | |
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 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
31959
diff
changeset
|
72 free(vf->priv->outbuf); |
5873 | 73 |
74 vf->priv->outbuf_size=10000+width*height; // must be enough! | |
75 vf->priv->outbuf = malloc(vf->priv->outbuf_size); | |
76 | |
34566
f3d53cd55376
Update deprecated avcodec_alloc_context()/avcodec_open() API calls
siretart
parents:
34457
diff
changeset
|
77 if (avcodec_open2(&lavc_venc_context, vf->priv->codec, NULL) != 0) { |
5873 | 78 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); |
79 return 0; | |
80 } | |
81 | |
82 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES); | |
83 } | |
84 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
85 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
5873 | 86 mp_image_t* dmpi; |
87 int out_size; | |
8413 | 88 AVFrame *pic= vf->priv->pic; |
5873 | 89 |
8339 | 90 pic->data[0]=mpi->planes[0]; |
91 pic->data[1]=mpi->planes[1]; | |
92 pic->data[2]=mpi->planes[2]; | |
93 pic->linesize[0]=mpi->stride[0]; | |
94 pic->linesize[1]=mpi->stride[1]; | |
95 pic->linesize[2]=mpi->stride[2]; | |
5873 | 96 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
97 out_size = avcodec_encode_video(&lavc_venc_context, |
8339 | 98 vf->priv->outbuf, vf->priv->outbuf_size, pic); |
5873 | 99 |
7368 | 100 if(out_size<=0) return 1; |
5873 | 101 |
102 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES, | |
103 MP_IMGTYPE_EXPORT, 0, | |
104 mpi->w, mpi->h); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
105 |
5873 | 106 vf->priv->pes.data=vf->priv->outbuf; |
107 vf->priv->pes.size=out_size; | |
108 vf->priv->pes.id=0x1E0; | |
109 vf->priv->pes.timestamp=-1; // dunno | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
110 |
7127 | 111 dmpi->planes[0]=(unsigned char*)&vf->priv->pes; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
112 |
34457
220497708307
propagate the pts to vf_next_put_image(); fixes playback with -correct-pts when reencoding is necessary
nicodvb
parents:
33871
diff
changeset
|
113 return vf_next_put_image(vf,dmpi, pts); |
5873 | 114 } |
115 | |
116 //===========================================================================// | |
117 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
118 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
5873 | 119 switch(fmt){ |
120 case IMGFMT_YV12: | |
121 case IMGFMT_I420: | |
122 case IMGFMT_IYUV: | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26069
diff
changeset
|
123 return vf_next_query_format(vf, IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_ACCEPT_STRIDE)); |
5873 | 124 } |
125 return 0; | |
126 } | |
127 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
128 static int vf_open(vf_instance_t *vf, char *args){ |
6019 | 129 int p_quality=0; |
130 float p_fps=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
131 |
5873 | 132 vf->config=config; |
133 vf->put_image=put_image; | |
134 vf->query_format=query_format; | |
135 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
136 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
137 | |
31959
f957f330aa6d
Introduce init_avcodec function to avoid duplicated FFmpeg initializations.
diego
parents:
30642
diff
changeset
|
138 init_avcodec(); |
5873 | 139 |
34691 | 140 vf->priv->codec = avcodec_find_encoder_by_name("mpeg1video"); |
5873 | 141 if (!vf->priv->codec) { |
142 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, "mpeg1video"); | |
143 return 0; | |
144 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26754
diff
changeset
|
145 |
34566
f3d53cd55376
Update deprecated avcodec_alloc_context()/avcodec_open() API calls
siretart
parents:
34457
diff
changeset
|
146 vf->priv->context=avcodec_alloc_context3(vf->priv->codec); |
8413 | 147 vf->priv->pic = avcodec_alloc_frame(); |
5873 | 148 |
149 // TODO: parse args -> | |
6019 | 150 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps); |
151 | |
152 if(p_quality<32){ | |
153 // fixed qscale | |
154 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
|
155 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
|
156 vf->priv->pic->quality = (int)(FF_QP2LAMBDA * ((p_quality<1) ? 1 : p_quality) + 0.5); |
6019 | 157 } else { |
158 // fixed bitrate (in kbits) | |
159 lavc_venc_context.bit_rate = 1000*p_quality; | |
160 } | |
15307 | 161 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
|
162 lavc_venc_context.time_base.den = (p_fps<1.0) ? 1000*1001*25 : (p_fps * lavc_venc_context.time_base.num); |
5873 | 163 lavc_venc_context.gop_size = 0; // I-only |
15349 | 164 lavc_venc_context.pix_fmt= PIX_FMT_YUV420P; |
5873 | 165 |
166 return 1; | |
167 } | |
168 | |
25221 | 169 const vf_info_t vf_info_lavc = { |
5873 | 170 "realtime mpeg1 encoding with libavcodec", |
171 "lavc", | |
172 "A'rpi", | |
173 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
174 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9577
diff
changeset
|
175 NULL |
5873 | 176 }; |
177 | |
178 //===========================================================================// |