dvgrab / ffmpeg capture / compression

Commands
Linux

Recently I volunteered to record video for the DrupalCamp Seattle 2008. It quickly dawned on me that to record 10 hours of video, bring it home and capture it to disk and then compress it would take 30+ hours. Also, that wouldn't be anywhere close to live and they were hoping to post the video as soon as possible. Since I am only running Linux on my laptops now, I decided to see what could be accomplished via command line tools in Linux. I quickly stumbled on ffmpeg and dvgrab. DVgrab can capture raw dv from firewire and has features for detecting scenes when capturing from tape. FFMPEG can also capture directly from the firewire, but specializes in converting (transcoding) video from one format to another.

When capturing directly from firewire using ffmpeg I would get glitches every now and then.

ffmpeg -f dv -i /dev/dv1394/0 -target ntsc-svcd output.mpg


FFMpeg takes an input file (or multiple input files) and an output file.
The parameters for each come before the file.

 

If I tried writing raw DV from ffmpeg I would get IO errors basically stating my computer couldn't andle the throughput.

But, dvgrab worked flawlessly!

dvgrab -format raw test.dv

Since both can use pipes I tried piping dvgrab directly into ffmpeg.

dvgrab -format dv1 - | ffmpeg -f dv -i - -target ntsc-vcd test.mpg

This worked wiithout any glitches.
 So the next step was to figure out which format would give me the best compression vs. quality.

To do this I wrote a perl script which allowed me to easily experiment by converting a raw dv input file to various formats.
I have attached that script called encodetest.pl below.

After experimenting, I decided to go with flv since the video was to be posted to blip.tv, and blip.tv will convert anything posted to flv accept for flv which it leaves alone.
I tried posting some short xvid samples, ad they were taking an hour or more for blip.tv to convert, so flv had the additional advantage of being available instantly.

Next I wrote a very tiny perl script to encode video using the current timestamp as the filename and added it as a command to my desktop. Now all I had to do is literally click an icon to record and compress video to the conference. I have attached this perl script as well named rec_druplicon.pl

essentially the command it produces is:

dvgrab -format dv1 - | ffmpeg -deinterlace -f dv -i - -f flv -vcodec flv -s 480x270 -aspect 16:9 -qscale 3.5 -acodec libmp3lame -ab 32k -ar 22050 timestamp.flv

 

So how did it turn out?

As far as the recording, it went flawlessly. I was even able to post some of the videos during the next talk. The conditions could have been better. For some talks the lighting was poor in that the ambient light in the room was too bright to see the projector. In the main theatre, I was in the far back of the room and there was no PA, so the audio is faint, but the realtime recording/encoding worked better than expected. You can view all of the recordings at http://seadug.blip.tv/posts?view=archive&nsfw=dc

Some of the benefits of realtime encoding.
1. I could change tape without interupting the hard disk recording.
2. I could stop and start which automatically created multiple files named by timestamp.
3. All of the video from 2 days of recording fit easily n a DVD.
4. Most important, no slow post capture / compression so I was done as soon as I left the conference.


AttachmentSize
encode_test.pl.txt12.82 KB
rec_druplicon.pl.txt956 bytes
Comments
(Thanks to everyone who comments)

just brilliant

I've been struggling with streaming from a firewire device for ages and this tutorial helped me sort it all out. Great stuff and thankyou.


Cool!

Any chance of pulling off something similar on osx?


It should work, but I

It should work, but I haven't tried it on OSX
I have a mac so I can give it a try.
First install ffmpeg and dvgrab. Either compile from source or use macports http://www.macports.org/

Then everything else should work as outlined above.


Instant Video

I love this approach. We do a similar thing when we broadcast our church sermons. Our biggest issue is swapping out the camera batteries in the middle of the sermon. We have an old church with very few outlets, so one of the cameras cannot run from electricity. We end up cutting away and go with the distant shot during the battery swap, which works out ok. I agree that Linux is the way to go to get these things done. So much easier and user friendly than Windows.


Camera batteries

If you're swapping out a lot of camera batteries then you should consider buying them in bulk. You can try this https://www.batterytex.com/browse/category/Digital%20Camera%20Batteries. They have really good prices.


nice!!

I'm also using Linux on my laptop. I used FFMpeg with input and found the result was effective and the quality of the image was perfect!! I noticed that the moving command was easier than I thought. Nice article!


Thanks mate!

Hey! Thanks for sharing this! You saved me some headaches on finding the right settings for doing that! Great!


realtime encoding doesn't work on my system

I tried your command lines, but I didn't got a realtime encoding. It seems that my pc is just grabbing dv video from my camera in 1gig pieces named -001.avi, -002, and so on, without encoding them. Cpu usage is very low.
I'm on ubuntu and tried also with a self compiled version of ffmpeg (and before with the medibuntu package). My system should be powerful enough (Athlon X2, 4gig ram). I cut and copied your string, and I can't find out what's wrong. May you or any other reader of this blog help me?
Thanks in advance

P.S. When I launch the commands, I get two warnings: Cannot set RR-scheduler and Cannot disable swapping


I got it

After two days of googling around hopelessly, I understood why your method wasn't working for me. It can be interesting for everyone has dvgrab 3.0 in his/her system. That version has stdout ( - ) broken. Man has to remove it and compile a newer ( or older) version from source. Hope it will be useful to someone.
Regdx, sorry for asking/writing something probably off topic to your blog, the reason is that's on top of google when searching about direct encoding or something similar...


Glad you were able to get

Glad you were able to get this working. And thanks for the comment about dvgrab being broken in the repositories. Instead of dvgrab you can also use ffmpeg an set the input to the firewire device, but on a slow laptop I had much better performance using dvgrab. On newer systems ffmpeg should work fine though.


great tip - thanks!

I'm going to be taking a multiday train trip soon, and your tip will let me record as much of it as I want, without wasting expensive HI-8 tapes. I'm using mpeg4 instead of flv, it works to be roughly 250mb/hour in my early tests. I might bump the bitrate a little - none the less, it's way better than having to store the raw uncompressed dv files.


sweet

Very glad to see that someone found this and that it helped. Thanks for leaving a comment too!


i would like to register on your site

what a really ventured article posted.


You can register if you want

Registrations are moderated.
You must include legitimate details to be approved.
Since you tried to include spam in your comment your request would be denied - sorry!


Post new comment

More information about formatting options