Udo Richter wrote:
I've been thinking about video cutting strategies, and I think its possible to speed up the cutting process noticeable, with some modifications to VDR.
Hi list,
I just had to do this in self-reply. ;) For reference, this is my 'original' post: http://linvdr.org/mailinglists/vdr/2004/12/msg00552.html
This has been in my mind for over two years, and now I just wanted to see it working: Using hard file system links to speed up editing whenever a 00x.vdr file is copied from source to destination recording without modification.
A first patch is available on my web page: http://www.udo-richter.de/vdr/patches.html#hlcutter http://www.udo-richter.de/vdr/patches.en.html#hlcutter
Though the patch has been working for a week for me very well, it is HIGHLY EXPERIMENTAL and should be used with caution. The patch is COMPLETELY UNTESTED and NOT ADAPTED for multiple /videoxx folders. The safety checks should prevent data loss, but hard linking may fail more often than necessary.
While editing a recording, the patch searches for any 00x.vdr files that dont contain editing marks and would normally be copied 1:1 unmodified to the edited recording. In this case the current target 00x.vdr file will be aborted, and the cutter process attempts to duplicate the source file as a hard link, so that both files share the same disk space. If this succeeds, the editing process fast-forwards through the duplicated file and continues normally beginning with the next source file. If hard linking fails, the cutter process continues with plain old copying. (but does not take up the aborted last file.)
After editing, the un-edited recording can be deleted as usual, the hard linked copies will continue to exist as the only remaining copy.
To be effective, the default 'Max. video file size (MB)' should be lowered. The patch lowers the smallest possible file size to 10mb, though this limits the recording length to 10*255 Mb (~100 minutes). A value of 100mb is a good compromise between speed improvement and recording length (~16 hours).
The patch must be enabled in Setup-> Recordings-> Hard Link Cutter. When disabled, the cutter process behaves identical to VDR's default cutter.
There's a //#define HARDLINK_TEST_ONLY in the cutter.c file that enables a test-mode that hard-links 00x.vdr_ files only, and continues the classic editing. The resulting 00x.vdr and 00x.vdr_ files should be identical. If you delete the un-edited recording, dont forget to delete the *.vdr_ files too, they will now eat real disk space.
Note: 'du' displays the disk space of hard links only on first appearance, and usually you will see a noticeably smaller size on the edited recording.
Future plans ------------
To solve the file size vs. recording size conflict, dynamic file sizes could be implemented, so that a recording starts with small file sizes, and increases the file size at some point to ensure enough space for huge recordings before 255.vdr is reached. For example, using 32Mb up to 192.vdr and 2000mb from 193.vdr on will give a total of 128 Gb or 84 hours, while using small files for up to 4 hours.
To support multiple /videoxx folders, the hard link must be placed on the same disk as the source file. This requires a more advanced linking strategy.
Since original and edited copy share disk space, free space is wrong if one of them is moved to *.del. Free space should only count files with hard link count = 1. This still goes wrong if all copies get deleted.
For more safety, the hard-linked files may be made read-only, as modifications to one copy will affect the other copy too. (except deleting, of course)
SetBrokenLink may get lost on rare cases, this needs some more thoughts.
Cheers,
Udo
Udo Richter wrote:
This has been in my mind for over two years, and now I just wanted to see it working: Using hard file system links to speed up editing whenever a 00x.vdr file is copied from source to destination recording without modification.
This has crossed my mind several times as well, thanks for implementing it!
Future plans
To solve the file size vs. recording size conflict, dynamic file sizes could be implemented, so that a recording starts with small file sizes, and increases the file size at some point to ensure enough space for huge recordings before 255.vdr is reached. For example, using 32Mb up to 192.vdr and 2000mb from 193.vdr on will give a total of 128 Gb or 84 hours, while using small files for up to 4 hours.
Why not just change the naming of video files to four, five or even eight digits?
/Richard
Hi,
Richard Lithvall wrote:
Why not just change the naming of video files to four, five or even eight digits?
The problem is not the file name, it's the index file. An index entry stores the file number as "uchar", which allows 256 recording files.
Bye.
On Sonntag, 18. März 2007, Reinhard Nissl wrote:
Hi,
Richard Lithvall wrote:
Why not just change the naming of video files to four, five or even eight digits?
The problem is not the file name, it's the index file. An index entry stores the file number as "uchar", which allows 256 recording files.
I do not know if the index file has a signature/magic-code at the start. If yes, it should be easy to define a new index-format with Longer integers for the file number.
Another thing that comes to my mind, but is sure hard to implement: If I do two or more simultanous recordings from the same channel, why couldn't VDR record this to the same file, and hardlink it to both directories. That would reduce the need to create one long recording, if one would like to record two or more shows that are broadcasted one after the other.
Matthias
Matthias Schwarzott wrote:
Another thing that comes to my mind, but is sure hard to implement: If I do two or more simultanous recordings from the same channel, why couldn't VDR record this to the same file, and hardlink it to both directories. That would reduce the need to create one long recording, if one would like to record two or more shows that are broadcasted one after the other.
This would indeed be very difficult to implement. The practical advantage however would probably be minimal. Its usually not a performance problem to do parallel recording, and there's no need for it except overlapping timers. And these overlaps of 15 minutes or so are not worth the effort.
Cheers,
Udo
Richard Lithvall wrote:
Why not just change the naming of video files to four, five or even eight digits?
The real limit is that the file format and the VDR API uses byte sized integers to represent this. (cIndexFile::Get uses an uchar *FileNumber.) This could be extended, even with moderate changes on the file format. (there are reserved bytes that could be used)
However, in any case it will break compatibility for the recording format and for the VDR API. And with some tricks, 255 files are enough too, so why break things?
Cheers,
Udo
Hello,
Udo Richter wrote:
I've been thinking about video cutting strategies, and I think its possible to speed up the cutting process noticeable, with some modifications to VDR.
i like your patch, but its work only on some recordings. Its failed with a segmentation fault, on cutting. The only differ are unbalanced marks (out missed)
======================================================================== 0:00:48.13 (in) 0:02:12.12 (out) 0:03:51.20 (in) 0:17:16.11 (out) 0:26:19.06 (in) 0:43:32.10 (out) 0:51:50.10 (in) ========================================================================
======================================================================== Core was generated by `/opt/vdr-1.4/bin/vdr -l 1 6 -v /video/vdr -L /opt/vdr-1.4/lib -s /opt/vdr-1.4/b'. Program terminated with signal 11, Segmentation fault. #0 0x080a37d7 in cCuttingThread::Action (this=0x8bbde18) at cutter.c:170 170 if (fromIndex->Get(Mark->position, &MarkFileNumber, &MarkFileOffset)
(gdb) print Mark $1 = (class cMark *) 0x0 Current language: auto; currently c++
(gdb) bt #0 0x080a37d7 in cCuttingThread::Action (this=0x8bbde18) at cutter.c:170 #1 0x0812ca45 in cThread::StartThread (Thread=0x8bbde18) at thread.c:244 #2 0xb7eff0bd in start_thread () from /lib/tls/libpthread.so.0 #3 0xb7d759ee in clone () from /lib/tls/libc.so.6 ========================================================================
HTH, Andreas
Andreas Brachold wrote:
i like your patch, but its work only on some recordings. Its failed with a segmentation fault, on cutting. The only differ are unbalanced marks (out missed)
Confirmed, the patch doesn't handle the case that the last mark is a cut-in mark, not a cut-out. In that case 'Mark' will be NULL, causing a segfault. The attached (untested) patch should do the trick.
Cheers,
Udo
Index: cutter.c =================================================================== --- cutter.c (revision 895) +++ cutter.c (working copy) @@ -167,8 +167,9 @@ uchar MarkFileNumber; int MarkFileOffset; // Get file number of next cut mark - if (fromIndex->Get(Mark->position, &MarkFileNumber, &MarkFileOffset) - && (MarkFileNumber != CurrentFileNumber)) { + if (!Mark + || fromIndex->Get(Mark->position, &MarkFileNumber, &MarkFileOffset) + && (MarkFileNumber != CurrentFileNumber)) { // The current source file will be copied completely. // Start new output file unless we did that already if (FileSize != 0) {