This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
采用命令行交互模式操作。
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,8 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
#test videos | ||
*.mp4 | ||
*.flv | ||
*.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from moviepy.editor import VideoFileClip, concatenate_videoclips, AudioFileClip | ||
from moviepy_tools import * | ||
from eyed3 import mp3 | ||
|
||
print("选择功能:\n 1.剪切视频 \n 2.剪切音频") | ||
func = input() | ||
if func == "1": | ||
print("请输入需要剪切的视频的路径:") | ||
file = input() | ||
clip = openv(file) | ||
print("请输入剪切起始时间(秒 整数):") | ||
start = input() | ||
print("请输入剪切终止时间(秒 整数):") | ||
end = input() | ||
clip = cut(clip,start,end) | ||
print("请输入输出文件名(默认为 output.mp4)") | ||
file_name = input() | ||
if file_name == "": | ||
writev(clip) | ||
else: | ||
writev(clip,file_name) | ||
elif func == "2": | ||
print("请输入需要剪切的音频的路径:") | ||
file = input() | ||
clip = opena(file) | ||
print("请输入剪切起始时间(秒 整数):") | ||
start = input() | ||
print("请输入剪切终止时间(秒 整数):") | ||
end = input() | ||
clip = cut(clip,start,end) | ||
print("请输入输出文件名(默认为 output.mp3)") | ||
file_name = input() | ||
f = mp3.Mp3AudioFile(file) | ||
bit_rate = f.info.bit_rate[1] * 1000 | ||
if file_name == "": | ||
writea(clip,bit_rate) | ||
else: | ||
writea(clip,file_name,bit_rate) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from moviepy.editor import VideoFileClip, concatenate_videoclips, AudioFileClip | ||
|
||
def openv(file): | ||
clipv = VideoFileClip(file) | ||
return clipv | ||
|
||
def opena(file): | ||
clipa = AudioFileClip(file) | ||
return clipa | ||
|
||
def cut(clip,start,end): | ||
clip = clip.subclip(start,end) | ||
return clip | ||
|
||
def writev(clip,file_name="output.mp4"): | ||
clip.write_videofile(file_name) | ||
|
||
def writea(clip,bit_rate,file_name="output.mp3"): | ||
clip.write_audiofile(file_name,bitrate=str(bit_rate)) |