kruton
Joined: 12 May 2006 Posts: 2 Location: KS, USA
|
Posted: Sun Oct 21, 2007 4:41 am Post subject: sws_scale swscaler ffmpeg patch |
|
|
I didn't see anyone talking about this issue, but with the latest FFMPEG packages from ATrpms, it uses the swscaler interface and deprecates the img_convert function. As such, ZoneMinder 1.22.3 doesn't work. I wrote a patch to enable it if HAVE_SWSCALER is setup.
| Code: | --- /tmp/ZoneMinder-1.22.3/src/zm_mpeg.cpp 2006-01-17 04:56:30.000000000 -0600
+++ /tmp/ZoneMinder-1.22.3/src/zm_mpeg.cpp 2007-10-20 23:33:43.000000000 -0500
@@ -27,6 +27,10 @@
bool VideoStream::initialised = false;
+#if HAVE_SWSCALER
+static int sws_flags = SWS_BICUBIC;
+#endif
+
VideoStream::MimeData VideoStream::mime_data[] = {
{ "asf", "video/x-ms-asf" },
{ "swf", "application/x-shockwave-flash" },
@@ -116,6 +120,9 @@
// some formats want stream headers to be seperate
if(!strcmp(ofc->oformat->name, "mp4") || !strcmp(ofc->oformat->name, "mov") || !strcmp(ofc->oformat->name, "3gp"))
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
+#if HAVE_SWSCALER
+ swsContext = NULL;
+#endif
}
}
@@ -268,6 +275,13 @@
/* write the trailer, if any */
av_write_trailer(ofc);
+#if HAVE_SWSCALER
+ if (swsContext) {
+ sws_freeContext(swsContext);
+ swsContext = NULL;
+ }
+#endif
+
/* free the streams */
for( int i = 0; i < ofc->nb_streams; i++)
{
@@ -302,12 +316,33 @@
#else
AVCodecContext *c = &ost->codec;
#endif
+
if (c->pix_fmt != pf)
{
memcpy( tmp_opicture->data[0], buffer, buffer_size );
+#ifndef HAVE_SWSCALER
img_convert((AVPicture *)opicture, c->pix_fmt,
(AVPicture *)tmp_opicture, pf,
c->width, c->height);
+#else
+ swsContext = sws_getCachedContext(swsContext,
+ c->width, c->height, pf,
+ c->width, c->height, c->pix_fmt,
+ sws_flags, NULL, NULL, NULL);
+
+ if (swsContext == NULL)
+ {
+ Fatal(( "swscale context initialization failed" ));
+ return 1;
+ }
+
+ sws_scale(swsContext,
+ ((AVPicture *)tmp_opicture)->data,
+ ((AVPicture *)tmp_opicture)->linesize,
+ 0, c->height,
+ ((AVPicture *)opicture)->data,
+ ((AVPicture *)opicture)->linesize);
+#endif
}
else
{
diff -urN /tmp/ZoneMinder-1.22.3/src/zm_mpeg.h /tmp/ZoneMinder-1.22.3/src/zm_mpeg.h
--- /tmp/ZoneMinder-1.22.3/src/zm_mpeg.h 2006-07-04 05:46:16.000000000 -0500
+++ /tmp/ZoneMinder-1.22.3/src/zm_mpeg.h 2007-10-20 23:33:13.000000000 -0500
@@ -26,6 +26,10 @@
#include <ffmpeg/avformat.h>
+#if HAVE_SWSCALER
+#include <ffmpeg/swscale.h>
+#endif
+
#if FFMPEG_VERSION_INT == 0x000408
#define ZM_FFMPEG_048 1
#elif FFMPEG_VERSION_INT == 0x000409
@@ -63,6 +67,9 @@
uint8_t *video_outbuf;
int video_outbuf_size;
double pts;
+#if HAVE_SWSCALER
+ struct SwsContext *swsContext;
+#endif
protected:
static void Initialise();
|
|
|