11 // 100=best >=80 very good >=50 fast
14 #include "img_format.h"
18 //#include "../libvo/fastmemcpy.h"
22 unsigned char* outbuf
;
24 fame_parameters_t params
;
29 //===========================================================================//
31 static int config(struct vf_instance_s
* vf
,
32 int width
, int height
, int d_width
, int d_height
,
33 unsigned int flags
, unsigned int outfmt
){
34 if(vf_next_query_format(vf
,IMGFMT_MPEGPES
)<=0) return 0;
36 vf
->priv
->params
.width
=width
;
37 vf
->priv
->params
.height
=height
;
39 vf
->priv
->outbuf_size
=10000+width
*height
; // must be enough!
40 if(vf
->priv
->outbuf
) free(vf
->priv
->outbuf
);
41 vf
->priv
->outbuf
= malloc(vf
->priv
->outbuf_size
);
43 fame_init(vf
->priv
->ctx
,&vf
->priv
->params
,vf
->priv
->outbuf
,vf
->priv
->outbuf_size
);
45 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,IMGFMT_MPEGPES
);
48 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
60 // out_size = fame_encode_frame(vf->priv->ctx, &yuv, NULL);
61 fame_start_frame(vf
->priv
->ctx
, &yuv
, NULL
);
62 out_size
= fame_encode_slice(vf
->priv
->ctx
);
63 fame_end_frame(vf
->priv
->ctx
, NULL
);
65 if(out_size
<=0) return 1;
67 dmpi
=vf_get_image(vf
->next
,IMGFMT_MPEGPES
,
71 vf
->priv
->pes
.data
=vf
->priv
->outbuf
;
72 vf
->priv
->pes
.size
=out_size
;
73 vf
->priv
->pes
.id
=0x1E0;
74 vf
->priv
->pes
.timestamp
=-1; // dunno
76 dmpi
->planes
[0]=(void*) &vf
->priv
->pes
;
78 return vf_next_put_image(vf
,dmpi
);
81 //===========================================================================//
83 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
88 // return (vf_next_query_format(vf,IMGFMT_MPEGPES) & (~(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE)));
89 return (vf_next_query_format(vf
,IMGFMT_MPEGPES
) & (~(VFCAP_CSP_SUPPORTED_BY_HW
)));
94 static int open(vf_instance_t
*vf
, char* args
){
99 vf
->put_image
=put_image
;
100 vf
->query_format
=query_format
;
101 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
102 memset(vf
->priv
,0,sizeof(struct vf_priv_s
));
104 vf
->priv
->ctx
=fame_open();
106 printf("FATAL: cannot open libFAME!\n");
110 // TODO: parse args ->
111 if(args
) sscanf(args
, "%d:%f", &p_quality
, &p_fps
);
115 vf
->priv
->params
.quality
=p_quality
?p_quality
:QUALITY
;
116 vf
->priv
->params
.bitrate
=0;
118 // fixed bitrate (in kbits)
119 vf
->priv
->params
.quality
=QUALITY
;
120 vf
->priv
->params
.bitrate
=1000*p_quality
;
123 if(p_fps
<1) p_fps
=25.0;
124 if(p_fps
== ((int)p_fps
)){
125 vf
->priv
->params
.frame_rate_num
=p_fps
;
126 vf
->priv
->params
.frame_rate_den
=1;
128 vf
->priv
->params
.frame_rate_num
=p_fps
*1001;
129 vf
->priv
->params
.frame_rate_den
=1001;
132 vf
->priv
->params
.coding
="I";
133 vf
->priv
->params
.slices_per_frame
=1;
134 vf
->priv
->params
.frames_per_sequence
=(int)p_fps
;
135 vf
->priv
->params
.shape_quality
=100;
136 vf
->priv
->params
.search_range
=8; // for "IPPP" only
137 vf
->priv
->params
.verbose
=0;
138 vf
->priv
->params
.profile
="mpeg1"; // TODO
143 vf_info_t vf_info_fame
= {
144 "realtime mpeg1 encoding with libFAME",
152 //===========================================================================//