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

How to stream live HDV/DV to iphone…..

datePosted on 13:36, March 5th, 2010 by Many Ayromlou

In this guide I’ll show you how to stream live HDV/DV video to your iphone using a linux box (Ubuntu 9.10) with firewire input running vlc/ffmpeg and a Imac with OSX 10.6.2 running mediastreamsegmenter and apache2.

Start out with the iPhone streaming media overview. Without understanding this document you’ll have a hard time getting things working.

First things first, you need to have a working Ubuntu 9.10 machine. I’m using a small footprint 2.4Ghz Core2Duo machine with PCI firewire 400 card in it. For video input I’m using a Canon HV30 set to HDV mode (1080i/60) connected via firewire.

Next you need to follow the instructions on this page (steps 0-5) to get a working ffmpeg with x264 and aac encoding. Without this working you’re not going anywhere….sorry. If you’re trying this on a different Ubuntu installation follow the other links to get a working ffmpeg setup.

Then install vlc using “sudo apt-get install vlc“. I used vlc as my encoder frontend as I understand it better than ffmpeg. You can use just straight ffmpeg as well if you can figure out how to get it to encode the live HDV stream over firewire.

You’ll also need dvgrab utility. Install it using “sudo apt-get install dvgrab“.

Now we want to make sure the internal firewire module is working so type this command and see if you get a vlc window with the camera output in it (make sure you turn the camera ON and hook it up first).
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).

Next we need to create a media stream out of our linux box and ship it over UDP to the Imac. The vlc command below gets the job done. Remember you’re sudo’ing and need to provide the password after you enter the command.
sudo dvgrab -f hdv -noavc -nostop -|vlc - --sout '#transcode{vcodec=h264,vb=256,venc=x264{aud,profile=baseline,level=30,keyint=30,bframes=0,ref=1,nocabac},acodec=mp4a,ab=64,scale=0.25,deinterlace,width=320,height=240}:duplicate{dst=std{access=udp,mux=ts,dst=192.168.1.97:1234}}'
The IP address toward the end of the command is the IP of the Imac machine receiving the stream. Port 1234 is arbitrary. The stream is comprised of h.264 video @ 256K and AAC audio @ 64K. Those elementary streams are then packaged in mpeg2 transport stream before being shipped to the Imac. This is the standard way of doing HTML5 video (from what I understand).

So now we can go over to the mac and see if we receive the video stream. For that just run VLC for OSX and open UDP network port on port 1234 (udp://). If things are working nicely you should see a 320×240 video from you HDV camera on the Imac.

Now that we have the video on the mac, we need to use the “mediastreamsegmenter” command line tool to create HTML5 video stream out of it. mediastreamsegmenter listens on a UDP port for incoming transport stream chops it (by default) into 10 sec. “mini” transport stream files and writes these mini files to wherever you tell it. This location is important since it needs to be accessible to your webserver. Remember, at the end of the chain (day), the webserver is doing all the heavy lifting of delivering the mini transport stream files to your iphone. mediastreamsegmenter also produces a file of type .m3u8
which is basically a live updated playlist.

Something you might not know is that apple ships standard OSX with apache builtin. All you have to do is use the following command to get it started.
apachectl start
Now point your browser on the mac to localhost and see if it loads a page. Now that apache is working we need to modify it so it knows how to deal with .ts and .m3u8 files. This involves adding a couple of lines to /etc/apache2/httpd.conf
AddType application/x-mpegURL .m3u8
AddType video/MP2T .ts

and /etc/apache2/mime.types
.m3u8 application/x-mpegURL
.ts video/MP2T

Next we need to restart apache
apachectl restart
By default OSX apache is setup to load it’s documents from /Library/WebServer/Documents, so I created a directory called “stream” to contain the media stuff (.ts files and .m3u8 file) and put the following into the index.html file in /Library/WebServer/Documents.
<html>
<head>
<title>Video Test</title>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head>
<body style="background-color:#FFFFFF; ">
<center>
<video width='320' height='240' src="prog_index.m3u8" controls autoplay> </video>
</center>
</body>
</html>

Now that we’ve got all the prep done on the mac, we issue the following command from terminal window to get the mediastreamsegmenter going (details can be found by using man mediastreamsegmenter).
mediastreamsegmenter -b http://192.168.1.97/stream -f /Library/WebServer/Documents/stream 192.168.1.64:1234
Here -b specifies the base of the URL that will be encoded into the .m3u8 file (this is the IP address of your Imac, stream is the folder in /Library/WebServer/Documents/ where the mini .ts files and the .m3u8 file are). The -f switch specifies the output directory for the mini .ts files and the .m3u8 file. and the last IP address:port is from your Linux box.

Now you should be able to open up your browser on your iphone/ipod touch and punch in http://192.168.1.97 (assuming the Imac is reachable from your phone) and see the streaming video (You might have to turn on “Plugins” feature under settings/safari on your device. Mine was turned off and drove me crazy until I figured it out). If Plugins is turned off, the index.html page will load, but no video.

Hopefully there is enough meat here to get you guys started……btw. I hear the following command (or variations of) can be used on linux side (instead of vlc). I haven’t tried it and can’t confirm if it works.
ffmpeg -i <in file> -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 320×240 -vcodec libx264 -b 96k -flags +loop -cmp +chroma -partitions +parti4×4+partp8×8+partb8×8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate 96k -bufsize 96k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 <output file>

Some excellent information can be found on Carson McDonald’s blog:

CineForm Direct-to-Disk Recorder

datePosted on 12:10, December 10th, 2007 by Many Ayromlou


I have to admit CineForm is one of my favourite companies out there. I’ve visited them once and they are the nicest bunch of engineers you’ll find on that side of the rockies :-). Aside from their famed CineForm Codec (which btw is awesome), they have just released the specs and conceptual drawings for what will probably be the coolest gadget at next years NAB ;-).

They anticipate developing multiple members in the recorder product family – each targeting different recording needs. This first device targets HDV camcorder users and offers the ability to bypass the highly-compressed MPEG format. The features specification is below. They also imagine a sister device that would support single-link and dual-link HD-SDI recording.

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 :-)