MPEG-2 resolution 1920x1080 opened and encoded with 1920x1088

Started by schach, November 04, 2016, 08:37:19 PM

Previous topic - Next topic

schach

There's a bug when opening and encoding MPEG-2 files with a Full-HD resolution of 1920x1080. They are by mistake opened recognized as files with a resolution of 1920x1088. If encoding them for example into MPEG4-H.264 they are encoded with this wrong resolution of 1920x1088

The MPEG-2 source files are having definately the correct resolution of 1920x1080, as several Video-software as VLC-Player, XMedia Recode, Magix Video and also Windows File Explorer are stating. I think it has something to do with the fact that "1088" but not "1080" is a multiple of "16" which is often used factor in Video sotware. 1280x720 MPEG-2 files are opened with their correct resolution (since 1280 and 720 are both multiples of "16")

I've uploaded a short example video, that you test it yourself:
1920x1080mpeg2.mpg

eumagga0x2a

Quote from: schach on November 04, 2016, 08:37:19 PM
There's a bug when opening and encoding MPEG-2 files with a Full-HD resolution of 1920x1080. They are by mistake opened recognized as files with a resolution of 1920x1088. [...] I think it has something to do with the fact that "1088" but not "1080" is a multiple of "16" which is often used factor in Video sotware.

Yes, the height (and the width, but the width doesn't matter here because 1920 is a multiple of 16) gets rounded up to a multiple of 16. While

diff --git a/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp b/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
index fc3b480..1080811 100644
--- a/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
+++ b/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
@@ -259,7 +259,7 @@ bool bAppend=false;
                           video.interlaced=0; // how to detect ?
                           video.w=val>>20;
                           video.w=((video.w+15)&~15);
-                          video.h= (((val>>8) & 0xfff)+15)& ~15;
+                          video.h= (val>>8) & 0xfff;

                           video.ar = (val >> 4) & 0xf;


fixes this particular issue, I don't have enough knowledge to overview possible implications. Handling 1920x1080 as a special case with

diff --git a/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp b/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
index fc3b480..35b2d9c 100644
--- a/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
+++ b/avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
@@ -260,6 +260,8 @@ bool bAppend=false;
                           video.w=val>>20;
                           video.w=((video.w+15)&~15);
                           video.h= (((val>>8) & 0xfff)+15)& ~15;
+                          if(video.h==1088)
+                              video.h=1080;

                           video.ar = (val >> 4) & 0xf;


solves/workarounds the issue as well, of course.

eumagga0x2a

A small addendum: It is worth mentioning that Avidemux fails to decode the sample video with hardware accelerated decoding via VDPAU enabled. Decoding in software works fine.

If you are unable to build Avidemux from source on your system, you can workaround the wrong height calculation for 1920x1080 mpeg2 videos editing respective .idx2 files and replacing the line

Height=1088

not far from the end of the file with

Height=1080

Close the video in Avidemux then and load it again. Avidemux will use the value found in the .idx2 file.

eumagga0x2a

Upon comparison with the similar code in avidemux_plugins/ADM_demuxers/MpegTS/ADM_tsIndexMpeg2.cpp, I think the same approach could be taken here. Pull request opened.

Please note that you must delete the .idx2 files related to misdetected full-hd mpeg2 videos first, otherwise even a fixed Avidemux will continue to believe the resolution were 1920x1088.

eumagga0x2a