movie2gif

버전 1.0 (18.2 MB) 작성자: Kenta
A tool for converting movie into gif
다운로드 수: 213
업데이트 날짜: 2021/7/24

View movie2gif on File Exchange

Convert movie into gif

[English]
This script converts movies into gif file. This demo was created based on MATLAB official document.

[Japanese]
このファイルでは、動画をGIFに変換します

What you can do in this script are

  1. Convert your movie files into GIF
  2. When isCrop is set at 1, you can crop the region of interst to save. If you set isCrop=0, you can run this program without the Image Processing Toolbox.
  3. The parameter rate controls the number of frames used for the GIF files. Increase this value if you would like to decrease the GIF file. However, the number of frames used is limited, accordingly, the GIF quality might be decreased.

Reference

  1. imwrite: MATLAB official documentation: Write image to graphics file

image_0.png

clear;clc;close all

The movieName is the movie name to input. Other file types like avi and mov are also fine.

movieName='sample.mp4';

The filename is gif name to save

filename='output.gif';

If you would like to crop the movie, please set isCrop at true.

isCrop=true;

DelayTime represents delay before displaying next image, in seconds

A value of 0 displays images as fast as your hardware allows.

DelayTime=0.1;

The video frame is used for gif for every "rate" frames. For example, if you set at 2, the second, forth, sixth, eighth, ... frames are saved as gif. Increasing this parameter decreases the file size of the gif.

rate=2;

Create video object to read frames from the movie

vidObj = VideoReader(movieName);

Please specify the area to crop if you want

if isCrop==1
    frame = read(vidObj,round(vidObj.NumFrames/2));
    figure;imshow(frame);title('please select the area to save')
    rect=getrect;
    % reset the video object
    vidObj = VideoReader(movieName);
end

figure_0.png

Loop over the movie to convert into gif

idx=1;
while hasFrame(vidObj)
    im = readFrame(vidObj);
    if mod(idx,rate)==1
    if isCrop==1
        im=imcrop(im,rect);
    end
    [A,map] = rgb2ind(im,256);
    if idx == 1
        imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',DelayTime)
    else
        imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',DelayTime);
    end
    end
    idx=idx+1;
end

인용 양식

Kenta (2024). movie2gif (https://github.com/KentaItakura/movie2gif-using-MATLAB/releases/tag/1.0), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2021a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
태그 태그 추가

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.