OK.
I found how to stop having this "ALSA buffer xrun" message:
1) when the output is a file on a local directory, you just need to change the 
command:
$ ffmpeg -y -f alsa -i default -f x11grab -r 10 -s 640x480 -async 1 -i :0.0 
-strict -2 -c:a aac -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 640x480 
-threads 0 -ar 44100 -b:a 64k -b:v 64k -bufsize 64k -f flv out.flv
2) when the output is a file on a NFS shared directory, you need to change the 
command like above and update the x264 library from 20120729.2245 to 
20140207.2245 [1].
3) when the output is a stream on twitch.tv, you need to change the command 
like above, you need to update x264 like above, but there is a remaining "ALSA 
buffer xrun" message at the beginning of the capture.

For 3) the problem could be caused by rtmp "handshake" which is 3 (see section 
5.2 of [2]).

My command is:
$ ffmpeg -y -f alsa -i default -f x11grab -r 10 -s 640x480 -async 1 -i :0.0 
-strict -2 -c:a aac -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 640x480 
-threads 0 -ar 44100 -b:a 64k -b:v 64k -bufsize 64k -f flv 
"rtmp://live-fra.twitch.tv/app/`cat ~/twitch.key`"

And I can see:
$ cat /proc/asound/card0/pcm0c/sub0/hw_params
access: MMAP_INTERLEAVED
format: S32_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 1024
buffer_size: 16384

So, my buffer time is: 16384/48000 = 0.34.

Now, I need to take the RTT from live-fra.twitch.tv, multiply by 3 and this 
value must be smaller than 0.34 (my buffer time above).

The problem is that live-fra.twitch.tv refuse the ping.
So, I can use tcpdump:
$ sudo tcpdump -ni eth0 host live-fra.twitch.tv
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
22:21:12.644355 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [S], seq 
2241789542, win 14600, options [mss 1460,sackOK,TS val 37145446 ecr 
0,nop,wscale 7], length 0
22:21:12.695150 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [S.], seq 
2043124064, ack 2241789543, win 5792, options [mss 1436,sackOK,TS val 
1662742014 ecr 37145446,nop,wscale 9], length 0
22:21:12.695178 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], ack 1, 
win 115, options [nop,nop,TS val 37145497 ecr 1662742014], length 0
22:21:12.695386 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
1:1425, ack 1, win 115, options [nop,nop,TS val 37145498 ecr 1662742014], 
length 1424
22:21:12.695439 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
1425:1538, ack 1, win 115, options [nop,nop,TS val 37145498 ecr 1662742014], 
length 113
22:21:12.757727 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 1425, 
win 17, options [nop,nop,TS val 1662742020 ecr 37145498], length 0
22:21:12.759387 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 1538, 
win 17, options [nop,nop,TS val 1662742020 ecr 37145498], length 0
22:21:13.120657 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], seq 
1:1425, ack 1538, win 17, options [nop,nop,TS val 1662742056 ecr 37145498], 
length 1424
22:21:13.120676 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], ack 1425, 
win 137, options [nop,nop,TS val 37145923 ecr 1662742056], length 0
22:21:13.122851 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [P.], seq 
1425:3074, ack 1538, win 17, options [nop,nop,TS val 1662742056 ecr 37145498], 
length 1649
22:21:13.122861 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], ack 3074, 
win 163, options [nop,nop,TS val 37145925 ecr 1662742056], length 0
22:21:13.122886 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
1538:2962, ack 3074, win 163, options [nop,nop,TS val 37145925 ecr 1662742056], 
length 1424
22:21:13.122891 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
2962:3074, ack 3074, win 163, options [nop,nop,TS val 37145925 ecr 1662742056], 
length 112
22:21:13.186668 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 2962, 
win 23, options [nop,nop,TS val 1662742063 ecr 37145925], length 0
22:21:13.187108 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3074, 
win 23, options [nop,nop,TS val 1662742063 ecr 37145925], length 0
22:21:13.187120 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3074:3233, ack 3074, win 163, options [nop,nop,TS val 37145989 ecr 1662742063], 
length 159
22:21:13.238634 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3233, 
win 29, options [nop,nop,TS val 1662742068 ecr 37145989], length 0
22:21:13.428350 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [P.], seq 
3074:3414, ack 3233, win 29, options [nop,nop,TS val 1662742087 ecr 37145989], 
length 340
22:21:13.428512 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3233:3245, ack 3414, win 185, options [nop,nop,TS val 37146231 ecr 1662742087], 
length 12
22:21:13.479104 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3245, 
win 29, options [nop,nop,TS val 1662742092 ecr 37146231], length 0
22:21:13.479122 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3245:3440, ack 3414, win 185, options [nop,nop,TS val 37146281 ecr 1662742092], 
length 195
22:21:13.531599 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3440, 
win 34, options [nop,nop,TS val 1662742097 ecr 37146281], length 0
22:21:13.720507 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [P.], seq 
3414:3643, ack 3440, win 34, options [nop,nop,TS val 1662742116 ecr 37146281], 
length 229
22:21:13.720645 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3440:3452, ack 3643, win 207, options [nop,nop,TS val 37146523 ecr 1662742116], 
length 12
22:21:13.769840 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3452, 
win 34, options [nop,nop,TS val 1662742121 ecr 37146523], length 0
22:21:13.769858 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3452:3526, ack 3643, win 207, options [nop,nop,TS val 37146572 ecr 1662742121], 
length 74
22:21:13.820389 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3526, 
win 34, options [nop,nop,TS val 1662742126 ecr 37146572], length 0
22:21:14.376738 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [P.], seq 
3643:3661, ack 3526, win 34, options [nop,nop,TS val 1662742182 ecr 37146572], 
length 18
22:21:14.377239 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [P.], seq 
3661:3812, ack 3526, win 34, options [nop,nop,TS val 1662742182 ecr 37146572], 
length 151
22:21:14.377272 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], ack 3812, 
win 230, options [nop,nop,TS val 37147179 ecr 1662742182], length 0
22:21:14.479079 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
3526:3538, ack 3812, win 230, options [nop,nop,TS val 37147281 ecr 1662742182], 
length 12
22:21:14.479876 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
3538:4962, ack 3812, win 230, options [nop,nop,TS val 37147282 ecr 1662742182], 
length 1424
22:21:14.479955 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
4962:6386, ack 3812, win 230, options [nop,nop,TS val 37147282 ecr 1662742182], 
length 1424
22:21:14.480013 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
6386:7810, ack 3812, win 230, options [nop,nop,TS val 37147282 ecr 1662742182], 
length 1424
22:21:14.503009 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
7810:9234, ack 3812, win 230, options [nop,nop,TS val 37147305 ecr 1662742182], 
length 1424
22:21:14.529153 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 3538, 
win 34, options [nop,nop,TS val 1662742197 ecr 37147281], length 0
22:21:14.529180 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
9234:9982, ack 3812, win 230, options [nop,nop,TS val 37147331 ecr 1662742197], 
length 748
22:21:14.542926 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 4962, 
win 40, options [nop,nop,TS val 1662742199 ecr 37147282], length 0
22:21:14.555229 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 6386, 
win 46, options [nop,nop,TS val 1662742200 ecr 37147282], length 0
22:21:14.568355 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 7810, 
win 51, options [nop,nop,TS val 1662742201 ecr 37147282], length 0
22:21:14.581640 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 9234, 
win 57, options [nop,nop,TS val 1662742202 ecr 37147305], length 0
22:21:14.587551 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 9982, 
win 62, options [nop,nop,TS val 1662742203 ecr 37147331], length 0
22:21:14.587569 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
9982:10524, ack 3812, win 230, options [nop,nop,TS val 37147390 ecr 
1662742203], length 542
22:21:14.642760 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
10524, win 68, options [nop,nop,TS val 1662742208 ecr 37147390], length 0
22:21:14.642783 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
10524:10886, ack 3812, win 230, options [nop,nop,TS val 37147445 ecr 
1662742208], length 362
22:21:14.696406 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
10886, win 74, options [nop,nop,TS val 1662742214 ecr 37147445], length 0
22:21:14.696430 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
10886:11523, ack 3812, win 230, options [nop,nop,TS val 37147499 ecr 
1662742214], length 637
22:21:14.750972 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
11523:12947, ack 3812, win 230, options [nop,nop,TS val 37147553 ecr 
1662742214], length 1424
22:21:14.751087 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
12947:14371, ack 3812, win 230, options [nop,nop,TS val 37147553 ecr 
1662742214], length 1424
22:21:14.752174 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
11523, win 79, options [nop,nop,TS val 1662742219 ecr 37147499], length 0
22:21:14.752192 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
14371:15191, ack 3812, win 230, options [nop,nop,TS val 37147554 ecr 
1662742219], length 820
22:21:14.815181 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
12947, win 85, options [nop,nop,TS val 1662742226 ecr 37147553], length 0
22:21:14.822662 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
15191:16615, ack 3812, win 230, options [nop,nop,TS val 37147625 ecr 
1662742226], length 1424
22:21:14.825566 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
14371, win 90, options [nop,nop,TS val 1662742227 ecr 37147553], length 0
22:21:14.834446 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
15191, win 96, options [nop,nop,TS val 1662742228 ecr 37147554], length 0
22:21:14.834466 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
16615:17456, ack 3812, win 230, options [nop,nop,TS val 37147637 ecr 
1662742228], length 841
22:21:14.884980 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
16615, win 102, options [nop,nop,TS val 1662742233 ecr 37147625], length 0
22:21:14.893509 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
17456, win 107, options [nop,nop,TS val 1662742234 ecr 37147637], length 0
22:21:14.893540 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
17456:18418, ack 3812, win 230, options [nop,nop,TS val 37147696 ecr 
1662742234], length 962
22:21:14.952716 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
18418, win 113, options [nop,nop,TS val 1662742240 ecr 37147696], length 0
22:21:14.952738 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
18418:18867, ack 3812, win 230, options [nop,nop,TS val 37147755 ecr 
1662742240], length 449
22:21:15.006909 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
18867, win 118, options [nop,nop,TS val 1662742245 ecr 37147755], length 0
22:21:15.006935 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
18867:19687, ack 3812, win 230, options [nop,nop,TS val 37147809 ecr 
1662742245], length 820
22:21:15.063867 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
19687, win 124, options [nop,nop,TS val 1662742251 ecr 37147809], length 0
22:21:15.063891 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
19687:20408, ack 3812, win 230, options [nop,nop,TS val 37147866 ecr 
1662742251], length 721
22:21:15.120557 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
20408, win 126, options [nop,nop,TS val 1662742256 ecr 37147866], length 0
22:21:15.120580 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
20408:20896, ack 3812, win 230, options [nop,nop,TS val 37147923 ecr 
1662742256], length 488
22:21:15.174701 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
20896, win 126, options [nop,nop,TS val 1662742262 ecr 37147923], length 0
22:21:15.208000 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
20896:20904, ack 3812, win 230, options [nop,nop,TS val 37148010 ecr 
1662742262], length 8
22:21:15.258457 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
20904, win 126, options [nop,nop,TS val 1662742270 ecr 37148010], length 0
22:21:15.258480 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
20904:21924, ack 3812, win 230, options [nop,nop,TS val 37148061 ecr 
1662742270], length 1020
22:21:15.317611 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
21924, win 126, options [nop,nop,TS val 1662742276 ecr 37148061], length 0
22:21:15.317635 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
21924:23184, ack 3812, win 230, options [nop,nop,TS val 37148120 ecr 
1662742276], length 1260
22:21:15.378962 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
23184, win 126, options [nop,nop,TS val 1662742282 ecr 37148120], length 0
22:21:15.406632 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
23184:23192, ack 3812, win 230, options [nop,nop,TS val 37148209 ecr 
1662742282], length 8
22:21:15.457324 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
23192, win 126, options [nop,nop,TS val 1662742290 ecr 37148209], length 0
22:21:15.457349 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
23192:24478, ack 3812, win 230, options [nop,nop,TS val 37148259 ecr 
1662742290], length 1286
22:21:15.518648 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
24478, win 126, options [nop,nop,TS val 1662742296 ecr 37148259], length 0
22:21:15.518671 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
24478:25845, ack 3812, win 230, options [nop,nop,TS val 37148321 ecr 
1662742296], length 1367
22:21:15.581263 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
25845, win 126, options [nop,nop,TS val 1662742302 ecr 37148321], length 0
22:21:15.606279 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
25845:25853, ack 3812, win 230, options [nop,nop,TS val 37148408 ecr 
1662742302], length 8
22:21:15.656219 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
25853, win 126, options [nop,nop,TS val 1662742310 ecr 37148408], length 0
22:21:15.656241 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
25853:26782, ack 3812, win 230, options [nop,nop,TS val 37148458 ecr 
1662742310], length 929
22:21:15.706905 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [.], seq 
26782:28206, ack 3812, win 230, options [nop,nop,TS val 37148509 ecr 
1662742310], length 1424
22:21:15.714573 IP 199.9.254.236.1935 > 192.168.0.2.42053: Flags [.], ack 
26782, win 126, options [nop,nop,TS val 1662742316 ecr 37148458], length 0
22:21:15.714593 IP 192.168.0.2.42053 > 199.9.254.236.1935: Flags [P.], seq 
28206:28277, ack 3812, win 230, options [nop,nop,TS val 37148517 ecr 
1662742316], length 71
^C
86 packets captured
92 packets received by filter
0 packets dropped by kernel

Do you see the RTT value here?

[1] ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
[2] 
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/rtmp/pdf/rtmp_specification_1.0.pdf

On Thu, 6 Feb 2014 20:14:57 +0100
YuGiOhJCJ Mailing-List <yugiohjcj-mailingl...@laposte.net> wrote:

> Hello,
> 
> I am using ffmpeg version 1.2.
> 
> To record (audio/video) my desktop with ffmpeg, I use this command:
> $ ffmpeg -f x11grab -r 15 -s 640x480 -i :0.0 -f alsa -i default out.mkv
> 
> Unfortunately, when I am playing this "out.mkv" file on VLC, I can remark 
> that the audio is out of sync.
> 
> In the console, I can see some warnings: "ALSA buffer xrun".
> 
> Do you see why ?
> 
> Thank you.
> Best regards.
> 
> ------------------------------------------------------------------------------
> Managing the Performance of Cloud-Based Applications
> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
> Read the Whitepaper.
> http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
> _______________________________________________
> Alsa-user mailing list
> Alsa-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-user

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user

Reply via email to