@@ -47,6 +47,8 @@ constexpr auto kImageFormat = QImage::Format_ARGB32_Premultiplied;
4747constexpr auto kMaxScaleByAspectRatio = 16 ;
4848constexpr auto kAvioBlockSize = 4096 ;
4949constexpr auto kMaxFrameStorageBytes = 64 * 1024 * 1024 ;
50+ constexpr auto kMaxPixelsPaddingRatio = 32 ;
51+ constexpr auto kMaxPixelsFixedPadding = 64 * 1024 ;
5052constexpr auto kTimeUnknown = std::numeric_limits<crl::time>::min();
5153constexpr auto kDurationMax = crl::time(std::numeric_limits<int >::max());
5254
@@ -417,6 +419,12 @@ const AVCodec *FindDecoder(not_null<AVCodecContext*> context) {
417419 : avcodec_find_decoder (context->codec_id );
418420}
419421
422+ int64_t MaxPixelsForAreaLimit (int64_t area) {
423+ // Decoders may check internally padded frame dimensions against max_pixels,
424+ // not just the visible frame size. Leave room for alignment/cropping slack.
425+ return area + area / kMaxPixelsPaddingRatio + kMaxPixelsFixedPadding ;
426+ }
427+
420428CodecPointer MakeCodecPointer (CodecDescriptor descriptor) {
421429 auto error = AvErrorWrap ();
422430
@@ -435,7 +443,8 @@ CodecPointer MakeCodecPointer(CodecDescriptor descriptor) {
435443 context->pkt_timebase = stream->time_base ;
436444 if ((descriptor.videoMaxArea > 0 )
437445 && (context->codec_type == AVMEDIA_TYPE_VIDEO )) {
438- context->max_pixels = descriptor.videoMaxArea ;
446+ context->max_pixels = MaxPixelsForAreaLimit (
447+ descriptor.videoMaxArea );
439448 }
440449 av_opt_set (context, " threads" , " auto" , 0 );
441450 av_opt_set_int (context, " refcounted_frames" , 1 , 0 );
0 commit comments