Taken out useless codecs.
[synfig.git] / synfig-core / src / tool / main.cpp
index 37f535b..03d9a08 100644 (file)
@@ -45,6 +45,7 @@
 #include <synfig/layer.h>
 #include <synfig/canvas.h>
 #include <synfig/target.h>
+#include <synfig/targetparam.h>
 #include <synfig/time.h>
 #include <synfig/string.h>
 #include <synfig/paramdesc.h>
@@ -68,6 +69,43 @@ int verbosity=0;
 bool be_quiet=false;
 bool print_benchmarks=false;
 
+//! Allowed video codecs
+/*! \warning This variable is linked to allowed_video_codecs_description,
+ *  if you change this you must change the other acordingly.
+ *  \warning These codecs are linked to the filename extensions for
+ *  mod_ffmpeg. If you change this you must change the others acordingly.
+ */
+const char* allowed_video_codecs[] =
+{
+       "flv", "h263p", "huffyuv", "libtheora", "libx264", "libxvid",
+       "mjpeg", "mpeg1video", "mpeg2video", "mpeg4", "msmpeg4",
+       "msmpeg4v1", "msmpeg4v2", "wmv1", "wmv2", NULL
+};
+
+//! Allowed video codecs description.
+/*! \warning This variable is linked to allowed_video_codecs,
+ *  if you change this you must change the other acordingly.
+ */
+const char* allowed_video_codecs_description[] =
+{
+       "Flash Video (FLV) / Sorenson Spark / Sorenson H.263.",
+       "H.263+ / H.263-1998 / H.263 version 2.",
+       "Huffyuv / HuffYUV.",
+       "libtheora Theora.",
+       "libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10.",
+       "libxvidcore MPEG-4 part 2.",
+       "MJPEG (Motion JPEG).",
+       "raw MPEG-1 video.",
+       "raw MPEG-2 video.",
+       "MPEG-4 part 2.",
+       "MPEG-4 part 2 Microsoft variant version 3.",
+       "MPEG-4 part 2 Microsoft variant version 1.",
+       "MPEG-4 part 2 Microsoft variant version 2.",
+       "Windows Media Video 7.",
+       "Windows Media Video 8.",
+       NULL
+};
+
 /* === T Y P E D E F S ===================================================== */
 
 typedef list<String> arg_list_t;
@@ -147,6 +185,7 @@ void display_help(bool full)
                display_help_option("--layer-info", "<layer>", _("Print out layer's description, parameter info, etc."));
                display_help_option("--layers", NULL, _("Print out the list of available layers"));
                display_help_option("--targets", NULL, _("Print out the list of available targets"));
+               display_help_option("--target-video-codecs", NULL, _("Print out the list of available target video codecs"));
                display_help_option("--importers", NULL, _("Print out the list of available importers"));
                display_help_option("--valuenodes", NULL, _("Print out the list of available ValueNodes"));
                display_help_option("--modules", NULL, _("Print out the list of loaded modules"));
@@ -165,6 +204,15 @@ void display_help(bool full)
        cerr << endl;
 }
 
+void display_target_video_codecs_help ()
+{
+       for (int i = 0; allowed_video_codecs[i] != NULL &&
+                                       allowed_video_codecs_description[i] != NULL; i++)
+               cout << " " << allowed_video_codecs[i] << ":   \t"
+                        << allowed_video_codecs_description[i]
+                        << endl;
+}
+
 int process_global_flags(arg_list_t &arg_list)
 {
        arg_list_t::iterator iter, next;
@@ -275,6 +323,13 @@ int process_global_flags(arg_list_t &arg_list)
                        return SYNFIGTOOL_HELP;
                }
 
+               if(*iter == "--target-video-codecs")
+               {
+                       display_target_video_codecs_help();
+
+                       return SYNFIGTOOL_HELP;
+               }
+
                if(*iter == "--valuenodes")
                {
                        Progress p(PACKAGE);
@@ -348,7 +403,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)
@@ -538,6 +593,7 @@ int extract_target(arg_list_t &arg_list,string &type)
                if(*iter=="-t")
                {
                        type = extract_parameter(arg_list, iter, next);
+                       VERBOSE_OUT(1)<<strprintf(_("Target set to %s"), type.c_str())<<endl;
                }
                else if (flag_requires_value(*iter))
                        iter++;
@@ -546,6 +602,63 @@ int extract_target(arg_list_t &arg_list,string &type)
        return SYNFIGTOOL_OK;
 }
 
+int extract_target_params(arg_list_t& arg_list,
+                                                 TargetParam& params)
+{
+       int ret;
+       ret = SYNFIGTOOL_OK;
+       // If -vc parameter is provided, -vb parameter is needed.
+       bool need_bitrate_parameter = false;
+       arg_list_t::iterator iter, next;
+
+       for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
+       {
+               if(*iter=="-vc")
+               {
+                       // Target video codec
+                       params.video_codec = extract_parameter(arg_list, iter, next);
+
+                       // video_codec string to lowercase
+                       transform (params.video_codec.begin(),
+                                          params.video_codec.end(),
+                                          params.video_codec.begin(),
+                                          ::tolower);
+
+                       int local_ret;
+                       local_ret = SYNFIGTOOL_UNKNOWNARGUMENT;
+
+                       // Check if the given video codec is allowed.
+                       for (int i = 0; local_ret != SYNFIGTOOL_OK &&
+                                                       allowed_video_codecs[i] != NULL; i++)
+                               if (params.video_codec == allowed_video_codecs[i])
+                                       local_ret = SYNFIGTOOL_OK;
+
+                       ret = local_ret;
+
+                       if (ret == SYNFIGTOOL_OK)
+                       {
+                               VERBOSE_OUT(1)<<strprintf(_("Target video codec set to %s"), params.video_codec.c_str())<<endl;
+                               need_bitrate_parameter = true;
+                       }
+               }
+               else if(*iter=="-vb")
+               {
+                       need_bitrate_parameter = false;
+                       // Target bitrate
+                       params.bitrate =
+                               atoi(extract_parameter(arg_list, iter, next).c_str());
+                       VERBOSE_OUT(1)<<strprintf(_("Target bitrate set to %dk"),params.bitrate)<<endl;
+               }
+               else if (flag_requires_value(*iter))
+                       iter++;
+       }
+
+       if (need_bitrate_parameter)
+               ret = SYNFIGTOOL_MISSINGARGUMENT;
+
+       return ret;
+}
+
 int extract_append(arg_list_t &arg_list,string &filename)
 {
        arg_list_t::iterator iter, next;
@@ -1056,6 +1169,32 @@ int main(int argc, char *argv[])
                                }
                        }
 
+                       TargetParam target_parameters;
+                       // Extract the extra parameters for the targets that
+                       // need them.
+                       if (target_name == "ffmpeg")
+                       {
+                               int status;
+                               status = extract_target_params(imageargs, target_parameters);
+                               if (status == SYNFIGTOOL_UNKNOWNARGUMENT)
+                               {
+                                       cerr << strprintf(_("Unknown target video codec: %s."),
+                                                                        target_parameters.video_codec.c_str())
+                                                << endl;
+                                       cerr << _("Available target video codecs are:")
+                                                << endl;
+                                       display_target_video_codecs_help();
+
+                                       return SYNFIGTOOL_UNKNOWNARGUMENT;
+                               }
+                               else if (status == SYNFIGTOOL_MISSINGARGUMENT)
+                               {
+                                       cerr << _("Missing argument: \"-vb\".") << endl;
+
+                                       return SYNFIGTOOL_MISSINGARGUMENT;
+                               }
+                       }
+
                        // If the target type is STILL not yet defined, then
                        // set it to a some sort of default
                        if(target_name.empty())
@@ -1080,7 +1219,10 @@ int main(int argc, char *argv[])
                        VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
 
                        VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
-                       job_list.front().target=synfig::Target::create(target_name,job_list.front().outfilename);
+                       job_list.front().target =
+                               synfig::Target::create(target_name,
+                                                                          job_list.front().outfilename,
+                                                                          target_parameters);
 
                        if(target_name=="sif")
                                job_list.front().sifout=true;