Log in

View Full Version : FFMS2 weirdness with Bluray M2TS input


zinga
1st October 2011, 10:42
Firstly, apologies for the long post (actually, most of it are code tags).

I'm getting some weird results with M2TS files through FFVideoSource.
I'm using FFMS v2.16, through wine, with the following command:
avs2yuv in.avs -o NUL

(note that I'm deleting the index file between tries to avoid any index weirdness issues)

Using this script
FFVideoSource("00000.m2ts")
I get a crash (unhandled exception) at around frame 8640 (I have Haali splitter installed) out of 71662 frames. Trying the following
FFIndex("00000.m2ts", demuxer="lavf")
FFVideoSource("00000.m2ts", seekmode=0)
goes fine, but crashes differently with 22 frames left:
in.avs: 1920x1080, 24000/1001 fps, 71664 frames
Avisynth error at frame 71642:
FFVideoSource: Insanity detected: decoder returned an empty frame

(also noting that lavf seems to have +2 frames)

This is a 23.976fps CFR file, and if I dump the timecodes, the number of entries equals the number of frames displayed above.
Adding 'threads=1' to FFVideoSource in the above script fixes the crashing issue (that is, runs to the end without error), but Haali's splitter will still crash the same with 'threads=1'.

However, this is where things get weird. I append to the above script:
DupMC(log="dup.txt")
and the resulting log file seems to be off by around 10-20 frames - that is, I get all the frames in the file, however they're shifted back around 10-20 frames.
Now I'm not sure whether this is an issue with FFMS2 or DupMC, but the shifting here doesn't appear to simply be FFMS2 adding/dropping frames - one would theorize that even if FFMS2 is adding/dropping frames, as long as it does it consistently, DeDup should be dropping the right frames. This isn't the case here - that is DeDup is removing non-duplicate frames before a sequence of duplicate frames due to this weird shifting.

If I remove the 'seekmode=0' flag and add a Trim() call straight after FFVideoSource, the results from DupMC seem to be shifted forward 21 frames. Example:
"Normal" output:

frm 1960: diff from frm 1961 = 13.6187% at (1056,352)
frm 1961: diff from frm 1962 = 20.2539% at (896,192)
frm 1962: diff from frm 1963 = 20.9221% at (896,192)
frm 1963: diff from frm 1964 = 16.6082% at (1120,288)
frm 1964: diff from frm 1965 = 16.9103% at (1184,288)
frm 1965: diff from frm 1966 = 18.2301% at (704,576)
frm 1966: diff from frm 1967 = 4.7536% at (544,128)
frm 1967: diff from frm 1968 = 3.7488% at (544,416)
frm 1968: diff from frm 1969 = 14.3858% at (544,128)
frm 1969: diff from frm 1970 = 86.2924% at (1024,256)
frm 1970: diff from frm 1971 = 7.5445% at (736,480)
frm 1971: diff from frm 1972 = 0.2090% at (544,480)
frm 1972: diff from frm 1973 = 21.9041% at (1024,512)
frm 1973: diff from frm 1974 = 73.7612% at (736,128)
frm 1974: diff from frm 1975 = 74.8645% at (704,192)
frm 1975: diff from frm 1976 = 73.8838% at (640,224)
frm 1976: diff from frm 1977 = 66.7258% at (544,192)
frm 1977: diff from frm 1978 = 68.2310% at (512,160)
frm 1978: diff from frm 1979 = 61.9041% at (288,416)
frm 1979: diff from frm 1980 = 0.4164% at (128,352)
frm 1980: diff from frm 1981 = 0.2040% at (288,192)
frm 1981: diff from frm 1982 = 0.2124% at (1024,416)
frm 1982: diff from frm 1983 = 0.1745% at (1056,416)
frm 1983: diff from frm 1984 = 0.2007% at (1024,416)
frm 1984: diff from frm 1985 = 60.1646% at (320,352)
frm 1985: diff from frm 1986 = 60.0856% at (640,512)
frm 1986: diff from frm 1987 = 58.5892% at (1184,448)
frm 1987: diff from frm 1988 = 59.5666% at (1184,448)
frm 1988: diff from frm 1989 = 52.0283% at (128,384)
frm 1989: diff from frm 1990 = 83.1620% at (128,384)
frm 1990: diff from frm 1991 = 90.5535% at (0,544)
frm 1991: diff from frm 1992 = 76.9253% at (992,576)
frm 1992: diff from frm 1993 = 83.5098% at (192,544)
frm 1993: diff from frm 1994 = 88.1986% at (0,480)
frm 1994: diff from frm 1995 = 56.7694% at (0,576)
frm 1995: diff from frm 1996 = 46.0401% at (160,384)
frm 1996: diff from frm 1997 = 81.1133% at (0,96)
frm 1997: diff from frm 1998 = 48.4874% at (960,576)
frm 1998: diff from frm 1999 = 57.4422% at (32,96)
frm 1999: diff from frm 2000 = 41.6045% at (288,608)
frm 2000: diff from frm 2001 = 50.3466% at (768,160)

Output with Trim(1400,2500): [compare the 1st line above with the 22nd below]

frm 1960: diff from frm 1961 = 9.7444% at (352,448)
frm 1961: diff from frm 1962 = 12.9654% at (1024,160)
frm 1962: diff from frm 1963 = 14.1855% at (992,160)
frm 1963: diff from frm 1964 = 15.0893% at (960,352)
frm 1964: diff from frm 1965 = 17.2635% at (96,416)
frm 1965: diff from frm 1966 = 18.6873% at (1216,576)
frm 1966: diff from frm 1967 = 78.0128% at (64,512)
frm 1967: diff from frm 1968 = 4.7706% at (224,160)
frm 1968: diff from frm 1969 = 18.2613% at (704,576)
frm 1969: diff from frm 1970 = 4.7424% at (224,160)
frm 1970: diff from frm 1971 = 7.5062% at (416,320)
frm 1971: diff from frm 1972 = 11.7557% at (704,576)
frm 1972: diff from frm 1973 = 7.4086% at (416,576)
frm 1973: diff from frm 1974 = 5.2788% at (544,96)
frm 1974: diff from frm 1975 = 3.7330% at (544,384)
frm 1975: diff from frm 1976 = 4.7669% at (224,160)
frm 1976: diff from frm 1977 = 10.3649% at (0,416)
frm 1977: diff from frm 1978 = 18.8493% at (704,576)
frm 1978: diff from frm 1979 = 17.6180% at (1120,128)
frm 1979: diff from frm 1980 = 17.6026% at (1120,128)
frm 1980: diff from frm 1981 = 18.8709% at (704,576)
frm 1981: diff from frm 1982 = 13.6187% at (1056,352)
frm 1982: diff from frm 1983 = 20.2539% at (896,192)
frm 1983: diff from frm 1984 = 20.9221% at (896,192)
frm 1984: diff from frm 1985 = 16.6082% at (1120,288)
frm 1985: diff from frm 1986 = 16.9103% at (1184,288)
frm 1986: diff from frm 1987 = 18.2301% at (704,576)
frm 1987: diff from frm 1988 = 4.7536% at (544,128)
frm 1988: diff from frm 1989 = 3.7488% at (544,416)
frm 1989: diff from frm 1990 = 14.3858% at (544,128)
frm 1990: diff from frm 1991 = 86.2924% at (1024,256)
frm 1991: diff from frm 1992 = 7.5445% at (736,480)
frm 1992: diff from frm 1993 = 0.2090% at (544,480)
frm 1993: diff from frm 1994 = 21.9041% at (1024,512)
frm 1994: diff from frm 1995 = 73.7612% at (736,128)
frm 1995: diff from frm 1996 = 74.8645% at (704,192)
frm 1996: diff from frm 1997 = 73.8838% at (640,224)
frm 1997: diff from frm 1998 = 66.7258% at (544,192)
frm 1998: diff from frm 1999 = 68.2310% at (512,160)
frm 1999: diff from frm 2000 = 61.9041% at (288,416)
frm 2000: diff from frm 2001 = 0.4164% at (128,352)


What strikes me as interesting is that the amount of frames shifted (21) seems to be about the same as the shortfall of frames before FFVideoSource crashed without the 'threads=1' param. Am aware that the lavf splitter supposedly doesn't do well with seeking in .m2ts, so can't say that this is accurate.

I've also tested with remuxing the video track from the .m2ts file into a .ts using tsMuxeR (are these really the same format though?).
The difference in DupMC log files is 13 frames:

frm 1960: diff from frm 1961 = 18.2613% at (704,576)
frm 1961: diff from frm 1962 = 4.7424% at (224,160)
frm 1962: diff from frm 1963 = 7.5062% at (416,320)
frm 1963: diff from frm 1964 = 11.7557% at (704,576)
frm 1964: diff from frm 1965 = 7.4086% at (416,576)
frm 1965: diff from frm 1966 = 5.2788% at (544,96)
frm 1966: diff from frm 1967 = 3.7330% at (544,384)
frm 1967: diff from frm 1968 = 4.7669% at (224,160)
frm 1968: diff from frm 1969 = 10.3649% at (0,416)
frm 1969: diff from frm 1970 = 18.8493% at (704,576)
frm 1970: diff from frm 1971 = 17.6180% at (1120,128)
frm 1971: diff from frm 1972 = 17.6026% at (1120,128)
frm 1972: diff from frm 1973 = 18.8709% at (704,576)
frm 1973: diff from frm 1974 = 13.6187% at (1056,352)
frm 1974: diff from frm 1975 = 20.2539% at (896,192)
frm 1975: diff from frm 1976 = 20.9221% at (896,192)
frm 1976: diff from frm 1977 = 16.6082% at (1120,288)
frm 1977: diff from frm 1978 = 16.9103% at (1184,288)
frm 1978: diff from frm 1979 = 18.2301% at (704,576)
frm 1979: diff from frm 1980 = 4.7536% at (544,128)
frm 1980: diff from frm 1981 = 3.7488% at (544,416)
frm 1981: diff from frm 1982 = 14.3858% at (544,128)
frm 1982: diff from frm 1983 = 86.2924% at (1024,256)
frm 1983: diff from frm 1984 = 7.5445% at (736,480)
frm 1984: diff from frm 1985 = 0.2090% at (544,480)
frm 1985: diff from frm 1986 = 21.9041% at (1024,512)
frm 1986: diff from frm 1987 = 73.7612% at (736,128)
frm 1987: diff from frm 1988 = 74.8645% at (704,192)
frm 1988: diff from frm 1989 = 73.8838% at (640,224)
frm 1989: diff from frm 1990 = 66.7258% at (544,192)
frm 1990: diff from frm 1991 = 68.2310% at (512,160)
frm 1991: diff from frm 1992 = 61.9041% at (288,416)
frm 1992: diff from frm 1993 = 0.4164% at (128,352)
frm 1993: diff from frm 1994 = 0.2040% at (288,192)
frm 1994: diff from frm 1995 = 0.2124% at (1024,416)
frm 1995: diff from frm 1996 = 0.1745% at (1056,416)
frm 1996: diff from frm 1997 = 0.2007% at (1024,416)
frm 1997: diff from frm 1998 = 60.1646% at (320,352)
frm 1998: diff from frm 1999 = 60.0856% at (640,512)
frm 1999: diff from frm 2000 = 58.5892% at (1184,448)
frm 2000: diff from frm 2001 = 59.5666% at (1184,448)


Looking at the difference between the .m2ts and .ts files, it appears the shifting starts right at the beginning and the "lost" blank frames are stuck on at the end.
.m2ts file:

DeDup 0.17 by Loren Merritt, based on Dup 2.20 beta 1 by Donald Graft/Klaus Post, Copyright 2004
frm 0: diff from frm 1 = 0.0000% at (0,0)
frm 1: diff from frm 2 = 47.6596% at (0,0)
frm 2: diff from frm 3 = 10.5963% at (1216,384)
frm 3: diff from frm 4 = 10.8880% at (1248,384)
frm 4: diff from frm 5 = 9.1755% at (1248,352)
frm 5: diff from frm 6 = 7.9920% at (1248,288)
frm 6: diff from frm 7 = 7.0350% at (1152,576)
frm 7: diff from frm 8 = 7.9023% at (1184,576)
frm 8: diff from frm 9 = 5.6952% at (1184,544)
frm 9: diff from frm 10 = 7.3458% at (1216,576)
frm 10: diff from frm 11 = 5.7251% at (1216,544)

...

frm 71591: diff from frm 71592 = 1.0302% at (1152,640)
frm 71592: diff from frm 71593 = 0.9961% at (1152,640)
frm 71593: diff from frm 71594 = 0.9878% at (1152,640)
frm 71594: diff from frm 71595 = 0.9990% at (1152,640)
frm 71595: diff from frm 71596 = 0.9267% at (1152,640)
frm 71596: diff from frm 71597 = 0.9230% at (1152,640)
frm 71597: diff from frm 71598 = 0.0000% at (0,0)
frm 71598: diff from frm 71599 = 0.0000% at (0,0)
frm 71599: diff from frm 71600 = 0.0000% at (0,0)
frm 71600: diff from frm 71601 = 0.0000% at (0,0)

...

.ts file:
DeDup 0.17 by Loren Merritt, based on Dup 2.20 beta 1 by Donald Graft/Klaus Post, Copyright 2004
frm 0: diff from frm 1 = 0.0000% at (0,0)
frm 1: diff from frm 2 = 0.0000% at (0,0)
frm 2: diff from frm 3 = 0.0000% at (0,0)
frm 3: diff from frm 4 = 0.0000% at (0,0)
frm 4: diff from frm 5 = 0.0000% at (0,0)
frm 5: diff from frm 6 = 0.0000% at (0,0)
frm 6: diff from frm 7 = 0.0000% at (0,0)
frm 7: diff from frm 8 = 0.0000% at (0,0)
frm 8: diff from frm 9 = 0.0000% at (0,0)
frm 9: diff from frm 10 = 0.0000% at (0,0)
frm 10: diff from frm 11 = 0.0000% at (0,0)
frm 11: diff from frm 12 = 0.0000% at (0,0)
frm 12: diff from frm 13 = 0.0000% at (0,0)
frm 13: diff from frm 14 = 0.0000% at (0,0)
frm 14: diff from frm 15 = 47.6596% at (0,0)
frm 15: diff from frm 16 = 10.5963% at (1216,384)
frm 16: diff from frm 17 = 10.8880% at (1248,384)
frm 17: diff from frm 18 = 9.1755% at (1248,352)
frm 18: diff from frm 19 = 7.9920% at (1248,288)
frm 19: diff from frm 20 = 7.0350% at (1152,576)
frm 20: diff from frm 21 = 7.9023% at (1184,576)
frm 21: diff from frm 22 = 5.6952% at (1184,544)
frm 22: diff from frm 23 = 7.3458% at (1216,576)
frm 23: diff from frm 24 = 5.7251% at (1216,544)

...

frm 71604: diff from frm 71605 = 1.0302% at (1152,640)
frm 71605: diff from frm 71606 = 0.9961% at (1152,640)
frm 71606: diff from frm 71607 = 0.9878% at (1152,640)
frm 71607: diff from frm 71608 = 0.9990% at (1152,640)
frm 71608: diff from frm 71609 = 0.9267% at (1152,640)
frm 71609: diff from frm 71610 = 0.9230% at (1152,640)
frm 71610: diff from frm 71611 = 0.0000% at (0,0)
frm 71611: diff from frm 71612 = 0.0000% at (0,0)
frm 71612: diff from frm 71613 = 0.0000% at (0,0)
frm 71613: diff from frm 71614 = 0.0000% at (0,0)

...



Quick comparison with DSS2 (ffdshow): [both .m2ts and .ts give same results]
DeDup 0.17 by Loren Merritt, based on Dup 2.20 beta 1 by Donald Graft/Klaus Post, Copyright 2004
frm 0: diff from frm 1 = 0.0000% at (0,0)
frm 1: diff from frm 2 = 0.0000% at (0,0)
frm 2: diff from frm 3 = 0.0000% at (0,0)
frm 3: diff from frm 4 = 0.0000% at (0,0)
frm 4: diff from frm 5 = 0.0000% at (0,0)
frm 5: diff from frm 6 = 0.0000% at (0,0)
frm 6: diff from frm 7 = 0.0000% at (0,0)
frm 7: diff from frm 8 = 0.0000% at (0,0)
frm 8: diff from frm 9 = 0.0000% at (0,0)
frm 9: diff from frm 10 = 0.0000% at (0,0)
frm 10: diff from frm 11 = 0.0000% at (0,0)
frm 11: diff from frm 12 = 0.0000% at (0,0)
frm 12: diff from frm 13 = 0.0000% at (0,0)
frm 13: diff from frm 14 = 0.0000% at (0,0)
frm 14: diff from frm 15 = 0.0000% at (0,0)
frm 15: diff from frm 16 = 0.0000% at (0,0)
frm 16: diff from frm 17 = 0.0000% at (0,0)
frm 17: diff from frm 18 = 0.0000% at (0,0)
frm 18: diff from frm 19 = 0.0000% at (0,0)
frm 19: diff from frm 20 = 0.0000% at (0,0)
frm 20: diff from frm 21 = 0.0000% at (0,0)
frm 21: diff from frm 22 = 0.0000% at (0,0)
frm 22: diff from frm 23 = 0.0000% at (0,0)
frm 23: diff from frm 24 = 93.0502% at (928,96)
frm 24: diff from frm 25 = 10.5963% at (1216,384)
frm 25: diff from frm 26 = 10.8880% at (1248,384)
frm 26: diff from frm 27 = 9.1755% at (1248,352)
frm 27: diff from frm 28 = 7.9920% at (1248,288)
frm 28: diff from frm 29 = 7.0350% at (1152,576)
frm 29: diff from frm 30 = 7.9023% at (1184,576)
frm 30: diff from frm 31 = 5.6952% at (1184,544)
frm 31: diff from frm 32 = 7.3458% at (1216,576)
frm 32: diff from frm 33 = 5.7251% at (1216,544)
Also, FFVideoSource with Haali's splitter gives the same as above.

DSS2 here seems to be accurate.
I've noticed that FFVideoSource seems to add a few grey frames at the beginning of the video, and, as such, the .ts version only seems to be actually off by about 1 frame, though it's difficult to confirm.

So basically, at this point, I can't seem to get the lavf splitter to work properly with this .m2ts source. Haali seems to work, but crashes part way through (I'm also a little worried about claims of corruption with Haali's splitter, mentioned in the documentation (http://ffmpegsource.googlecode.com/svn/trunk/doc/ffms2-avisynth.html)).
Does anyone know what's causing these weird DupMC issues, and is there a non-DirectShow source which works reliably with .m2ts files, preferably without remuxing?

Thanks for reading!

the_weirdo
1st October 2011, 11:12
is there a non-DirectShow source which works reliably with .m2ts files, preferably without remuxing?

Don't know about your problem, but there's an answer for above question: DGDecNV (http://neuron2.net/dgdecnv/dgdecnv.html) (or DGAVCDecDI (http://neuron2.net/dgavcdecdi/dgavcdecdi.html) if your video source is AVC and your don't have a nVidia graphic card).

zinga
1st October 2011, 12:20
Thanks!
Unfortunately I don't have such a card. :( (also, I presume that uses its own internal codec for splitting as well, not just decoding?)

Guest
1st October 2011, 17:22
Also DGDecNV and DGAVCDecDI are useless, because there are random audio delays and needs to recode them to *.264. I don't follow your point here. Can you elaborate? If there are issues with DGDecNV I will do my best to resolve them.

If you can provide a stream and a process to reproduce your issue, I'll have a good chance of resolving it for you.

TheFluff
1st October 2011, 18:30
M2TS support in FFMS2 is really really bad, especially if the M2TS contains interlaced h264. As one of the FFMS2 maintainers don't recommend using it until someone's gotten around to fixing it.

zinga
2nd October 2011, 00:16
Thanks for the responses!
May I request the documentation (http://ffmpegsource.googlecode.com/svn/trunk/doc/ffms2-avisynth.html) be updated to indicate that these sorts of issues are known with M2TS handling? From what I read, it seems that M2TS (through lavf) should be fine as long as one doesn't seek. I think this may help others with similar issues.

It seems the simplest solution for me is to remux into MP4:
ffmpeg -i 00000.m2ts -vcodec copy -an 00000.mp4

Not sure how well this works with all sources, but it seems (haven't verified yet) to work okay for this 23.976 progressive M2TS.


(also, I'm still interested if anyone knows why DupMC/DeDup is acting weird despite the issues with FFMS2)

Guest
2nd October 2011, 00:48
neuron2, I have no nvidia card now. It was too hot to usage. Just replaced with Radeon. Thanks.
Feature requests: Please support Radeon, also mkv and audio reading directly, and MT modes. Why are you spreading FUD about my tools? You said they are "useless". You need to back that up or retract it.

DGDecNV and DGAVCDecDI are useless...

Guest
3rd October 2011, 22:49
Ok, correction: useless for me. Because I have many *.mts sources with different audio delays. I cannot use your code in automatic mode - a/v sync problem, That's because you don't know what you are doing.

MT problem MT Avisynth is a massive hacky kludge. Don't blame my tools if it is fubar and I refuse to hack up my own tools to make them limp along with MT. Anyway, what's the point of MT'ing a GPU-based source filter?

hot video card problem (95°C) Nothing to do with my tools.

very slow index problem Actually it is very fast. Where's your evidence? A full BluRay indexed in 5-10 minutes isn't fast enough for you?

also it cannot open mkv and so on Wrong.

I don't see any point in continuing this as you have no nVidia card and so are not in a position to try to support your erroneous statements. I do need to refute your FUD, however.

Finally, my thousands of satisfied users know that I am very responsive to trouble reports. Funny that I never received any from you.

Groucho2004
4th October 2011, 11:38
I bought nVidia-card in a store, downloaded your program and played with it for several hours to test before my buy.

Hm, I was not aware that there is a trial version of DGDecNV.

Guest
4th October 2011, 13:55
Hm, I was not aware that there is a trial version of DGDecNV. There isn't one and there never was one.

What version did you test, rean, and how did you manage to circumvent the license? Build 2013, almost 30 versions old, perhaps?