Unable to use structName.?ClassName for VideoWriter class

I am finding the structName.?ClassName method of arguments validation does not work when trying to validate name-value arguments for the VideoWriter class.
I have a short function:
function myDemo(videoData,fileName,vwOpts)
arguments
videoData
fileName
vwOpts.?VideoWriter
end
disp(vwOpts);
videoObj = VideoWriter(fileName);
% Open video, write, close, etc.
end % MakeVideo
I would expect that calling this function with VideoWriter properties such as FrameRate would result in vwOpts being a struct that contains values passed to the function. However, I am getting the error:
>> myDemo(0:10,"myVideo.avi","FrameRate",20)
Error using myDemo
Too many input arguments.
I validated my approach by attempting to filter for arguments to the Bar() function by mimicking the matlab.graphics.chart.primitive.Bar example shown in the documentation and was successful.
I noticed I get this same error when failing to specify the full name of the Bar class, so looked for other methods of specifying the VideoWriter class, using matlab.audiovideo.VideoWriter as the full class name, with no success.
What am I missing about this approach? Is there a way of locating the full name of the VideoWriter class, or is there some reason I should not expect this example to work?
Thanks!

 Accepted Answer

The .?Classname syntax only works on the class properties with public SetAccess. Unfortunately, the VideoWriter class does not have any such properties. FrameRate is also not the name of a property at all:
mc=?VideoWriter;
pl=mc.PropertyList;
table(string({pl.Name}'), string({pl.SetAccess}'), ...
'Var', {'Property Name','SetAccess'})
ans = 12×2 table
Property Name SetAccess ___________________________ _________ "Duration" "private" "Filename" "private" "Path" "private" "FileFormat" "private" "IsOpen" "private" "IsFilenameValidated" "private" "IsWriteVideoCalled" "private" "InternalFramesWritten" "private" "NumFramesWrittenToDisk" "private" "Profile" "private" "AllowedDataTypes" "private" "FrameIntervalToCheckError" "none"

3 Comments

Thanks for the insight. I had seen this before but was confused regarding how the properties listed via the method you show are radically different than the properties shown in a created object:
>> videoObj = VideoWriter("myFileName.avi")
videoObj =
VideoWriter
General Properties:
Filename: 'myFileName.avi'
Path: 'C:\Users\userName'
FileFormat: 'avi'
Duration: 0
Video Properties:
ColorChannels: 3
Height: []
Width: []
FrameCount: 0
FrameRate: 30
VideoBitsPerPixel: 24
VideoFormat: 'RGB24'
VideoCompressionMethod: 'Motion JPEG'
Quality: 75
Methods
After some digging in the VideoWriter class, it appears the properties shown in an actual video object are dynamic properties set from the assigned Profile. Which explains the issue I'm having, but is not exactly helpful for resolving it.
Thanks for your help.
I think the best you can do is to let VideoWriter()'s argument validation do the work. You can use a try...catch if for some reason you want myDemo() to customize the error messaging,
function myDemo(videoData,fileName,vwNames,vwVals)
arguments
videoData
fileName
end
arguments (Repeating)
vwNames char
vwVals
end
nv=[vwNames;vwVals];
disp(struct(nv{:}));
try
videoObj = VideoWriter(fileName,nv{:});
catch ME
end
end % MakeVideo
I'm mixing the option inputs to myDemo() with other option sets, which is why I was hoping to use the opts.?VideoWriter syntax. However, I think with your approach I can make a separate copy of the options cell array, remove options that I know aren't applicable, and let VideoWriter do the remaining work. Thanks for the suggestion.

Sign in to comment.

More Answers (1)

I think the options.?ClassName syntax is not supported within arguments block. You should specify each name-value pair individually.
function myDemo(videoData,fileName,vwOpts)
arguments
videoData
fileName
vwOpts.FrameRate
% vwOpts.optionname //list distinct VideoWriter option name
% ...
end
disp(vwOpts);
videoObj = VideoWriter(fileName);
% Open video, write, close, etc.
end % MakeVideo
myDemo(0:10,"myVideo.avi",FrameRate=20)
FrameRate: 20

1 Comment

Unfortunately, this use case is exactly the purpose of the options.?ClassName syntax--to automate the handling of properties so changes to ClassName can be seamlessly handled in other classes that use them. As discussed, I successfully used this syntax with the matlab.graphics.chart.primitive.Bar class, so problem is more specific to the class. I suspect it's in how the class is named in the myDemo() function, but I'm not sure because I haven't found the answer yet.

Sign in to comment.

Products

Release

R2022b

Asked:

on 17 Sep 2025

Commented:

on 23 Sep 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!