@@ -1469,6 +1469,32 @@ static int producer_open(
14691469 AVDictionaryEntry * hwaccel = av_dict_get (params , "hwaccel" , NULL , 0 );
14701470 AVDictionaryEntry * hwaccel_device = av_dict_get (params , "hwaccel_device" , NULL , 0 );
14711471 const char * hwaccel_env = getenv ("MLT_AVFORMAT_HWACCEL" );
1472+ const char * pps_env = getenv ("MLT_AVFORMAT_HWACCEL_PPS" );
1473+
1474+ if (pps_env && self -> video_index >= 0 ) {
1475+ int64_t pps_threshold = strtoll (pps_env , NULL , 10 );
1476+ if (pps_threshold > 0 ) {
1477+ // Calculate PPS while avoiding overflow
1478+ AVStream * stream = self -> video_format -> streams [self -> video_index ];
1479+ int64_t width = stream -> codecpar -> width ;
1480+ int64_t height = stream -> codecpar -> height ;
1481+ double fps = av_q2d (guess_frame_rate (self , stream ));
1482+
1483+ if (width > 0 && height > 0 && fps > 0.0 ) {
1484+ // Calculate pixels per second using double to avoid overflow
1485+ double pps = (double ) width * (double ) height * fps ;
1486+
1487+ if (pps > (double ) pps_threshold ) {
1488+ mlt_log_verbose (MLT_PRODUCER_SERVICE (self -> parent ),
1489+ "Disabling hwaccel: PPS %.0f exceeds threshold %lld\n" ,
1490+ pps ,
1491+ (long long ) pps_threshold );
1492+ hwaccel = NULL ;
1493+ hwaccel_env = NULL ;
1494+ }
1495+ }
1496+ }
1497+ }
14721498
14731499 if (((hwaccel && hwaccel -> value ) || hwaccel_env ) && !test_open ) {
14741500 // Leaving `device=NULL` will cause query string parameter `hwaccel_device` to be ignored
0 commit comments