[MPlayer-dev-eng] [PATCH] JPEG video output to multiple subdirectories

Ivo ivop at euronet.nl
Wed Jul 14 06:24:09 CEST 2004


Hi!

This is my first patch to mplayer. I hope I did everything right. I read the 
docs in DOCS/tech/patches.txt and patched against the latest CVS checkout.

Checkout date: Wed Jul 14 05:48 CEST 2004

I updated the JPEG video output code. It used to write all JPEG files to the 
same directory. After a (few) thousand files, the filesystem performance 
drops significantly. It's better to split the output and write only a 
certain amount of frames to the same directory.

I added the following options to the -jpeg comandline option:

subdirs=%s	prefix to the names of the subdirectories created in outdir
maxfiles=%d	maximum number of files written to the subdirectories

example:

$ mkdir foo
$ mplayer -vo jpeg -jpeg outdir=foo:subdirs=bar:maxfiles=1536 -ao null 
foobar.avi

Within the 'outdir' directory, several subdirs are created, in which the 
JPEG files are written.

I'll include the "cvs diff -u" inlined here and attach a file that includes 
the same. I don't know whether this mailinglist accepts attachments, that's 
why I do both. Please tell me what's the right way to submit these kind of 
patches, since I plan to add the same functionality to the .png video 
output module.

Kind regards,
--Ivo


Patch:


? vo_jpeg_patch
Index: cfg-mplayer.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
retrieving revision 1.221
diff -u -r1.221 cfg-mplayer.h
--- cfg-mplayer.h       28 Jun 2004 12:17:36 -0000      1.221
+++ cfg-mplayer.h       14 Jul 2004 04:18:48 -0000
@@ -36,6 +36,8 @@
 extern int jpeg_smooth;
 extern int jpeg_quality;
 extern char * jpeg_outdir;
+extern char * jpeg_subdirs;
+extern int jpeg_maxfiles;
 #endif
 #ifdef HAVE_SDL
 //extern char *sdl_driver;
@@ -149,6 +151,8 @@
        {"smooth", &jpeg_smooth, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
        {"quality", &jpeg_quality, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
        {"outdir", &jpeg_outdir, CONF_TYPE_STRING, 0, 0, 0, NULL},
+       {"subdirs", &jpeg_subdirs, CONF_TYPE_STRING, 0, 0, 0, NULL},
+       {"maxfiles", &jpeg_maxfiles, CONF_TYPE_INT, 0, 0, 0, NULL},
        {NULL, NULL, 0, 0, 0, 0, NULL}
 };
 #endif
Index: DOCS/man/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
retrieving revision 1.622
diff -u -r1.622 mplayer.1
--- DOCS/man/en/mplayer.1       13 Jul 2004 20:59:47 -0000      1.622
+++ DOCS/man/en/mplayer.1       14 Jul 2004 04:18:56 -0000
@@ -1926,6 +1926,10 @@
 Quality factor [0\-100]
 .IPs outdir=<value>
 Directory to save the JPEG files
+.IPs subdirs=<value>
+Prefix of the subdirectories to which the JPEG files are saved.
+.IPs maxfiles=<value>
+Maximum number of JPEG files to be saved per subdirectory.
 .RE
 .PD 1
 .
Index: libvo/vo_jpeg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_jpeg.c,v
retrieving revision 1.11
diff -u -r1.11 vo_jpeg.c
--- libvo/vo_jpeg.c     25 Apr 2003 20:37:26 -0000      1.11
+++ libvo/vo_jpeg.c     14 Jul 2004 04:18:57 -0000
@@ -36,6 +36,8 @@
 int jpeg_smooth = 0;
 int jpeg_quality = 75;
 char * jpeg_outdir = ".";
+char * jpeg_subdirs = "subdir";
+int jpeg_maxfiles=250;
 
 static int framenum=0;
 
@@ -91,10 +93,33 @@
 
 static uint32_t draw_frame(uint8_t * src[])
 {
- char buf[256];
+ static uint32_t framecounter=0, subdircounter=0;
+ char buf[512];
  uint8_t *dst= src[0];
-    
- snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum);
+ static char subdirname[256] = "subdir00000000";
+
+/* Create jpeg_outdir at first call; if it already exists, no harm is done 
*/
+ if (framecounter==0 && subdircounter==0) {
+  snprintf (buf, 512, "%s", jpeg_outdir);
+  mkdir (buf, 0755);
+ } 
+
+/* Start writing to new subdirectory after a certain amount of frames */
+ if ( framecounter == jpeg_maxfiles ) {
+  framecounter = 0;
+ }
+
+/* If framecounter is zero (or reset to zero), increment subdirectory 
number */
+ if ( framecounter == 0 ) {
+  snprintf (subdirname, 256, "%s%08d", jpeg_subdirs, subdircounter++);
+  snprintf (buf, 512, "%s/%s", jpeg_outdir, subdirname);
+  mkdir (buf, 0755);
+ }
+
+/* snprintf the full pathname of the outputfile */
+ snprintf (buf, 512, "%s/%s/%08d.jpg", jpeg_outdir, subdirname,++framenum);
+
+ framecounter++;
 
  return jpeg_write( buf,src[0] );
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vo_jpeg_patch
Type: text/x-diff
Size: 3068 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20040714/25b91a26/attachment.diff>


More information about the MPlayer-dev-eng mailing list