Skip to content

Commit 78636ab

Browse files
Vadim Zubovfacebook-github-bot
authored andcommitted
torchvision decoder. fix artifacts, blury images for frame dimensions not multiple of 8 (#7523)
Summary: Pull Request resolved: #7523 In MUI we found an artifact for video with resolution 426x426, not equal to 8. We find that root cause is torchvision decoder, which MUI uses extensively Tiny black bar on the right in the image Before the fix {F949912112} After the fix {F949913076} Full video https://pxl.cl/2CN1G https://pxl.cl/2CN1L Differential Revision: D45035410 fbshipit-source-id: 2d4f6a4812df075fc4677e6b96dc2e0029ea6e92
1 parent 4d86879 commit 78636ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

torchvision/csrc/io/decoder/video_sampler.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ bool VideoSampler::init(const SamplerParameters& params) {
181181
// set output format
182182
params_ = params;
183183

184+
if (params.in.video.format == AV_PIX_FMT_YUV420P) {
185+
/* When the video width and height are not multiples of 8,
186+
* and there is no size change in the conversion,
187+
* a blurry screen will appear on the right side
188+
* This problem was discovered in 2012 and
189+
* continues to exist in version 4.1.3 in 2019
190+
* This problem can be avoided by increasing SWS_ACCURATE_RND
191+
* details https://trac.ffmpeg.org/ticket/1582
192+
*/
193+
if ((params.in.video.width & 0x7) || (params.in.video.height & 0x7)) {
194+
VLOG(1) << "The width " << params.in.video.width
195+
<< " and height " << params.in.video.height
196+
<< " the image is not a multiple of 8, "
197+
<< "the decoding speed may be reduced";
198+
swsFlags_ |= SWS_ACCURATE_RND;
199+
}
200+
}
201+
184202
scaleContext_ = sws_getContext(
185203
params.in.video.width,
186204
params.in.video.height,

0 commit comments

Comments
 (0)