Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7217d1c

Browse files
committed
add creating video from images tutorial
1 parent45ba1f8 commit7217d1c

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
267267
-[How to Add Audio to Video in Python](https://www.thepythoncode.com/article/add-audio-to-video-in-python). ([code](python-for-multimedia/add-audio-to-video))
268268
-[How to Compress Images in Python](https://www.thepythoncode.com/article/compress-images-in-python). ([code](python-for-multimedia/compress-image))
269269
-[How to Remove Metadata from an Image in Python](https://thepythoncode.com/article/how-to-clear-image-metadata-in-python). ([code](python-for-multimedia/remove-metadata-from-images))
270+
-[How to Create Videos from Images in Python](https://thepythoncode.com/article/create-a-video-from-images-opencv-python). ([code](python-for-multimedia/create-video-from-images))
270271

271272
-###[Web Programming](https://www.thepythoncode.com/topic/web-programming)
272273
-[Detecting Fraudulent Transactions in a Streaming Application using Kafka in Python](https://www.thepythoncode.com/article/detect-fraudulent-transactions-with-apache-kafka-in-python). ([code](general/detect-fraudulent-transactions))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#[How to Create Videos from Images in Python](https://thepythoncode.com/article/create-a-video-from-images-opencv-python)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
importcv2
2+
importargparse
3+
importglob
4+
frompathlibimportPath
5+
importshutil
6+
7+
# Create an ArgumentParser object to handle command-line arguments
8+
parser=argparse.ArgumentParser(description='Create a video from a set of images')
9+
10+
# Define the command-line arguments
11+
parser.add_argument('output',type=str,help='Output path for video file')
12+
parser.add_argument('input',nargs='+',type=str,help='Glob pattern for input images')
13+
parser.add_argument('-fps',type=int,help='FPS for video file',default=24)
14+
15+
# Parse the command-line arguments
16+
args=parser.parse_args()
17+
18+
# Create a list of all the input image files
19+
FILES= []
20+
foriinargs.input:
21+
FILES+=glob.glob(i)
22+
23+
# Get the filename from the output path
24+
filename=Path(args.output).name
25+
print(f'Creating video "{filename}" from images "{FILES}"')
26+
27+
# Load the first image to get the frame size
28+
frame=cv2.imread(FILES[0])
29+
height,width,layers=frame.shape
30+
31+
# Create a VideoWriter object to write the video file
32+
fourcc=cv2.VideoWriter_fourcc(*'mp4v')
33+
video=cv2.VideoWriter(filename=filename,fourcc=fourcc,fps=args.fps,frameSize=(width,height))
34+
35+
# Loop through the input images and add them to the video
36+
forimage_pathinFILES:
37+
print(f'Adding image "{image_path}" to video "{args.output}"... ')
38+
video.write(cv2.imread(image_path))
39+
40+
# Release the VideoWriter and move the output file to the specified location
41+
cv2.destroyAllWindows()
42+
video.release()
43+
shutil.move(filename,args.output)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
opencv-python

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp