Clear Filters
Clear Filters

Create a video from frames after compression

12 views (last 30 days)
i'm doing video compression. Firstly i convert the video to frames and compress each frame individually and store the compressed file in a folder.
Now i want to create a video from the compressed file. i did so using
writerObj = VideoWriter('out.avi');
writerObj.FrameRate = reader.FrameRate;
open(writerObj);
for i = 1 : 10
thisimage = imread(['comp_out/' num2str(i) '.jpg']);
writeVideo(writerObj, thisimage);
end
close(writerObj);
but the fileSize of first 10 frames before compression was 2.19MB and after compression is 122KB but when i create a video the size of video before compression is 191KB after compression is 186KB. The videoSize of the full video with 141 frames is just 204KB.
How to make the compression effective when creating a video also, so that the fileSize difference is noticeable as in frames.

Accepted Answer

Walter Roberson
Walter Roberson on 11 Sep 2017
You cannot do the compression yourself and have MATLAB used the compressed version to write video. It is possible to ask VideoWriter to compress frames, but you pass it uncompressed frames and it does the compression automatically. You have to ask for compression; See https://www.mathworks.com/help/matlab/ref/videowriter.html#inputarg_profile
  2 Comments
Elysi Cochin
Elysi Cochin on 13 Sep 2017
sir i used 'Archival' still i dont find much difference when we compare it to frame compression.
Walter Roberson
Walter Roberson on 13 Sep 2017
Each frame you pass to VideoWriter is treated as if it contains a full-quality original. The compression algorithm is then applied as frames are added one by one. The amount of compression that will be achieved will depend upon the "profile" chosen and the details of the algorithm. Some compression algorithms compress a frame at a time; other compression algorithms compare against a small number of previous frames. If I understand the data flow correctly, none of the compression algorithms will be able to implement forward prediction.
When you apply lossy compression to your data frames, you reduce the amount of information contained in them. If the way you reduced the amount of information happens to coincide with something that is noticeable by the compression algorithms, then this can have the effect of reducing the output size. However, it is entirely possible that you reduced the amount of information in a way that the compression algorithm does not notice, so doing lossy information reducing before writing the frame is not necessarily going to reduce the output file size.
VideoWriter does not support custom compression algorithms. It is not possible to do your own compression of frames and submit the compressed data (which might be variable sized) to be written, with the expectation that when any media player reads the resulting file, that it would somehow know how to decompress the result.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!