Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] vdrcutter2 (standalone vdr cutter)



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

i was in need for a standalone cutter/editor for the vdr recordings,
which result is stdout .. (for the repackmpeg2-v0.7)

well, i just modified the cutter.[ch] -> cutter2.[ch],
within vdr-1.2.5 to provide such a beast.

the ugly thing is .. well, everything is being linked to,
therefore the binary is about 4 MB of size .. anyway .. it works.

the big pointsa(as used in repackmpeg2):
	- just mark recordings
	- add them all to a xform.lst
	- start the worker task, which 
		- cuts
		- deplex + syncs
		- requants
		- mplex
		- remove source files

well .. TODO:
	- make dependencies smaller or better: a very single package.

	- STDIN support for vdrsync.pl, so no intermediate cut files
	  are needed !

	- convert vdrsync.pl -> ansi-c(++) 

@klaus: may be this is something for the next and very later dev. version ?

any ideas are wellcome ..

cheers, sven

- -- 
health & wealth
mailto:sgoethel@jausoft.com
www   : http://www.jausoft.com ; pgp: http://www.jausoft.com/gpg/
voice : +49-5121-999600 ; fax : +49-5121-999602
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/f4i1HdOA30NoFAARAkb7AJ98jKukRbEyO/jL909kdfR7oImYRgCfZ9NE
zBvh+g/RZHl8yJQK/Cxu2OQ=
=DFME
-----END PGP SIGNATURE-----
diff -Nur vdr-1.2.5/Makefile vdr-1.2.5-vdrcutter2/Makefile
--- vdr-1.2.5/Makefile	2003-08-09 13:09:45.000000000 +0200
+++ vdr-1.2.5-vdrcutter2/Makefile	2003-10-05 03:29:51.000000000 +0200
@@ -33,11 +33,13 @@
 
 DTVLIB   = $(DTVDIR)/libdtv.a
 
-OBJS = audio.o channels.o ci.o config.o cutter.o device.o diseqc.o dvbdevice.o dvbosd.o\
+OBJSBASE = audio.o channels.o ci.o config.o cutter.o device.o diseqc.o dvbdevice.o dvbosd.o\
        dvbplayer.o dvbspu.o eit.o eitscan.o font.o i18n.o interface.o keys.o\
        lirc.o menu.o menuitems.o osdbase.o osd.o player.o plugin.o rcu.o\
        receiver.o recorder.o recording.o remote.o remux.o ringbuffer.o sources.o\
-       spu.o status.o svdrp.o thread.o timers.o tools.o transfer.o vdr.o videodir.o
+       spu.o status.o svdrp.o thread.o timers.o tools.o transfer.o videodir.o
+
+OBJS = $(OBJSBASE) vdr.o
 
 OSDFONT = -adobe-helvetica-medium-r-normal--23-*-100-100-p-*-iso8859-1
 FIXFONT = -adobe-courier-bold-r-normal--25-*-100-100-m-*-iso8859-1
@@ -63,7 +65,7 @@
 DEFINES += -DVFAT
 endif
 
-all: vdr
+all: vdr vdrcutter2
 font: genfontfile fontfix.c fontosd.c
 	@echo "font files created."
 
@@ -86,6 +88,9 @@
 vdr: $(OBJS) $(DTVLIB)
 	$(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(NCURSESLIB) -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr
 
+vdrcutter2: cutter2.o $(OBJSBASE)
+	$(CXX) $(CXXFLAGS) -rdynamic $^ -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o $@
+
 # The font files:
 
 fontfix.c:
diff -Nur vdr-1.2.5/cutter2.c vdr-1.2.5-vdrcutter2/cutter2.c
--- vdr-1.2.5/cutter2.c	1970-01-01 01:00:00.000000000 +0100
+++ vdr-1.2.5-vdrcutter2/cutter2.c	2003-10-05 03:29:06.000000000 +0200
@@ -0,0 +1,231 @@
+/*
+ * cutter.c: The video cutting facilities
+ *
+ * See the main source file 'vdr.c' for copyright information and
+ * how to reach the author.
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+
+#include "cutter2.h"
+#include "recording.h"
+#include "remux.h"
+#include "thread.h"
+#include "videodir.h"
+
+// --- cCutting2Thread --------------------------------------------------------
+
+class cCutting2Thread : public cThread {
+private:
+  const char *error;
+  bool active;
+  int fromFile, toFile;
+  cFileName *fromFileName;
+  cIndexFile *fromIndex;
+  cMarks fromMarks;
+protected:
+  virtual void Action(void);
+public:
+  cCutting2Thread(const char *FromFileName, int foutdesc);
+  virtual ~cCutting2Thread();
+  const char *Error(void) { return error; }
+  };
+
+cCutting2Thread::cCutting2Thread(const char *FromFileName, int foutdesc)
+{
+  error = NULL;
+  active = false;
+  fromFile = toFile = -1;
+  fromFileName = NULL;
+  fromIndex = NULL;
+  if (fromMarks.Load(FromFileName) && fromMarks.Count()) {
+     fromFileName = new cFileName(FromFileName, false, true);
+     fromIndex = new cIndexFile(FromFileName, false);
+     toFile=foutdesc;
+     Start();
+     }
+  else
+     esyslog("no editing marks found for %s", FromFileName);
+}
+
+cCutting2Thread::~cCutting2Thread()
+{
+  active = false;
+  Cancel(3);
+  delete fromFileName;
+  delete fromIndex;
+}
+
+void cCutting2Thread::Action(void)
+{
+  dsyslog("video cutting thread started (pid=%d)", getpid());
+
+  cMark *Mark = fromMarks.First();
+  if (Mark) {
+     fromFile = fromFileName->Open();
+     active = fromFile >= 0 && toFile >= 0;
+     int Index = Mark->position;
+     Mark = fromMarks.Next(Mark);
+     int FileSize = 0;
+     int CurrentFileNumber = 0;
+     int LastIFrame = 0;
+     uchar buffer[MAXFRAMESIZE];
+     bool LastMark = false;
+     bool cutIn = true;
+     while (active) {
+           uchar FileNumber;
+           int FileOffset, Length;
+           uchar PictureType;
+
+           // Make sure there is enough disk space:
+
+           AssertFreeDiskSpace(-1);
+
+           // Read one frame:
+
+           if (fromIndex->Get(Index++, &FileNumber, &FileOffset, &PictureType, &Length)) {
+              if (FileNumber != CurrentFileNumber) {
+                 fromFile = fromFileName->SetOffset(FileNumber, FileOffset);
+                 CurrentFileNumber = FileNumber;
+                 }
+              if (fromFile >= 0) {
+                 int len = ReadFrame(fromFile, buffer,  Length, sizeof(buffer));
+                 if (len < 0) {
+                    error = "ReadFrame";
+                    break;
+                    }
+                 if (len != Length) {
+                    CurrentFileNumber = 0; // this re-syncs in case the frame was larger than the buffer
+                    Length = len;
+                    }
+                 }
+              else {
+                 error = "fromFile";
+                 break;
+                 }
+              }
+           else
+              break;
+
+           // Write one frame:
+
+           if (PictureType == I_FRAME) { // every file shall start with an I_FRAME
+              if (LastMark) // edited version shall end before next I-frame
+                 break;
+              LastIFrame = 0;
+
+              if (cutIn) {
+                 cRemux::SetBrokenLink(buffer, Length);
+                 cutIn = false;
+                 }
+              }
+           if (safe_write(toFile, buffer, Length) < 0) {
+              error = "safe_write";
+              break;
+              }
+           FileSize += Length;
+
+           // Check editing marks:
+
+           if (Mark && Index >= Mark->position) {
+              Mark = fromMarks.Next(Mark);
+              if (Mark) {
+                 Index = Mark->position;
+                 Mark = fromMarks.Next(Mark);
+                 CurrentFileNumber = 0; // triggers SetOffset before reading next frame
+                 cutIn = true;
+                 }
+              else
+                 LastMark = true;
+              }
+           }
+     }
+  else
+     esyslog("no editing marks found!");
+  dsyslog("end video cutting thread");
+}
+
+// --- cCutter2 ---------------------------------------------------------------
+
+cCutting2Thread *cCutter2::cuttingThread = NULL;
+bool cCutter2::error = false;
+bool cCutter2::ended = false;
+
+bool cCutter2::Start(const char *FileName)
+{
+  if (!cuttingThread) {
+     error = false;
+     ended = false;
+     cuttingThread = new cCutting2Thread(FileName, fileno(stdout));
+     return true;
+     }
+  return false;
+}
+
+void cCutter2::Stop(void)
+{
+  bool Interrupted = cuttingThread && cuttingThread->Active();
+  const char *Error = cuttingThread ? cuttingThread->Error() : NULL;
+  delete cuttingThread;
+  cuttingThread = NULL;
+  if ((Interrupted || Error)) {
+     if (Interrupted)
+        fprintf(stderr, "editing process has been interrupted");
+     if (Error)
+        fprintf(stderr, "ERROR: '%s' during editing process", Error);
+     }
+}
+
+bool cCutter2::Active(void)
+{
+  if (cuttingThread) {
+     if (cuttingThread->Active())
+        return true;
+     error = cuttingThread->Error();
+     Stop();
+     ended = true;
+     }
+  return false;
+}
+
+bool cCutter2::Error(void)
+{
+  bool result = error;
+  error = false;
+  return result;
+}
+
+bool cCutter2::Ended(void)
+{
+  bool result = ended;
+  ended = false;
+  return result;
+}
+
+int main (int argc, char * argv[])
+{
+     if(argc!=2) {
+	printf ("usage: %s <recording directory>\n", argv[0]);
+	return 1;
+     }
+
+     cMarks marks;
+
+     marks.Load(argv[1]);
+
+     if (!cCutter2::Active()) {
+        if (!marks.Count())
+           fprintf(stderr, "No editing marks defined!");
+        else if (!cCutter2::Start(argv[1]))
+           fprintf(stderr, "Can't start editing process!");
+        else {
+           fprintf(stderr, "Editing process started");
+	   while ( cCutter2::Active() ) sleep (1);
+          }
+        }
+     else
+        fprintf(stderr, "Editing process already active!");
+}
+
diff -Nur vdr-1.2.5/cutter2.h vdr-1.2.5-vdrcutter2/cutter2.h
--- vdr-1.2.5/cutter2.h	1970-01-01 01:00:00.000000000 +0100
+++ vdr-1.2.5-vdrcutter2/cutter2.h	2003-10-05 03:29:06.000000000 +0200
@@ -0,0 +1,28 @@
+/*
+ * cutter.h: The video cutting facilities
+ *
+ * See the main source file 'vdr.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id: cutter.h 1.1 2002/06/22 10:03:15 kls Exp $
+ */
+
+#ifndef __CUTTER2_H
+#define __CUTTER2_H
+
+class cCutting2Thread;
+
+class cCutter2 {
+private:
+  static cCutting2Thread *cuttingThread;
+  static bool error;
+  static bool ended;
+public:
+  static bool Start(const char *FileName);
+  static void Stop(void);
+  static bool Active(void);
+  static bool Error(void);
+  static bool Ended(void);
+  };
+
+#endif //__CUTTER2_H
Binary files vdr-1.2.5/cutter2.o and vdr-1.2.5-vdrcutter2/cutter2.o differ
Binary files vdr-1.2.5/vdrcutter2 and vdr-1.2.5-vdrcutter2/vdrcutter2 differ

Home | Main Index | Thread Index