


Python gadget: Complete a day's workload in five minutes, it's so delicious
Introduction
FFmpeg is a set of powerful audio and video processing programs and the basis of many audio and video software. In fact, FFmpeg has become the industry standard for audio and video processing. . However, there is a certain learning cost for using FFmpeg from the command line, and the ffmpeg-python library solves this problem very well.
After simple installation through pip, you can use ffmpeg in python code.
pip3 install ffmpeg-python
Get video information
path = 'main.mp4' probe = ffmpeg.probe(path) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) width = int(video_stream['width']) height = int(video_stream['height']) print(width, height)
We can use stream to get some basic information of the video, such as size, duration, frame rate, etc.
Mirror processing
# 左右镜像 ffmpeg.input(path).hflip().output('output.mp4').run() # 上下镜像 ffmpeg.input(path).vflip().output('output.mp4').run()
can be simply understood as the abbreviation of the English words horizontal (horizontal) and vertical (vertical).
Add watermark
main = ffmpeg.input(path) logo = ffmpeg.input('logo.png') ffmpeg.filter([main, logo], 'overlay', 0, 500).output('out.mp4').run()
This command means to place the logo watermark image above the main video at the coordinate of (0,500). The upper left corner of the video can be understood as the position of the origin (0,0), and the x-axis and y-axis are represented to the right and downward from the origin respectively.
Of course, if you make the logo big enough, larger than the video, and then change the positions of the two sides, it will become the video on the logo, which is actually equivalent to adding a Background image.
ffmpeg.filter([logo, main], 'overlay', 0, 500).output('out.mp4').run()
Video interception
ffmpeg.input(path).trim(start_frame=10,end_frame=20).output('out3.mp4').run()
This command seems easy to understand. start_frame and end_frame represent the start and end frames respectively.
Video splicing
base = ffmpeg.input(path) ffmpeg.concat( base.trim(start_frame=10, end_frame=20), base.trim(start_frame=30, end_frame=40), base.trim(start_frame=50, end_frame=60) ).output('out3.mp4').run()
Video splicing can be done using the concat function.
Summary
Today I will share with you a good library for processing videos in python. I hope it can bring some efficiency improvements to your work/side job.
The above is the detailed content of Python gadget: Complete a day's workload in five minutes, it's so delicious. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

MySQL can run without network connections for basic data storage and management. However, network connection is required for interaction with other systems, remote access, or using advanced features such as replication and clustering. Additionally, security measures (such as firewalls), performance optimization (choose the right network connection), and data backup are critical to connecting to the Internet.

MySQL database performance optimization guide In resource-intensive applications, MySQL database plays a crucial role and is responsible for managing massive transactions. However, as the scale of application expands, database performance bottlenecks often become a constraint. This article will explore a series of effective MySQL performance optimization strategies to ensure that your application remains efficient and responsive under high loads. We will combine actual cases to explain in-depth key technologies such as indexing, query optimization, database design and caching. 1. Database architecture design and optimized database architecture is the cornerstone of MySQL performance optimization. Here are some core principles: Selecting the right data type and selecting the smallest data type that meets the needs can not only save storage space, but also improve data processing speed.

For production environments, a server is usually required to run MySQL, for reasons including performance, reliability, security, and scalability. Servers usually have more powerful hardware, redundant configurations and stricter security measures. For small, low-load applications, MySQL can be run on local machines, but resource consumption, security risks and maintenance costs need to be carefully considered. For greater reliability and security, MySQL should be deployed on cloud or other servers. Choosing the appropriate server configuration requires evaluation based on application load and data volume.

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

HadiDB: A lightweight, high-level scalable Python database HadiDB (hadidb) is a lightweight database written in Python, with a high level of scalability. Install HadiDB using pip installation: pipinstallhadidb User Management Create user: createuser() method to create a new user. The authentication() method authenticates the user's identity. fromhadidb.operationimportuseruser_obj=user("admin","admin")user_obj.

MySQL cannot directly store PDF files, and can be achieved by storing file paths or hash values of binary data. The core idea is to use a table to store the following fields: ID, file name, file path (or hash value). The file path scheme stores file paths, which are simple and efficient, but depend on the file system for security; the file hash scheme stores the SHA-256 hash value of PDF files, which is more secure and can perform data integrity verification.

No, MySQL cannot connect directly to SQL Server. But you can use the following methods to implement data interaction: Use middleware: Export data from MySQL to intermediate format, and then import it to SQL Server through middleware. Using Database Linker: Business tools provide a more friendly interface and advanced features, essentially still implemented through middleware.
