Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: FFMPEG streaming to Justin.tv/Twitch.tv

  1. #1
    Join Date
    Jul 2007
    Location
    Mount Pleasant, PA USA
    Beans
    19
    Distro
    Ubuntu 10.10 Maverick Meerkat

    FFMPEG streaming to Justin.tv/Twitch.tv

    Does anyone have any advice on how to make this work? I am using a modified script found using google.
    Running Ubuntu 11.10 with Unity

    Code:
    #Streaming screen to Justin.tv
    streaming() {
    INRES="1920x1080" # input resolution
    OUTRES="1280x720"
    FPS="30" # target FPS
    QUAL="medium"  # one of the many FFMPEG preset
    STREAM_KEY="$1"
    URL="rtmp://live.justin.tv/app/$STREAM_KEY" #flashver=FMLE/3.0\20(compatible;\20FMSc/1.0)"  
    
    #ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 -ab 22050\
    # -f alsa -ac 2 -i pulse -vcodec libx264 -s "$OUTRES" -level 30 -f mpegts \
    # -acodec libmp3lame -ac 1  \
    # -f flv "$URL"
    
    
    
    
    ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0  -ab 96k \
        -f alsa -ac 2 -i pulse -vcodec libx264 -crf 30 -vpre "$QUAL" -s "1280x720" \
        -acodec libmp3lame -ar 44100 -threads 8 \
        -f flv "$URL"
    }
    After modifying slighly I have it working, somewhat, it doesn't throw errors in the command line, but I don't get any video coming through when I load my channel on Juistin.tv.

    Any sugestions? Pointers? and please don't say Webcamstudio, ffmpeg is far lighter weight, and all things considered easier to deal with. Aside from this little hiccup of course.
    Last edited by SAKeeler; April 7th, 2012 at 03:14 PM. Reason: Added OS version and desktop manager detail

  2. #2
    Join Date
    Apr 2006
    Location
    USA
    Beans
    404

    Re: FFMPEG streaming to Justin.tv/Twitch.tv


  3. #3
    Join Date
    Jul 2007
    Location
    Mount Pleasant, PA USA
    Beans
    19
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    Quote Originally Posted by guitara View Post
    I really was trying to avoid it, but I will be giving it a read through and testing it this weekend. Still tinkering with the ffmpeg solution though,
    it's infuriating, it should work but just isn't, and I can't figure out why.
    Makes me crazy.

    Thanks for the link btw.

  4. #4
    Join Date
    Apr 2006
    Location
    USA
    Beans
    404

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    LOL -- ok, here's an example of ffmpeg working

    Code:
    #!/bin/bash
    API_KEY="live_*****************"
    FPS="15"
    
    INRES='1280x1024'
    OUTRES='1280x1024'
    
    ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0+1280 \
           -f alsa -i pulse -vcodec libx264  -s "$OUTRES"  \
           -acodec libmp3lame -ab 64k -ar 22050 -threads 0 \
           -f flv "rtmp://live.justin.tv/app/$API_KEY"

  5. #5
    Join Date
    Jul 2012
    Beans
    2

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    It's actually kinda weird that this issue hasn't been resolved yet. At least I just couldn't find any solution whether googling or posting the official FFmpeg IRC channels. Any idea why I get a blank video on such RTMP resources as justin.tv, own3d and so on. Once again, there's no issue with local recordings, it works just fine.

  6. #6
    Join Date
    Jul 2012
    Beans
    2

    Wink Re: FFMPEG streaming to Justin.tv/Twitch.tv

    The solution came from a member of FFmpeg development group. Since the video itself is fine when it's examined locally, there must be some trouble with some of the formats. Actually it was all about pixel format.

    If we capture the screen locally with the output option set as -f flv out.flv, the later examining of the video with ffprobe out.flv would show that the pixel format is 444, and it's not yet widely supported. Hence, it's necessary to add -pix_fmt yuv420p in the encoder properties to get your video playable by justin, twitch, own3d, ustream and other rtmp services

  7. #7
    Join Date
    Jul 2007
    Location
    Mount Pleasant, PA USA
    Beans
    19
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    Man, I'll have to make note and try it when i get a Ubuntu box up and running again.

    thanks, wouldn't have thought of that.

    Quote Originally Posted by vitrums View Post
    The solution came from a member of FFmpeg development group. Since the video itself is fine when it's examined locally, there must be some trouble with some of the formats. Actually it was all about pixel format.

    If we capture the screen locally with the output option set as -f flv out.flv, the later examining of the video with ffprobe out.flv would show that the pixel format is 444, and it's not yet widely supported. Hence, it's necessary to add -pix_fmt yuv420p in the encoder properties to get your video playable by justin, twitch, own3d, ustream and other rtmp services

  8. #8
    Join Date
    May 2006
    Location
    Milwaukee,WI
    Beans
    6,280
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    trying to accomplish this and I get the following error.
    my script looks like this trying to implement your idea about the -pix_fmt as well as set the threads to 2 since I have a core 2 duo CPU.
    Code:
    #!/bin/bash
    API_KEY="live_xxxxxxxxxxxxxxxxxxxx"
    FPS="15"
    
    INRES='1440x900'
    OUTRES='1440x900'
    
    ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0+1440 \
           -f alsa -i pulse -vcodec libx264 -pix_fmt yuv420p  -s "$OUTRES"  \
           -acodec libmp3lame -ab 64k -ar 22050 -threads 2 \
           -f flv "rtmp://live.twitch.tv/app/$API_KEY"
    Code:
    ./stream 
    ffmpeg version 0.8.4-6:0.8.4-0ubuntu0.12.10.1, Copyright (c) 2000-2012 the Libav developers
      built on Nov  6 2012 16:49:20 with gcc 4.7.2
    *** THIS PROGRAM IS DEPRECATED ***
    This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
    [x11grab @ 0x9f4bce0] device: :0.0+1440 -> display: :0.0 x: 1440 y: 0 width: 1440 height: 900
    [x11grab @ 0x9f4bce0] shared memory extension  found
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  130 (MIT-SHM)
      Minor opcode of failed request:  4 (X_ShmGetImage)
      Serial number of failed request:  11
      Current serial number in output stream:  11
    ANy help would be appreciated


    UPDATE: i posted how I got it all fixed over here: http://ubuntuforums.org/showthread.p...ghlight=twitch In short, the script is a tiny bit different and the inres and outres changed and there was no need for -pix_fmt
    Last edited by dannyboy79; December 11th, 2012 at 03:55 PM.

  9. #9
    Join Date
    May 2013
    Beans
    8

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    You need to change the video output in the player to x11.

    i've got all that working but i'm having sync issues with the sound. The video is behind the audio and it gets progressively worse as the stream goes through the playlist.

  10. #10
    Join Date
    Dec 2011
    Location
    Istanbul, Turkey
    Beans
    53
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: FFMPEG streaming to Justin.tv/Twitch.tv

    I've had some success with the code modified from here.
    My version: (on pastebin)
    #! /bin/bash

    # streaming on Ubuntu via ffmpeg.
    # see http://ubuntuguide.org/wiki/Screencasts for full documentation

    # input resolution, currently fullscreen.
    # you can set it manually in the format "WIDTHxHEIGHT" instead.
    INRES=$(xdpyinfo | grep 'dimensions:'|awk '{print $2}')

    # output resolution.
    # keep the aspect ratio the same or your stream will not fill the display.
    OUTRES="960x540"

    # input audio. You can use "/dev/dsp" for your primary audio input.
    INAUD="pulse"

    # target fps
    FPS="30"

    # video preset quality level.
    # more FFMPEG presets avaiable in /usr/share/ffmpeg
    QUAL="fast"

    # stream key. You can set this manually, or reference it from a hidden file like what is done here.
    STREAM_KEY=$(cat /some_dir/twitch.key)

    # stream url. Note the formats for twitch.tv and justin.tv
    # twitch:"rtmp://live.twitch.tv/app/$STREAM_KEY"
    # justin:"rtmp://live.justin.tv/app/$STREAM_KEY"
    STREAM_URL="rtmp://live.twitch.tv/app/$STREAM_KEY"

    ffmpeg \
    -f alsa -ac 2 -i "$INAUD" \
    -f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
    -vcodec libx264 -pix_fmt yuv420p -s "$OUTRES" -preset "$QUAL" \
    -acodec libmp3lame -threads 6 -qscale 5 -b 64KB \
    -f flv -ar 44100 "$STREAM_URL"
    Per this discussion I've changed xwininfo to xdpyinfo, -vpre to -preset and audio sample rate from 22050 to 44100. It works, though it produces the following warnings (full log) and, more importantly, it is only recording sound from the microphone. Any suggestions regarding how to fix this?

    Also, now that it's working, how do I optimize it. I want this to work on a Core 2 laptop, with display resolution of up to 1920x1080. Will I save much CPU power if I reduce the streaming resolution? I'm using preset "fast", there's also "lossless_ultrafast". How do I see which presets are there? When the streaming is running, there's a line like
    Code:
    frame=  229 fps= 21 q=-1.0 Lsize=     532kB time=00:00:10.68 bitrate= 408.0kbits/s
    Can I use it to gauge the performance of streaming? I'm not sure I understand it: it says something like "fps=21" which is always less than the fps I asked for. Looks like it's dropping frames, even if CPU isn't at 100%.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •