]> git.sesse.net Git - casparcg/commitdiff
[ffmpeg_producer] Add relative and "from end" seeking
authorDimitry Ishenko <dimitry.ishenko@gmail.com>
Sun, 26 Jun 2016 13:38:24 +0000 (09:38 -0400)
committerDimitry Ishenko <dimitry.ishenko@gmail.com>
Mon, 3 Oct 2016 19:45:04 +0000 (15:45 -0400)
modules/ffmpeg/producer/ffmpeg_producer.cpp

index a77994896eabfd92baf5fa8acaba7da712e6987b..634e4dd627de6ad6dc39de5c84c4c449c1ce79b9 100644 (file)
@@ -391,7 +391,7 @@ public:
        std::future<std::wstring> call(const std::vector<std::wstring>& params) override
        {
                static const boost::wregex loop_exp(LR"(LOOP\s*(?<VALUE>\d?)?)", boost::regex::icase);
-               static const boost::wregex seek_exp(LR"(SEEK\s+(?<VALUE>\d+))", boost::regex::icase);
+               static const boost::wregex seek_exp(LR"(SEEK\s+(?<VALUE>(\+|-)?\d+)(\s+(?<WHENCE>REL|END))?)", boost::regex::icase);
                static const boost::wregex length_exp(LR"(LENGTH\s+(?<VALUE>\d+)?)", boost::regex::icase);
                static const boost::wregex start_exp(LR"(START\\s+(?<VALUE>\\d+)?)", boost::regex::icase);
 
@@ -409,8 +409,19 @@ public:
                }
                else if(boost::regex_match(param, what, seek_exp))
                {
-                       auto value = what["VALUE"].str();
-                       input_.seek(boost::lexical_cast<uint32_t>(value));
+                       auto value = boost::lexical_cast<uint32_t>(what["VALUE"].str());
+                       auto whence = what["WHENCE"].str();
+
+                       if(boost::iequals(whence, L"REL"))
+                       {
+                               value = file_frame_number() + value;
+                       }
+                       else if(boost::iequals(whence, L"END"))
+                       {
+                               value = file_nb_frames() - value;
+                       }
+
+                       input_.seek(value);
                }
                else if(boost::regex_match(param, what, length_exp))
                {