app-thumbnail-movies.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED
00039 #define APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED
00040
00041 #include "Component/ModelManager.H"
00042 #include "Image/FilterOps.H"
00043 #include "Image/Image.H"
00044 #include "Image/Pixels.H"
00045 #include "Image/ShapeOps.H"
00046 #include "Media/MpegInputStream.H"
00047 #include "Media/FrameSeries.H"
00048 #include "Transport/FrameInfo.H"
00049 #include "Util/csignals.H"
00050 #include "Util/sformat.H"
00051 #include "rutz/trace.h"
00052
00053 #include <cmath>
00054 #include <vector>
00055
00056 int submain(int argc, const char** argv)
00057 {
00058 GVX_TRACE(__PRETTY_FUNCTION__);
00059
00060 volatile int signum = 0;
00061 catchsignals(&signum);
00062
00063 ModelManager mgr("movie thumbnailer");
00064
00065 nub::ref<InputMPEGStream> indummy(new InputMPEGStream(mgr));
00066 mgr.addSubComponent(indummy);
00067
00068 nub::ref<OutputFrameSeries> out(new OutputFrameSeries(mgr));
00069 mgr.addSubComponent(out);
00070
00071 if (mgr.parseCommandLine(argc, argv, "nskipframes movie1.mpg movie2.mpg ...",
00072 2, -1) == false)
00073 exit(1);
00074
00075 std::vector<nub::ref<InputMPEGStream> > inputs;
00076
00077 const int nskipframes = mgr.getExtraArgAs<int>(0);
00078
00079 LINFO("got nskipframes=%d", nskipframes);
00080
00081 for (uint i = 1; i < mgr.numExtraArgs(); ++i)
00082 {
00083 inputs.push_back(nub::ref<InputMPEGStream>(new InputMPEGStream(mgr)));
00084 mgr.addSubComponent(inputs.back());
00085 inputs.back()->setFileName(mgr.getExtraArg(i));
00086 }
00087
00088 mgr.exportOptions(MC_RECURSE);
00089 mgr.start();
00090
00091 std::vector<Image<PixRGB<byte> > > images(inputs.size());
00092
00093 const int nx = int(ceil(sqrt(inputs.size())));
00094
00095 for (int sk = 0; sk < nskipframes; ++sk)
00096 {
00097 if (signum != 0)
00098 {
00099 LINFO("quitting because %s was caught", signame(signum));
00100 return -1;
00101 }
00102
00103 LINFO("skipping input frame %d", sk);
00104
00105 bool done = false;
00106
00107 for (uint i = 0; i < inputs.size(); ++i)
00108 {
00109 if (!inputs[i]->readAndDiscardFrame())
00110 {
00111 LINFO("quitting because %s reached EOF",
00112 mgr.getExtraArg(i).c_str());
00113 done = true;
00114 }
00115 }
00116
00117 if (done)
00118 break;
00119 }
00120
00121 while (1)
00122 {
00123 if (signum != 0)
00124 {
00125 LINFO("quitting because %s was caught", signame(signum));
00126 return -1;
00127 }
00128
00129 bool done = false;
00130
00131 for (uint i = 0; i < inputs.size(); ++i)
00132 {
00133 images[i] = inputs[i]->readRGB();
00134 if (!images[i].initialized())
00135 {
00136 LINFO("quitting because %s reached EOF",
00137 mgr.getExtraArg(i).c_str());
00138 done = true;
00139 }
00140 else
00141 images[i] = decXY(lowPass3(images[i]));
00142 }
00143
00144 if (done)
00145 break;
00146
00147 const Image<PixRGB<byte> > thumb =
00148 concatArray(&images[0], images.size(), nx);
00149
00150 const FrameState os = out->updateNext();
00151
00152 out->writeRGB(thumb, "thumbnail",
00153 FrameInfo(sformat("array of %"ZU" movies",
00154 inputs.size()), SRC_POS));
00155
00156 if (os == FRAME_FINAL)
00157 {
00158 LINFO("quitting because output reached EOF");
00159 break;
00160 }
00161 }
00162
00163 return 0;
00164 }
00165
00166 int main(const int argc, const char **argv)
00167 {
00168 try
00169 {
00170 return submain(argc, argv);
00171 }
00172 catch (...)
00173 {
00174 REPORT_CURRENT_EXCEPTION;
00175 }
00176
00177 return 1;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187 #endif // APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED