I would like to create a video file with the .gif extension (using ffmpeg if possible)!!!

조회 수: 7 (최근 30일)
Please understand that I cannot upload my files due to capacity limitations. : - (
In the case of ffmpeg, I downloaded the Windows version - compressed ffmpeg folder (ffmpeg-git-essentials.7z) from https://www.gyan.dev/ffmpeg/builds/ , unzipped it, and changed the outermost folder name to 'ffmpeg'.
While doing my homework, I'm trying to convert the 'zeta' item in a nc(NetCDF) file into a video with a .gif extension. The problem is, every time I run this code (HW_06) it keeps telling me that the profile I specified is invalid. I am currently using the internal ffmpeg.exe file to create a gif file. Below is the code I am using right now. What should I fix in this code to create a video with a .gif extension? nc files were read normally, and 289 PNG images were also printed normally.
clear all; close all; clc;
%% Directory %%
pwd;
mkdir('01__Data')
mkdir('02__Figure')
inp.dir = fullfile(pwd, '01__Data');
fig.dir = fullfile(pwd, '02__Figure');
ffmpegPath = fullfile(pwd, '01__Data', 'ffmpeg', 'bin');
ffmpegRelativePath = fullfile(ffmpegPath, 'ffmpeg.exe');
output_directory = ['01__Time_series'];
output_directory1 = ['01_Zeta'];
output_directory2 = ['02_Salinity'];
mkdir([output_directory,'/',output_directory1]);
mkdir([output_directory,'/',output_directory2]);
%% Model data reading %%
tp = dir('*.nc');
% 파일 이름 목록 정의
file_names = {'homework_0001.nc', 'homework_0002.nc', 'homework_0003.nc'};
% 파일 경로와 이름을 결합하여 읽을 파일 목록 생성
filn = fullfile(inp.dir, file_names);
for i = 1:length(filn)
x = ncread(filn{i},'x');
y = ncread(filn{i},'y');
xc = double(ncread(filn{i},'xc'));
yc = double(ncread(filn{i},'yc'));
lon = ncread(filn{i},'lon');
lat = ncread(filn{i},'lat');
lonc = double(ncread(filn{i},'lonc'));
latc = double(ncread(filn{i},'latc'));
node_number = length(x);
cell_number = length(xc);
nv = ncread(filn{i},'nv');
time = double(ncread(filn{i},'time'))';
zeta = ncread(filn{i},'zeta');
salinity = ncread(filn{i},'salinity');
%% Plot (Zeta) %%
for i = 1:length(time)
figure('visible','off')
set(gca,'fontname','Arial','fontweight','bold','fontsize',15,'Box','on');
hold on
set(gcf,'color','w','Units','Normalized','OuterPosition',[0.1 0.1 0.7 0.4]);
patch('Faces',nv,'Vertices',[x,y],'FaceColor','w','linewidth',1);
patch('Faces',nv,'Vertices',[x,y],'FaceColor','w','linestyle','none');
patch('Faces',nv,'Vertices',[x,y],'FaceVertexCData',zeta(:,i),'FaceColor','flat','LineStyle','none');
% patch('Faces',nv,'Vertices',[x,y],'FaceVertexCData',salinity(:,i),'FaceColor','flat','LineStyle','none');
axis equal;
colormap('jet');
c = colorbar;
caxis([-3 3]);
% caxis([30 32]);
% c.Ticks = [-3: 1: 3];
c.Label.String = 'Zeta (m)';
% c.Label.String = 'Salinity (psu)';
c.Label.FontSize = 18;
xlabel('Distance (m)','FontSize',18,'FontWeight','bold')
ylabel('Distance (m)','FontSize',18,'FontWeight','bold')
title(datestr(time(i),'dd HH:MM:SS'),'fontsize',20,'fontweight','bold')
print([output_directory,'/',output_directory1,'/','Tide_',datestr(time(i),'dd HH_MM_SS')],'-dpng')
% print([output_directory,'/',output_directory2,'/','Sal_',datestr(time(i),'dd HH_MM_SS')],'-dpng')
end
end
%% Video (Zeta) %%
outputVideoFileName1 = fullfile(fig.dir, 'HW_06_Zeta.gif');
pngDirectory1 = fullfile(pwd, '01__Time_series', '01_Zeta');
outputVideo1 = VideoWriter(outputVideoFileName1, 'FFmpeg');
outputVideo1.FrameRate = 10;
outputVideo1.FileFormat = 'gif';
open(outputVideo1);
for i = 1:length(time)
time_str = datestr(time(i), 'dd HH_MM_SS');
img = imread(fullfile(pngDirectory1, ['Tide_', time_str, '.png']));
writeVideo(outputVideo1, img);
end
close(outputVideo1);

채택된 답변

Angelo Yeo
Angelo Yeo 2023년 10월 11일
편집: Angelo Yeo 2023년 10월 11일
VideoWriter 문서에 기재되어 있는 것 처럼 이 함수는 'FFmpeg'라는 프로파일을 지원하지 않습니다. 더군다나 ffmpeg는 동영상의 profile이 아닙니다. (FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata. 소스)
또, gif 출력을 위해서 VideoWriter 대신에 exportgrahics의 GIF로 내보내기 기능을 사용해보는 건 어떨까요?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by