Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate GIF and MP4 formats by Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Python generates GIF and MP4 formats. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Preface

This is a GIF generated by Python, and you can also output video in MP4 format. How on earth did you do it? Let me talk about it-- the dataset, the code, and the details.

Data set acquisition mode

You can go to the website of the National Bureau of Statistics to search for the data you want. For example, in this case, we need population data. As shown in the figure below, you can download the data. I prefer csv format.

Kernel function

Please take a look at the screenshot below in the part of the code, here we only look at the main parameters of the core function, which is very important!

The function FuncAnimation (fig,func,frames,init_func,interval,blit) is the main function for drawing dynamic graphs, and its parameters are as follows:

The name of the canvas in which fig draws the animation

Func custom animation function, that is, the function update defined by the following program

The length of the frames animation, the number of frames contained in a loop, and its value is passed to the formal parameter "n" of the function update (n) when the function is running

Init_func custom start frame, that is, pass in the newly defined function init to initialize the function

Interval update frequency, in ms

Blit chooses whether to update all points or just the points that make changes. True should be selected, but mac users please select False, otherwise it cannot be displayed

Configure Video

There will still be errors when running the above code. Error message: RuntimeError: Requested MovieWriter (ffmpeg) not available

Because we also need to install FFmpeg, a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams. Use the LGPL or GPL license. It provides a complete solution for recording, converting and streaming audio and video.

Here we will only talk about the installation steps of ffmpeg:

Download the installation package, unzip it to a folder, copy the path to ffmpeg.exe in the extracted bin directory, and dip it in the code ffmpegpath = os.path.abspath () above.

Thank you for reading! This is the end of the article on "how Python generates GIF and MP4 format". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report