Archive for ‘MP4’ Category
Browse:
MP4 »
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.

Elgato turbo.264 HD video encoding coprocessor review…….

datePosted on 18:00, January 15th, 2010 by Many Ayromlou

I just picked one of these babies up from the apple store and after testing it a bit for the past hour, I have one word for it: WOW. This little guy is no gimmick, it’s zippy as hell and it does exactly what they say it would. The details for the device are on Elgato’s Website, but this is just a mini review of the tests I ran against a couple of software encoders.

Here is my setup:

– Mac OSX 10.5.8 with latest updates running on a 2.16Ghz Intel Core 2 Duo Black MacBook w/ 2 GB 667Mhz DDR2 SDRAM.
– Test input file was a HD movie I grabbed from vimeo through BT. It’s 12.5 minutes in lenght.


– Output was done through the Elgato Turbo stick, Mpeg Streamclip encoder and ffmpegX.

– In all cases I’ve tried to produce a single pass h264/x264 file with the same dimensions and settings as the Elgato software preset for ipod best (640×360 @ 24 fps @ 1500 kbps at 80-90% quality).

The results blew my mind:

  • Elgato Turbo took 8:43 min to encode the 12:29 min movie.
  • Mpeg Streamclip took 50:25 min to encode the 12:29 min movie.
  • ffmpegX took 49:52 min to encode the entire 12:29 min movie.

Here are a couple of full size frames (640×360 px) blown up to 1920×1200 to exaggerate imperfections (click on the pics to see them full size):
– Elgato Turbo stick


– Mpeg Streamclip

– ffmpegX

– And last but not least all three at the original size (left to right): Elgato Turbo Stick, Mpeg Streamclip, ffmpegX

Best C$179 I’ve spent in a while. It just works.

Well kids are you ready for todays lesson in transcoding DV video. So first you need a decent machine. I’m using a P4 2.4Ghz oldie that has Firewire on-board and am chewing up 50% CPU for NTSC encoding. Then you need to get Ubuntu 8.04 installed. Once that’s done use the following command to install vlc (Video Lan Client):
sudo apt-get install vlc
Then either follow this guide or if you’re using 8.04 (Hardy Heron) ONLY, use the following command to add Medibuntu to your repository sources.list:
sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
followed by
sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update
to add the GPG key for Medibuntu Repository. You may be asked to accept this package even though it cannot be authenticated. This is normal; typing “Yes” means you trust Medibuntu.
Now do the following commands to get libdvdcss and other codecs installed on your machine:
sudo apt-get install libdvdcss2
sudo apt-get install w32codecs (for i386 architecture) OR
sudo apt-get install w64codecs (for amd64 architecture)

Now that we have all the goodies installed and ready to go you can go ahead and connect that DV camera to your Ubuntu box using Firewire. Make sure it’s in Camera mode (NOT VCR) and open up a command line and type in the following command to get the encoder setup:
sudo -i (This will put you in superuser mode.....ie: root account)
cat /dev/dv1394/0 | vlc - :demux=rawdv -I dummy --sout '#transcode{vcodec=mp4v,vb=1024,acodec=mpga,ab=192,scale=1,width=720,height=480}:duplicate{dst=std{access=udp,mux=ts,dst=IPAddressofDestinationMachine:PortNumber}}'

You could also run the above command from your user account by adding sudo infront of it and supply your password followed by Enter key.

The above command (in case you’re wondering) will literally open device zero on the firewire chain and redirect it’s raw output into the VLC program. VLC is told to accept input from a pipe in rawdv format and to transcode it to mpeg4 Video @ 1Mb/s with mpeg1-layer3 audio @ 192 Kb/s.

Once the above command is running you’ll need to go to your receiving machine (the machine who’s IP you supplied in the command above), run VLC and from the File menu choose “Open Network Stream” and go with the default UDP/RTP on port 1234 (or whatever port you chose in the encoder command line).

Another neat thing you can do with your new found opensource goody bag is capture DV from your camera/settop box and save it in mpeg4 format for archival purposes (or mpeg2 for editing maybe). I’m not gonna get into the details, but assuming you’ve done the above commands, skip the encoder command and issue the following command to get your DV stream saved:
sudo -i
cat /dev/dv1394/0 | ffmpeg -f dv -i - -f mp4 -s 720x480 -vcodec mpeg4 -acodec aac -ab 128 -ar 44100 -deinterlace -b 3000k -y yourfilename.mp4

This command will take rawdv from the camera, pass it to ffmpeg, which will chew on it and spit it out as mpeg4 video @ 3Mb/s with AAC audio @ 128Kb/s into a file named yourfilename.mp4 (if the file exists it will overwrite it). Stopping is accomplished by CTRL-C. More info on this command can be found on ffmpeg’s man page.

Have Fun….

How to live transcode and stream HDV to MP4 using VLC and Linux

datePosted on 22:20, November 21st, 2007 by Many Ayromlou

I’ve been trying to figure out a way to do this on the cheap for a long time and I finally figured it out today. This process allows you to grab HDV from a HDV Camera via firewire, feed it into linux, transcode the 25Mb/s mpeg-ts stream to a 4 Mb/s mpeg4 stream (inside a TS). This mpeg4 stream in turn can be viewed at full resolution (1920×1080) on a remote client running just vlc. Here is the prerequisites:

  1. A decent machine with working Firewire port (anything from the past 2-3 years should do). Laptops might work as well although I have not tried it yet. My machine is a Athlon 4200+ w/ 2GB of RAM and a 512 MB NVIDIA 7900.
  2. Ubuntu 7.10 (Gutsy Gibbon) installation CD.
  3. 4-pin to 6-pin Firewire cable.
  4. HDV Camera with Firewire out (I use a Canon HV20).
Okay so here we go, follow the steps below to get setup:
  1. Get Ubuntu 7.10 installed on your machine. This should be standard installation from the Live-CD.
  2. Reboot, do all adjustments to your display, get network setup, install all the updates.
  3. Using synaptic package manager install the following extra packages: ubuntu-extras, ffmpeg, dvgrab 3 and VLC plus anything else you might want.
  4. Connect the firewire camera to the computer and check /var/log/messages to make sure it gets recognized.
Now that you have the chain setup, it’s time to do a quick test and see if the system is working. Issue the following command from a xterm, making sure that the camera is turned on and in “Camera” mode.

sudo dvgrab -f hdv -noavc -nostop -|vlc -
You have to use sudo under ubuntu to get proper access to the firewire device. The above command runs dvgrab with hdv format and makes sure that 1394 AV/Device control is turned off (this way you can be in Camera mode and get a live feed). The nostop switch prevents dvgrab from sending stop commands to the camera everytime you stop it via Ctrl-C, which I though was a good thing. The last dash forces dvgrab to output to stdout, which we’ll then pipe into vlc (the dash for vlc tells it to use stdin as input).

If this works you should get a vlc window and be able to see live video from your HDV camera. If you didn’t then stop here and make sure you get this working first.
So now that we have dvgrab working, lets grab that 25Mb/s HDV stream and squish it down to 4Mb/s mpeg4 stream using the following command:

sudo dvgrab -f hdv -noavc -nostop -|vlc - --sout '#transcode{vcodec=mp4v,vb=4096,acodec=mpga,ab=256,scale=0.5,deinterlace,width=1920,height=1080}:duplicate{dst=std{access=udp,mux=ts,dst=receiver_ip_address:1234}}'
This is one massive command, the first part we already discussed, so lets take a look at the second half:

  • –sout is our output chain.
  • #transcode tells vlc that we first want to transcode the input using parameters to follow
  • {} contains our transcoding parameters
  • vcodec=mp4v sets the video codec to mpeg4 video
  • vb=4096 sets the bitrate of the transcoded video (4Mb/s)
  • acodec=mpga sets the audio codec to mpeg audio (mp3)
  • ab=256 sets the bitrate of the transcoded audio (256 Kb/s)
  • scale=1 sets the scaling value
  • deinterlace sets guess what?
  • width=1920 sets the width of the transcoded video to 1920 pixels
  • height=1080 sets the height of the transcoded video to 1080 pixels
  • :duplicate tells VLC that we want to duplicate the transcoded signal and send a copy of it to our receiver machine.
  • dst is the destination string
  • access=udp specifies UDP protocol
  • mux=ts sets multiplexing to mpeg-2 Transport stream
  • dst=receiver_ip_address:1234 is the ip address and port number of the receiving machine
So now you should be able to open up vlc on the receiver machine, goto File/Open Network menu and select UDP/RTP and specify port number 1234. Once you press OK, you should see the video stream on your receiver machine. Audio works as well and is perfectly synced since it’s captured by the HDV camera at the source and travels together with the video at all time. The delay is about 3 seconds.
This is a great way to quickly setup a HD Video Conference between a couple of locations. You could even modify the network portion of the chain to let VLC multicast the HD stream onto your network…..lots of possibilities. Enjoy :-)