LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   H.264 video lagging with MPlayer (https://www.linuxquestions.org/questions/linux-software-2/h-264-video-lagging-with-mplayer-808103/)

Electrode 05-16-2010 01:46 AM

H.264 video lagging with MPlayer
 
As mentioned in an earlier thread, I've been playing around with a DVB-S card for about a week. I've worked out most of the initial problems I ran into, but now another one has cropped up.

Some broadcasts use H.264 video, rather than the more common MPEG-2. MPlayer plays it, but the audio and video go badly out of sync. It looks like the video is only running at half speed. I don't think this is due to a lack of CPU or video card power, because top shows only 76% utilization, and the desync still happens even if I disable video output (-vo null), or even if I transcode with MEncoder (the resulting file is desynched).

If it matters, the video I'm trying to watch is in 1080i resolution at 29.97 fps.

Any ideas?

thecarpy 05-16-2010 07:38 AM

What CPU, mem and graphics card is in your system?
Do you have the open source or proprietary graphics drivers?

Electrode 05-16-2010 01:42 PM

CPU: 2x dual-core AMD Opteron 290 (2.8 GHz)
RAM: 5.12 GB PC2100
GFX: Nvidia GeForce 7800GS AGP w/ binary driver 195.36.15

thecarpy 05-16-2010 02:40 PM

Those specs should be enough, this is weird. Have you tried playing around with the nvidia settings (e.g. Anti-aliasing and stuff like that)? I would not know of anything else you could possibly try, sorry. One moment, maybe you need a realtime kernel, I need one of those because I do audio recording, with ardour. Maybe that could help? The latency on stock linux kernels is too high, maybe that is a possible solution. Then again, I have a core2quad 2.3Ghz, 6Gb Ram, Ge9800GT, and my work linux has an ordinary debian kernel, I sometimes don't bother rebooting into my "home" linux and watch tv over ADSL. I have HD content I watch with vlc, have not seen this happen on my system, it should technically be the same thing, hm. When I watch HD content fullscreen, my CPU use is at ~35%.

Electrode 05-16-2010 02:55 PM

Haven't done much of anything with the video driver config other than setting up my dual-head display, but as I mentioned in the original post, I don't think the video card or driver has anything to do with this, since I can play HD MPEG-2 video just fine, and this problem occurs even when I disable video output.

I'm using a realtime kernel here as well.

Electrode 05-16-2010 07:15 PM

I just tried VLC and that actually seems to be even worse than mplayer. CPU usage goes up to about 104% according to top and the video plays at about 2 FPS. During one test it actually crashed X, with dmesg showing several "machine checks".

H_TeXMeX_H 05-17-2010 04:46 AM

Maybe try to increase the buffer size for mplayer, if the buffer is too small it could cause lagging and a/v desync:

Code:

mplayer -cache 4096

Electrode 05-17-2010 09:10 AM

There doesn't appear to be a -bufsize option, did you mean -cache?

H_TeXMeX_H 05-17-2010 09:19 AM

Oh, yeah, oops, that must be deprecated, yes in the manual it says:

Code:

-cache <kBytes>
    This option specifies how much memory (in kBytes) to use when precaching a file or URL. Especially useful on slow media.

It is '-cache'.

Electrode 05-17-2010 03:10 PM

I've been using -cache 8192 all along (it's in my ~/.mplayer/config), it makes no difference in this case.

If it's of any significance, I see a lot of this when I try to play the video:
Code:

electrode@belphegor:~$ mplayer /dev/dvb/adapter1/dvr0
MPlayer SVN-r30554-4.4.2 (C) 2000-2010 MPlayer Team

Playing /dev/dvb/adapter1/dvr0.
Cache fill:  19.43% (1630208 bytes) 
TS file format detected.
VIDEO H264(pid=517) AUDIO MPA(pid=751) NO SUBS (yet)!  PROGRAM N. 9
FPS seems to be: 29.970030
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 48000 Hz, 2 ch, s16le, 384.0 kbit/25.00% (ratio: 48000->192000)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
[AO SDL] Samplerate: 48000Hz Channels: Stereo Format s16le
AO: [sdl] 48000Hz 2ch s16le (2 bytes per sample)
Starting playback...
[h264 @ 0xa5b9e0]number of reference frames exceeds max (probably corrupt input), discarding one
(previous message repeated hundreds of times)
[h264 @ 0xa5b9e0]mmco: unref short failure
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
VO: [xv] 1920x1080 => 1920x1080 Planar YV12
[h264 @ 0xa5b9e0]mmco: unref short failure  2/  2 ??% ??% ??,?% 0 0
[h264 @ 0xa5b9e0]mmco: unref short failure  8/  8 ??% ??% ??,?% 0 0
A:18127.0 V:18125.8 A-V:  1.193 ct:  0.168 126/126 56%  5%  1.1% 0 0
Exiting... (Quit)

In this case I killed the playback after about 3 seconds.

Shadow_7 05-17-2010 05:26 PM

You might try:

-nocache

-lavdopts skiploopfilter=all
(-skiploopfilter 0 in vlc)

mpeg2video is a lot less CPU needy. Not that that cpu should be struggling that much. You might try:

ffplay -threads 0

Was that 5.12 GB of ram or 512MB aka 0.512GB?

Electrode 05-17-2010 06:01 PM

The options you suggested have no impact whatsoever. ffplay maintains sync, but stutters badly and shows ~130% CPU utilization.

System has 5120 MB of RAM.

Shadow_7 05-17-2010 06:24 PM

Are you running a kernel optimized for an i386? or 686 or better?

Distro version of mplayer? Or compiled from source?

Does -noaudio for mplayer make a noticeable difference (cpu usage)? If it's AAC audio, some implementations of it are in a lot of flux and some are not optimized well. To the point of almost taking longer to decode the audio than it does to decode the video.

Electrode 05-17-2010 06:30 PM

x86-64 kernel. Everything built from source.

-noaudio makes no difference. Audio is in MP3 format.

Electrode 05-17-2010 07:08 PM

Some observations:

* the latest ffmpeg gives garbled video output. SVN r20373 works better.
* I tried building a 32-bit ffplay binary in a chroot, and that uses much less CPU (102% vs. 130%).
* Building a 32-bit mplayer seems to make no difference vs. 64-bit.

Electrode 05-17-2010 08:00 PM

If it helps anyone, I have uploaded a 10 second dump (19 MB) of the stream I'm trying to watch.

mac.tieu 05-17-2010 08:45 PM

Quote:

Originally Posted by Electrode (Post 3972081)
Some observations:

* the latest ffmpeg gives garbled video output. SVN r20373 works better.
* I tried building a 32-bit ffplay binary in a chroot, and that uses much less CPU (102% vs. 130%).
* Building a 32-bit mplayer seems to make no difference vs. 64-bit.

Have you ever tried hardware video acceleration version of mplayer (vdpau/vaapi)? It must be less CPU usage.

MT.

Electrode 05-17-2010 09:06 PM

Hardware-accelerated playback doesn't appear to work on x86-64. -vo xv, gl, gl2 all give similar results.

Further observations:
* CPU utilization with mplayer is about 75-80% with 32-bit build and 70-73% with 64-bit build (video still runs slow and desyncs)
* -vo null does not have any effect on CPU usage or desync
* -nosound or -ao null has no effect, video still runs slightly faster than half speed, no change in CPU usage

mac.tieu 05-17-2010 09:50 PM

Quote:

Originally Posted by Electrode (Post 3972195)
Hardware-accelerated playback doesn't appear to work on x86-64. -vo xv, gl, gl2 all give similar results.

Further observations:
* CPU utilization with mplayer is about 75-80% with 32-bit build and 70-73% with 64-bit build (video still runs slow and desyncs)
* -vo null does not have any effect on CPU usage or desync
* -nosound or -ao null has no effect, video still runs slightly faster than half speed, no change in CPU usage

I am running ArchLinux (x86_64) and mplayer-vaapi work just fine. All I need are libav, vdpau-video driver and mplayer-vaapi.

Have a look at:
Video Acceleration (VA) API

MT.

H_TeXMeX_H 05-18-2010 03:06 AM

When I try to play that dump it says:

Code:

h264 @ 0xf056c0]number of reference frames exceeds max (probably corrupt input), discarding one
lots of times with mplayer, which then hangs.

However, it plays fine with 'ffplay', try that.

I think that this message might be correct, the input may be corrupt. It could be a driver problem with the capture card or something.

Electrode 05-18-2010 09:06 AM

I have already tried ffplay, as mentioned earlier in the thread. It maintains sync but stutters due to high CPU consumption.

H_TeXMeX_H 05-18-2010 09:41 AM

Did you enable vdpau in ffplay ? when compiling it ? that might help.

Electrode 05-18-2010 02:56 PM

Quote:

Originally Posted by H_TeXMeX_H (Post 3972849)
Did you enable vdpau in ffplay ? when compiling it ? that might help.

Makes no difference

mac.tieu 05-20-2010 12:04 AM

Quote:

Originally Posted by Electrode (Post 3973144)
Makes no difference

I've tried to play your 'test.ts' sample on my ArchLinux (x86_64)
Code:

mplayer -va vaapi -vo vaapi test.ts
CPU usage is very low. This is output log:
Code:

...
Playing test.ts.
TS file format detected.
VIDEO H264(pid=517) AUDIO MPA(pid=751) NO SUBS (yet)!  PROGRAM N. 9
FPS seems to be: 29.970030
libva: libva version 0.31.0
Xlib:  extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns 0
libva: Trying to open /usr/local/lib/dri/nvidia_drv_video.so
libva: va_openDriver() returns 0
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
[VD_FFMPEG] VA API accelerated codec.
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 48000 Hz, 2 ch, s16le, 384.0 kbit/25.00% (ratio: 48000->192000)
Selected audio codec: [ffmp2] afm: ffmpeg (FFmpeg MPEG layer-1 and layer-2 audio)
==========================================================================
AO: [oss] 48000Hz 2ch s16le (2 bytes per sample)
Starting playback...
[VD_FFMPEG] Trying pixfmt=0.
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
VO: [vaapi] 1920x1080 => 1920x1080 H.264 VA API Acceleration
[vo_vaapi] Using 1:1 VA surface mapping
[VD_FFMPEG] XVMC-accelerated MPEG-2.
...

Regards,
MT.

Electrode 05-20-2010 01:23 AM

Alright, tried building mplayer-vaapi as mentioned earlier in the thread. Builds OK but I get this when I try to run it:

Code:

Playing test.ts.
TS file format detected.
VIDEO H264(pid=517) AUDIO MPA(pid=751) NO SUBS (yet)!  PROGRAM N. 9
FPS seems to be: 29.970030
libva: libva version 0.31.0-sds6
Xlib:  extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns 0
libva: Trying to open /usr/lib64/va/drivers/nvidia_drv_video.so
vdpau_video: error: Assertion failed in file vdpau_driver.c at line 227

mac.tieu: What versions of mplayer, libva, vdpau_video and Nvidia driver are you using?

mac.tieu 05-20-2010 05:20 AM

Quote:

Originally Posted by Electrode (Post 3975038)
...What versions of mplayer, libva, vdpau_video and Nvidia driver are you using?

I am using nVidia driver version 195.36.15-2, latest snapshot of libva, vdpau_video, mplayer-vaapi.

You should check for valid path of nvidia_drv_video.so (your is /usr/lib64/va/drivers/nvidia_drv_video.so). There are a utility named 'vainfo' which use to check whether libva installed properly or not.
Code:

$ ./vainfo
libva: libva version 0.31.0
Xlib:  extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns 0
libva: Trying to open /usr/local/lib/dri/nvidia_drv_video.so
libva: va_openDriver() returns 0
vainfo: VA API version: 0.31
vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA API - 0.6.3
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :        VAEntrypointVLD
      VAProfileMPEG2Main              :        VAEntrypointVLD
      VAProfileH264Main              :        VAEntrypointVLD
      VAProfileH264High              :        VAEntrypointVLD
      VAProfileVC1Simple              :        VAEntrypointVLD
      VAProfileVC1Main                :        VAEntrypointVLD
      VAProfileVC1Advanced            :        VAEntrypointVLD

You should also pay attention at matching two defines of libva and vdpau-video. Mine is:
Code:

File config.h of vdpau-video:
#define VA_DRIVER_INIT_FUNC __vaDriverInit_0_31

Code:

File va.c of libva:
#define DRIVER_INIT_FUNC "__vaDriverInit_0_31"

Good lucks,
MT.

Shadow_7 05-20-2010 08:39 AM

Is your user in the video group?

What's your specs with regards to other baselines speeds?

$ glxinfo | grep -i "direct"

$ glxgears -info
(or -printfps depending on distro / version)

$ xvidtune -show

$ ffmpeg -i <video>

$ cat /proc/cpuinfo | grep -i "bogomip"
(while you're trying to play the video, frequency scaling ruins it if you're not maxed)

Electrode 05-20-2010 09:25 AM

mac.tieu: I checked the defines you mentioned and they match. I'm using the same versions of everything as you except for the Nvidia driver: 195.36.24

vainfo does the same thing:

Code:

electrode@belphegor:~$ vainfo
libva: libva version 0.31.0-sds6
Xlib:  extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns 0
libva: Trying to open /usr/lib64/va/drivers/nvidia_drv_video.so
vdpau_video: error: Assertion failed in file vdpau_driver.c at line 227
Aborted

/usr/lib64/va/drivers/nvidia_drv_video.so exists and is a symlink to vdpau_drv_video.so in the same directory.

Shadow_7: User is in video group. All video and 3D apps run correctly and at reasonable speeds. MPEG-1/2/4 HD video plays without difficulty. CPU scaling is disabled in the kernel (I was using it at one point but found that it screwed up virtualbox).

mac.tieu 05-20-2010 10:02 AM

Quote:

Originally Posted by Electrode (Post 3975508)
Code:

electrode@belphegor:~$ vainfo
libva: libva version 0.31.0-sds6
Xlib:  extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns 0
libva: Trying to open /usr/lib64/va/drivers/nvidia_drv_video.so
vdpau_video: error: Assertion failed in file vdpau_driver.c at line 227
Aborted


vdp_device_create_x11 had been failed. It may be due to multiple nvidia library existed. I suggest you to search 'vdp_device_create_x11 error', there are several results related.

Hope that help,
MT.

Electrode 05-22-2010 08:48 PM

After doing some research, it looks like my card (Geforce 7800 AGP) does not support VDPAU/VA API, so this was all a dead end.

If there are no other suggestions, I give up.

Shadow_7 05-22-2010 09:44 PM

Have you checked the /usr/lib/codecs/ to see if you have the latest versions of things?

Some of the players like VLC enable filters by default. Disabling them might boost performance to a tolerable level. ffplay is good in running multi-threaded that which can be run multi-threaded. mpeg2video is multi-threaded. msmpeg4v2 is not. Most things h.264 are becoming multi-threaded. Make sure you enable threading (pthreads?) where appropriate. Plus all that other stuff. Your card on that system should be more than capable IMO. I got an aftermarket card, just to get HDMI output. If you're in the market for a new card, you might check out some of that Cuda stuff.

H_TeXMeX_H 05-23-2010 05:16 AM

Quote:

Originally Posted by Electrode (Post 3978019)
After doing some research, it looks like my card (Geforce 7800 AGP) does not support VDPAU/VA API, so this was all a dead end.

If there are no other suggestions, I give up.

Oh, so that's why it doesn't work. I didn't know that, sorry.


All times are GMT -5. The time now is 03:16 PM.