Tutorial: HD-PVR to Twitch on Mac OS with ffmpeg

Twitch with HDPVR and ffmpeg on a mac

Over the christmas holidays I tried to figure out how to live stream the video from my HD-PVR to Twitch.tv on Mac OS with ffmpeg without CamTwist, without XSplit and without JTVLC. Twitch.TV is a video broadcast service where you can stream and watch your gaming content. Its main purpose is for the e-sport and speedrun community but there are more and more normal gamers streaming their content – including me since a few days.

Streaming without preview windows recording

I am not able understand why most people try to record a preview window of the HD-PVR with a desktop recording software. The HD-PVR sends a high quality 1920 × 1080 pixel MPEGTS Stream over HDMI or Component and I thought that is should be possible to process this stream directly. It seems like it is possible and it quite easy if you know how to do it.

The downside is that I don’t know any option to include a stream from a webcam and microphone. Maybe someone else is more clever than me and will provide one. The HD-PVR Capture Software will cost you $30 but it is worth any penny for people who want to record their recorded HD-PVR footage with a mac . Here we go.

Step 1 : Configuring HD-PVR Capture

Download and install HD-PVR Capture. There is also a demo version available.

With this software we will send the output signal of the HDPVR to the ffmpeg encoder using UDP. I strongly prefer this software over Arcsoft Showbiz on Windows because of its simplicity and reliability.

HD-PVR Capture UDP Streaming Mac

In HD-PVR Capture are two important settings: Video Encoder and Network.

Video Encoder

  • Select the preset „best“.
    Personally I think that the insane setting is unnecessary in this case because we will encode the video for web streaming.


  • Uncheck the „Store video recording“ option.
    We don’t want to fill up our hard drives with tons of videos.
  • Check the „Send the captured video to network using UDP“ option.
    As the IP address use your local ip and the port 1234.

You can verify that it works this if you press the record button, start VLC and go to file -> open network and put this into the address field: udp://@:1234. Hit the play button and you should see the output video mpegts stream of your HDPVR.

Dashboard: Live streaming Twitch with HDPVR and ffmpeg on a mac

Step 2: Setting up ffmpeg

Download and install ffmpeg for mac. You can do this via „brew„. Inside the zip archive you will find the the extracted file „ffmpeg“. This is the executable file and should be moved to the directory /usr/local/bin/. You can do this using Terminal with the command:

sudo mv ~/Downloads/ffmpeg /usr/local/bin/ 

Or copy it with the finder from Downloads to the /usr/local/bin/ folder.

Step 3: Executing the ffmpeg command

This is the ffmpeg command with several parameters which has to be executed using the Terminal. This will grab the stream from HDPVR Capture, encode it on the fly and sent it directly to the twitch servers.

ffmpeg -f mpegts -re -i 'udp://' -vcodec libx264 -s 1280x720 -g:v 40 -threads 4 -preset medium -b:v 850k -minrate 850k -maxrate 850k -bufsize 1600k -r 30 -acodec libmp3lame -ar 44100 -b:a 64k -async 44100 -f flv "rtmp://live.justin.tv/app/live_XXXXXXX_XXXXXXX"

Replace live_XXXXX_XXXXXXXX with your personal Twitch.tv Key and then use this command on the terminal to stream the UDP Stream from HDPVR Capture to Twitch.tv.

Here is a little explanation of the few options I think I understand:

Sets the input format to MPEGTS. Should be set automatically but I wanted to be sure.
-i Sets the UDP stream from HD-PVR Capture as the input file for the encoding.
Parameters for the UDP stream. buffer_size was my missing piece to
get rid of the artifacts I was getting in twitch. Took me 2 days to figure this out.
-reactivates realtime mode
-vcodecSets the video codec to libx264. It is an open source video codec for H.264.
-sThe resolution of the encoded output format. I chose 720p because it made the most sense to me. Change this if you need to.
UPDATE: Changed it to 720p. Better quality.
-g:vSets the maximum keyframe interval to 2. Important for twitch.
qscale:v Sets the quality scale. :v means that this is only used for video and not audio. 1 is best, 31 is worst.
UPDATE: Removed this part because -b:v overrides this setting.
-threadsSpecifies the number of CPU Threads used for encoding. I use 6 on my Core i7.
UPDATE: Removed.
-presetThere are many presets for the encoder from ultrafast, fast and medium to slow and very slow. Ultrafast is too blocky. The presets „medium“ and „fast“ seem right.
Sets the encoding bitrate to 800 kbytes with a maximum and minimum bitrate of 800 kbytes excluding audio. This simulates a Constant Bitrate (CBR) which is important for twitch. Change this if you have more bandwidth for the upstream than me (10Mbit).
-bufsizeHonestly I don’t really understand what it does. I think this is the size of the buffer for the encoding but I am not sure. I read that this is important for the CBR.
-r Sets the frame rate to 30 frames per second. Change this if you like.
Sets the LAME Audio as audio encoder with a sample rate of 44,100 Hz and 64kbytes per second for the encoding.
-fSets the output format to a FLV container.
rtmprtmp://live.justin.tv/app/live_key sets the output format to Real Time Messaging Protocol with the server address of twitch.tv or justin.tv. live_XXXX_XXXXXXXXXX has the be replace with your personal Twitch.tv API Key. You will find the key on your twitch.tv dashboard under API Key.

The result should look like this:

ffmpeg udp input and flv output

Step 4: Check the twitch dashboard

The UDP Stream from the HD-PVR Capture software is now used by the ffmpeg encoder and is directly send to the twitch servers using RTMP. I get a descent result, a stable frame rate of 30 frames, nearly no compression artifacts and a Stream Configuration Quality: Excellent message on twitch. I don’t know why there are these not-existing PPS referenced error messages showing up but it does not seem to harm the stream quality.

I developed a plugin for wordpress MarcTV Twitch Status which shows the „Live!“-Status of your Twitch account.

You can find my twitch channel here. Feel free to correct my settings and post them in the comment section below.

Streaming Capture Test

Beitrag veröffentlicht





47 Antworten zu „Tutorial: HD-PVR to Twitch on Mac OS with ffmpeg“

  1. Avatar von ben_

    I haz no clue, what dis Article is all about, but it looks pretty tekky with da Terminal-Screenshotz. And why the hell I am talking Engrish? :)

    Happy New Year, my Dear!

    1. Avatar von Marc

      It’s about how to stream videogame videos live to a service call You can watch me play =)

    2. Avatar von ben_

      Dis is sooo crazy, you crazy Motherfrakker! :)

  2. Avatar von Marc

    I developed a WordPress Plugin MarcTV Twitch Status to display the twitch status.

  3. Avatar von Evan Shanks
    Evan Shanks

    Ich bin nicht sicher, wie alt ist dieser Artikel, aber alles funktioniert gut, außer für die Kommandozeile im Terminal. Ich habe alles genau so, wie Sie zu der in diesem HowTo konnten aber nicht Terminal, mit mir zu kooperieren. Dies hat sehr frustrierend für mich, so dass, wenn es eine Möglichkeit gibt Sie wieder zu mir könnte, das wäre toll.

    1. Avatar von Evan Shanks
      Evan Shanks

      Sorry für die schlechte Übersetzung. Ich musste Google verwenden, weil es hat mir gesagt, Englisch war Spam.

    2. Avatar von Marc

      Sorry for the inconvenience. English should now be allowed in the comments.

      Did you install ffmpeg?
      Did you insert your twitch key correctly?

      What happens after you used the ffmpeg command in the terminal? Any error messages?

  4. Avatar von Peter

    I’ve used hdpvr capture for mac for a while now so I get everything on step 1 but when I start step 2 my ffmpeg doesn’t look the same as yours in terminal and I can’t type anything in it.

    1. Avatar von Marc

      What do you mean by looks different? Can you please copy the output of the terminal? Do you see the preview in Vlc if you hit the preview button in HDPRV capture?

    2. Avatar von Peter

      Thanks for the quick response. I should have checked for a reply earlier. I can see the preview of my recording on Vlc. As for step 2, when I open ffmpeg it gives me this (below). Am I supposed to open up a new blank terminal and then type in everything by hand? Any help is very appreciated.

      Last login: Wed Feb 19 05:16:02 on ttys000
      SMBP-0958:~ s150789$ /Users/s150789/Downloads/ffmpeg-2 ; exit;
      ffmpeg version 2.1.3 Copyright (c) 2000-2013 the FFmpeg developers
      built on Jan 17 2014 09:39:01 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
      configuration: –prefix=/Volumes/Ramdisk/sw –enable-gpl –enable-pthreads –enable-version3 –enable-libspeex –enable-libvpx –disable-decoder=libvpx –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-avfilter –enable-libopencore_amrwb –enable-libopencore_amrnb –enable-filters –enable-libgsm –arch=x86_64 –enable-runtime-cpudetect
      libavutil 52. 48.101 / 52. 48.101
      libavcodec 55. 39.101 / 55. 39.101
      libavformat 55. 19.104 / 55. 19.104
      libavdevice 55. 5.100 / 55. 5.100
      libavfilter 3. 90.100 / 3. 90.100
      libswscale 2. 5.101 / 2. 5.101
      libswresample 0. 17.104 / 0. 17.104
      libpostproc 52. 3.100 / 52. 3.100
      Hyper fast Audio and Video encoder
      usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…

      Use -h to get full help or, even better, run ‚man ffmpeg‘

    3. Avatar von Peter

      I should add, I’m not very experienced with using terminal. I’ve also tried copying the whole ffmpeg command with my twitch key and nothing happens.

    4. Avatar von Marc

      Please copy the whole command and show me the output. In your first example you executed only ffmepg without the parameters.

    5. Avatar von Peter

      > ffmpeg -f mpegts -i ‚udp://
      fifo_size=1000000&buffer_size=10000000&overrun_nonfatal=1‘ -vcodec libx264 -s 1280×720 -g:v 40 -qscale:v 2 -threads 4 -preset medium -b:v 1136k -minrate 1300k -maxrate 1300k -bufsize 8000k -r 30 -acodec libmp3lame -ar 44100 -b:a 64k -f flv „rtmp://live.justin.tv/app/live_(my twitch key)
      -bash: ffmpeg: command not found

      My HDPVRCapture is sending the video to the IP address but I can’t get the command to work and stream it on twitch.

    6. Avatar von Marc

      -bash: ffmpeg: command not found means that ffmpeg is not installed correctly. Did you copy it to /usr/local/bin ? The command needs to be available everywhere and should be within the path variable. Or execute the command inside the folder where you extracted ffmpeg.

    7. Avatar von Jogadrogba

      Could you make a youtube video of you doing all this?

  5. Avatar von FuurinRei

    Cheers! I just got my first Mac and i tried this setup and it works flawless!

  6. Avatar von Andrew

    I was thrilled to find this site but I’m having trouble with Step 2. I downloaded the ffmpeg but whenever I try and run the command in the terminal I get this error, „-bash: ffmpeg: command not found“. I tried rebooting and typing in your supplied code by hand but I get that message every time. If there’s any advice or help you have I would really appreciate it!

    1. Avatar von Marc

      Hi Andrew,

      I expanded the tutorial a bit to cover this problem in step 2. Would you be so kind and tell me if this works for you?

    2. Avatar von Andrew

      So I tried to do this, but the /usr/local/bin/ cannont be found and I have no clue what to do about it. Any Advice?

    3. Avatar von Marc

      Are you sure you are using a Mac? And not a PC?

    4. Avatar von Andrew w
      Andrew w

      Yep. I don’t know what is wrong.

    5. Avatar von Marc

      What happens if you execute this command in your terminal:

      cd /usr/local/bin/


    6. Avatar von Andrew w
      Andrew w

      this is the given response: -bash: cd: /usr/local/bin/: No such file or directory

    7. Avatar von func0der

      This directory is not there by default. You can create it with `sudo mkdir /usr/bin/local`.

      But copying the ffmpeg binary there is NOT needed. You can run it without copying it there by providing the full path to the binary in step 3. So instead of `ffmpeg -f mpegts…` you’ll use `~/Downloads/ffmpeg -f mpegts…`. No problem there.
      Copying the binary to `/usr/local/bin` just makes it accessible everywhere, because `/usr/local/bin` is in your $PATH by default (see: `echo $PATH`).

  7. Avatar von Shaan

    Hello, I think I have everything set up right but when I try to start it I get this:

    [udp @ 0x7fd89bc0c620] setsockopt(SO_RECVBUF): No buffer space available
    [h264 @ 0x7fd89c823200] non-existing PPS 0 referenced
    Last message repeated 1 times
    [h264 @ 0x7fd89c823200] decode_slice_header error
    [h264 @ 0x7fd89c823200] no frame!
    [h264 @ 0x7fd89c823200] non-existing PPS 0 referenced
    Last message repeated 1 times
    Input #0, mpegts, from ‚udp://‘:
    Duration: N/A, start: 193.812311, bitrate: 192 kb/s
    Program 1
    Stream #0:0[0x1011]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920×1080 [SAR 1:1 DAR 16:9], 30 tbr, 90k tbn, 60 tbc
    Stream #0:1[0x1100]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 192 kb/s
    [NULL @ 0x7fd89c00a000] Unable to find a suitable output format for ‚2‘
    2: Invalid argument
    Conversion failed!

    Any advice?

    1. Avatar von Marc

      Have you tried this:

      You can verify that it works this if you press the record button, start VLC and go to file -> open network and put this into the address field: udp://@:1234. Hit the play button and you should see the output video mpegts stream of your HDPVR.

      Do you see the video stream? Because it looks like that ffmpeg does not receive an input stream from the HDPVR.

    2. Avatar von Shaan

      Yes, everything seems to be working fine following your tutorial up until actually running ffmpeg. I see the video in VLC and everything, but get that error when I start ffmpeg.

    3. Avatar von Marc

      Maybe you have a typo in your command? It basically says that there is a problem with the argument „2“. Is there a „space“ or something like that?

    4. Avatar von Shaan

      First of all, thanks for spending your time trying to help me.
      I was just copy and pasting, replacing the XXX with my key of course. I tried again today and now seem to be getting something different, yet still not working.
      “ Duration: N/A, start: 238.739756, bitrate: 192 kb/s
      Program 1
      Stream #0:0[0x1011]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920×1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
      Stream #0:1[0x1100]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 192 kb/s
      Option re (read input at native frame rate) cannot be applied to output file 2 — you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
      Error parsing options for output file 2.
      Error opening output files: Invalid argument
      Conversion failed!

      Thanks for your time.

    5. Avatar von Marc

      Please leave away the -re parameter. I removed it from the article as well. What does it say now?

    6. Avatar von Shaan

      I tried that earlier, we go back to the primary problem.
      “ Duration: N/A, start: 1744.038178, bitrate: 192 kb/s
      Program 1
      Stream #0:0[0x1011]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920×1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
      Stream #0:1[0x1100]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 192 kb/s
      [NULL @ 0x7fce34869a00] Unable to find a suitable output format for ‚2‘
      2: Invalid argument“

    7. Avatar von Marc

      My guess is a line break somewhere in the command you have copied.

      Invalid argument: ‚2‘ does not make any sense. Even google does not come up with anything. Maybe somebody else got an idea to help?

  8. Avatar von Marc

    I optimized all parameters for fast and high quality encoding. Here is an example with Dark Souls 2.

  9. Avatar von Erik

    Finally got this to work. I had to change the buffer size to the same as min and max bitrate. Didn’t work otherwise. Thanks!

    1. Avatar von Marc

      You’re welcome.

  10. Avatar von angel

    ~/Downloads/ffmpeg -f mpegts -re -i ‚udp://‘ -vcodec libx264 -s 1280×720 -g:v 40 -threads 4 -preset medium -b:v 850k -minrate 850k -maxrate 850k -bufsize 1600k -r 30 -acodec libmp3lame -ar 44100 -b:a 64k -async 44100 -f flv
    ffmpeg version 2.2.4 Copyright (c) 2000-2014 the FFmpeg developers
    built on Jun 27 2014 09:57:37 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
    configuration: –prefix=/Volumes/Ramdisk/sw –enable-gpl –enable-pthreads –enable-version3 –enable-libspeex –enable-libvpx –disable-decoder=libvpx –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-avfilter –enable-libopencore_amrwb –enable-libopencore_amrnb –enable-filters –enable-libgsm –enable-libvidstab –enable-libx265 –arch=x86_64 –enable-runtime-cpudetect
    libavutil 52. 66.100 / 52. 66.100
    libavcodec 55. 52.102 / 55. 52.102
    libavformat 55. 33.100 / 55. 33.100
    libavdevice 55. 10.100 / 55. 10.100
    libavfilter 4. 2.100 / 4. 2.100
    libswscale 2. 5.102 / 2. 5.102
    libswresample 0. 18.100 / 0. 18.100
    libpostproc 52. 3.100 / 52. 3.100
    [udp @ 0x7f98a9d003e0] bind failed: Address already in use
    udp:// Input/output error
    Conversion failed! WHAT IM I DOING WRONG?

    1. Avatar von func0der

      Seems like your port :1234 is already in use.
      Port configuration for HD-PVR Capture needs to get changed. Ports for custom software should be used between 49152-65535. If not there at least over 10000 to make sure no other programm is using it.

      Whatever port you are configuring in HD-PVR Capture, you need to use it from there on.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert