[파이썬] moviepy 동영상 색상 조절하기

If you are working with videos in Python, you might come across the need to adjust the color of a video. Whether it’s correcting the color balance, enhancing the saturation, or applying creative color grading, moviepy offers a simple and effective way to accomplish this.

In this blog post, we will explore how to adjust the color of a video using moviepy library in Python. We will cover the process step by step and provide example code to demonstrate each step.

Installing moviepy

Before getting started, make sure you have moviepy installed. You can install it using pip:

pip install moviepy

Importing moviepy and reading the video

The first step is to import the necessary modules from moviepy and then read the video file. Here’s an example of how to import and read the video file:

from moviepy.editor import VideoFileClip

# Define the path to the video file
video_path = "path/to/your/video.mp4"

# Read the video file
clip = VideoFileClip(video_path)

Adjusting the color

Once the video is loaded, we can now proceed to adjust the color. Moviepy provides a handy fx module that allows us to apply various effects to the video. In this case, we will focus on adjusting the color of the video.

To adjust the color, we can use the fx.colorx functions provided by moviepy. Here’s an example of how to apply different color adjustments:

1. Color Balance:

clip = clip.fx.vfx.colorx(balance=1.2)

2. Saturation:

clip = clip.fx.vfx.colorx(balance=0.8, saturation=1.5)

3. Brightness:

clip = clip.fx.vfx.colorx(balance=0.8, saturation=1.2, brightness=1.2)

Exporting the video

Finally, once we have made the desired color adjustments, we can export the modified video. Moviepy provides a simple method write_videofile() to export the video file. Here’s an example of how to export the video:

# Define the output path and filename
output_path = "path/to/output/video.mp4"

# Write the modified video file
clip.write_videofile(output_path)

Conclusion

In this blog post, we have learned how to adjust the color of a video using moviepy library in Python. We covered the steps required to read the video, adjust the color, and export the modified video. Remember to experiment with different color adjustments to achieve the desired visual effect. Moviepy provides a wide range of options to explore and fine-tune the color of your videos.

Feel free to utilize the provided example code as a starting point for your own color adjustment projects. Enjoy exploring and creating stunning videos with moviepy!