docs/mindstab.net_blog/2011-01-17-liberating-flash...

5.8 KiB
Raw Blame History

Liberating Flash Video From an RTMP Server

Jan 17, 2011

Let's say you did a presentation that was recorded and you'd like to post it to your website. Sadly, let's now say there are some problems, like that your 5 minute presentation is part of a nearly 2 hour video only available in a flash player that doesn't even have a time display so you couldn't even point people to the video and say jump to 1 hour and 15 minutes to see me. It sucks. Technically your presentation is available online, but it's not really accessible. So here is how you might rescue it!

It turns out there are two ways flash players server videos these days. The first and easiest is that a simple flash player loads in your browser, and uses your browser to make a GET request to the server to load a .flv file (FLash Video). This is relatively easy to intercept, there are lots of tools and plugins for Firefox that do this automatically for you. Even better, on Linux for example, these videos are usually stored in /tmp so your browser does the whole job and gives them to you. No work required.

The other more complicated but more secure option is that the flash player connects to a dedicated rtmp server that streams flash video. The flash plugin does the networking and there is no file to save, it's a stream.

If you are lucky enough to have a player using the first option, you are done. Assuming you have the second option, then your fun has just begun.

First we need to try and figure out where the server that your flash video is.

My first approach was to use wireshark to sniff the traffic. Through this I discovered the basics, like the address the server and the port, 1935.

Next I installed rtmpdump. RTMP is the Real Time Messaging Protocol and rtmpdump is a program that can connect to an RTMP server, get a stream and save it to a file. Sadly the data I got from wireshark didn't have all the parameters I needed to get the file. Or I couldn't read it properly. So while I knew where the server was and could now connect to it, I still didn't know how to ask for the video I wanted.

Thankfully rtmpdump comes with several other utilities. After reading its README I went the rtmpsuck route. I set local redirecting of all port 1935 requests to localhost with iptables and ran the rtmpsuck proxy server. In theory it was supposed to intercept all calls from the flash player to the rtmp server, decode and spit them out, and then forward them along. Even better, it would try to save the stream on the way back as it passed through it.

# iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner --uid-owner OWNER_UID  -j REDIRECT
$ ./rtmpsuck

Where OWNER_UID is the uid of the user running rtmpsuck. With this running I just reloaded the page with the player (twice, it's a bit glitchy) and then tried to skip to where my part was so it would save the stream from there.

It was partially successful. It spit out on the console all the pertinent path parameters about the video on the server, but it kept chocking on bad packets of data and stopped recording. Also for some reason the video it did store was very large, space-consuming wise.

Armed with the right parameters though I was able to use rtmpdump to suck down the whole video from the server surprisingly quickly and in a reasonably sized format.

$ ./rtmpdump  -r rtmp://server.net/app_name/blah/event/date/date-1 -o video.flv

Now the video was liberated from its flash interface and in my possession, I just had to cut out my small part and then convert it to a more common format.

$ mencoder -ss 1:15:50  -endpos 0:05:57  -ovc copy -oac copy video.flv -o result.flv
$ ffmpeg -i result.flv result.avi

And volia. I now have just my part of the video and in a common format. I mean you hypothetically do! Yes...

Completely unrelatedly, you can expect to see my presentation on my project Cortex from the BCNet Broadband Innovation Challenge (where I got second place) online soon.

Comments

Alun Jones Says:

May 31st, 2011

Silly question since youre using ffmpeg to convert the FLV to AVI, why not use ffmpeg to read the FLV from the RTMP server in the first place?

Dan Ballard Says:

May 31st, 2011

Can it do that for streams? If so, then because I didnt know it could and my clearly flawed google search didnt reveal that :( And glancing at their website it looks like it can. Shame on me. Thanks!

Alun Jones Says:

June 1st, 2011

ffmpeg -i “rtmp://site:port/app/file ” -vcodec copy -acodec copy -f flv output.flv

This is working for me, although I do find that often the stream gets interrupted, and theres no “resume”. [If you figure that out, Id appreciate you repeating how!] My target server requires a number of options to be given, such as the swfUrl, swfVfy, pageUrl, etc. These can each be set with options. You have, of course, to have an ffmpeg compiled with rtmp support in this is a compile-time option. The Windows downloads seem to have it. I note that the start and end time are also options (specified in milliseconds), so you should be able to make the whole operation one single ffmpeg command. To get a list of RTMP options, run the command:

ffmpeg -i “rtmp:/// =”

Alun Jones Says:

June 1st, 2011

Theres a lot about ffmpeg that is implemented, but not documented. Im still just discovering what I can use from it. Id love to know, for instance, how to add a subtitle stream.

Dan Ballard Says:

June 2nd, 2011

Well thank you very much for the info anyways. As does presumably anyone else stumbling upon this article :) Yeah, mplayer, among many crufty old and massively powerful open source project, does a poor job of documenting all the awesome tucked away inside it. Its a bit of a shame, but oh well, and good luck for anyone doing spelunking into it!