Opened 16 years ago

Closed 16 years ago

#5462 closed defect (fixed)

Displayed program length is 1.25X of actual length with pvrusb2

Reported by: dan.bodoh@… Owned by: danielk
Priority: minor Milestone: unknown
Component: mythtv Version: unknown
Severity: medium Keywords:
Cc: Ticket locked: no

Description

When playing back recordings, the program length displayed with the "i" keystroke is too long. For a 1 hour program, it says 1:15.

Hardware: PVR-USB2 encoder, NTSC input, displayed on S-Video out port of intel gm965 using 'intel' driver in Ubuntu Hardy.

Workaround is to set the video_gop_size for the PVR-USB2 to 15. The default is 12. (echo 15 > /sys/class/pvrusb2/<PUT YOUR SERIAL NUMBER HERE>/ctl_video_gop_size/cur_val).

In other words, it appears that the mythtv decoder doesn't properly display the recorded time length for NTSC signals encoded in MPEG2 with a gop size of 12. [12 * 1.25 = 15, which mythtv seems to assume] There's also a jerkiness during motion that might be solved by this workaround, but I need to observe more recordings to make sure.

I don't know much about MPEG-2, so I don't know if a gop size of 12 is legal for NTSC. If not, this is probably a pvrusb2 or cx2341x driver bug. From inspection of the linux 2.26.25 source, it appears that cx2341 module sets the default of frames per gop of 12, and pvrusb2 does not change it (although at least older versions of IVTV changed it 15 for my old pvr-350).

Attachments (1)

5462-dbg-v1.patch (394 bytes) - added by danielk 16 years ago.
debugging patch

Download all attachments as: .zip

Change History (15)

comment:1 Changed 16 years ago by dan.bodoh@…

There's a discussion about this issue on the pvrusb2 mailing list. See the thread that follows http://www.isely.net/pipermail/pvrusb2/2008-June/001832.html.

Dan Bodoh

comment:2 Changed 16 years ago by dan.bodoh@…

The jerkiness during motion is not solved by this workaround as I previously thought.

But setting the gop to 15 fixes the other issues: 1 hour shows are displayed as 1 hour, and marking a position and then restarting playback starts at the correct place.

comment:3 Changed 16 years ago by danielk

Owner: changed from Isaac Richards to danielk
Status: newassigned

I'm assuming the pvrusb2 uses the MpegRecorder? ?

Do you have the patch that makes the MpegRecorder? work with the pvrusb2? Or are people manually modifying the DB to make it work?

BTW We use ioctl(chanfd, VIDIOC_G_EXT_CTRLS, &ctrls) to get the GOP size, if the driver returns the GOP size in use we should be writing keyframes correctly...

comment:4 Changed 16 years ago by dan.bodoh@…

Not sure I understand the question, probably because I know very little about the pvrusb2 driver and even less about mythtv code. I don't have a patch, but I've done a little research and some code inspection of the linux driver code.

The Hauppauge PVR-USB2 is an MPEG2 encoding device (really, it's just a PVR-350 over the USB bus). Mythtv talks to it via the pvrusb2 module, which is similar to the old ivtv module since the devices share hardware. In fact, I believe that mythtv doesn't really know that it's talking to a PVR-USB2; the module interface is no different that ivtv.

So I don't understand what you mean that "we should be writing keyframes correctly". It would seem to me that the keyframes are already part of the MPEG2 stream coming in, and mythtv really doesn't do much but save that stream to disk.

There's a technical discussion about the use of gop size of 12, instead of 15, for NTSC by the pvrusb2 module in the thread following http://www.isely.net/pipermail/pvrusb2/2008-June/001832.html. It appears that pvrusb2 or a lower module *should* set the gop size to 15 for NTSC, but they don't.

However, if gop size of 12 is legal (but undesirable?) for NTSC, it appears that there is a bug in the mythtv playback (not recording). Playing gop=12 NTSC seems to have 2 effects in mythtv playback: (1) the OSD display of program length is 1.25X of the actual length, probably because mythtv assumes a gop of 15, which is 1.25X of the actual gop of 12. (2) marking a position, and then jumping to that position when re-entering playback actually jumps to an earlier position in the recording.

comment:5 Changed 16 years ago by Isaac Richards

Daniel - we could also just switch to the frame-based map instead of gop-based. Then it'd work regardless of if the driver's correct about its gopsize or not..

comment:6 Changed 16 years ago by danielk

ijr, yep.. I thought someone was working on that...

BTW Mike Isely is going to work on fixing the ioctl return value this weekend.

comment:7 Changed 16 years ago by isely@…

Actually I think there might be at least 2 problems here. I said to Daniel in e-mail that I would implement a workaround for one problem this weekend, but I don't have a good characterization for the other problem (yet).

First Problem: Default GOP size is not really correct for NTSC. This input to the mpeg encoder happens via the cx2341x module. The module is relying on the parent driver (e.g. pvrusb2) to set this up correctly. Hans thinks that the module should be taking on a more proactive role here. In the mean time (this weekend) I'll see about implementing a workaround in the driver for.

However that's just the default GOP size.

Second Problem: If mythtv is querying the driver to discover the current GOP size then things should still work, even with the wrong default. But apparently it isn't, so there's a second problem going on. I will look at the pvrusb2 driver and verify that this is being passed through correctly however I do not know what the problem here is yet. So I can't promise a fix if I don't even know if the driver is the cause.

-Mike

Changed 16 years ago by danielk

Attachment: 5462-dbg-v1.patch added

debugging patch

comment:8 Changed 16 years ago by danielk

dan, can you use the attached patch and attach the "mythbackend -vrecord" log you get when recording with it applied?

That should tell us if we're getting the GOP size from the driver.

comment:9 Changed 16 years ago by dan.bodoh@…

I'll try, but it will probably take a little while. I've been using MythBuntu?, so I haven't compiled the source. I don't want to mess up my database, so I'll do the compile with 0.21 rather than the trunk.

I've looked at the code online, and I understand where you want the log message.

Nothing looks too strange in the code, and my problems occur during playback. Could the bug exist in the playback code, rather than in the recording code?

comment:10 Changed 16 years ago by skamithi

i have the same problem and would like to see this fixed too :). i compiled the debug patch. here is my info

2008-06-24 20:57:20.262 AutoExpire: CalcParams(): Max required Free Space: 21.0 GB w/freq: 15 min
2008-06-24 20:57:20.333 MPEGRec(/dev/v4l/video0) Error: Could not set MPEG Stream type to 1
                        eno: Invalid argument (22)
2008-06-24 20:57:20.337 MPEGRec(/dev/v4l/video0) Error: Could not set Video Peak Bitrate to 4200000
                        eno: Numerical result out of range (34)
2008-06-24 20:57:20.338 V4L2_CID_MPEG_VIDEO_GOP_SIZE: 12

modinfo pvrusb2
filename:       /lib/modules/2.6.22-gentoo-r10/kernel/drivers/media/video/pvrusb2/pvrusb2.ko
license:        GPL
description:    Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner
author:         Mike Isely <isely@pobox.com>
alias:          usb:v2040p2400d*dc*dsc*dp*ic*isc*ip*
alias:          usb:v2040p2900d*dc*dsc*dp*ic*isc*ip*
depends:        tveeprom,videodev,i2c-core,v4l2-common,usbcore,cx2341x,firmware_class
vermagic:       2.6.22-gentoo-r10 SMP mod_unload PENTIUM4 

comment:11 Changed 16 years ago by dan.bodoh@…

I can confirm skamithi's results, using the 0.21 branch. The gop size is being read correctly. danielk, your patch didn't work exactly; I added the array index to make it spit out 'ext_ctrl[0].value', and inserted it in the correct location for 0.21 (mpegrecorder.cpp:680)

First, with the gop size manually forced to 15 with the sysfs interface:

2008-06-25 21:11:48.694 Using profile 'Live TV' to record
2008-06-25 21:11:48.698 TVRec(3): CreateLiveTVRingBuffer()
2008-06-25 21:11:48.700 TVRec(3): GetProgramRingBufferForLiveTV()
2008-06-25 21:11:48.712 New DB connection, total: 4
2008-06-25 21:11:48.717 Connected to database 'mythconverg' at host: localhost
2008-06-25 21:11:49.765 TVRec(3): StartedRecording(0x82b6108) fn(/home/video/100
3_20080625211148.mpg)
2008-06-25 21:11:49.777 Chain: Appended@0 '1003_20080625211148'
2008-06-25 21:11:49.781 TVRec(3): SetFlags(RingBufferReady,) -> RunMainLoop,Need
ToStartRecorder,RingBufferReady,
2008-06-25 21:11:49.787 RecBase(3:/dev/pvrusb2): SetRingBuffer(0x82dff08) '/home
/video/1003_20080625211148.mpg'
2008-06-25 21:11:49.788 RecBase(3:/dev/pvrusb2): SetRecording(0x82df950) title(P
rimetime: Crime)
2008-06-25 21:11:49.810 

Not ivtv driver??


2008-06-25 21:11:49.810 TVRec(3): SetFlags(CancelNextRecording,) -> RunMainLoop,
CancelNextRecording,NeedToStartRecorder,RingBufferReady,
2008-06-25 21:11:49.817 MPEGRec(/dev/pvrusb2): usingv4l2(1) has_v4l2_vbi(1) has_
buggy_vbi(0)
2008-06-25 21:11:49.822 AutoExpire: CalcParams(): Max required Free Space: 2.0 G
B w/freq: 15 min
2008-06-25 21:11:49.869 V4L2_CID_MPEG_VIDEO_GOP_SIZE: 15
2008-06-25 21:11:49.882 TVRec(3): SetFlags(RecorderRunning,RingBufferReady,) -> RunMainLoop,CancelNextRecording,NeedToStartRecorder,RecorderRunning,RingBufferReady,
2008-06-25 21:11:49.886 TVRec(3): ClearFlags(NeedToStartRecorder,) -> RunMainLoop,CancelNextRecording,RecorderRunning,RingBufferReady,
2008-06-25 21:11:51.650 TVRec(3): SetFlags(FrontendReady,) -> FrontendReady,RunMainLoop,CancelNextRecording,RecorderRunning,RingBufferReady,
2008-06-25 21:11:58.344 TVRec(3): StopLiveTV(void) curRec: 0x82b6108 pseudoRec: 0
2008-06-25 21:11:58.355 TVRec(3): Changing from WatchingLiveTV to None

Then, with the gop size manually forced to 12 via sysfs:

2008-06-25 21:13:19.485 Using profile 'Live TV' to record
2008-06-25 21:13:19.489 TVRec(3): CreateLiveTVRingBuffer()
2008-06-25 21:13:19.491 TVRec(3): GetProgramRingBufferForLiveTV()
2008-06-25 21:13:20.523 TVRec(3): StartedRecording(0xae253220) fn(/home/video/10
03_20080625211319.mpg)
2008-06-25 21:13:20.531 Chain: Appended@0 '1003_20080625211319'
2008-06-25 21:13:20.535 TVRec(3): SetFlags(RingBufferReady,) -> RunMainLoop,Need
ToStartRecorder,RingBufferReady,
2008-06-25 21:13:20.540 RecBase(3:/dev/pvrusb2): SetRingBuffer(0xb36f6640) '/hom
e/video/1003_20080625211319.mpg'
2008-06-25 21:13:20.541 RecBase(3:/dev/pvrusb2): SetRecording(0xae449360) title(
Primetime: Crime)
2008-06-25 21:13:20.563 

Not ivtv driver??


2008-06-25 21:13:20.563 TVRec(3): SetFlags(CancelNextRecording,) -> RunMainLoop,
CancelNextRecording,NeedToStartRecorder,RingBufferReady,
2008-06-25 21:13:20.571 AutoExpire: CalcParams(): Max required Free Space: 2.0 G
B w/freq: 15 min
2008-06-25 21:13:20.566 MPEGRec(/dev/pvrusb2): usingv4l2(1) has_v4l2_vbi(1) has_
buggy_vbi(0)
2008-06-25 21:13:20.621 V4L2_CID_MPEG_VIDEO_GOP_SIZE: 12
2008-06-25 21:13:20.624 TVRec(3): SetFlags(RecorderRunning,RingBufferReady,) -> RunMainLoop,CancelNextRecording,NeedToStartRecorder,RecorderRunning,RingBufferReady,
2008-06-25 21:13:20.629 TVRec(3): ClearFlags(NeedToStartRecorder,) -> RunMainLoop,CancelNextRecording,RecorderRunning,RingBufferReady,
2008-06-25 21:13:22.480 TVRec(3): SetFlags(FrontendReady,) -> FrontendReady,RunMainLoop,CancelNextRecording,RecorderRunning,RingBufferReady,
2008-06-25 21:13:30.127 TVRec(3): StopLiveTV(void) curRec: 0xae253220 pseudoRec: 0
2008-06-25 21:13:30.166 TVRec(3): Changing from WatchingLiveTV to None
2008-06-25 21:13:30.169 TVRec(3): ClearFlags(FrontendReady,CancelNextRecording,) -> RunMainLoop,RecorderRunning,RingBufferReady,

And my modinfo:

danb@mythbox:~$ modinfo pvrusb2
filename:       /lib/modules/2.6.24-18-generic/kernel/drivers/media/video/pvrusb2/pvrusb2.ko
license:        GPL
description:    Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner
author:         Mike Isely <isely@pobox.com>
srcversion:     E72D8CD6A2CD1A14A1C9C05
alias:          usb:v2040p2400d*dc*dsc*dp*ic*isc*ip*
alias:          usb:v2040p2900d*dc*dsc*dp*ic*isc*ip*
depends:        tveeprom,videodev,i2c-core,v4l2-common,usbcore,cx2341x,v4l1-compat
vermagic:       2.6.24-18-generic SMP mod_unload 586 
parm:           video_nr:Offset for device's video dev minor (array of int)
parm:           radio_nr:Offset for device's radio dev minor (array of int)
parm:           vbi_nr:Offset for device's vbi dev minor (array of int)
parm:           ctlchg:0=optimize ctl change 1=always accept new ctl value (int)
parm:           init_pause_msec:hardware initialization settling delay (int)
parm:           initusbreset:Do USB reset device on probe (int)
parm:           procreload:Attempt init failure recovery with firmware reload (int)
parm:           tuner:specify installed tuner type (array of int)
parm:           video_std:specify initial video standard (array of int)
parm:           tolerance:specify stream error tolerance (array of int)
parm:           debug:Debug trace mask (int)
parm:           i2c_scan:scan i2c bus at insmod time (int)
parm:           ir_mode:specify: 0=disable IR reception, 1=normal IR (array of int)

comment:12 Changed 16 years ago by Isaac Richards

There's other code (in the playback section) for the ivtv cards that assumes that if the framerate isn't PAL, the gopsize is 15. That's why it'll fail if the driver's set to 12.

Best way to fix this would be to use the MARK_GOP_BYFRAME (raw framecount) tagging instead of MARK_GOP_START (gop count) like the rest of the encoders do.

comment:13 Changed 16 years ago by dan.bodoh@…

For anyone looking for another workaround: The latest pvrusb2 driver snapshot (20080629) at http://www.isely.net/pvrusb2/download.html seems to fix the bug by setting the gop size to 15 for NTSC at the driver level.

comment:14 Changed 16 years ago by danielk

Resolution: fixed
Status: assignedclosed

(In [17826]) Fixes #5462. Refs #1088. Use MARK_GOP_BYFRAME for PS recordings in MPEGRecorder.

Note: See TracTickets for help on using tickets.