Load frames from video - aviread replacement

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Load frames from video - aviread replacement

vrozos
Hi,

Currently, the video package is being rewritten. The new version will be
able to handle a variety of codecs. Until then, if you need a function
to load a frame from a video, you can use the following function. It
calls ffmpeg to do the job and is as fast as a turtle, but it does the
job. The last argument is a boolean flag  whether to delete the
temporary file of the extracted image.


% Copyright (C) 2019 Evangelos Rozos
%
% This program 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 3 of the License, or
% (at your option) any later version.
%
% This program 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.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see
% <https://www.gnu.org/licenses/>.

% -*- texinfo -*-
% @deftypefn {} {@var{img} =} extractframe (@var{projectpath},
@var{videofilename}, @var{framenumber}, @var{deleteimg} )
%
% @seealso{}
% @end deftypefn

% Author: Evangelos Rozos
% Created: 2019-05-22

function img = extractframe (projectpath, videofilename, framenumber,
deleteimg)

   if (nargin ~= 4)
     error ('img = extractframe (projectpath, videofilename,
framenumber, deleteimg)');
   end

   video= [projectpath filesep videofilename];
   if not(exist (video, 'file' ) )
     error([video ' does not exist!'])
   end

   extractedframe= [projectpath, filesep(), 'extractedframe_', ...
num2str(framenumber), '.jpg'];


   cmd= ['ffmpeg -i "' video '" -vf "select=gte(n\,' ...
          num2str(framenumber-1), ')"' ' -vframes 1' ' -f image2 ' ...
          '"' extractedframe '"  2> "' projectpath filesep() 'log.txt"' ];
   system(cmd);
   if exist(extractedframe, 'file')
     img= imread(extractedframe);
   else
     img=[];
     return
   end
   if deleteimg
     delete(extractedframe);
   end

end


Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

Andreas Weber-6
Hi Evangelos,

Am 23.02.20 um 21:14 schrieb Evangelos Rozos:
> Currently, the video package is being rewritten. The new version will be
> able to handle a variety of codecs. Until then, if you need a function
> to load a frame from a video, you can use the following function.

Have you tried the devel branch on
https://sourceforge.net/p/octave/video/ci/devel/tree/ ?

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

vrozos
Hi,

No, I haven't. I don't know how to install it. Is it something trivial
like download devel branch and then pkg install
octave-video-27b41daa71182ce7c00d32bc054797d9d64fcdc3.zip?

On 24/02/2020 10:12, Andreas Weber wrote:

> Hi Evangelos,
>
> Am 23.02.20 um 21:14 schrieb Evangelos Rozos:
>> Currently, the video package is being rewritten. The new version will be
>> able to handle a variety of codecs. Until then, if you need a function
>> to load a frame from a video, you can use the following function.
> Have you tried the devel branch on
> https://sourceforge.net/p/octave/video/ci/devel/tree/ ?
>
> -- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

Andreas Weber-6
Am 24.02.20 um 09:27 schrieb Evangelos Rozos:
> No, I haven't. I don't know how to install it. Is it something trivial
> like download devel branch and then pkg install
> octave-video-27b41daa71182ce7c00d32bc054797d9d64fcdc3.zip?

You can download a snapshot from here:
http://josoansi.de/files/video-2.0.0.tar.gz

then open GNU Octave, navigate to the download destination:
pkg install video-2.0.0.tar.gz
pkg load video
demo VideoReader

if this doesn't work for you use:
pkg -verbose install video-2.0.0.tar.gz

and add used OS, distribution and ffmpeg or libav version you've installed.

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

vrozos
I tested it in two machines, Win 7 32 bit and Win 10 64 bit. In both
machines I get the following warning during the installation.

warning: doc_cache_create: unusable help text found in file 'VideoReader'
warning: doc_cache_create: unusable help text found in file 'VideoWriter'
For information about changes from previous versions of the video
package, run 'news video'.

Octave version is  5.1.0 in both. In Win 10 I get

error: '__cap_open__' undefined near line 77 column 15
error: called from
     VideoReader at line 77 column 13
     loadframes at line 13 column 8
     scriptloadframes at line 1 column 7

In Win 7 seems to work fine.

ER.

On 24/02/2020 17:20, Andreas Weber wrote:

> Am 24.02.20 um 09:27 schrieb Evangelos Rozos:
>> No, I haven't. I don't know how to install it. Is it something trivial
>> like download devel branch and then pkg install
>> octave-video-27b41daa71182ce7c00d32bc054797d9d64fcdc3.zip?
> You can download a snapshot from here:
> http://josoansi.de/files/video-2.0.0.tar.gz
>
> then open GNU Octave, navigate to the download destination:
> pkg install video-2.0.0.tar.gz
> pkg load video
> demo VideoReader
>
> if this doesn't work for you use:
> pkg -verbose install video-2.0.0.tar.gz
>
> and add used OS, distribution and ffmpeg or libav version you've installed.
>
> -- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

Andreas Weber-6
Hi Evangelos,

Am 25.02.20 um 10:55 schrieb Evangelos Rozos:
> warning: doc_cache_create: unusable help text found in file 'VideoReader'
> warning: doc_cache_create: unusable help text found in file 'VideoWriter'

This is bug https://savannah.gnu.org/bugs/?43047 /
https://savannah.gnu.org/bugs/?53874

> Octave version is  5.1.0 in both. In Win 10 I get
>
> error: '__cap_open__' undefined near line 77 column 15
> error: called from
>     VideoReader at line 77 column 13
>     loadframes at line 13 column 8
>     scriptloadframes at line 1 column 7
>
> In Win 7 seems to work fine.

Where is "loadframes" and "scriptloadframes" defined? Are you sure this
is a Windows 7 vs. 10 thing and not a problem with your installation
(octaverc)?

Thanks again for testing
-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

vrozos

"loadframes" and "scriptloadframes" are functions of a tool I am developing. What '__cap_open__' is supposed to do and where is found?


On 25/02/2020 12:39, Andreas Weber wrote:
Octave version is  5.1.0 in both. In Win 10 I get

error: '__cap_open__' undefined near line 77 column 15
error: called from
    VideoReader at line 77 column 13
    loadframes at line 13 column 8
    scriptloadframes at line 1 column 7

In Win 7 seems to work fine.
Where is "loadframes" and "scriptloadframes" defined? Are you sure this
is a Windows 7 vs. 10 thing and not a problem with your installation
(octaverc)?
Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

Andreas Weber-6
Am 25.02.20 um 11:50 schrieb Evangelos Rozos:
> "loadframes" and "scriptloadframes" are functions of a tool I am
> developing. What '__cap_open__' is supposed to do and where is found?

If you install the package with "pkg install", the sourcecode in the
.tar.gz is compiled and cap_ffmpeg_wrapper.oct is created. I guess on
Windows it's somewhere in your personal settings folder under
octave/video-2.0.0/x64... please have a look for cap_ffmpeg_wrapper.oct

__cap_open__ is a function inside this cap_ffmpeg_wrapper.oct
You'll find a PKG_ADD in the same directory which tells Octave where to
look for this function:

...
autoload ("__cap_open__", "cap_ffmpeg_wrapper.oct");
...

From your error message I can just guess that you haven't executed "pkg
load video" before trying to use it or some problem with the search path.

I don't use windows so it's hard to tell and the fact that it works on
windows 7 but not 10 makes it even harder for me.

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Load frames from video - aviread replacement

vrozos
I am not positive whether had run "pkg load video" or not, but If i
hadn't then the error message would be about VideoReader and not
__cap_open__.

Anyhow, I restarted Octave and now works fine!

On 25/02/2020 13:04, Andreas Weber wrote:
>  From your error message I can just guess that you haven't executed "pkg
> load video" before trying to use it or some problem with the search path.