For the pictures in the video , Sometimes for special requirements such as special effect processing, we want to carry out the effect similar to negative photo .
Negative film (Negative Film) It's an image after exposure and development , The light and shade are opposite to the subject , Its color is the complementary color of the subject , It needs to be printed on the photo before it can be restored to a positive image . Take black and white movies , On the negative film, people's hair is white , In fact, white clothes are black on the film ; Color film , The color on the film is just complementary to the actual color of the scene , Such as : The clothes that are actually red are cyan on the film . Negative film, whether black and white or color, is the most commonly used film for photography . What we usually say is the negative film used to develop photos .
This article introduces through Python+Moviepy Two lines of code to realize the video anti color processing, so that each frame is the negative effect of the original picture .
In order to achieve video anti color processing , The sample code is as follows :
from moviepy.editor import * clip = VideoFileClip(r"F:\video\scenery.mp4") clipInvert_colors = clip.fx(vfx.invert_colors) clipInvert_colors.write_videofile (r"F:\video\scenery_invert_colors.mp4")
The above four lines of code realize Moviepy Module loading 、 Then read in the video file 、 Invert the video 、 Output the inverted video to the result video file . The above four lines of code can also be reduced to the following two lines :
from moviepy.editor import * VideoFileClip(r"F:\video\scenery.mp4").fx(vfx.invert_colors).write_videofile (r"F:\video\scenery_invert_colors.mp4")
The output color reversal video is as follows :
You can see the inverted video, which has a magical feeling .
3、 ... and 、 Background knowledge
3.1、moviepy brief introduction
To achieve video editing , The old ape used it moviepy library .MoviePy It's a video editor Python modular , Can be used for basic video operations ( Like cutting 、 Connect 、 Title insertion )、 Video synthesis ( Also known as nonlinear editing )、 Video processing or creating advanced effects . It can read and write the most common video formats , Include GIF.MoviePy The video that can be processed is ffmpeg Format , The old ape understands that the supported file types include at least :*.mp4 *.wmv *.rm *.avi *.flv *.webm *.wav *rmvb.
MoviePy Very simple installation , Use pip When installing , Please point the site to the domestic mirror site , Otherwise, the download will be slow or unable to download , The old ape uses the mirror image of Tsinghua University , Instruction is :
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple moviepy
3.2、 The code uses related functions to introduce
The related functions involved in the above code include VideoFileClip、fx、invert_colors、write_videofile, among :
Four 、 Summary
This paper introduces the use of Python+Moviepy Two lines of code to achieve video color reversal method , Video color reversal is similar to negative processing in photo development .