From: Diego Barrios Romero Date: Fri, 19 Feb 2010 00:51:48 +0000 (+0100) Subject: New targets parameters class. Tool accepts video codec and bitrate parameters. All... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6202fa9106fb2e71a2684094cb534eda9588fadd;p=synfig.git New targets parameters class. Tool accepts video codec and bitrate parameters. All modules updated. --- diff --git a/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp b/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp index 2985c53..fe2d433 100644 --- a/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp +++ b/synfig-core/src/modules/mod_bmp/trgt_bmp.cpp @@ -110,7 +110,7 @@ inline short little_endian_short(const short &x) #define little_endian_short(x) (x) #endif -bmp::bmp(const char *Filename) +bmp::bmp(const char *Filename, const synfig::TargetParam& /* params */) { file=NULL; filename=Filename; diff --git a/synfig-core/src/modules/mod_bmp/trgt_bmp.h b/synfig-core/src/modules/mod_bmp/trgt_bmp.h index 8a045c7..9d93b97 100644 --- a/synfig-core/src/modules/mod_bmp/trgt_bmp.h +++ b/synfig-core/src/modules/mod_bmp/trgt_bmp.h @@ -29,6 +29,7 @@ #include #include +#include #include /* === M A C R O S ========================================================= */ @@ -51,7 +52,7 @@ private: synfig::PixelFormat pf; public: - bmp(const char *filename); + bmp(const char *filename, const synfig::TargetParam& /* params */); virtual ~bmp(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_dv/trgt_dv.cpp b/synfig-core/src/modules/mod_dv/trgt_dv.cpp index 13fed5c..6174af0 100644 --- a/synfig-core/src/modules/mod_dv/trgt_dv.cpp +++ b/synfig-core/src/modules/mod_dv/trgt_dv.cpp @@ -80,7 +80,8 @@ SYNFIG_TARGET_SET_CVS_ID(dv_trgt,"$Id$"); /* === M E T H O D S ======================================================= */ -dv_trgt::dv_trgt(const char *Filename) +dv_trgt::dv_trgt(const char *Filename, + const synfig::TargetParam& /* params */) { pid=-1; file=NULL; diff --git a/synfig-core/src/modules/mod_dv/trgt_dv.h b/synfig-core/src/modules/mod_dv/trgt_dv.h index 11ba75e..7cb544c 100644 --- a/synfig-core/src/modules/mod_dv/trgt_dv.h +++ b/synfig-core/src/modules/mod_dv/trgt_dv.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -53,7 +54,7 @@ private: unsigned char *buffer; synfig::Color *color_buffer; public: - dv_trgt(const char *filename); + dv_trgt(const char *filename, const synfig::TargetParam& /* params */); virtual ~dv_trgt(); diff --git a/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp b/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp index 5b5b2bc..0f2a728 100644 --- a/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp +++ b/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp @@ -7,6 +7,7 @@ ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** Copyright (c) 2007 Chris Moore +** Copyright (c) 2010 Diego Barrios Romero ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -79,7 +80,8 @@ SYNFIG_TARGET_SET_CVS_ID(ffmpeg_trgt,"$Id$"); /* === M E T H O D S ======================================================= */ -ffmpeg_trgt::ffmpeg_trgt(const char *Filename) +ffmpeg_trgt::ffmpeg_trgt(const char *Filename, + const synfig::TargetParam& params) { pid=-1; file=NULL; @@ -88,6 +90,8 @@ ffmpeg_trgt::ffmpeg_trgt(const char *Filename) buffer=NULL; color_buffer=0; set_remove_alpha(); + video_codec = params.video_codec; + bitrate = params.bitrate; } ffmpeg_trgt::~ffmpeg_trgt() @@ -158,9 +162,23 @@ ffmpeg_trgt::init() string command; if( filename.c_str()[0] == '-' ) - command=strprintf("ffmpeg -f image2pipe -vcodec ppm -an -r %f -i pipe: -loop -hq -title \"%s\" -vcodec mpeg1video -y -- \"%s\"\n",desc.get_frame_rate(),get_canvas()->get_name().c_str(),filename.c_str()); + command = strprintf("ffmpeg -f image2pipe -vcodec ppm -an" + " -r %f -i pipe: -loop -hq" + " -title \"%s\" -vcodec %s -b %i" + " -y -- \"%s\"\n", + desc.get_frame_rate(), + get_canvas()->get_name().c_str(), + video_codec.c_str(), bitrate, + filename.c_str()); else - command=strprintf("ffmpeg -f image2pipe -vcodec ppm -an -r %f -i pipe: -loop -hq -title \"%s\" -vcodec mpeg1video -y \"%s\"\n",desc.get_frame_rate(),get_canvas()->get_name().c_str(),filename.c_str()); + command = strprintf("ffmpeg -f image2pipe -vcodec ppm -an" + " -r %f -i pipe: -loop -hq" + " -title \"%s\" -vcodec %s -b %i" + " -y -- \"%s\"\n", + desc.get_frame_rate(), + get_canvas()->get_name().c_str(), + video_codec.c_str(), bitrate, + filename.c_str()); file=popen(command.c_str(),POPEN_BINARY_WRITE_TYPE); @@ -192,9 +210,24 @@ ffmpeg_trgt::init() // Close the unneeded pipeout close(p[0]); if( filename.c_str()[0] == '-' ) - execlp("ffmpeg", "ffmpeg", "-f", "image2pipe", "-vcodec", "ppm", "-an", "-r", strprintf("%f", desc.get_frame_rate()).c_str(), "-i", "pipe:", "-loop", "-hq", "-title", get_canvas()->get_name().c_str(), "-vcodec", "mpeg1video", "-y", "--", filename.c_str(), (const char *)NULL); + execlp("ffmpeg", "ffmpeg", "-f", "image2pipe", "-vcodec", + "ppm", "-an", "-r", + strprintf("%f", desc.get_frame_rate()).c_str(), + "-i", "pipe:", "-loop", "-hq", + "-title", get_canvas()->get_name().c_str(), + "-vcodec", video_codec.c_str(), + "-b", bitrate, + "-y", "--", filename.c_str(), (const char *)NULL); else - execlp("ffmpeg", "ffmpeg", "-f", "image2pipe", "-vcodec", "ppm", "-an", "-r", strprintf("%f", desc.get_frame_rate()).c_str(), "-i", "pipe:", "-loop", "-hq", "-title", get_canvas()->get_name().c_str(), "-vcodec", "mpeg1video", "-y", filename.c_str(), (const char *)NULL); + execlp("ffmpeg", "ffmpeg", "-f", "image2pipe", "-vcodec", + "ppm", "-an", "-r", + strprintf("%f", desc.get_frame_rate()).c_str(), + "-i", "pipe:", "-loop", "-hq", + "-title", get_canvas()->get_name().c_str(), + "-vcodec", video_codec.c_str(), + "-b", bitrate, + "-y", filename.c_str(), (const char *)NULL); + // We should never reach here unless the exec failed synfig::error(_("Unable to open pipe to ffmpeg")); return false; diff --git a/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.h b/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.h index c5fc1ae..d723bae 100644 --- a/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.h +++ b/synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.h @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2010 Diego Barrios Romero ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -31,6 +32,7 @@ #include #include +#include #include #include @@ -40,6 +42,8 @@ /* === C L A S S E S & S T R U C T S ======================================= */ +class TargetParam; + class ffmpeg_trgt : public synfig::Target_Scanline { SYNFIG_TARGET_MODULE_EXT @@ -51,8 +55,11 @@ private: synfig::String filename; unsigned char *buffer; synfig::Color *color_buffer; + std::string video_codec; + int bitrate; public: - ffmpeg_trgt(const char *filename); + ffmpeg_trgt(const char *filename, + const synfig::TargetParam& params); virtual bool set_rend_desc(synfig::RendDesc *desc); virtual bool init(); diff --git a/synfig-core/src/modules/mod_gif/trgt_gif.cpp b/synfig-core/src/modules/mod_gif/trgt_gif.cpp index 2068995..a520ff3 100644 --- a/synfig-core/src/modules/mod_gif/trgt_gif.cpp +++ b/synfig-core/src/modules/mod_gif/trgt_gif.cpp @@ -57,7 +57,7 @@ SYNFIG_TARGET_SET_CVS_ID(gif,"$Id$"); /* === M E T H O D S ======================================================= */ -gif::gif(const char *filename_): +gif::gif(const char *filename_, const synfig::TargetParam& /* params */): filename(filename_), file( (filename=="-")?stdout:fopen(filename_,POPEN_BINARY_WRITE_TYPE) ), imagecount(0), diff --git a/synfig-core/src/modules/mod_gif/trgt_gif.h b/synfig-core/src/modules/mod_gif/trgt_gif.h index ae10e31..fa90efd 100644 --- a/synfig-core/src/modules/mod_gif/trgt_gif.h +++ b/synfig-core/src/modules/mod_gif/trgt_gif.h @@ -35,6 +35,7 @@ #include #include #include +#include /* === M A C R O S ========================================================= */ @@ -194,7 +195,7 @@ private: void output_curr_palette(); public: - gif(const char *filename); + gif(const char *filename, const synfig::TargetParam& /* params */); virtual bool set_rend_desc(synfig::RendDesc *desc); virtual bool init(); diff --git a/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.cpp b/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.cpp index 32dd839..dc024ae 100644 --- a/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.cpp +++ b/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.cpp @@ -80,7 +80,8 @@ SYNFIG_TARGET_SET_CVS_ID(imagemagick_trgt,"$Id$"); /* === M E T H O D S ======================================================= */ -imagemagick_trgt::imagemagick_trgt(const char *Filename) +imagemagick_trgt::imagemagick_trgt(const char *Filename, + const synfig::TargetParam& /* params */) { pid=-1; file=NULL; diff --git a/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.h b/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.h index 2a9a171..253fb4c 100644 --- a/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.h +++ b/synfig-core/src/modules/mod_imagemagick/trgt_imagemagick.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -54,7 +55,8 @@ private: synfig::Color *color_buffer; synfig::PixelFormat pf; public: - imagemagick_trgt(const char *filename); + imagemagick_trgt(const char *filename, + const synfig::TargetParam& /* params */); virtual ~imagemagick_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_jpeg/trgt_jpeg.cpp b/synfig-core/src/modules/mod_jpeg/trgt_jpeg.cpp index 3ff854d..b0def32 100644 --- a/synfig-core/src/modules/mod_jpeg/trgt_jpeg.cpp +++ b/synfig-core/src/modules/mod_jpeg/trgt_jpeg.cpp @@ -58,7 +58,8 @@ SYNFIG_TARGET_SET_CVS_ID(jpeg_trgt,"$Id$"); /* === M E T H O D S ======================================================= */ -jpeg_trgt::jpeg_trgt(const char *Filename) +jpeg_trgt::jpeg_trgt(const char *Filename, + const synfig::TargetParam& /* params */) { file=NULL; filename=Filename; diff --git a/synfig-core/src/modules/mod_jpeg/trgt_jpeg.h b/synfig-core/src/modules/mod_jpeg/trgt_jpeg.h index 65518d0..8cbb4dc 100644 --- a/synfig-core/src/modules/mod_jpeg/trgt_jpeg.h +++ b/synfig-core/src/modules/mod_jpeg/trgt_jpeg.h @@ -32,6 +32,7 @@ #define NOMINMAX #include #include +#include #include _ETL_BEGIN_CDECLS #include @@ -60,7 +61,7 @@ private: unsigned char *buffer; synfig::Color *color_buffer; public: - jpeg_trgt(const char *filename); + jpeg_trgt(const char *filename, const synfig::TargetParam& /* params */); virtual ~jpeg_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_libavcodec/trgt_av.cpp b/synfig-core/src/modules/mod_libavcodec/trgt_av.cpp index 5ad733a..f329081 100644 --- a/synfig-core/src/modules/mod_libavcodec/trgt_av.cpp +++ b/synfig-core/src/modules/mod_libavcodec/trgt_av.cpp @@ -815,7 +815,8 @@ public: /* === M E T H O D S ======================================================= */ -Target_LibAVCodec::Target_LibAVCodec(const char *Filename): +Target_LibAVCodec::Target_LibAVCodec(const char *Filename, + const synfig::TargetParam& /* params */): filename(Filename) { if(!registered) diff --git a/synfig-core/src/modules/mod_libavcodec/trgt_av.h b/synfig-core/src/modules/mod_libavcodec/trgt_av.h index a2df7d7..3b09af2 100644 --- a/synfig-core/src/modules/mod_libavcodec/trgt_av.h +++ b/synfig-core/src/modules/mod_libavcodec/trgt_av.h @@ -29,6 +29,7 @@ #include #include +#include #include #include "synfig/surface.h" @@ -52,7 +53,8 @@ private: synfig::Surface surface; public: - Target_LibAVCodec(const char *filename); + Target_LibAVCodec(const char *filename, + const synfig::TargetParam& /* params */); virtual ~Target_LibAVCodec(); virtual bool init(); diff --git a/synfig-core/src/modules/mod_magickpp/trgt_magickpp.h b/synfig-core/src/modules/mod_magickpp/trgt_magickpp.h index 57a0c01..8705e1d 100644 --- a/synfig-core/src/modules/mod_magickpp/trgt_magickpp.h +++ b/synfig-core/src/modules/mod_magickpp/trgt_magickpp.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -54,7 +55,9 @@ private: public: - magickpp_trgt(const char *filename) : filename(filename) { } + magickpp_trgt(const char *filename, + const synfig::TargetParam& /* params */) : + filename(filename) { } virtual ~magickpp_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_mng/trgt_mng.cpp b/synfig-core/src/modules/mod_mng/trgt_mng.cpp index 7a97c7c..3540490 100644 --- a/synfig-core/src/modules/mod_mng/trgt_mng.cpp +++ b/synfig-core/src/modules/mod_mng/trgt_mng.cpp @@ -99,7 +99,9 @@ mng_error_proc(mng_handle mng __attribute__ ((unused)), mng_int32 error __attrib return MNG_TRUE; } -mng_trgt::mng_trgt(const char *Filename) : filename(Filename) +mng_trgt::mng_trgt(const char *Filename, + const synfig::TargetParam& /* params */) : + filename(Filename) { file=NULL; buffer=NULL; diff --git a/synfig-core/src/modules/mod_mng/trgt_mng.h b/synfig-core/src/modules/mod_mng/trgt_mng.h index a194b35..6fc848a 100644 --- a/synfig-core/src/modules/mod_mng/trgt_mng.h +++ b/synfig-core/src/modules/mod_mng/trgt_mng.h @@ -27,6 +27,7 @@ #include #include +#include #include // #include @@ -82,7 +83,7 @@ private: public: - mng_trgt(const char *filename); + mng_trgt(const char *filename, const synfig::TargetParam& /* params */); virtual ~mng_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp b/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp index ccfa576..2ad34f5 100644 --- a/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp +++ b/synfig-core/src/modules/mod_openexr/trgt_openexr.cpp @@ -63,7 +63,8 @@ exr_trgt::ready() return (bool)exr_file; } -exr_trgt::exr_trgt(const char *Filename): +exr_trgt::exr_trgt(const char *Filename, + const synfig::TargetParam& /* params */): multi_image(false), imagecount(0), filename(Filename), diff --git a/synfig-core/src/modules/mod_openexr/trgt_openexr.h b/synfig-core/src/modules/mod_openexr/trgt_openexr.h index 9a4e13f..a7bfb28 100644 --- a/synfig-core/src/modules/mod_openexr/trgt_openexr.h +++ b/synfig-core/src/modules/mod_openexr/trgt_openexr.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -59,7 +60,7 @@ private: bool ready(); public: - exr_trgt(const char *filename); + exr_trgt(const char *filename, const synfig::TargetParam& /* params */); virtual ~exr_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_png/trgt_png.cpp b/synfig-core/src/modules/mod_png/trgt_png.cpp index bc38548..a0a58b1 100644 --- a/synfig-core/src/modules/mod_png/trgt_png.cpp +++ b/synfig-core/src/modules/mod_png/trgt_png.cpp @@ -79,7 +79,8 @@ png_trgt::png_out_warning(png_struct *png_data,const char *msg) //Target *png_trgt::New(const char *filename){ return new png_trgt(filename);} -png_trgt::png_trgt(const char *Filename) +png_trgt::png_trgt(const char *Filename, + const synfig::TargetParam& /* params */) { file=NULL; filename=Filename; diff --git a/synfig-core/src/modules/mod_png/trgt_png.h b/synfig-core/src/modules/mod_png/trgt_png.h index 19dd82b..350b6f2 100644 --- a/synfig-core/src/modules/mod_png/trgt_png.h +++ b/synfig-core/src/modules/mod_png/trgt_png.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -57,7 +58,7 @@ private: unsigned char *buffer; synfig::Color *color_buffer; public: - png_trgt(const char *filename); + png_trgt(const char *filename, const synfig::TargetParam& /* params */); virtual ~png_trgt(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_ppm/trgt_mpg.cpp b/synfig-core/src/modules/mod_ppm/trgt_mpg.cpp index e379eb0..c90ebfd 100644 --- a/synfig-core/src/modules/mod_ppm/trgt_mpg.cpp +++ b/synfig-core/src/modules/mod_ppm/trgt_mpg.cpp @@ -64,7 +64,8 @@ bsd_mpeg1::New(const char *filename) return new bsd_mpeg1(filename); } -bsd_mpeg1::bsd_mpeg1(const char *Filename) +bsd_mpeg1::bsd_mpeg1(const char *Filename, + const synfig::TargetParam& /* params */) { filename=Filename; passthru=ppm::New((tmp_dir+"temp.ppm").c_str()); diff --git a/synfig-core/src/modules/mod_ppm/trgt_mpg.h b/synfig-core/src/modules/mod_ppm/trgt_mpg.h index 5ce96dc..e1707d9 100644 --- a/synfig-core/src/modules/mod_ppm/trgt_mpg.h +++ b/synfig-core/src/modules/mod_ppm/trgt_mpg.h @@ -49,7 +49,7 @@ private: String filename; FILE *paramfile; public: - bsd_mpeg1(const char *filename); + bsd_mpeg1(const char *filename, const synfig::TargetParam& /* params */); virtual bool set_rend_desc(synfig::RendDesc *desc); virtual bool start_frame(synfig::ProgressCallback *cb); diff --git a/synfig-core/src/modules/mod_ppm/trgt_ppm.cpp b/synfig-core/src/modules/mod_ppm/trgt_ppm.cpp index 8fc4810..0859d84 100644 --- a/synfig-core/src/modules/mod_ppm/trgt_ppm.cpp +++ b/synfig-core/src/modules/mod_ppm/trgt_ppm.cpp @@ -57,7 +57,7 @@ SYNFIG_TARGET_SET_CVS_ID(ppm,"$Id$"); /* === M E T H O D S ======================================================= */ -ppm::ppm(const char *Filename) +ppm::ppm(const char *Filename, const synfig::TargetParam& /* params */) { filename=Filename; multi_image=false; diff --git a/synfig-core/src/modules/mod_ppm/trgt_ppm.h b/synfig-core/src/modules/mod_ppm/trgt_ppm.h index f1a5134..fd93e38 100644 --- a/synfig-core/src/modules/mod_ppm/trgt_ppm.h +++ b/synfig-core/src/modules/mod_ppm/trgt_ppm.h @@ -32,6 +32,7 @@ #include #include #include +#include #include /* === M A C R O S ========================================================= */ @@ -52,7 +53,7 @@ private: synfig::Color *color_buffer; unsigned char *buffer; public: - ppm(const char *filename); + ppm(const char *filename, const synfig::TargetParam& /* params */); virtual ~ppm(); virtual bool set_rend_desc(synfig::RendDesc *desc); diff --git a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp index bad2dca..a6d3455 100644 --- a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp +++ b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.cpp @@ -63,7 +63,7 @@ SYNFIG_TARGET_SET_CVS_ID(yuv,"$Id$"); /* === M E T H O D S ======================================================= */ -yuv::yuv(const char *FILENAME): +yuv::yuv(const char *FILENAME, const synfig::TargetParam& /* params */): filename(FILENAME), file( (filename=="-")?stdout:fopen(filename.c_str(),POPEN_BINARY_WRITE_TYPE) ), dithering(true) diff --git a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.h b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.h index f176607..8ffa7bd 100644 --- a/synfig-core/src/modules/mod_yuv420p/trgt_yuv.h +++ b/synfig-core/src/modules/mod_yuv420p/trgt_yuv.h @@ -32,6 +32,7 @@ #include #include #include +#include #include /* === M A C R O S ========================================================= */ @@ -54,7 +55,7 @@ private: public: - yuv(const char *filename); + yuv(const char *filename, const synfig::TargetParam& /* params */); virtual ~yuv(); virtual bool init(); diff --git a/synfig-core/src/synfig/module.h b/synfig-core/src/synfig/module.h index d064fe9..29455e3 100644 --- a/synfig-core/src/synfig/module.h +++ b/synfig-core/src/synfig/module.h @@ -115,11 +115,13 @@ //! Marks the start of the targets in the module's inventory #define BEGIN_TARGETS { -#define TARGET(x) \ - synfig::Target::book()[synfig::String(x::name__)].factory = \ - reinterpret_cast (x::create); \ - synfig::Target::book()[synfig::String(x::name__)].filename = \ - synfig::String(x::ext__); \ +#define TARGET(x) \ + synfig::Target::book()[synfig::String(x::name__)].factory = \ + reinterpret_cast (x::create); \ + synfig::Target::book()[synfig::String(x::name__)].filename = \ + synfig::String(x::ext__); \ + synfig::Target::book()[synfig::String(x::name__)].target_param = \ + synfig::TargetParam(); \ synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__; #define TARGET_EXT(x,y) synfig::Target::ext_book()[synfig::String(y)]=x::name__; diff --git a/synfig-core/src/synfig/target.cpp b/synfig-core/src/synfig/target.cpp index 47727be..b6aa1c4 100644 --- a/synfig-core/src/synfig/target.cpp +++ b/synfig-core/src/synfig/target.cpp @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2010 Diego Barrios Romero ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -33,6 +34,7 @@ #include "canvas.h" #include "target_null.h" #include "target_null_tile.h" +#include "targetparam.h" using namespace synfig; using namespace etl; @@ -57,12 +59,14 @@ Target::subsys_init() // At least one target must be available. book()["null"].factory = reinterpret_cast(&Target_Null::create); - book()["null"].filename = "null"; + book()["null"].filename = "null"; + book()["null"].target_param = TargetParam(); ext_book()["null"]="null"; book()["null-tile"].factory = - reinterpret_cast(&Target_Null_Tile::create); - book()["null-tile"].filename = "null-tile"; + reinterpret_cast(&Target_Null_Tile::create); + book()["null-tile"].filename = "null-tile"; + book()["null-tile"].target_param = TargetParam(); ext_book()["null-tile"]="null-tile"; return true; @@ -110,10 +114,11 @@ synfig::Target::set_canvas(etl::handle c) Target::Handle -Target::create(const String &name, const String &filename) +Target::create(const String &name, const String &filename, + synfig::TargetParam params) { if(!book().count(name)) return handle(); - return Target::Handle(book()[name].factory(filename.c_str())); + return Target::Handle(book()[name].factory(filename.c_str(), params)); } diff --git a/synfig-core/src/synfig/target.h b/synfig-core/src/synfig/target.h index f93cf87..5fcaaeb 100644 --- a/synfig-core/src/synfig/target.h +++ b/synfig-core/src/synfig/target.h @@ -7,6 +7,7 @@ ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** Copyright (c) 2007 Chris Moore +** Copyright (c) 2010 Diego Barrios Romero ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -38,11 +39,15 @@ //#include "general.h" #include "color.h" #include "canvas.h" +#include "targetparam.h" /* === M A C R O S ========================================================= */ //! \writeme -#define SYNFIG_TARGET_MODULE_EXT public: static const char name__[], version__[], ext__[],cvs_id__[]; static Target *create(const char *filename); +#define SYNFIG_TARGET_MODULE_EXT public: static const char name__[], \ + version__[], ext__[], cvs_id__[]; \ + static Target* create (const char *filename, \ + synfig::TargetParam p); //! Sets the name of the target #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x @@ -57,7 +62,10 @@ #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x //! \writeme -#define SYNFIG_TARGET_INIT(class) synfig::Target* class::create(const char *filename) { return new class(filename); } +#define SYNFIG_TARGET_INIT(class) \ + synfig::Target* class::create (const char *filename, \ + synfig::TargetParam p) \ + { return new class(filename, p); } /* === T Y P E D E F S ===================================================== */ @@ -69,6 +77,7 @@ class Surface; class RendDesc; class Canvas; class ProgressCallback; +class TargetParam; /*! \class Target ** \brief Render-target @@ -106,12 +115,13 @@ public: /*! As a pointer to the constructor, it represents a "factory" of targets. ** Receives the output filename (including path). */ - typedef Target* (*Factory)(const char *filename); - + typedef Target* (*Factory)(const char *filename, TargetParam p); + struct BookEntry { Factory factory; String filename; ///< Output filename including path + TargetParam target_param; ///< Target module parameters }; //! Book of types of targets indexed by the name of the Target. @@ -186,7 +196,8 @@ public: virtual bool init() { return true; } //! Creates a new Target described by \a type, outputting to a file described by \a filename. - static Handle create(const String &type, const String &filename); + static Handle create(const String &type, const String &filename, + synfig::TargetParam params); }; // END of class Target }; // END of namespace synfig diff --git a/synfig-core/src/synfig/targetparam.h b/synfig-core/src/synfig/targetparam.h new file mode 100644 index 0000000..c54f15a --- /dev/null +++ b/synfig-core/src/synfig/targetparam.h @@ -0,0 +1,45 @@ +/* === S Y N F I G ========================================================= */ +/*! \file synfig/targetparam.h +** \brief Class for extra parameters of the target modules +** +** $Id$ +** +** \legal +** Copyright (c) 2010 Diego Barrios Romero +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_TARGETPARAM_H +#define __SYNFIG_TARGETPARAM_H + +#include + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig { + +struct TargetParam +{ + std::string video_codec; + int bitrate; +}; + +}; // END of namespace synfig + +/* === E N D =============================================================== */ + +#endif + diff --git a/synfig-core/src/tool/main.cpp b/synfig-core/src/tool/main.cpp index 38aa168..06d1488 100644 --- a/synfig-core/src/tool/main.cpp +++ b/synfig-core/src/tool/main.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -348,7 +349,7 @@ bool flag_requires_value(String flag) flag=="-Q" || flag=="-s" || flag=="-t" || flag=="-T" || flag=="-w" || flag=="--append" || flag=="--begin-time" || flag=="--canvas-info"|| flag=="--dpi" || flag=="--dpi-x" || flag=="--dpi-y" || flag=="--end-time" || flag=="--fps" || flag=="--layer-info" || flag=="--start-time" || - flag=="--time" ); + flag=="--time" || flag=="-vc" || flag=="-vb"); } int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster) @@ -544,6 +545,31 @@ int extract_target(arg_list_t &arg_list,string &type) return SYNFIGTOOL_OK; } +int extract_target_params(arg_list_t& arg_list, + TargetParam& params) +{ + arg_list_t::iterator iter; + + for(iter=arg_list.begin(); iter!=arg_list.end(); iter++) + { + if(*iter=="-vc") + { + // Target video codec + params.video_codec = extract_parameter(arg_list, iter); + } + else if(*iter=="-vb") + { + // Target bitrate + params.bitrate = + atoi(extract_parameter(arg_list, iter).c_str()); + } + else if (flag_requires_value(*iter)) + iter++; + } + + return SYNFIGTOOL_OK; +} + int extract_append(arg_list_t &arg_list,string &filename) { arg_list_t::iterator iter; @@ -1053,6 +1079,12 @@ int main(int argc, char *argv[]) } } + TargetParam target_parameters; + // Extract the extra parameters for the targets that + // need them. + if (target_name == "ffmpeg") + extract_target_params(imageargs, target_parameters); + // If the target type is STILL not yet defined, then // set it to a some sort of default if(target_name.empty()) @@ -1077,7 +1109,10 @@ int main(int argc, char *argv[]) VERBOSE_OUT(4)<<"outfile_name="<