[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Extract frame from video - aviread replacement
From: |
Evangelos Rozos |
Subject: |
Extract frame from video - aviread replacement |
Date: |
Mon, 24 Feb 2020 10:06:58 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
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 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 or keep 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Extract frame from video - aviread replacement,
Evangelos Rozos <=