Author: rafael2k
Date: 2008-04-11 05:07:55 +0200 (Fri, 11 Apr 2008)
New Revision: 1056
Modified:
trunk/hvirtual/cinelerra/ffmpeg.C
trunk/hvirtual/cinelerra/ffmpeg.h
trunk/hvirtual/configure.in
Log:
ffmpeg swscale patch
Modified: trunk/hvirtual/cinelerra/ffmpeg.C
===================================================================
--- trunk/hvirtual/cinelerra/ffmpeg.C 2008-03-08 22:33:45 UTC (rev 1055)
+++ trunk/hvirtual/cinelerra/ffmpeg.C 2008-04-11 03:07:55 UTC (rev 1056)
@@ -1,10 +1,18 @@
#include <string.h>
+#ifdef HAVE_SWSCALER
+extern "C" {
+#include <swscale.h>
+}
+#endif
+
+
#include "filebase.h"
#include "quicktime.h"
#include "ffmpeg.h"
#include "guicast.h"
+
FFMPEG::FFMPEG(Asset *asset) {
this->asset = asset;
codec = 0;
@@ -139,23 +147,49 @@
color_model_to_pix_fmt(frame_in->get_color_model());
PixelFormat pix_fmt_out =
color_model_to_pix_fmt(frame_out->get_color_model());
-
+#ifdef HAVE_SWSCALER
+ // We need a context for swscale
+ struct SwsContext *convert_ctx;
+#endif
// do conversion within libavcodec if possible
if (pix_fmt_in != PIX_FMT_NB && pix_fmt_out != PIX_FMT_NB) {
// set up a temporary pictures from frame_in and frame_out
AVPicture picture_in, picture_out;
init_picture_from_frame(&picture_in, frame_in);
init_picture_from_frame(&picture_out, frame_out);
-
- int result = img_convert(&picture_out,
- pix_fmt_out,
- &picture_in,
- pix_fmt_in,
- frame_in->get_w(),
- frame_out->get_h());
+ int result;
+#ifndef HAVE_SWSCALER
+ result = img_convert(&picture_out,
+ pix_fmt_out,
+ &picture_in,
+ pix_fmt_in,
+ frame_in->get_w(),
+ frame_out->get_h());
if (result) {
printf("FFMPEG::convert_cmodel img_convert() failed\n");
}
+#else
+ convert_ctx = sws_getContext(frame_in->get_w(), frame_in->get_h(),pix_fmt_in,
+ frame_out->get_w(),frame_out->get_h(),pix_fmt_out,
+ SWS_BICUBIC, NULL, NULL, NULL);
+
+ if(convert_ctx == NULL){
+ printf("FFMPEG::convert_cmodel : swscale context initialization failed\n");
+ return 1;
+ }
+
+ result = sws_scale(convert_ctx,
+ picture_in.data, picture_in.linesize,
+ frame_in->get_w(), frame_in->get_h(),
+ picture_out.data, picture_out.linesize);
+
+
+ sws_freeContext(convert_ctx);
+
+ if(result){
+ printf("FFMPEG::convert_cmodel sws_scale() failed\n");
+ }
+#endif
return result;
}
@@ -207,20 +241,48 @@
int cmodel_out = frame_out->get_color_model();
PixelFormat pix_fmt_out = color_model_to_pix_fmt(cmodel_out);
+#ifdef HAVE_SWSCALER
+ // We need a context for swscale
+ struct SwsContext *convert_ctx;
+#endif
+ int result;
+#ifndef HAVE_SWSCALER
// do conversion within libavcodec if possible
if (pix_fmt_out != PIX_FMT_NB) {
- int result = img_convert(&picture_out,
- pix_fmt_out,
- picture_in,
- pix_fmt_in,
- width_in,
- height_in);
+ result = img_convert(&picture_out,
+ pix_fmt_out,
+ picture_in,
+ pix_fmt_in,
+ width_in,
+ height_in);
if (result) {
printf("FFMPEG::convert_cmodel img_convert() failed\n");
}
return result;
}
+#else
+ convert_ctx = sws_getContext(width_in, height_in,pix_fmt_in,
+ frame_out->get_w(),frame_out->get_h(),pix_fmt_out,
+ SWS_BICUBIC, NULL, NULL, NULL);
+
+ if(convert_ctx == NULL){
+ printf("FFMPEG::convert_cmodel : swscale context initialization failed\n");
+ return 1;
+ }
+
+ result = sws_scale(convert_ctx,
+ picture_in->data, picture_in->linesize,
+ width_in, height_in,
+ picture_out.data, picture_out.linesize);
+
+ sws_freeContext(convert_ctx);
+
+ if(result){
+ printf("FFMPEG::convert_cmodel sws_scale() failed\n");
+ }
+#endif
+
// make an intermediate temp frame only if necessary
int cmodel_in = pix_fmt_to_color_model(pix_fmt_in);
if (cmodel_in == BC_TRANSPARENCY) {
Modified: trunk/hvirtual/cinelerra/ffmpeg.h
===================================================================
--- trunk/hvirtual/cinelerra/ffmpeg.h 2008-03-08 22:33:45 UTC (rev 1055)
+++ trunk/hvirtual/cinelerra/ffmpeg.h 2008-04-11 03:07:55 UTC (rev 1056)
@@ -3,7 +3,7 @@
extern "C" {
#include <avcodec.h>
-};
+}
#include "asset.h"
#include "guicast.h"
Modified: trunk/hvirtual/configure.in
===================================================================
--- trunk/hvirtual/configure.in 2008-03-08 22:33:45 UTC (rev 1055)
+++ trunk/hvirtual/configure.in 2008-04-11 03:07:55 UTC (rev 1056)
@@ -345,9 +345,30 @@
AC_ARG_WITH([external-ffmpeg], AC_HELP_STRING([--with-external-ffmpeg], [use external ffmpeg library]))
if test "x$with_external_ffmpeg" = "xyes"; then
- PKG_CHECK_MODULES([FFMPEG], [libavcodec libpostproc])
+ PKG_CHECK_MODULES([FFMPEG_TEMP], [libavcodec libpostproc])
FFMPEG_FOLDER=""
FFMPEG_EXTERNALTEXT="External ffmpeg"
+
+ dnl --------------------------------------------------------------
+ dnl check if libavcodec contains img_convert
+ dnl if not, that means that libswscale is compiled in
+
+ AC_MSG_CHECKING(for ffmpeg swscale support)
+ saved_LIBS="$LIBS"
+ LIBS="$saved_LIBS $FFMPEG_TEMP_LIBS"
+ AC_TRY_LINK([#include <libavcodec/avcodec.h>],
+ [img_convert(0, 0, 0,0,0,0)],
+ enable_ffmpeg_swscale=no,enable_ffmpeg_swscale=yes)
+ LIBS="$saved_LIBS"
+ AC_MSG_RESULT($enable_ffmpeg_swscale)
+ if test x"$enable_ffmpeg_swscale" = xyes; then
+ dnl AC_DEFINE(HAVE_SWSCALER)
+ PKG_CHECK_MODULES([FFMPEG], [libavcodec libpostproc libswscale])
+ FFMPEG_CFLAGS="$FFMPEG_CFLAGS -I/usr/include/libavcodec -I/usr/include/libswscale -DHAVE_SWSCALER"
+ else
+ PKG_CHECK_MODULES([FFMPEG], [libavcodec libpostproc])
+ fi
+ FFMPEG_EXTERNALTEXT="External ffmpeg"
else
FFMPEG_FOLDER=ffmpeg
FFMPEG_CFLAGS="-I\$(top_srcdir)/quicktime/ffmpeg/libavcodec"
_______________________________________________
Cinelerra-commits mailing list
Cinelerra-commits@???
https://init.linpro.no/mailman/skolelinux.no/listinfo/cinelerra-commits