Code covered by the BSD License  

Highlights from
Tools for generating and playing video realtime

image thumbnail

Tools for generating and playing video realtime

by

 

22 Mar 2012 (Updated )

Generation of video in matlab, with the means of playing it realtime in a separte thread via VLC

playVid(fileName, speedRatio,bOneInstance, bDeinterlace)
function playVid(fileName, speedRatio,bOneInstance, bDeinterlace)
% This simple program illustrates how to call the VLC player with cusomized
% settings from the command prompt in matlab UNDER WINDOWS. This can be used 
% to display video with REALTIME demands, as is the case for perceptual 
% investigations for example. Most of the settings used to call VLC this way 
% can also be achieved through the GUI. This program starts the vlc player 
% without halting matlab execution, but for proper perceptual studies, 
% further execution of matlab scripts should be halted during playback. 
% 
% Example usage. Assuming a file "video.avi" in current folder:
% playVid('video.avi');
% 
% speedRatio - changes the playback speed of the video
% bOneInstance -  determines whether new calls to this function should open
% a new instance of the VLC playback window, if a previous call isnt
% finished (playVid does not halt matlab execution)
% bDeinterlace - to illustrate how to set VLC filtering operations from the
% prompt. If you have recorded interlaced video, this tells VLC to
% deinterlace it.

% see licence.txt for licence details. Copyright 2012 Stefan Karlsson

% of course, the solution of having a 'VLC_system_Location' could be
% replaced by simply putting the vlc.exe executable in the system path.
VLC_system_Location = '"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"';
if exist(VLC_system_Location(2:end-1), 'file') ~= 2
    error('Before running this script, you are required to define where the VLC executable is by opening playVid.m and changing the variable "VLC_system_Location" to point correct.');end
if strcmp(fileName, '--Check_VLC_system_Location') 
    return; end
height = 640; %height of video window;

if nargin<2
    speedRatio = 1;end
if nargin <3
    bOneInstance = 1;end
if nargin<4
    bDeinterlace = 0;end

%  --high-priority
sysString = ['start "' fileName '" /b /realtime ' VLC_system_Location ' --play-and-exit --no-video-title-show --no-media-library --no-interact --qt-minimal-view --no-qt-notification --no-qt-system-tray --no-sub-autodetect-file  --no-ffmpeg-hurry-up --no-skip-frames --video-on-top'];
if(strcmpi(fileName,'quit'))
    system(['start "" ' VLC_system_Location ' --one-instance  --play-and-exit vlc:quit']);
    return;
end
if bOneInstance
    sysString = [sysString ' --one-instance']; end
if bDeinterlace
    sysString = [sysString ' --video-filter=deinterlace --deinterlace=1 --filter-deinterlace-mode=blend']; end

sysString = [sysString ' --height=' num2str(height) ' --rate=' num2str(speedRatio)];
[status, result] = system([sysString ' ' fileName]);
commandwindow;     

Contact us