Linux: Direct Flash Video Download

Update: Found a nice Linux console tool that allows downloading Youtube (and other) videos directly only by passing its URL as an argument: cclive


From time to time I find an interesting video in the web I want to buffer (temporarily store) for later offline viewing. In most cases these videos are hosted on one of the major video sites (e.g. YouTube or Vimeo) and are accessible via Flash plugin. But downloading is in most cases prevented (although many videos are under a creative commons license) and “download helper” tools (at least for Chrome) are not really usable.

When viewing such a video in the browser window, the video is locally cached but not directly accessible — or so I thought. A few weeks ago I stumbled across a posting which describes how to copy the contents of such a cached video into a file and thereby creating a direct copy of the video. Please note: I do not take credit for the following steps — I have read them in a Linux (Ubuntu?) forum but forgot to store a direct link to the original source. Sorry.

The first step is to open the video (and only one to avoid confusion) in your browser. Let the flash video start and thereby being cached onto your hard drive. Flash creates an inode with the name “/tmp/FlashXXzzzzzz”. It keeps the file handle open but deletes the file itself right after its creation, rendering it (in theory) inaccessible. But as the file is still open, the shell command “lsof” is still able to show it. So entering

$ lsof +L1 | grep /tmp/Flash

in the console will show all open files with “/tmp/Flash” in their name (grep) that are unlinked (+L1).

chromium- 12345 kai 25u REG 8,3 121314 0 1425364 /tmp/FlashXX1AbcdE (deleted)
i.e.
chromium- <PID> kai <FD> REG 8,3 121314 0 1425364 /tmp/FlashXX1AbcdE (deleted)

In the sample above I’m using Chromium as browser, the process ID <PID> is “12345”. The interesting number is the “25u” which represents the file descriptor <FD>. In combination with the process ID it can be used to access the cached video data. (This might have to be done with root permissions.)

$ cp /proc/12345/fd/25 /tmp/video.mp4
i.e.
$ cp /proc/<PID>/fd/<FD> /tmp/video.mp4

Now the file “video.mp4” should contain the video (stream) data in a playable form. Keep in mind: if the caching process was not finished while copying, the video file will also be incomplete.

Leave a Reply

Your email address will not be published.