LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-09-2008, 12:15 PM   #1
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Sound lag with television?


Get tv sound with sox or aplay and using sox, especially with alsa oss emulation and a small buffer, can get an acceptable latency (I mean delay between the picture and the sound). But, despite having two channels, sox does not seem to give stereo. If I go for stereo the latency becomes grotesque even with quite a big computer.

This must be a very common problem.

Thought this might give reasonable latency and stereo:
Code:
$ sox -c 2 --buffer 2048 -t ossdsp /dev/dsp1 -c 2 -t wav - | aplay -c 6 -D duplicate
sorry. This from memory. It works apparently giving stereo. But the latency is silly. (The 'duplicate' is just a bespoke alsa thing for using all the surround sound speakers.)

N-million people must have this problem, how do you get round it?
 
Old 12-10-2008, 07:27 AM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
With mencoder and -audio-delay. With a value in proximity of 0.164 for my system.

Assuming you're referencing a tv capture card. Sox is audio only. I'm still working on an intentional latency for live viewing. But it encodes fine with mencoders audio-delay option. It's a shame that mplayer doesn't also have a -delay-audio option. But it plays for the most part while encoding. For some odd reason while doing both tasks simultaneously, the audio seems lowered by a couple hertz. Resulting in manly sounding women. And named pipes doesn't work when encoding to mjpeg video.

mencoder tv://3 -audio-delay 0.164 -aspect 4:3 -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:autoaspect=1 -o tvcapture.avi

With some options offloaded into /etc/mplayer/mencoder.conf.

fps=60000/1001
ofps=30000/1001
tv=driver=v4l2:input=9:chanlist=us-cable:norm=NTSC-M:width=720:height=480:brightness=10:contrast=5:amode=1:audiorate=48000:quality=100
vf=yadif,scale
ovc=lavc=yes
oac=lavc=yes
lavcopts=vcodec=mjpeg:acodec=pcm

amode=1 is stereo audio. input=9 is one of the input format options for video from v4l-info (4:2:2 uyvy).
 
Old 12-11-2008, 04:59 AM   #3
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215

Original Poster
Blog Entries: 2

Rep: Reputation: 49
Thanks. I'll try that; and maybe send output to something to play.

Also thinking of going the whole hog and using something to get rid of alsa's ridiculous delay - error sounds, for example occur about half an hour after the error, this on a fast computer. Patch the kernel with something I've forgotten and use jack. Use AGNULA http://demudi.agnula.info/images/1.2.1 .

Last edited by lugoteehalt; 12-11-2008 at 05:08 AM.
 
Old 12-12-2008, 01:11 AM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
http://ywwg.com/wordpress/?cat=13

As I notice that the title of this thread is a little off, as it's not the audio that is lagged, it's the video. Anyway jack-rack in combination with jackd and qjackctl allows a plugin effect of an audio delay. So audio is just as lagged as the video, and therefor in sync. ~ 0.164 seconds for my system.

In short:

start jackd:

$ jackd -d alsa -C hw:0 -P hw:0 -S -r 48000 &

start jack-rack
start qjackctl

$ jack-rack &
$ qjackctl

- click Connect on qjackctl. Another window should pop up.
- Expand the lists on each side.
- Connect capture_1 of system to in_1 of jack_rack. Do the same for 2.
- Connect out_1 of jack_rack with playback_1 of system. Do the same for 2.

In my case my VCR is providing audio input to the same card that will be playing the output. If you used a cd-audio cable, then your setup is roughly equivalent. Onto jack-rack.

- Click channels, and say OK to 2 channels. (it's probably already that way)
- Click ADD, then Uncategorised -> E -> Echo Delay Line (Maximum Delay 5s)
- Adjust the delay "Delay (Seconds)" to your liking (0.164 for me).
- Start your TV viewer. (if it's not already)
- Sit back and enjoy much better sync between video and audio.

In my case I hooked up my Sony Cybershot to my VCR, and my audio gear to the VCR. And controlling what I was watching while making adjustments. Which is how I got my delay fine tuned. Otherwise I was +/- 0.050 seconds. In the ballpark, but enunciations still bugged me. Especially with various programs / commercials which are not broadcast in sync. I'll probably do the same with an actual metronome to "do the math" and get the real number, eventually.

HTH
 
Old 12-12-2008, 05:23 AM   #5
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215

Original Poster
Blog Entries: 2

Rep: Reputation: 49
Quote:
Originally Posted by Shadow_7 View Post
http://ywwg.com/wordpress/?cat=13

As I notice that the title of this thread is a little off, as it's not the audio that is lagged, it's the video.
I may be misunderstanding but it's the lips moving and then the sound only happening half a second later that's my problem.

Thanks again. The above stuff is very interesting, I'll try it. Am not in a position to say now if it'll fix the problem since don't understand it untill tried it.

Probably should not do this to you since it is off topic, but you don't happen to know how to get 5.1 surround from a Dolby surround sound DVD movie played on mplayer?
Code:
$ mplayer -channels 6 dvd://1
This says it is producing six audio channels, but just get the normal 2 front and subwoofer stereo. It is using the correct codec: the one for ac3. I've tried the channels filter. Incidentally it makes the speech, but not the music and FX, faint and indistinct. Omit '-channels 6' and the speach is all right. Suspect this problem is alsa's doing, not mplayer's.
 
Old 12-12-2008, 07:17 AM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
That's probably an alsa configuration issue. There's ways to configure surround sound in ~/.asoundrc or /etc/alsa/asound.conf (or similarly named file). And then in mplayer you use -ao alsa:device=pseudoname_from_asoundrc. Also bear in mind that surround sound probably has a different aid. So -aid 129 and probably -alang en and other options when it comes to DVDs. Parse the information when you start mplayer for relative specifics. You might just try ogle which lets you navigate the DVDs menus for stuff like that. And lets you drop down and select various DVD extras. Like the audio track.

That's odd that you're getting sound late. Mine is getting the audio early. Since it's directly connected to the soundcard with a low latency kernel. It's the video that takes a while to decode/render and is therefor arriving AFTER the sound. -delay-audio in mencoder compensates for either as positive values delay the audio, and negative values delay the video. Or vise versa, since mplayer shows -200 ms when using the hotkeys and mencoder is passed a positive value for me. There's also a -delay parameter which is older, as not all codecs use the -delay-audio option(avi only). The above jackd stuff will only delay audio AFAIK. It is hard to tell since the brain processes at various speeds. Which varies depending on age, awareness, and other factors.

Of course I can compensate by moving further and further away from the display as light travels faster than sound. The human brain is somewhat equipped to hear sounds over a distance after a visual cue. But when the audio happens before the event, it drives you mad. Outside of watching yourself play drums, or watching drumline, it's kind of hard to adjust in intervals less than 100 ms. mplayer allows adjustment via + and - hotkeys of the delay(in 100ms intervals only). It's just not an mplayer parameter afaik. As -delay-audio is mencoder only.

mplayer -list-options
mencoder -list-options

HTH
 
Old 12-13-2008, 04:15 AM   #7
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215

Original Poster
Blog Entries: 2

Rep: Reputation: 49
Quote:
Originally Posted by Shadow_7 View Post
That's probably an alsa configuration issue. There's ways to configure surround sound in ~/.asoundrc or /etc/alsa/asound.conf (or similarly named file). And then in mplayer you use -ao alsa:device=pseudoname_from_asoundrc. Also bear in mind that surround sound probably has a different aid. So -aid 129 and probably -alang en and other options when it comes to DVDs.
That's great, I'm trying to figure out how to change the alsa default device at the moment - thought that might be it. Playing tv on mplayer might get rid of my latency problem (with the audio-delay thing) if I can get sound produced. I'll experiment with -ao alsa:device=surround51 or something.

Don't have a low latency kernel probably accounts for the latency difference. Can well believe it drives you mad. Incidentally just discovered that
Code:
$ ac3dec -6 surround_sound_file.ac3
plays surround sound, disproportionately spiffy for some reason.

MPlayer produced surround sound with
Code:
mplayer -channels 6 -ao alsa:device=plug=swap51 -dvd-device /dev/scd0 dvd://1
The plug=swap51 may be replaced with swap51.

A problem was the speech was comming out of the subwoofer and was therefore unintelligible so swapped the feed chennels to the front centre and subwoofer by putting this into ~/.asoundrc:
Code:
pcm.swap51 {    # Try to swap over feed to LFE, i.e. subwoofer, and centre.
    type dmix
    ipc_key 2048
    slave {
        pcm "hw:0"
        rate 48000    #  don't know if this is correct.  Dito the other values.
        period_time 0
        period_size 1024
        buffer_size 8192
        channels 6
    }
    bindings {    # changed this round a lot, trial and error. Origionally simply 0 0 to 3 3.  Used $ speaker-test -c 6 -D swap51 -t wav to test each configuration.
        0 0
        1 1
        2 4
        3 5
        4 3
        5 2
    }
}

Last edited by lugoteehalt; 12-15-2008 at 05:45 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get sound on Mplayer for television? lugoteehalt Linux - Software 3 08-02-2008 10:48 AM
sound lag in WoW Mow Linux - Games 2 03-02-2007 05:29 AM
get sound lag in Quake 4 hedpe Linux - Games 2 03-11-2006 02:44 PM
video and sound lag.... SlipAway172 Ubuntu 4 05-26-2005 08:15 AM
Flash Sound Lag LGBR Linux - Software 0 07-14-2003 04:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration