Opened 10 years ago

Closed 7 years ago

#12047 closed Patch - Bug Fix (Abandoned)

mythplayer picks the wrong fps for 1080i matroska, degrading to 1xHW deint

Reported by: angela.schmid@… Owned by: Karl Egly
Priority: major Milestone:
Component: MythTV - Video Playback Version: Master Head
Severity: high Keywords: deinterlace mkv 1080i
Cc: Ticket locked: no

Description

mythplayer chooses to use the avg_fps (50) instead of the codec_fps (25) for 1080i matroska movies, therefor mythplayer decides to degrade deinterlacing to max 1xHW.

The problem is most clearly with a movie with extreme horizontal panning. I have a movie which I want to archive in mkv (lossless_cut) with a view on a large Chinese dragon wall.

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Format settings, GOP                     : M=4, N=28
Codec ID                                 : V_MPEG4/ISO/AVC
Bit rate                                 : 2 884 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Original frame rate                      : 25.000 fps
Standard                                 : Component
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Bottom Field First
CoreContext avformatdecoder.cpp:1247 (normalized_fps) - AFD: Selected FPS is 50 (avg 50 codec 25 container 1000 estimated 50)

Setting primary deinterlacing option (2xHW):

CoreContext videodisplayprofile.cpp:354 (GetFilteredDeint) - VDP: GetFilteredDeint() : vdpau -> 'vdpaubasicdoublerate'

Degrade to fallback deinterlacing option (max 1xHW):

CoreContext mythplayer.cpp:2384 (VideoStart) - Player(0): Video sync method can't support double framerate (refresh rate too low for 2x deint)
CoreContext videodisplayprofile.cpp:354 (GetFilteredDeint) - VDP: GetFilteredDeint(vdpauadvanced) : vdpau -> 'vdpauadvanced'

Mythplayer should use the codec_fps, which is correct for 1080i.

The following dirty patch fixes the problem:

diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 3a42b40..6698484 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -1221,7 +1221,11 @@ float AvFormatDecoder::normalized_fps(AVStream *stream, AVCodecContext *enc)

     // matroska demuxer sets the default_duration to avg_frame_rate
     // mov,mp4,m4a,3gp,3g2,mj2 demuxer sets avg_frame_rate
-    if ((QString(ic->iformat->name).contains("matroska") ||
+    if ((QString(ic->iformat->name).contains("matroska")) &&
+        container_fps < 121.0f && container_fps > 3.0f)
+        fps = container_fps;
+    else
+    if ((QString(ic->iformat->name).contains("xmatroska") ||
         QString(ic->iformat->name).contains("mov")) &&
         avg_fps < 121.0f && avg_fps > 3.0f)
         fps = avg_fps;

Attachments (5)

0002-divide-framerate-by-number-of-ticks-fields-per-frame.patch (1.5 KB) - added by Karl Egly 10 years ago.
0001-divide-framerate-by-number-of-ticks-fields-per-frame.patch (4.0 KB) - added by Karl Egly 10 years ago.
0001-use-av_guess_frame_rate-from-ffmpeg-2.2-to-replace-o.patch (2.8 KB) - added by Karl Egly 10 years ago.
chinesewall_avconv_5min.mkv.log (13.7 KB) - added by angela.schmid@… 10 years ago.
chinesewall_lossless_cut_5min.mkv.log (20.7 KB) - added by angela.schmid@… 10 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 10 years ago by stuartm

Milestone: unknown0.28
Priority: minormajor

Changed 10 years ago by Karl Egly

comment:2 Changed 10 years ago by Karl Egly

Status: newinfoneeded_new

Good catch, but can't we simply use av_guess_frame_rate which handles interlaced content, too? Either way, the attached patch should handle both progressive and interlaced content. Does it fix your issue?

comment:3 Changed 10 years ago by angela.schmid@…

Patch didn't compile on 0.27 and master:

avformatdecoder.cpp: In member function ‘float AvFormatDecoder::normalized_fps(AVStream*, AVCodecContext*)’:
avformatdecoder.cpp:1351:13: error: ‘st’ was not declared in this scope

Changed 'st' to 'stream' and tested on 0.27-fixes.

The patch works for media as the one shown above.

I didn't had good luck with lossless_cut (uses mkvmerge) and 1080i material with minimal glitches, so I changed my workflow in the meantime and use ts-doctor (which at the end produces correct total times and proper FFWD) and avconv.

I don't have the original chinese wall recording anymore and the resulting mkv has been converted with the following:

avconv -y -i input-tsdoctor.mpg -r 25 -c:v libx264  -flags +ilme+ildct+loop -cmp chroma -deblock 0:0 -r 25 -bt 256k -coder 0 -me_method full -me_range 16 -subq 5 -partitions +parti4x4+parti8x8+partp8x -g 250 -keyint_min 25 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qdiff 4 -refs 2 -direct-pred 1 -wpredp 2 -rc_lookahead 30 -profile:v baseline -level 30 -bf 0 -coder 0 -crf 22 -qmin 2 -qmax 30 -b:v 5000K -c:a copy -ar 44100 -ac 2 -b:a 128K -map 0:0 -map 0:a:0 -sn -f matroska output.mkv

which produces MBAFF

General
Unique ID                                : 63265251044264927949292968836987650338 (0x2F9871B35334230A54E4639435FC8122)
Complete name                            : Die sieben Wunder Chinas S01E06 Die Verbotene Stadt.mkv
Format                                   : Matroska
Format version                           : Version 2
File size                                : 1.69 GiB
Duration                                 : 23mn 59s
Overall bit rate                         : 10.1 Mbps
Writing application                      : Lavf53.21.1
Writing library                          : Lavf53.21.1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.0
Format settings, CABAC                   : No
Format settings, ReFrames                : 2 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 23mn 59s
Bit rate                                 : 9 489 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : MBAFF
Bits/(Pixel*Frame)                       : 0.183
Stream size                              : 1.59 GiB (94%)
Writing library                          : x264 core 120 r2151 a3f4407
Encoding settings                        : cabac=0 / ref=2 / deblock=1:0:0 / analyse=0x1:0x1 / me=umh / subme=5 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=12 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=tff / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=22.0 / qcomp=0.60 / qpmin=2 / qpmax=30 / qpstep=4 / ip_ratio=1.41 / aq=1:1.00
Default                                  : Yes
Forced                                   : No

Your patch produces for MBAFF media the wrong FPS, interlacing is detected correctly:

CoreContext avformatdecoder.cpp:1256 (normalized_fps) - AFD: Selected FPS is 12.5 (avg 12.5 codec 25 container 1000 estimated 25 ticks_per_frame 2)
CoreContext mythplayer.cpp:1748 (SetFrameInterval) - Player(6): SetFrameInterval ps:1 scan:3
CoreContext mythplayer.cpp:670 (detectInterlace) - Player(6): detectInterlace(Detect Scan, Interlaced Scan, 12.5, 1080) ->Interlaced Scan

For MBAFF no patch is needed, my patch does not interfere.

OT: I searched for other tools other than mediainfo to inspect the interlace status, but couldn't find one showing interlacing for MBAFF media, any suggestions.

OT: Is MBAFF good, or should I use another avconv command, any suggestions.

comment:4 Changed 10 years ago by Karl Egly

Thanks for testing. Sorry, I noticed the copy'n'paste error only after uploading the patch but forgot to upload the fixed patch :/ A quick search for MBAFF (mixed progressive and interlaced in within a frame) and ticks_per_frame leads to suggestion of "do not encode to interlaced unless your display really is interlaced" hints, see http://mewiki.project357.com/wiki/X264_Settings#tff OT: As you are reencoding the video you might as well deinterlace before encoding. Lets try with ffmpeg's own new helper function in the new patch. (this time its compile tested)

Changed 10 years ago by Karl Egly

comment:5 Changed 10 years ago by Karl Egly

Owner: set to Karl Egly

comment:6 Changed 10 years ago by angela.schmid@…

All 1080i movies play correct, although I cannot tell the deinterlacing qualities as the best example I have is the chinese wall movie which I only have in MBAFF, which .

CoreContext avformatdecoder.cpp:1291 (normalized_fps) - AFD: Selected FPS is 25 (guess 25 avg 25 codec 25 container 1000 estimated 25)
CoreContext mythplayer.cpp:1748 (SetFrameInterval) - Player(0): SetFrameInterval ps:1 scan:3
CoreContext mythplayer.cpp:670 (detectInterlace) - Player(0): detectInterlace(Detect Scan, Interlaced Scan, 25, 1080) ->Interlaced Scan

However, I noticed converted with lossless_cut workflow media, plays correct, but deinterlacing is degraded and the debug information shows "misleading" data:

Unique ID                                : 215050711015139973841239614612672134380 (0xA1C942A8F50B9E98D99CE20C4FF4BCEC)
Complete name                            : lossless_cut.mkv
Format                                   : Matroska
Format version                           : Version 4 / Version 2
File size                                : 2.16 GiB
Duration                                 : 44mn 54s
Overall bit rate                         : 6 879 Kbps
Encoded date                             : UTC 2014-04-27 09:49:24
Writing application                      : mkvmerge v6.9.1 ('Blue Panther') 64bit built on Apr 18 2014 17:43:56
Writing library                          : libebml v1.3.0 + libmatroska v1.4.1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 3 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Bit rate                                 : 6 358 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Original frame rate                      : 25.000 fps
Standard                                 : Component
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
Default                                  : Yes
Forced                                   : No
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
CoreContext avformatdecoder.cpp:1291 (normalized_fps) - AFD: Selected FPS is 50 (guess 50 avg 50 codec 25 container 1000 estimated 50)
CoreContext mythplayer.cpp:1748 (SetFrameInterval) - Player(1): SetFrameInterval ps:1 scan:3
CoreContext mythplayer.cpp:670 (detectInterlace) - Player(1): detectInterlace(Detect Scan, Interlaced Scan, 50, 1080) ->Progressive Scan
...
CoreContext mythplayer.cpp:3907 (ClearAfterSeek) - Player(7): ClearAfterSeek(0)
CoreContext mythxdisplay.cpp:201 (GetRefreshRate) - Doubling refresh rate for interlaced display.
CoreContext videodisplayprofile.cpp:354 (GetFilteredDeint) - VDP: GetFilteredDeint() : vdpau -> 'vdpaubasicdoublerate'
CoreContext videoout_vdpau.cpp:350 (SetupDeinterlace) - VidOutVDPAU: Enabled deinterlacing.
CoreContext vsync.cpp:265 (TryInit) - VSYNC: DRMVideoSync: Could not open device /dev/dri/card0, No such file or directory
CoreContext mythplayer.cpp:2384 (VideoStart) - Player(7): Video sync method can't support double framerate (refresh rate too low for 2x deint)
CoreContext videodisplayprofile.cpp:354 (GetFilteredDeint) - VDP: GetFilteredDeint(vdpauadvanced) : vdpau -> 'vdpauadvanced'
CoreContext videoout_vdpau.cpp:350 (SetupDeinterlace) - VidOutVDPAU: Enabled deinterlacing.
CoreContext mythxdisplay.cpp:201 (GetRefreshRate) - Doubling refresh rate for interlaced display.
CoreContext mythplayer.cpp:1780 (InitAVSync) - Player(7): Video timing method: RTC
CoreContext mythplayer.cpp:1784 (InitAVSync) - Player(7): Display Refresh Rate: 60.053 Video Frame Rate: 50.000

Never saw two different fps values. Deinterlacing is correctly detected during playback.

In playback debug: Video:1920x1080@50fps, FPS: 25.00fps
In Video Scan: detect(I)

OT: Thanks for the links: https://trac.bunkus.org/wiki/FAQ:WrongFrameRateDisplayed: which explains the mkv behaviour and the mediainfo peculiarities, but also does not suggest other tools.

http://mewiki.project357.com/wiki/X264_Settings#tff I have a 1080i display. Deinterlacing to 1080p or 720p didn't give me good results. Using vdpau 2xdeinterlacing is the best. Thats the reason I detected the deinterlacing degradation for mkv.

comment:7 Changed 10 years ago by angela.schmid@…

Hi Karl, I found a backup of the original Chinese wall recording (between 03:40-04:20). If you are interested please sent me a PM, I will make it available on my web server.

comment:8 Changed 10 years ago by angela.schmid@…

Hello Karl, I see the issue is on info needed. I can not give you further infos. I can provide you with a test file as written above.

Changed 10 years ago by Karl Egly

comment:9 Changed 10 years ago by Karl Egly

Hi Angela, I did not understand if the patch fixed the issue without introducing a regression. Here's an updated version of the patch attachment:0001-use-av_guess_frame_rate-from-ffmpeg-2.2-to-replace-o.patch

comment:10 Changed 10 years ago by angela.schmid@…

Hi Karl, no, the patch does not fix the issue, when the mkv contains scan type interlaced. I have a file converted with avconv, which works, scan type MBAFF. A file converted with lossless_cut does not work, scan type interlaced.

I rerun the test with both files before and after the 0001-divide-framerate-by-number-of-ticks-fields-per-frame.patch on 0.27.1

The documented log files are attached below. I can provide the original ts and the two converted mkv files on my web server, please PM.

Changed 10 years ago by angela.schmid@…

Changed 10 years ago by angela.schmid@…

comment:11 Changed 10 years ago by paulh

Status: infoneeded_newnew

comment:12 Changed 8 years ago by Karl Egly

Milestone: 0.28

comment:13 Changed 7 years ago by angela.schmid@…

Works in 0.28-fixes correct:

CoreContext avformatdecoder.cpp:1456 (normalized_fps) - AFD: Selected FPS is 25 (avg 25 codec 25 container 1000 estimated 25)
CoreContext mythplayer.cpp:685 (detectInterlace) - Player(0): detectInterlace(Detect Scan, Interlaced Scan, 25, 1080) ->Interlaced Scan
CoreContext videodisplayprofile.cpp:354 (GetFilteredDeint) - VDP: GetFilteredDeint() : vdpau -> 'vdpaubasicdoublerate'

In playback debug: Video:1920x1080@25fps, FPS: 25.00fps

In Video Scan: detect(I)

2xHW Deinterlace

Issue can be closed.

comment:14 Changed 7 years ago by Karl Egly

Resolution: Abandoned
Status: newclosed

thank you for reporting back

Note: See TracTickets for help on using tickets.