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

Commit04e8d51

Browse files
committed
add joining video files tutorial
1 parent49b5302 commit04e8d51

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
9696
-[How to Create a Watchdog in Python](https://www.thepythoncode.com/article/create-a-watchdog-in-python). ([code](general/directory-watcher))
9797
-[How to Extract Audio from Video in Python](https://www.thepythoncode.com/article/extract-audio-from-video-in-python). ([code](general/video-to-audio-converter))
9898
-[How to Combine a Static Image with Audio in Python](https://www.thepythoncode.com/article/add-static-image-to-audio-in-python). ([code](python-for-multimedia/add-photo-to-audio))
99+
-[How to Concatenate Video Files in Python](https://www.thepythoncode.com/article/concatenate-video-files-in-python). ([code](python-for-multimedia/combine-video))
99100

100101

101102
-###[Web Scraping](https://www.thepythoncode.com/topic/web-scraping)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[How to Concatenate Video Files in Python](https://www.thepythoncode.com/article/concatenate-video-files-in-python)
2+
To run this:
3+
-`pip3 install -r requirements.txt`
4+
-
5+
```
6+
$ python concatenate_video.py --help
7+
```
8+
**Output**:
9+
```
10+
usage: concatenate_video.py [-h] [-c CLIPS [CLIPS ...]] [-r REDUCE] [-o OUTPUT]
11+
12+
Simple Video Concatenation script in Python with MoviePy Library
13+
14+
optional arguments:
15+
-h, --help show this help message and exit
16+
-c CLIPS [CLIPS ...], --clips CLIPS [CLIPS ...]
17+
List of audio or video clip paths
18+
-r REDUCE, --reduce REDUCE
19+
Whether to use the `reduce` method to reduce to the lowest quality on the resulting clip
20+
-o OUTPUT, --output OUTPUT
21+
Output file name
22+
```
23+
- To combine`zoo.mp4` and`directed-by-robert.mp4` to produce`output.mp4`:
24+
```
25+
$ python concatenate_video.py -c zoo.mp4 directed-by-robert.mp4 -o output.mp4
26+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
frommoviepy.editorimportconcatenate_videoclips,VideoFileClip
2+
3+
4+
defconcatenate(video_clip_paths,output_path,method="compose"):
5+
"""Concatenates several video files into one video file
6+
and save it to `output_path`. Note that extension (mp4, etc.) must be added to `output_path`
7+
`method` can be either 'compose' or 'reduce':
8+
`reduce`: Reduce the quality of the video to the lowest quality on the list of `video_clip_paths`.
9+
`compose`: type help(concatenate_videoclips) for the info"""
10+
# create VideoFileClip object for each video file
11+
clips= [VideoFileClip(c)forcinvideo_clip_paths]
12+
ifmethod=="reduce":
13+
# calculate minimum width & height across all clips
14+
min_height=min([c.hforcinclips])
15+
min_width=min([c.wforcinclips])
16+
# resize the videos to the minimum
17+
clips= [c.resize(newsize=(min_width,min_height))forcinclips]
18+
# concatenate the final video
19+
final_clip=concatenate_videoclips(clips)
20+
elifmethod=="compose":
21+
# concatenate the final video with the compose method provided by moviepy
22+
final_clip=concatenate_videoclips(clips,method="compose")
23+
# write the output video file
24+
final_clip.write_videofile(output_path)
25+
26+
27+
if__name__=="__main__":
28+
importargparse
29+
parser=argparse.ArgumentParser(
30+
description="Simple Video Concatenation script in Python with MoviePy Library")
31+
parser.add_argument("-c","--clips",nargs="+",
32+
help="List of audio or video clip paths")
33+
parser.add_argument("-r","--reduce",action="store_true",
34+
help="Whether to use the `reduce` method to reduce to the lowest quality on the resulting clip")
35+
parser.add_argument("-o","--output",help="Output file name")
36+
args=parser.parse_args()
37+
clips=args.clips
38+
output_path=args.output
39+
reduce=args.reduce
40+
method="reduce"ifreduceelse"compose"
41+
concatenate(clips,output_path,method)
687 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
moviepy
719 KB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp