Ubuntu – Save video which is playing in vlc

data-recoveryvideovlc

Weird question, but here's the context. I was playing a video in VLC on Ubuntu 16.04. I accidentally deleted the video while I was still playing it. I can still move to any point on the video stream in VLC and play it, but the physical file is deleted from the disk.

Is there a way to recover this cache? I still have VLC open.

Edit per comments:

lsof | grep vlc | grep dvgrab

returns

vlc       2671           peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2674      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2676      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2677      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2686      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2689      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2692      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2694      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2695      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2696      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2697      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2698      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2699      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2700      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)

Best Answer

As @ridgy so helpfully pointed out in the comments:

As long as the file is in use it will not be really deleted, but removed from the directory. The inode of the file is still in use. You may find the inode number by issuing lsof | grep vlc; this will show a file with no name and the message (deleted) instead. The inode number is the number in front of that. You can then relink the file to the directory with ln <inode#> <filename>.

And later on:

The inode is 45 (the number in front of the file path). But I just realized that ln does not work on inodes (could not get it to work..). But as you see that the file is used by vlc, filedescriptor # 31 (see 31r before REG), you could do cat /proc/2671/fd/31 > file_to_save, which will copy the content to a new file. 2671 is the process # of vlc (number after vlc).

And, indeed, running

 cat /proc/2671/fd/31 > file_to_save

grabbed the file and stored it to my hard drive. Thanks!

Related Question