本文整理汇总了Python中moviepy.editor.VideoFileClip.set_duration方法的典型用法代码示例。如果您正苦于以下问题:Python VideoFileClip.set_duration方法的具体用法?Python VideoFileClip.set_duration怎么用?Python VideoFileClip.set_duration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moviepy.editor.VideoFileClip
的用法示例。
在下文中一共展示了VideoFileClip.set_duration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_out
# 需要导入模块: from moviepy.editor import VideoFileClip [as 别名]
# 或者: from moviepy.editor.VideoFileClip import set_duration [as 别名]
def save_out(tracks, outfile=None, filetype='mp4'):
out = []
vids = [t for t in tracks if t['type'] == 'vid']
texts = [t for t in tracks if t['type'] == 'text']
for v in vids:
c = VideoFileClip(v['content']).subclip(v['in'], v['in'] + v['duration'])
c = c.set_start(v['start'])
out.append(c)
size = out[0].size
for t in texts:
c = create_sub(t['content'], size, rect_offset=195, min_height=55)
c = c.set_start(t['start'])
c = c.set_duration(t['duration'])
out.append(c)
final_clip = CompositeVideoClip(out)
if outfile is None:
outfile = 'msg_' + str(int(time.time())) + '.mp4'
if filetype == 'gif':
outfile = outfile.replace('.mp4', '.gif')
final_clip.speedx(1.7).write_gif(outfile, fps=7, loop=1)
else:
final_clip.write_videofile(outfile, fps=24, codec='libx264')
return outfile
示例2: VideoFileClip
# 需要导入模块: from moviepy.editor import VideoFileClip [as 别名]
# 或者: from moviepy.editor.VideoFileClip import set_duration [as 别名]
type=str, help='Output filename', default='out.mp4')
parser.add_argument('-R', dest='reverse', help='Reverse order',
action='store_true', default=False)
parser.add_argument('-r', dest='round', metavar='decimal_places',
type=int, help='Luminosity precision, in decimal places, or 0 to disable rounding', default=2)
parser.add_argument('-l', dest='length', metavar='duration_seconds',
type=float, help='Duration to crop to')
args = parser.parse_args()
if args.round == 0:
args.round = 12
clip = VideoFileClip(args.input)
if args.length is not None:
clip = clip.set_duration(args.length)
print "Read clip, duration = %.1fs, FPS = %.1f" % (clip.duration, clip.fps)
#------------------------------------------------------------------------
# Non-integer frame rates (e.g. 29.97) cause problems when retrieving
# offsets. Round to an integer.
#------------------------------------------------------------------------
clip.fps = round(clip.fps)
#------------------------------------------------------------------------
# Transform brightnesses into a list of (offset_seconds, brightness)
#------------------------------------------------------------------------
print "Analysing brightness ...."
brightnesses = [ (index / clip.fps, round(np.mean(frame) / 255.0, args.round)) for index, frame in enumerate(clip.iter_frames()) ]
示例3: poop
# 需要导入模块: from moviepy.editor import VideoFileClip [as 别名]
# 或者: from moviepy.editor.VideoFileClip import set_duration [as 别名]
def poop(source, destination, midi_file, stretch, fadeout, rebuild, max_stack):
"""
Create multiple pitchshifted versions of source video and arrange them to
the pattern of the midi_file, also arrange the video if multiple notes play
at the same time.
"""
print "Reading input files"
video = VideoFileClip(source, audio=False)
"""
Non-main tracks are 30% the size of the main and have a white border and a
margin around them.
"""
smaller = video.resize(0.3)\
.margin(mar=2, color=3*[255])\
.margin(mar=8, opacity=0)
audio = AudioFileClip(source, fps=44100)
mid = MidiFile(midi_file)
ignoredtracks = ["Percussion", "Bass"]
print "Analysing MIDI file"
notes = [] # the number of messages in each track
lowest = 127 # will contain the lowest note
highest = 0 # will contain the highest note
for i, track in enumerate(mid.tracks):
notes.append(0)
#if track.name in ignoredtracks: continue
for message in track:
if message.type == "note_on":
lowest = min(lowest, message.note)
highest = max(highest, message.note)
notes[-1] += 1
"""
The main track is the one featured in the center. It is probably the one
with the most notes. Also record the lowest, highest, and average note to
generate the appropriate pitches.
"""
maintrack = max(enumerate(notes), key=lambda x: x[1])[0]
midpitch = int((lowest+highest)/2)
print "Main track is probably", str(maintrack)+":", mid.tracks[maintrack].name
mid.tracks.insert(0, mid.tracks.pop(maintrack)) # move main track to front
notes.insert(0, notes.pop(maintrack)) # move main note count to front
print sum(notes), "notes ranging from", lowest, "to", highest, "centering around", midpitch
print "Transposing audio"
sound = audio.to_soundarray(fps=44100) # source, original audio
tones = range(lowest-midpitch, highest-midpitch) # the range of pitches we need
pitches = [] # this will contain the final AudioFileClips
if not os.path.exists("pitches/"):
print "Creating folder for audio files"
os.makedirs("pitches/")
for n in tones:
"""
Pitches only need to be generated if they do not already exist or if
we force the creation of new ones. Save them in order in pitches.
"""
name = "pitches/"+source+"_"+str(n)+".mp3"
if not os.path.isfile(name) or rebuild:
print "Transposing pitch", n
splitshift(sound, n).write_audiofile(name)
pitches.append(AudioFileClip(name, fps=44100))
print "Adding video clips"
clips = [video.set_duration(1)] # to set the video size
positions = [("left", "bottom"), ("right", "bottom"), ("left", "top"),
("right", "top"), ("center", "bottom"), ("center", "top"),
("left", "center"), ("right", "center")] # non-main tracks
"""
curpos is the current corner position on the screen and changes with each track.
cache is used to make a unique file name whenever a new temporary file is created.
endtime will be used at the end to set the end TextClip. It is the latest time any clip ends.
"""
curpos = -2
cache = endtime = 0
for i, track in enumerate(mid.tracks):
#if track.name in ignoredtracks: continue
print("Processing {} notes: {}".format(notes[i], track.name))
t = 1.0 # not 0 because we added one second of original video for size
opennotes = [] # will contain all notes that are still playing
curpos += 1
for message in track:
if not isinstance(message, MetaMessage):
message.time *= stretch
t += message.time
if message.type == "note_on":
"""
Add a video clip with the appropriate starting time and
pitch. Also add an entry to opennotes (we don't know when
the note ends yet).
"""
part = video
mainvid = i is 0# and len(opennotes) is 0
if not mainvid: part = smaller
part = part\
.set_audio(pitches[min(len(pitches)-1, max(0, message.note-lowest))])\
.set_start(t/1000)
opennotes.append((message.note, len(clips), t))
"""
If this isn't the main track, the video will be smaller and
placed at the edge. We'll get a position for each track.
#.........这里部分代码省略.........