• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python editor.VideoFileClip类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中moviepy.editor.VideoFileClip的典型用法代码示例。如果您正苦于以下问题:Python VideoFileClip类的具体用法?Python VideoFileClip怎么用?Python VideoFileClip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VideoFileClip类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_clip

def get_clip(video_title, start=(0,0), seconds=5):
    video = VideoFileClip(video_title)

    end = (start[0], start[1]+seconds)
    clip = video.subclip(start, end)

    return clip
开发者ID:tankorsmash,项目名称:youtube_gif,代码行数:7,代码来源:youtube_gif.py


示例2: processProjectVideo

def processProjectVideo():
    CHALLENGEVIDEOOUTPUT = 'test_videos_output/ChallengeVideoOutput%04d.mp4'
    PROJECTVIDEOOUTPUT = './output_images/video/ProjectVideoOutput_%04d-%04d.mp4'
    CLIPLENGTH=10 # process 10 second clips
    ## To speed up the testing process you may want to try your pipeline on a shorter subclip of the video
    ## To do so add .subclip(start_second,end_second) to the end of the line below
    ## Where start_second and end_second are integer values representing the start and end of the subclip
    ## You may also uncomment the following line for a subclip of the first 5 seconds
    ##clip2 = VideoFileClip('test_videos/solidYellowLeft.mp4').subclip(0,5)
    
    video = VideoFileClip('./project_video.mp4')
    #video = VideoFileClip("./test_video.mp4")

    duration = video.duration
    #duration=31.4
    numberOfClips=int(round(duration/float(CLIPLENGTH)+0.5))
    print ("processProjectVideo-duration:", duration, ", CLIPLENGTH:", CLIPLENGTH, ", numberOfClips:", numberOfClips)
    for clipNumber in range(0, numberOfClips): # 
        clipStart=clipNumber*CLIPLENGTH
        clipStop=min((clipNumber+1)*CLIPLENGTH,duration)
        print ("processProjectVideo-clipNumber:", clipNumber, ", clipStart:", clipStart, ", clipStop:", clipStop)
        videoClip = video.subclip(clipStart,clipStop)
        annotatedClip = videoClip.fl_image(process_image)
        videoFileName=PROJECTVIDEOOUTPUT % (clipStart,clipStop)
        print ("processProjectVideo-videoFileName:", videoFileName)
        annotatedClip.write_videofile(videoFileName, audio=False)
开发者ID:autohandle,项目名称:CarNdVehicleDetection-,代码行数:26,代码来源:ProcessVideo.py


示例3: create_video_thumbnails

def create_video_thumbnails(repo, file_id, path, size, thumbnail_file, file_size):

    t1 = timeit.default_timer()
    token = seafile_api.get_fileserver_access_token(repo.id,
            file_id, 'view', '', use_onetime=False)

    if not token:
        return (False, 500)

    inner_path = gen_inner_file_get_url(token, os.path.basename(path))
    clip = VideoFileClip(inner_path)
    tmp_path = str(os.path.join(tempfile.gettempdir(), '%s.png' % file_id[:8]))

    clip.save_frame(tmp_path, t=THUMBNAIL_VIDEO_FRAME_TIME)
    t2 = timeit.default_timer()
    logger.debug('Create thumbnail of [%s](size: %s) takes: %s' % (path, file_size, (t2 - t1)))

    try:
        ret = _create_thumbnail_common(tmp_path, thumbnail_file, size)
        os.unlink(tmp_path)
        return ret
    except Exception as e:
        logger.error(e)
        os.unlink(tmp_path)
        return (False, 500)
开发者ID:haiwen,项目名称:seahub,代码行数:25,代码来源:utils.py


示例4: MoviePyReader

class MoviePyReader(FramesSequence):
    class_priority = 4
    @classmethod
    def class_exts(cls):
        return {'mov', 'mp4', 'avi', 'mpeg', 'wmv', 'mkv'}
    def __init__(self, filename):
        if VideoFileClip is None:
            raise ImportError('The MoviePyReader requires moviepy to work.')
        self.clip = VideoFileClip(filename)
        self.filename = filename
        self._fps = self.clip.fps
        self._len = int(self.clip.fps * self.clip.end)

        first_frame = self.clip.get_frame(0)
        self._shape = first_frame.shape
        self._dtype = first_frame.dtype

    def get_frame(self, i):
        return Frame(self.clip.get_frame(i / self._fps), frame_no=i)

    def __len__(self):
        return self._len

    @property
    def frame_shape(self):
        return self._shape

    @property
    def frame_rate(self):
        return self._fps

    @property
    def pixel_type(self):
        return self._dtype  
开发者ID:soft-matter,项目名称:pims,代码行数:34,代码来源:moviepy_reader.py


示例5: save_out

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
开发者ID:UnforeseenOcean,项目名称:stocktalk,代码行数:29,代码来源:stocktalk.py


示例6: create_movie_dataset

def create_movie_dataset(movie_path, target_folder):
  if not os.path.isdir(target_folder): os.makedirs(target_folder)
  video = VideoFileClip(movie_path)
  num_frames = int(video.fps * video.duration)
  video = video.set_fps(1).set_duration(num_frames).resize(0.5)
  first_frame = 650
  num_cpus = multiprocessing.cpu_count()

  saved_frames = set(map(lambda x: int(x) if x else 0, map(lambda f: ''.join(x for x in f if x.isdigit()), os.listdir(target_folder))))
  num_done = len(saved_frames)
  if num_done == 0:
    offsets = np.random.randint(0, 10, num_frames - first_frame - 9)
    offset_file = os.path.join(target_folder, 'offsets.npz')
    np.savez_compressed(offset_file, offsets=offsets)

  frames_per_process = (num_frames - first_frame) / num_cpus
  for i in xrange(num_cpus):
    start_i = i * frames_per_process + first_frame
    end_i = num_frames if i == num_cpus - 1 else start_i + frames_per_process
    print start_i, end_i
    multiprocessing.Process(
      target=create_movie_process,
      args=(video, target_folder, start_i, end_i, first_frame, i, saved_frames)
    ).start()

  return True
开发者ID:MosNicholas,项目名称:audio-video-alignment,代码行数:26,代码来源:create_datasets.py


示例7: make_small_gif

def make_small_gif(gif_path="F:\\input_gif.gif"):
    """
    shrink gif
    """
    output_file = 'F:\\\output.gif'
    video = VideoFileClip(gif_path).resize(0.6)
    length = int(video.fps * video.duration)
    
    video.write_gif(output_file,
                   fps=video.fps,
                   program="ffmpeg")
    

    new_frame_speed = int(1/(video.fps/2) * 100)
          
    options = ["gifsicle",
               output_file,
               '-O3',
               '-o', output_file
               
               ]
    result = subprocess.Popen(options,
                              stdout = subprocess.PIPE,
                              stderr = subprocess.STDOUT)
    for l in result.stdout.readlines():
        print l    
开发者ID:inkleby,项目名称:inklebyrobots,代码行数:26,代码来源:culture_chef.py


示例8: add_intro

    def add_intro(self):
        for _, _, filenames in os.walk('../intros'):
            choice = os.path.join("../intros", random.choice(filenames))
            sys.stdout.write("Adding intro: %s\n" % choice)
            clip = VideoFileClip(choice)
            clip = clip.set_start(0)
 
        return clip
开发者ID:LumbaJack,项目名称:Vine-Compilation-Bot,代码行数:8,代码来源:makevideo_helper.py


示例9: avi_to_gif

def avi_to_gif(odbname):
    """converts an avi video file to an animated gif so that it can easily be
        easily inserted into a pptx
        avidir = 'customBeamExample'
    """
    avinames=glob.glob(os.path.dirname(odbname)+'/*.avi')
    for aviname in avinames:
        clip = VideoFileClip(aviname)
        clip.write_gif(os.path.splitext(aviname)[0]+'.gif')
开发者ID:GeoZac,项目名称:mechpy,代码行数:9,代码来源:abaqus_report.py


示例10: decrypt_video

def decrypt_video(filename, t0=56):
	vid = VideoFileClip(filename)

	vid.save_frame("frame.png", t=t0+0.05)

	img = Image.open("frame.png").convert(mode='RGB')
	msg = stepic.decode(img)

	return msg 
开发者ID:tcyrus-archive,项目名称:scurvy-detect-pirates,代码行数:9,代码来源:detect.py


示例11: gen_gif

def gen_gif(gif_video_id):
    gif_video = GifVideo.objects.get(pk=gif_video_id)
    vid = download_video(gif_video.video)

    clip = VideoFileClip(vid).subclip((0, 0), (0, 5)).resize((320, 240))
    clip.to_gif(
        "./gif_gallery/static/gif_gallery/gifs/{}.gif".format(vid),
        program='ffmpeg',
        fps=5)

    gif_video.gif_uri = '{}.gif'.format(vid)
    gif_video.save()
    os.remove(vid)
开发者ID:j0die,项目名称:gifgal,代码行数:13,代码来源:utils.py


示例12: create_compilation

def create_compilation(filename, index):
    dims = get_video_dimensions(filename)
    subclips = []
    video_file = VideoFileClip(filename)
    for label in sorted(index.keys()):
        label_img_filename = create_title_frame(label_as_title(label), dims)
        label_clip = ImageClip(label_img_filename, duration=2)
        os.remove(label_img_filename)
        subclips.append(label_clip)
        for region in index[label]:
            subclip = video_file.subclip(*region)
            subclips.append(subclip)
    if not subclips: return None
    return concatenate_videoclips(subclips)
开发者ID:HermanHGF,项目名称:thingscoop,代码行数:14,代码来源:utils.py


示例13: create_trump_dataset

def create_trump_dataset(movie_path, target_folder):
  # To write video to file: clip.write_videofile(outfile, codec='libx264', audio_codec='aac', temp_audiofile='china-%02d.m4a' % i, remove_temp=True)
  # moviepy help: http://zulko.github.io/blog/2014/06/21/some-more-videogreping-with-python/ 
  #               https://zulko.github.io/moviepy/ref/ref.html
  cuts = [(1.7, 2.5), (4.2, 4.6), (4.7, 5.2), (5.35, 5.93), (5.95, 6.45), (6.45, 6.95), (7, 7.34), (7.38, 7.82), (7.85, 8.24), (8.44, 9.04), (9.43, 9.7), (16.44, 16.7), (16.77, 17), (17, 17.31), (17.39, 17.67), (17.9, 18), (18.56, 18.8), (19, 19.4), (19.41, 19.75), (19.78, 20), (20.75, 21), (21, 21.52), (21.9, 22.41), (23, 23.52), (23.7, 23.96), (24.4, 24.7), (24.73, 24.98), (25, 25.38), (26.63, 27.15), (30, 30.36), (31.3, 31.77), (31.9, 32.16), (32.2, 32.5), (32.9, 33.16), (33.23, 33.4), (33.47, 33.79), (33.81, 34.25), (34.3, 34.65), (34.75, 35.23), (35.27, 35.95), (36.03, 36.59), (36.63, 37.04), (38.66, 39.1), (39.85, 40.3), (40.4, 40.75), (40.83, 41.271), (41.59, 41.95), (42.96, 43.33), (43.58, 43.88), (44, 44.6), (47, 47.48), (50.45, 50.75), (51, 51.33), (52.15, 52.48), (58.3, 58.55), (59, 59.4), (60, 60.4), (61.35, 61.71), (62.44, 62.8), (64.3, 64.6), (65.15, 65.58), (67.45, 67.8), (68.8, 69.15), (69.27, 69.6), (70.63, 70.97), (71, 71.4), (72.35, 72.8), (73.3, 73.7), (74.2, 74.61), (76, 76.9), (80.3, 80.65), (81.1, 81.4), (82.4, 82.75), (83.52, 84), (84.14, 84.49), (85.3, 85.6), (86.1, 86.4), (86.8, 87), (87.1, 87.48), (88, 88.2), (88.9, 89.37), (90.3, 90.7), (90.9, 91.2), (91.3, 91.5), (91.55, 91.78), (91.79, 92.06), (92.33, 92.67), (93.3, 93.55), (94.2, 94.5), (96.6, 96.96), (98, 98.44), (98.9, 99.1), (99.14, 99.53), (100.68, 100.92), (100.93, 101.25), (101.45, 101.8), (102.7, 102.96), (103.7, 104), (105.2, 105.7), (105.88, 106.1), (106.2, 106.6), (106.65, 107), (107.05, 107.85), (108.57, 109), (109.1, 109.48), (110.24, 110.74), (113.5, 113.85), (115.12, 115.4), (115.8, 116.25), (116.56, 116.95), (117.95, 118.35), (118.9, 119.3), (119.6, 120.2), (120.4, 120.9), (121.48, 121.9), (122.95, 123.25), (124.25, 124.65), (125, 125.39), (129.58, 129.9), (130.9, 131.3), (131.8, 132.15), (135, 135.5), (135.75, 136.1), (136.2, 136.65), (137, 137.4), (138.55, 138.8), (145.3, 145.75), (152.1, 152.5), (154.8, 155.25), (156.68, 156.95), (157.3, 157.8), (159.4, 159.78), (159.8, 160), (160.46, 160.8), (162.6, 163), (163.9, 164.18), (164.25, 164.63), (164.64, 165.1), (165.33, 165.7), (165.73, 166.1), (166.28, 166.58), (166.6, 167.06), (167.27, 167.65), (167.69, 168), (168.05, 168.45), (168.93, 169.25), (169.28, 169.6), (169.7, 170.15), (171.82, 172.24), (172.8, 173.1), (173.2, 173.6), (174.6, 175.04), (175.2, 175.6), (177, 177.35), (178.55, 178.97)]
  video = VideoFileClip(movie_path)
  subclips = [video.subclip(start, end) for (start, end) in cuts]
  for i in xrange(len(subclips)):
    clip = subclips[i]
    video_outfile = os.path.join(target_folder, 'video', 'china-%03d.mp4' % i)
    audio_outfile = os.path.join(target_folder, 'audio', 'china-%03d.m4a' % i)
    clip.write_videofile(video_outfile, codec='libx264', audio=False)
    clip.audio.write_audiofile(audio_outfile, codec='aac')
  return True
开发者ID:MosNicholas,项目名称:audio-video-alignment,代码行数:14,代码来源:create_datasets.py


示例14: average_video

def average_video(filepath, outpath, start=None, end=None, sample_every=1):
    """Calculate average of video frames"""

    # Load video
    vid = VideoFileClip(filepath, audio=False)
    width = vid.w
    height = vid.h

    if start is None and end is None:
        frame_generator = vid.iter_frames(progress_bar=True, dtype=np.uint8)
    else:
        if start is None:
            start = 0
        if end is None:
            end = vid.duration
        # compute time increment for sampling by frames
        sample_inc = sample_every / vid.fps
        frame_generator = tqdm(vid.get_frame(f) for f in frange(start, end, sample_inc))

    # create starting matrix of zeros
    sum_fs = np.zeros(shape=(height, width, 3), dtype=int)
    ma_sum_fs = np.zeros(shape=(height, width, 3), dtype=int)
    prev_f = np.zeros(shape=(height, width, 3), dtype=int)
    sum_delta_fs = np.zeros(shape=(height, width, 3), dtype=int)

    n_frames = 0
    for f in frame_generator:
        delta = f - prev_f
        sum_delta_fs += delta
        sum_fs += f

        ma_sum_fs += f
        if divmod(n_frames, 100)[1] == 0 and n_frames > 0:
            ma_f = ma_sum_fs / 100
            Image.fromarray(ma_f.astype(np.uint8))\
                .save(os.path.join(outpath, 'movavg_{}.png'.format(n_frames)))
            ma_sum_fs = np.zeros(shape=(height, width, 3), dtype=int)

        n_frames += 1
        prev_f = f

    # average out the values for each frame
    average_delta_f = sum_delta_fs / n_frames
    average_f = sum_fs / n_frames

    # Create images
    delta_img = Image.fromarray(average_delta_f.astype(np.uint8))
    delta_img.save(os.path.join(outpath, 'average_delta.png'))
    final_img = Image.fromarray(average_f.astype(np.uint8))
    final_img.save(os.path.join(outpath, 'average.png'))
开发者ID:nicodv,项目名称:research,代码行数:50,代码来源:frameprocessor.py


示例15: video2rollscan

def video2rollscan(videofile, focus, start=0, end=None, savefile=None):
    """
    
    Makes a scan of the roll from the video.
    Requires the pyton module MoviePy
    
    Parameters
    -----------
    
    video
        Any videofile that MoviePy (FFMPEG) can read.
        
    focus
        A function ( f(image)->rectangular image ). For instance
        if the line of interest is defined by y=15 and x=10...230
        
        >>> focus = lambda im : im[ [15], 10:230 ]
        
    start,end
        Where to start and stop, each one either in seconds, or in
        format `(minutes, seconds)`. By default `start=0` and `end`
        is the end of the video.
        
    savefile
        If provided, the scan image will be saved under this name.
    
    Returns
    --------
    
      A W*H*3 RGB picture of the piano roll made by stacking the focus
      lines of the different frames under one another.
    """

    from moviepy.editor import VideoFileClip

    if end is None:
        end = video.duration

    video = VideoFileClip(videofile, audio=False).subclip(start, end)

    tt = np.arange(0, video.duration, 1.0 / video.fps)
    result = np.vstack([focus(video.get_frame(t)) for t in tt])

    if savefile:
        import matplotlib.pyplot as plt

        plt.imsave(savefile)

    return result
开发者ID:99plus2,项目名称:unroll,代码行数:49,代码来源:video.py


示例16: create_summary

def create_summary(filename, regions):
    """ Join segments

    Args:
        filename(str): filename
        regions():
    Returns:
        VideoFileClip: joined subclips in segment

    """
    subclips = []
    input_video = VideoFileClip(filename)
    last_end = 0
    for (start, end) in regions:
        subclip = input_video.subclip(start, end)
        subclips.append(subclip)
        last_end = end
    return concatenate_videoclips(subclips)
开发者ID:modihere,项目名称:vidsum,代码行数:18,代码来源:sum.py


示例17: convert_to_mp4_file

def convert_to_mp4_file(src_path, dest_path,
                        video_codec=DEFAULT_VIDEO_CODEC,
                        audio_codec=DEFAULT_VIDEO_AUDIO_CODEC):
    """
    Takes an existing movie file and converts it to mp4

    src_path (str): full path to the video file to be copied/processed

    dest_path (str): full path to where the video file should be copied

    video_codec (str): optional string to specify a codec. Otherwise
        all copied videos will be mp4 regardless of extension

    returns: dest_path
    """
    movie = VideoFileClip(src_path)
    movie.write_videofile(dest_path, codec=video_codec, audio_codec=audio_codec)
    return dest_path
开发者ID:Ahome7490,项目名称:watson-word-watcher,代码行数:18,代码来源:audio_video.py


示例18: average_video

def average_video(filepath, outpath, start=None, end=None, sample_every=1):
    """Calculate average of video frames"""

    # Load video
    vid = VideoFileClip(filepath, audio=False).resize(width=66)
    width = vid.w
    height = vid.h

    if start is None and end is None:
        frame_generator = vid.iter_frames(progress_bar=True, dtype=np.uint8)
    else:
        if start is None:
            start = 0
        if end is None:
            end = vid.duration
        # compute time increment for sampling by frames
        sample_inc = sample_every / vid.fps
        frame_generator = tqdm(vid.get_frame(f) for f in frange(start, end, sample_inc))

    # create starting matrix of zeros
    sum_fs = np.zeros(shape=(height, width, 3), dtype=int)
    ma_sum_fs = np.zeros(shape=(height, width, 3), dtype=int)
    prev_f = np.zeros(shape=(height, width, 3), dtype=int)
    sum_delta_fs = np.zeros(shape=(height, width, 3), dtype=int)

    n_frames = 0
    for f in frame_generator:
        #delta = f - prev_f
        #sum_delta_fs += delta
        #sum_fs += f

        #ma_sum_fs += f
        #if divmod(n_frames, 100)[1] == 0 and n_frames > 0:
        #    ma_f = ma_sum_fs / 100
        #    Image.fromarray(ma_f.astype(np.uint8))\
        #        .save(os.path.join(outpath, 'movavg_{}.png'.format(n_frames)))
        #    ma_sum_fs = np.zeros(shape=(height, width, 3), dtype=int)

        #n_frames += 1
        #prev_f = f
        print len(f)
        time.sleep(1.0/float(sample_every))
开发者ID:cheetahray,项目名称:Shanghai,代码行数:42,代码来源:frameprocessor.py


示例19: __init__

    def __init__(self, filename):
        if VideoFileClip is None:
            raise ImportError('The MoviePyReader requires moviepy to work.')
        self.clip = VideoFileClip(filename)
        self.filename = filename
        self._fps = self.clip.fps
        self._len = int(self.clip.fps * self.clip.end)

        first_frame = self.clip.get_frame(0)
        self._shape = first_frame.shape
        self._dtype = first_frame.dtype
开发者ID:soft-matter,项目名称:pims,代码行数:11,代码来源:moviepy_reader.py


示例20: excerpt_and_compile_video_file

def excerpt_and_compile_video_file(src_path, dest_path, timestamps,
                                  left_padding=0.01,
                                  right_padding=0.01,
                                  video_codec=DEFAULT_VIDEO_CODEC,
                                  audio_codec=DEFAULT_VIDEO_AUDIO_CODEC):
    """
    creates a new video compiled from cuts of `src_path`

    timestamps (list): a sequence of tuples, in (start, end) (in seconds)
    """
    video = VideoFileClip(src_path)
    max_ts = video.duration
    clips = []
    for ts in timestamps:
        x = max(0, ts[0] - left_padding)
        y = min(max_ts, ts[1] + right_padding)
        clips.append(video.subclip(x, y))
    allclips = concatenate_videoclips(clips)
    allclips.write_videofile(dest_path, codec=video_codec, audio_codec=audio_codec)
    return dest_path
开发者ID:Ahome7490,项目名称:watson-word-watcher,代码行数:20,代码来源:audio_video.py



注:本文中的moviepy.editor.VideoFileClip类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.subprocess_call函数代码示例发布时间:2022-05-27
下一篇:
Python config.get_setting函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap