Archive for ‘ffmpeg’ Category
Browse:
ffmpeg »
Subcategories:

Stream your Windows desktop using ffmpeg

datePosted on 10:26, November 3rd, 2011 by Many Ayromlou

I’ve already covered how to do this with vlc a while back in parts 1 followed by part 2. I just found out that something very similar in results can be done with ffmpeg. ffmpeg has recently added support for directshow filters which now allows one to capture the screen and stream and/or save it. Here is how you can do this:

1.) Grab a copy of the Screen Capture DirectShow source filter from Unreal Streaming Technologies. It’s about half way down that page. They have both the UScreenCapture X86 Edition and the X64 Edition (depending on your OS installation). I used the 64 bit filter on a Windows 7 64 bit installation.

2.) Install the filter and make sure you make the following changes to your windows registry using regedit. The default frame rate for UScreenCapture filter is 10 f/s and we need to boost this to 30 frames/sec. You need to find the key HKLM\SOFTWARE\UNREAL\Live\UScreenCapture and insert a DWORD value of 30 for FrameRate (You have to create FrameRate, it does not exist by default). Once you’ve done the registry tweak, reboot.

3.) Install the latest greatest version of ffmpeg for your windows version from Zeranoe. I grabbed the 64 bit Static build since I didn’t want to deal with libraries and such. Extract it and stick it somewhere on your hard drive. Remember the path to this folder since we will need it later.

4.) Open a command line window and cd to the directory where you extracted ffmpeg into, find the bin directory and cd into it. This is were the ffmpeg executable resides. In my case (I extracted the ffmpeg files into “Program Files” directory) it is C:\Program Files\ffmpeg-git-059707e-win64-static\bin.

5.) If you’ve made it this far, hand in there, we’re almost home. Now you need to issue the command that gets the screen streaming going. But first we need to find out the name of the Screen filter device. So issue the following command:

ffmpeg -list_devices true -f dshow -i dummy

In the output look for a device called “UScreenCapture“. Hopefully if everything is working with the directshow filter you have a entry in the list. That’s the name of our device that we need to pass onto ffmpeg. While you’re there also look for your audio device entry as well. Mine was the truncated word “Stereo Mix (Realtek High Defini” (Yes mine was missing the end of that line). Jot that down somewhere as well. I will show you how to get audio going as well.

6.) So first step is to get video going. Assuming you have a “UScreenCapture” device (You could use another directshow filter if you like, this will work with most of them. I just used the Unreal filter for the heck of it), here is the command to start encoding and sending video:

ffmpeg -f dshow  -i video="UScreenCapture"  -r 30 -vcodec mpeg4 -q 12 -f mpegts udp://aaa.bbb.ccc.ddd:6666?pkt_size=188?buffer_size=65535
  • -f dshow specifies that you’re going to be using a directshow device as your input.
  • -i video=”UScreenCapture” is the name of the input directshow device which we picked up in step 5.
  • -r 30 is the frame rate.
  • -vcodec mpeg4 is our video codec of choice.
  • -q 12 is a quality measure for the encoding process (1 is the best and 30 the worst). We’re doing VBR encoding so this measures the compression ratio vs. picture quality.
  • -f mpegts is our output filetype. In this case mpeg-2 transport stream. Yes, we’re encapsulating mpeg4 video inside a mpeg-2 transport stream…..why?….google it.
  • udp://aaa.bbb.ccc.ddd:6666?pkt_size=188?buffer_size=65535 this last bit specifies the address and port number of the recipient machine (aaa.bbb.ccc.ddd is the ip address of that machine and 6666 is my arbitrary port number). We’re also instructing ffmpeg to create smaller 188 byte size udp packets (which is the size of the transport stream packets) to decrease latency and our buffer size is 64kb.

7.) On the receiving machine you should be able to use vlc, ffmpeg or mplayer to catch the stream. In vlc simply open the Network stream rtp://@:6666 , in ffmpeg you can use the command ffplay -i udp://:6666 or using mplayer you can issue the command mplayer -framedrop -double udp://:6666 .

8.) Now to optionally add sound to the whole thing we can use this command on the encoding machine (instead of step 6). You need to know the device name for your sound card and you probably want to turn the volume down (at least initially) on the decoding machine.

ffmpeg -f dshow  -i video="UScreenCapture" -f dshow -i audio="Stereo Mix (Realtek High Defini" -r 30 -vcodec mpeg4 -q 20 -acodec libmp3lame -ab 128k -f mpegts udp://141.117.224.74:6666?pkt_size=188?buffer_size=65535
  • -f dshow specifies that you’re going to be using a directshow device as your input (VIDEO).
  • -i video=”UScreenCapture” is the name of the input directshow video device which we picked up in step 5.
  • -f dshow specifies that you’re going to be using a directshow device as your input (AUDIO).
  • -i audio=”Stereo Mix (Realtek High Defini” is the name of the input directshow audio device which we picked up in step 5.
  • -r 30 is the frame rate.
  • -vcodec mpeg4 is our video codec of choice.
  • -q 20 is a quality measure for the encoding process (1 is the best and 30 the worst). We’re doing VBR encoding so this measures the compression ratio vs. picture quality. I went with 20 instead of 12 from step 6 since the audio encoding slows the machine down a bit.
  • -acodec libmp3lame is our video codec of choice
  • -f mpegts is our output filetype. In this case mpeg-2 transport stream. Yes, we’re encapsulating mpeg4 video inside a mpeg-2 transport stream…..why?….google it.
  • udp://aaa.bbb.ccc.ddd:6666?pkt_size=188?buffer_size=65535 this last bit specifies the address and port number of the recipient machine (aaa.bbb.ccc.ddd is the ip address of that machine and 6666 is my arbitrary port number). We’re also instructing ffmpeg to create smaller 188 byte size udp packets (which is the size of the transport stream packets) to decrease latency and our buffer size is 64kb.

FFmpeg commands for ipod video encoding…

datePosted on 12:04, September 25th, 2008 by Many Ayromlou

So I found out the hard way that the new ipod’s (with video out) can actually play 640×480 video and also figured out how to get iTunes to accept the encoded files (so that I could sync them with the device)…….here is the run down:

  • “TV-Out” mode - 1.5Mbit/s 640×480 H.264 videos
    • BIT_RATE <= 1500 kbps
    • 640×480
    • Up to 30 fps
    • “Low-Complexity” H.264 Baseline Profile
    • 1 reference frame
    • Up to H.264 level 3
    • 640 pixels maximum frame width
    • Sample Aspect Ratio (SAR) must be 1:1
    • UUID atom must exist containing the following hex data: 6B 68 40 F2 5F 24 4F C5 BA 39 A5 1B CF 03 23 F3….This allows you to add the video into iTunes. You need AtomicParsley for this which can be checked out from their subversion repository . See below for usage.
  1. For 1-pass encoding use:
  2. ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect WIDTH:HEIGHT OUTPUT.mp4AtomicParsley OUTPUT.mp4 --DeepScan --iPod-uuid 1200 --overWrite

  3. For 2-pass encoding use:
  4. ffmpeg -i INPUT -an -pass 1 -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect WIDTH:HEIGHT OUTPUT.mp4 ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect WIDTH:HEIGHT OUTPUT.mp4AtomicParsley OUTPUT.mp4 --DeepScan --iPod-uuid 1200 --overWrite

  • “Standard” mode - 768kbit/s 320×240 H.264 videos
    • BIT_RATE <= 768 kbps
    • 320×240
    • Up to 30 fps
    • H.264 Baseline Profile up to level 1.3
  1. For 1-pass encoding use:
  2. ffmpeg -i INPUT -acodec libfaac -ab 128k -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 768k -bufsize 2M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 -title SOME_TITLE OUTPUT.mp4

  3. For 2-pass encoding use:
  4. ffmpeg -i INPUT -an -pass 1 -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 768k -bufsize 2M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 -title SOME_TITLE OUTPUT.mp4 ffmpeg -i INPUT -acodec libfaac -ab 128k -pass 2 -s WIDTHxHEIGHT -vcodec libx264 -b BIT_RATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt BIT_RATE -maxrate 768k -bufsize 2M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 -title SOME_TITLE OUTPUT.mp4

      ffmpeg command line quickies…..

      datePosted on 11:05, September 25th, 2008 by Many Ayromlou

      Here are a bunch of ffmpeg command lines that will do just about everything you need.

      1. Getting info from a video file
      2. ffmpeg -i video.avi

      3. Turn a sequence of images into video
      4. ffmpeg -f image2 -i image%d.jpg video.mpg

      5. Turn a video into a sequence of images
      6. ffmpeg -i video.mpg image%d.jpg

      7. Encode video for Ipod/IPhone
      8. ffmpeg -i source_video_file.avi -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv -trell 1 -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X output_file.mp4

      9. Encode video for PSP
      10. ffmpeg -i source_video_file.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac output_file.mp4ORffmpeg -i "OriginalFile.avi" -f psp -r 29.97 -b 768k -ar 24000 -ab 64k -s 320x240 "OutputFile.mp4"

      11. Extract audio from a video file and save it as mp3 format
      12. ffmpeg -i source_video_file.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 output_file.mp3

      13. Convert a wave file to mp3
      14. ffmpeg -i original_audio_file.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 output_file.mp3

      15. Convert a avi video to mpeg
      16. ffmpeg -i original_movie.avi output_file.mpg

      17. Convert a mpeg video to avi
      18. ffmpeg -i original_movie.mpg output_file.avi

      19. Convert a avi video to uncompressed animated gif
      20. ffmpeg -i original_movie.avi output_file.gif

      21. Add audio to an existing video-only file (mix audio and video)
      22. ffmpeg -i son.wav -i original_movie.avi output_file.mpg

      23. Convert a avi video to flv (flash video)
      24. ffmpeg -i original_movie.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output_file.flv

      25. Convert a flv video to mpeg
      26. ffmpeg -i myFile.flv -ab 56 -ar 22050 -b 500 -s 320x240 myFile.mpg

      27. Convert a avi video to dv
      28. ffmpeg -i original_movie.avi -s ntsc -r ntsc -aspect 4:3 -ar 48000 -ac 2 output_file.dvORffmpeg -i original_movie.avi -target ntsc-dv output_file.dv

      29. Convert a avi video to mpeg specifically for DVD creation
      30. ffmpeg -i source_video.avi -target ntsc-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg

      31. Compress a avi video to Divx
      32. ffmpeg -i original_movie.avi -s 320x240 -vcodec msmpeg4v2 output_file.avi

      33. Convert a Ogg Theora video to mpeg specifically for DVD creation
      34. ffmpeg -i original_movie.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 output_file.mpg

      35. Convert a avi video to mpeg2 for SVCD creation
      36. ffmpeg -i original_movie.avi -target ntsc-svcd output_file.mpg

      37. Convert a avi video to mpeg2 for VCD creation
      38. ffmpeg -i original_movie.avi -target ntsc-vcd output_file.mpg