Synfig Project Forum

Forums for Synfig Project
It is currently Wed May 22, 2013 12:06 pm

All times are UTC - 4 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: developer challenge!
PostPosted: Mon Jun 23, 2008 8:03 am 
Offline
Site Admin
User avatar

Joined: Fri Nov 30, 2007 8:25 pm
Posts: 292
Hi all,

This topic is for anyone who wants to contribute to the code and get their name into the about dialog of synfigstudio!

Today's challenge is to port the libav plugin to a newer version of ffmpeg. ffmpeg upstream developers have depreciated the img_convert function and written a new library, libswscale, that does a similar thing. Your challenge will be to change the code to use the new library and change the build scripts so that it checks for and builds against the new libswscale library. The ideal patch will also revert to using img_convert when libswscale is not available.

A bit extra information is available in this Debian bug:

http://bugs.debian.org/487639

If anyone needs some help, feel free to ping me on IRC.

I'll try and come up with one challenge every two weeks or so, so it would be great if people were interested in helping solve them!

_________________
bye, pabs


Top
 Profile  
 
 Post subject: Re: developer challenge!
PostPosted: Sat Aug 02, 2008 3:06 pm 
Is this what you're looking for? Below is a basic path that adds the required code and the detection of libswscale. There are four points of discussion though:
* I used a pair of sws_getContext/sws_freeContext because I'm not clear on the multi-threading aspect. Otherwise sws_getCachedContext could probably be used.
* I've taken the SWS_BICUBIC interpolation from the example link, but a simpeler interpolation computation might be sufficient.
* On my system the fallback (deprecated function img_convert) is detected, and compiles, but the code fails (apparently somewhere else before my changes are touched.
* The output looks okay, but I've not looked at it in detail.

With regards,
Gerco.


Index: src/modules/mod_libavcodec/trgt_av.cpp
===================================================================
--- src/modules/mod_libavcodec/trgt_av.cpp (revision 2030)
+++ src/modules/mod_libavcodec/trgt_av.cpp (working copy)
@@ -36,6 +36,9 @@
extern "C"
{
#include <avformat.h>
+#ifdef HAVE_LIBSWSCALE
+# include <ffmpeg/swscale.h>
+#endif
}

#include <synfig/general.h>
@@ -386,13 +389,26 @@
}


- if ( pict && context->pix_fmt != PIX_FMT_RGB24 )
+ if (pict && context->pix_fmt != PIX_FMT_RGB24)
{
- //We're using RGBA at the moment, write custom conversion code later (get less accuracy errors)
+ // We're using RGBA at the moment, write custom conversion code later
+ // (get less accuracy errors).
+#ifdef HAVE_LIBSWSCALE
+ struct SwsContext* img_convert_ctx =
+ sws_getContext(context->width, context->height, PIX_FMT_RGB24,
+ context->width, context->height, context->pix_fmt,
+ SWS_BICUBIC, NULL, NULL, NULL);
+
+ sws_scale(img_convert_ctx, pict->data, pict->linesize,
+ 0, context->height, encodable->data,
+ encodable->linesize);
+
+ sws_freeContext (img_convert_ctx);
+#else
img_convert((AVPicture *)encodable, context->pix_fmt,
- (AVPicture *)pict, PIX_FMT_RGB24,
- context->width, context->height);
-
+ (AVPicture *)pict, PIX_FMT_RGB24,
+ context->width, context->height);
+#endif
pict = encodable;
}

Index: configure.ac
===================================================================
--- configure.ac (revision 2030)
+++ configure.ac (working copy)
@@ -246,7 +246,33 @@
} ; fi


+if test $with_libavcodec = "yes" ; then {
+ AC_ARG_WITH(libswscale,
+ [AS_HELP_STRING([--without-libswscale],
+ [disable support for libswscale (Default=auto)])],
+ [],
+ [with_libswscale="yes"]
+ )

+ if test $with_libswscale != "no" ; then {
+ AC_CHECK_LIB(swscale, sws_getContext, [], [echo no; with_libswscale="no"], [])
+ } ; fi
+
+ if test $with_libswscale = "yes" ; then {
+ LIBAVCODEC_LIBS="$LIBAVCODEC_LIBS -lswscale"
+ AM_CONDITIONAL(HAVE_LIBSWSCALE, true)
+ } else {
+ AM_CONDITIONAL(HAVE_LIBSWSCALE, false)
+
+ AC_CHECK_LIB(avcodec, img_convert,
+ [AC_MSG_RESULT([ *** Using deprecated function img_convert.])],
+ [AC_MSG_FAILURE([Neither libswscale nor function img_convert was found.])],
+ []
+ )
+ } ; fi
+} ; fi
+
+
# FREETYPE2 CHECK--------------------

AC_ARG_WITH(freetype,[
@@ -647,6 +673,7 @@
FreeType2 ------------------------> $with_freetype
fontconfig -----------------------> $with_fontconfig
libavcodec -----------------------> $with_libavcodec
+libswscale -----------------------> $with_libswscale
vImage ---------------------------> $with_vimage
ImageMagick ----------------------> $with_imagemagick
Magick++ -------------------------> $with_magickpp


Top
  
 
 Post subject: Re: developer challenge!
PostPosted: Sun Aug 03, 2008 4:54 am 
Offline
Site Admin
User avatar

Joined: Sat Dec 01, 2007 6:26 am
Posts: 4127
Location: Spain
Hi Gerco!
your patch is welcome!!. I hope pabs3 can commit it after he return from the meeting in Argentina.
You're invited to place this or other patches at

https://sourceforge.net/projects/synfig/

Thanks for your help :)

-G

_________________
Synfig needs your help!
Developers, packagers, bug testers, translators, artists, web developers, wiki writers... you can contribute! :D


Top
 Profile  
 
 Post subject: Re: developer challenge!
PostPosted: Sun Aug 03, 2008 12:02 pm 
OK.

I added my patch to the patch list of sourceforge.

I noticed that
* ImgReSampleContext
* AVFrac
are also deprecated.

Gerco.


Top
  
 
 Post subject: Re: developer challenge!
PostPosted: Sun Aug 03, 2008 2:08 pm 
Offline
Site Admin
User avatar

Joined: Sat Dec 01, 2007 6:26 am
Posts: 4127
Location: Spain
Hey Gerco,
we would be so pleased if you drop by the Synfig IRC and let us meet you and talk about synfig developing.
During the summer some people is missing but most of the time major contributors of synfig are there. I'm project contributor but I'm not prepared yet to send any useful patch. I hope one day I can, though. :)

Again welcome and thanks for your help. :D

-G

_________________
Synfig needs your help!
Developers, packagers, bug testers, translators, artists, web developers, wiki writers... you can contribute! :D


Top
 Profile  
 
 Post subject: Re: developer challenge!
PostPosted: Wed Aug 06, 2008 3:12 pm 
Offline
Site Admin
User avatar

Joined: Fri Nov 30, 2007 8:25 pm
Posts: 292
AFAICT, synfig's mod_libav doesn't use ImgReSampleContext or AVFrac.

I applied your patch to svn with a few minor modifications and it works nicely.

Update: my commit actually failed. Once sf.net has fixed the issue I'll apply your patch.

The only issue I can see is that there are some buffer underflow messages sometimes.

The SWS_BICUBIC can be changed when/if output targets are allowed to accept arbitrary parameters.

It would be great to see you on IRC :)

_________________
bye, pabs


Top
 Profile  
 
 Post subject: Re: developer challenge!
PostPosted: Wed Aug 06, 2008 5:38 pm 
Offline
User avatar

Joined: Mon Aug 04, 2008 6:10 pm
Posts: 265
Location: Amsterdam, the Netherlands
Hi,

You're right about ImgReSampleContext and AVFrac. The warnings originate in ffmpeg/avcodec.h en ffmpeg/avformat.h. So, that's probably an issue of my development environment (Debian 4).

W.r.t. the SWS_BICUBIC parameter, is it actually used or relevant when the image size remains the same and there is only a format change?

Gerco.


Top
 Profile  
 
 Post subject: Re: developer challenge!
PostPosted: Thu Aug 07, 2008 10:52 am 
Offline
Site Admin
User avatar

Joined: Fri Nov 30, 2007 8:25 pm
Posts: 292
No idea about SWS_BICUBIC as I haven't read the libswscale code, I would assume that it would not be used when the size isn't changed though.

_________________
bye, pabs


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 4 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group