annotate libmpcodecs/vf_fame.c @ 20342:2357bde391b7

r20341: Remove obsolete parts, some updates.
author kraymer
date Sun, 22 Oct 2006 06:00:31 +0000
parents a1807995e2ab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
1 #include <stdio.h>
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
2 #include <stdlib.h>
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
3 #include <string.h>
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
4 #include <inttypes.h>
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
5
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 12605
diff changeset
6 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 12605
diff changeset
7 #include "mp_msg.h"
18004
bcd805923554 Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents: 17906
diff changeset
8 #include "help_mp.h"
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
9
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
10 // 100=best >=80 very good >=50 fast
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
11 #define QUALITY 90
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
12
5607
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5565
diff changeset
13 #include "img_format.h"
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5565
diff changeset
14 #include "mp_image.h"
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
15 #include "vf.h"
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
16
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 12605
diff changeset
17 //#include "libvo/fastmemcpy.h"
12605
27706a9c2015 libfame has been removed from MPlayer long ago. Compilation fix pointed
diego
parents: 9593
diff changeset
18 #include <fame.h>
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
19
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
20 struct vf_priv_s {
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
21 unsigned char* outbuf;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
22 int outbuf_size;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
23 fame_parameters_t params;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
24 fame_context_t *ctx;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
25 vo_mpegpes_t pes;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
26 };
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
27
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
28 //===========================================================================//
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
29
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
30 static int config(struct vf_instance_s* vf,
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
31 int width, int height, int d_width, int d_height,
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
32 unsigned int flags, unsigned int outfmt){
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
33 if(vf_next_query_format(vf,IMGFMT_MPEGPES)<=0) return 0;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
34
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
35 vf->priv->params.width=width;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
36 vf->priv->params.height=height;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
37
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
38 vf->priv->outbuf_size=10000+width*height; // must be enough!
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
39 if(vf->priv->outbuf) free(vf->priv->outbuf);
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
40 vf->priv->outbuf = malloc(vf->priv->outbuf_size);
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
41
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
42 fame_init(vf->priv->ctx,&vf->priv->params,vf->priv->outbuf,vf->priv->outbuf_size);
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
43
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
44 return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_MPEGPES);
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
45 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
46
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
47 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
48 fame_yuv_t yuv;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
49 mp_image_t *dmpi;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
50 int out_size;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
51
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
52 yuv.w=mpi->width;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
53 yuv.h=mpi->height;
6260
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
54 yuv.p=mpi->stride[0];
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
55 yuv.y=mpi->planes[0];
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
56 yuv.u=mpi->planes[1];
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
57 yuv.v=mpi->planes[2];
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
58
6260
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
59 // out_size = fame_encode_frame(vf->priv->ctx, &yuv, NULL);
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
60 fame_start_frame(vf->priv->ctx, &yuv, NULL);
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
61 out_size = fame_encode_slice(vf->priv->ctx);
6261
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
62 fame_end_frame(vf->priv->ctx, NULL);
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
63
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 6261
diff changeset
64 if(out_size<=0) return 1;
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
65
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
66 dmpi=vf_get_image(vf->next,IMGFMT_MPEGPES,
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
67 MP_IMGTYPE_EXPORT, 0,
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
68 mpi->w, mpi->h);
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
69
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
70 vf->priv->pes.data=vf->priv->outbuf;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
71 vf->priv->pes.size=out_size;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
72 vf->priv->pes.id=0x1E0;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
73 vf->priv->pes.timestamp=-1; // dunno
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
74
7557
f296ff05bcd0 warning fixes
arpi
parents: 7368
diff changeset
75 dmpi->planes[0]=(void*) &vf->priv->pes;
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
76
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
77 return vf_next_put_image(vf,dmpi, MP_NOPTS_VALUE);
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
78 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
79
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
80 //===========================================================================//
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
81
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
82 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
83 switch(fmt){
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
84 case IMGFMT_YV12:
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
85 case IMGFMT_I420:
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
86 case IMGFMT_IYUV:
6260
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
87 // return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE)));
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
88 return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW)));
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
89 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
90 return 0;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
91 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
92
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
93 static int open(vf_instance_t *vf, char* args){
6261
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
94 int p_quality=0;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
95 float p_fps=0;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
96
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
97 vf->config=config;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
98 vf->put_image=put_image;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
99 vf->query_format=query_format;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
100 vf->priv=malloc(sizeof(struct vf_priv_s));
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
101 memset(vf->priv,0,sizeof(struct vf_priv_s));
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
102
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
103 vf->priv->ctx=fame_open();
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
104 if(!vf->priv->ctx){
18004
bcd805923554 Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents: 17906
diff changeset
105 mp_msg(MSGT_VFILTER, MSGL_ERR, MSGTR_MPCODECS_FatalCantOpenlibFAME);
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
106 return 0;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
107 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
108
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
109 // TODO: parse args ->
6261
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
110 if(args) sscanf(args, "%d:%f", &p_quality, &p_fps);
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
111
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
112 if(p_quality<=100){
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
113 // fixed quality
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
114 vf->priv->params.quality=p_quality?p_quality:QUALITY;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
115 vf->priv->params.bitrate=0;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
116 } else {
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
117 // fixed bitrate (in kbits)
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
118 vf->priv->params.quality=QUALITY;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
119 vf->priv->params.bitrate=1000*p_quality;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
120 }
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
121
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
122 if(p_fps<1) p_fps=25.0;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
123 if(p_fps == ((int)p_fps)){
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
124 vf->priv->params.frame_rate_num=p_fps;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
125 vf->priv->params.frame_rate_den=1;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
126 } else {
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
127 vf->priv->params.frame_rate_num=p_fps*1001;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
128 vf->priv->params.frame_rate_den=1001;
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
129 }
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
130
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
131 vf->priv->params.coding="I";
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
132 vf->priv->params.slices_per_frame=1;
6261
5b76ba46fc72 fame=quality:fps args support, small fixes for 0.9.0 api
arpi
parents: 6260
diff changeset
133 vf->priv->params.frames_per_sequence=(int)p_fps;
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
134 vf->priv->params.shape_quality=100;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
135 vf->priv->params.search_range=8; // for "IPPP" only
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
136 vf->priv->params.verbose=0;
6260
96b5efcad587 use new api of libfame 0.9.0
arpi
parents: 5876
diff changeset
137 vf->priv->params.profile="mpeg1"; // TODO
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
138
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
139 return 1;
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
140 }
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
141
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
142 vf_info_t vf_info_fame = {
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
143 "realtime mpeg1 encoding with libFAME",
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
144 "fame",
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
145 "A'rpi",
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
146 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7557
diff changeset
147 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 7557
diff changeset
148 NULL
5536
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
149 };
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
150
3cd118559307 vf_fame added - yv12->mpes converter
arpi
parents:
diff changeset
151 //===========================================================================//