Commit dab4f163 authored by Mickaël Turnel's avatar Mickaël Turnel

Add a function to retrieve the worst video configuration for a fixed size

parent e59f02a1
......@@ -408,6 +408,15 @@ MS2_PUBLIC MSVideoConfiguration ms_video_find_best_configuration_for_bitrate(con
*/
MS2_PUBLIC MSVideoConfiguration ms_video_find_best_configuration_for_size(const MSVideoConfiguration *vconf_list, MSVideoSize vsize, int cpucount);
/**
* Find the worst video configuration from a list of configuration according to a given video size.
* @param[in] vconf_list The list of video configurations to choose from.
* @param[in] vsize The maximum video size the chosen configuration is allowed to use.
* @param[in] cpucount the number of cpu that can be used for this encoding.
* @return The best video configuration found in the given list.
*/
MS2_PUBLIC MSVideoConfiguration ms_video_find_worst_configuration_for_size(const MSVideoConfiguration *vconf_list, MSVideoSize vsize, int cpucount);
MS2_PUBLIC MSVideoConfiguration ms_video_find_best_configuration_for_size_and_bitrate(const MSVideoConfiguration *vconf_list, MSVideoSize vsize, int cpu_count, int bitrate);
/**
......
......@@ -970,6 +970,41 @@ MSVideoConfiguration ms_video_find_best_configuration_for_size(const MSVideoConf
return best_vconf;
}
MSVideoConfiguration ms_video_find_worst_configuration_for_size(const MSVideoConfiguration *vconf_list, MSVideoSize vsize, int cpu_count) {
const MSVideoConfiguration *vconf_it = vconf_list;
MSVideoConfiguration best_vconf={0};
int min_score=INT32_MAX;
int ref_pixels=vsize.height*vsize.width;
/* search for configuration that is first nearest to target video size, then second has the lowest bitrate but the greater fps,
* but any case making sure the the cpu count is sufficient*/
while(TRUE) {
int pixels=vconf_it->vsize.width*vconf_it->vsize.height;
int score=abs(pixels-ref_pixels);
if (cpu_count>=vconf_it->mincpu){
if (score<min_score){
best_vconf=*vconf_it;
min_score=score;
}else if (score==min_score){
if (best_vconf.required_bitrate == vconf_it->required_bitrate && best_vconf.bitrate_limit == vconf_it->bitrate_limit){
if (best_vconf.fps<vconf_it->fps) {
best_vconf=*vconf_it;
}
} else {
best_vconf=*vconf_it;
}
}
}
if (vconf_it->required_bitrate==0) {
break;
}
vconf_it++;
}
best_vconf.vsize=vsize;
return best_vconf;
}
MSVideoConfiguration ms_video_find_best_configuration_for_size_and_bitrate(const MSVideoConfiguration *vconf_list, MSVideoSize vsize, int cpu_count, int bitrate) {
const MSVideoConfiguration *vconf_it = vconf_list;
MSVideoConfiguration best_vconf={0};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment