程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Use Python to achieve perfect pseudo originality of short videos and make unique videos

編輯:Python

1. scene

Hello everyone , I am a J Brother .

Some time ago, someone wrote to me , Say you've worked so hard to edit a short video , After uploading to a certain platform , Because of the amount of play , received Right reduction The notice of , It directly leads to the invalidation of this account !

Actually , Each big video platform has its own set of identification algorithm , For video Second creation , If you carry it directly , There will be some unknown risks

This article will take you to use Python Do some special processing for short videos , Make sure the video is originality and Uniqueness .

2. Realization

The following will be from MD5、 The light 、 color 3 To illustrate

The first 1 Step , Modify the video MD5 value

MD5 It's a cryptographic hash function , Of documents MD5 Value can determine whether the file has been modified

Use Python Self contained hashlib modular , Section read file , Can get the file MD5 value

Dry goods mainly include :

① 200 Multiple copies Python e-book ( And classic books ) Should have

② Python Standard library information ( The most complete Chinese version )

③ Project source code ( Forty or fifty interesting and reliable hand training projects and source code )

④ Python Basic introduction 、 Reptiles 、 Network development 、 Big data analysis video ( Suitable for Xiaobai to learn )

⑤ Python Learning Roadmap ( Farewell to bad learning )

Python Exchange of learning Q Group 101677771

 

def get_file_md5(file_path): """ Segment read , retrievable md5 value :param file_path: :return: """ with open(file_path, 'rb') as file: md5_obj = hashlib.md5() while True: buffer = file.read(8096) if not buffer: break md5_obj.update(buffer) hash_code = md5_obj.hexdigest() md5 = str(hash_code).lower() return md5

To modify the file MD5 value , Just append a string to the end of the file

def modify_file_md5(file_path): """ Modify the file md5 value :param file_path: :return: """ with open(file_path, 'a') as file: file.write("####&&&&")

The first 2 Step , Brightness adjustment

Brightness adjustment , It's equivalent to adjusting the exposure of the entire video , Increase or decrease the light of the video

First , install moviepy Dependency Library

# Install dependency library pip3 install moviepy 

next , Increase screen brightness , Here are two There are two ways to increase video brightness

The first way , For every frame of the video , Adjust the brightness value

def handle_frame(image_frame): """ Processing picture frames :param image_frame: Picture frame :return: """ image_frame_result = image_frame * 1.2 # If the color value exceeds 255, Set it directly to 255 image_frame_result[image_frame_result > 255] = 255 return image_frame_result def increase_video_brightness(file_path): """ Increase the overall brightness of the video :param file_path: Source video path :return: """ video = VideoFileClip(file_path) result = video.fl_image(handle_frame) file_path_new = "/Users/xingag/Desktop/new.mp4" result.write_videofile(file_path_new) 

The second way , Extract video clips from files VideoFileClip, Use fx() Function vfx.colorx Parameters , Specify a coefficient , Adjust the brightness of the video directly

def increase_video_brightness2(file_path): """ Increase the overall brightness of the video 2 :param file_path: Source video path :return: """ # Adjust the value of the coefficient coefficient_value = 1.2 video = VideoFileClip(file_path) file_path_new = "/Users/xingag/Desktop/new.mp4" video.fx(vfx.colorx, coefficient_value).write_videofile(file_path_new) 

If you want to reduce the overall brightness of the video , You can adjust the above coefficient to less than 1 The number can be

The first 3 Step , Color adjustment

Color adjustment , Specifically including : Hue 、 Color brightness 、 Saturation, etc , Here's an example of converting video to black and white

Again , Use fx() Function vfx.blackwhite Parameters , You can turn color video into black and white video with one button

def change_video_bhd(file_path): """ Black and white processing :param file_path: :return: """ video = VideoFileClip(file_path) file_path_new = "/Users/xingag/Desktop/new.mp4" video.fx(vfx.blackwhite).write_videofile(file_path_new)

3. Last

In addition to the above several video modification methods , You can also use CV2 and MoviePy, Add some special templates 、 The end of the clip has a gradient animation to ensure the originality and uniqueness of the video . Source code download


https://github.com/xingag/tools_python/blob/master/ Video special processing .py


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved