By | 24 octobre 2014

Diffusion vidéo sur Twitch.

Distribution de travail : Ubuntu 12.04

1) Installation des outils audio/vidéo et du codec h.264/libx264 :

[~] ➔ sudo apt-get install libav-tools libavcodec-extra-53 ffmpeg libx264-dev

2) Récupération de la clé Twitch : http://www.twitch.tv/

Sous le nom d’utilisateur : [Tableau de bord]->[Clé de flux]->[Afficher clé]

Copier la clé.

3) Créer le fichier de la clé :

Ouvrir :

~/.twitch_key

Ajouter :

4) Fichier de lancement :

Ouvrir :

diffusionAudioVideoJeu.sh

Ajouter :

#! /bin/bash

TOPXY="$1,$2" 
INRES="$3x$4"                                                                                    
OUTRES="800x500"                                          
FPS="30"                                                 
QUAL="medium"                                           

STREAM_KEY=$(cat ~/.twitch_key)

avconv \
    -f x11grab -s $INRES  -r "$FPS" -i :0.0+$TOPXY \
    -f alsa -ac 2 -i pulse  \
    -vcodec libx264 -s $OUTRES -preset $QUAL -tune zerolatency -maxrate 1000 -bufsize 1000 \
    -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b 712000  -bufsize 512k \
    -f flv "rtmp://live-cdg.twitch.tv/app/$STREAM_KEY"

Action :

chmod +x diffusionAudioVideoJeu.sh

Liste des serveurs :

http://bashtech.net/twitch/ingest.php

5) Lancer Minecraft

[Echap] pour retourner au « Menu du jeu » et avoir le contrôle de la souris.

6) Récupérer la position de la fenêtre de jeu :

[~] ➔ xwininfo -name "Minecraft 1.7.10"

xwininfo: Window id: 0x4000002 "Minecraft 1.7.10"

  Absolute upper-left X:  20
  Absolute upper-left Y:  69
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 854
  Height: 480
  Depth: 24
  Visual: 0x120
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x4000001 (not installed)
  Bit Gravity State: ForgetGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +20+69  -566+69  -566-351  +20-351
  -geometry 854x480+12+41

7) Lancer la diffusion :

Pour bien centrer la fenêtre de capture, il faut modifier les valeur topx, topy, width et height.
Par exemple : (+5, +25, +5, +0), soit :

[~] ➔ ./diffusionAudioVideoJeu.sh 17 66 859 480
avconv version 0.8.16-4:0.8.16-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 16 2014 18:35:14 with gcc 4.6.3
[x11grab @ 0x9e4c3c0] device: :0.0+17,66 -> display: :0.0 x: 17 y: 66 width: 859 height: 480
[x11grab @ 0x9e4c3c0] shared memory extension  found
[x11grab @ 0x9e4c3c0] Estimating duration from bitrate, this may be inaccurate
Input #0, x11grab, from ':0.0+17,66':
  Duration: N/A, start: 1414175393.779555, bitrate: 395827 kb/s
    Stream #0.0: Video: rawvideo, bgra, 859x480, 395827 kb/s, 30 tbr, 1000k tbn, 30 tbc
[alsa @ 0x9e58140] capture with some ALSA plugins, especially dsnoop, may hang.
[alsa @ 0x9e58140] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'pulse':
  Duration: N/A, start: 1414175392.998035, bitrate: N/A
    Stream #1.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Incompatible pixel format 'bgra' for codec 'libx264', auto-selecting format 'yuv420p'
[buffer @ 0x9e5c220] w:859 h:480 pixfmt:bgra
[scale @ 0x9e5e5e0] w:859 h:480 fmt:bgra -> w:800 h:500 fmt:yuv420p flags:0x4
[libx264 @ 0x9e48100] max bitrate less than average bitrate, assuming CBR
[libx264 @ 0x9e48100] lookaheadless mb-tree requires intra refresh or infinite keyint
[libx264 @ 0x9e48100] using cpu capabilities: MMX2 SSE2Fast FastShuffle SSEMisalign LZCNT
[libx264 @ 0x9e48100] profile Main, level 3.1
[libx264 @ 0x9e48100] 264 - core 120 r2151 a3f4407 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 sliced_threads=1 slices=6 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=0 rc=cbr mbtree=0 bitrate=712 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=712 vbv_bufsize=512 nal_hrd=none ip_ratio=1.25 aq=1:1.00
Output #0, flv, to 'rtmp://live-cdg.twitch.tv/app/live_73498806_wA4LUo8kfZNpG1FGSEogS2Rouuvt4k':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: libx264, yuv420p, 800x500, q=-1--1, 712 kb/s, 1k tbn, 30 tbc
    Stream #0.1: Audio: libmp3lame, 44100 Hz, 2 channels, s16, 712 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)
  Stream #1:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press ctrl-c to stop encoding
[libx264 @ 0x9e48100] max bitrate less than average bitrate, assuming CBR
VBV underflow (frame 251, -855787 bits)kB time=13.24 bitrate= 449.0kbits/s dup=0 drop=2    
VBV underflow (frame 466, -608387 bits)kB time=24.35 bitrate= 445.4kbits/s dup=0 drop=7     
frame= 1060 fps= 18 q=16.0 size=    3979kB time=61.54 bitrate= 529.7kbits/s dup=0 drop=10   

8) Visualisation du flux sur la chaîne Twitch:

http://www.twitch.tv/solomonkane666

9) Retourner au jeu.

10) Capture d’écran :

twitch

11) Liens :

http://www.thegameengine.org/miscellaneous/streaming-twitch-tv-ubuntu/
http://www.creativetux.com/2012/11/streaming-to-twitchtv-with-linux.html