[hatari-devel] [patch] AVI recording PNG compression level

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

Douglas commented that depending on (Falcon screen) content,
AVI recording performance can drastically change:
http://www.atari-forum.com/viewtopic.php?f=68&t=26775&p=261461#p261358

Attached is patch allowing to specify PNG compression
level from command line, in case someone wants to
experiment with it.

According to png.h header, levels 3-6 would offer nearly
same compression for PNGs as Hatari's default (9, highest),
but potentially with significantly lower CPU overhead.



	- Eero

PS. When we were (nearly decade ago) testing different
image format libraries for ARM and optimizing them, JPG
compression and decompression were in general clearly faster
than PNG.  PNG was better just in not losing details from
images with high contrast / few colors.  C-code for JPG
handling was also much more natural fit for SIMD
optimizations.

-> Especially for recording Falcon hi-color demos,
   JPG compression could be better fit than PNG.
diff -r 1fc4d1648073 src/avi_record.c
--- a/src/avi_record.c	Mon Nov 03 22:21:53 2014 +0200
+++ b/src/avi_record.c	Sun Nov 09 17:43:20 2014 +0200
@@ -954,13 +954,32 @@
 }
 
 
+/* PNG compression level, 0-9 */
+static int compression_level = 9;
+
+/**
+ * Set recording level from given string
+ * return true for valid, false for invalid value
+ */
+bool Avi_SetCompressionLevel(const char *str)
+{
+	char *end;
+	long level = strtol(str, &end, 10);
+	if (*end)
+		return false;
+	if (level < 0 || level > 9)
+		return false;
+	compression_level = level;
+	return true;
+}
+
 
 bool	Avi_StartRecording ( char *FileName , bool CropGui , Uint32 Fps , Uint32 Fps_scale , int VideoCodec )
 {
 	memset ( &AviParams , 0 , sizeof ( AviParams ) );
 
 	AviParams.VideoCodec = VideoCodec;
-	AviParams.VideoCodecCompressionLevel = 9;	/* png compression level */
+	AviParams.VideoCodecCompressionLevel = compression_level;
 	AviParams.AudioCodec = AVI_RECORD_AUDIO_CODEC_PCM;
 	AviParams.AudioFreq = ConfigureParams.Sound.nPlaybackFreq;
 	AviParams.Surface = sdlscrn;
diff -r 1fc4d1648073 src/includes/avi_record.h
--- a/src/includes/avi_record.h	Mon Nov 03 22:21:53 2014 +0200
+++ b/src/includes/avi_record.h	Sun Nov 09 17:43:20 2014 +0200
@@ -25,6 +25,7 @@
 extern bool	Avi_RecordAudioStream ( Sint16 pSamples[][2] , int SampleIndex , int SampleLength );
 
 extern bool	Avi_AreWeRecording ( void );
+extern bool	Avi_SetCompressionLevel(const char *str);
 extern bool	Avi_StartRecording ( char *FileName , bool CropGui , Uint32 Fps , Uint32 Fps_scale , int VideoCodec );
 extern bool	Avi_StopRecording ( void );
 
diff -r 1fc4d1648073 src/options.c
--- a/src/options.c	Mon Nov 03 22:21:53 2014 +0200
+++ b/src/options.c	Sun Nov 09 17:43:20 2014 +0200
@@ -86,6 +86,7 @@
 	OPT_SCREEN_CROP,        /* screen capture options */
 	OPT_AVIRECORD,
 	OPT_AVIRECORD_VCODEC,
+	OPT_AVIRECORD_LEVEL,
 	OPT_AVIRECORD_FPS,
 	OPT_AVIRECORD_FILE,
 	OPT_JOYSTICK,		/* device options */
@@ -250,11 +251,13 @@
 	{ OPT_AVIRECORD, NULL, "--avirecord",
 	  NULL, "Start AVI recording" },
 	{ OPT_AVIRECORD_VCODEC, NULL, "--avi-vcodec",
-	  "<x>", "Select avi video codec (x = bmp/png)" },
+	  "<x>", "Select AVI video codec (x = bmp/png)" },
+	{ OPT_AVIRECORD_LEVEL, NULL, "--avi-level",
+	  "<x>", "Select AVI PNG compression level (x = 0-9)" },
 	{ OPT_AVIRECORD_FPS, NULL, "--avi-fps",
-	  "<x>", "Force avi frame rate (x = 50/60/71/...)" },
+	  "<x>", "Force AVI frame rate (x = 50/60/71/...)" },
 	{ OPT_AVIRECORD_FILE, NULL, "--avi-file",
-	  "<file>", "Use <file> to record avi" },
+	  "<file>", "Use <file> to record AVI" },
 
 	{ OPT_HEADER, NULL, NULL, NULL, "Devices" },
 	{ OPT_JOYSTICK,  "-j", "--joystick",
@@ -1109,6 +1112,12 @@
 			}
 			break;
 
+		case OPT_AVIRECORD_LEVEL:
+			i += 1;
+			if (!Avi_SetCompressionLevel(argv[i]))
+				return Opt_ShowError(OPT_AVIRECORD_LEVEL, argv[i], "Invalid compression level");
+			break;
+
 		case OPT_AVIRECORD_FPS:
 			val = atoi(argv[++i]);
 			if (val < 0 || val > 100)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/