Пример #1
0
def generate_thumbnail(video):
    if video.thumbnail:
        return
    video_filename = os.path.join(settings.MEDIA_ROOT, video.video.name)
    # adjust start time to generate thumbnails for smaller videos
    video_length = effects.video_length(video_filename)
    if effects.Vtime(video_length).total_seconds < 5:
        start_at = 0
    else:
        start_at = 4
    command = "ffmpeg -itsoffset -%(start_at)d -i %(video)s" + " -vframes 1 -s 192x108 %(dest)s"
    thumbnail_filename = generate_tempfilename(suffix=".jpg")
    try:
        cmdargs = {"video": video_filename, "dest": thumbnail_filename, "start_at": start_at}
        response = subprocess.call(command % cmdargs, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # Fail silently if ffmpeg is not installed.
        # the ffmpeg commandline tool that is.
        if response != 0:
            logger.error("couldn't generate thumbnail - ffmpeg failed: %s", command % cmdargs)
            return

        if not os.path.exists(thumbnail_filename):
            logger.error("couldn't generate thumbnail - no file " + "generated: %s", command % cmdargs)
            return

        video.thumbnail.save(os.path.basename(thumbnail_filename), File(file(thumbnail_filename)))
    finally:
        os.remove(thumbnail_filename)
    return True
Пример #2
0
 def test_split_video(self):
     """
     Test that a video file can be split and that length of the split file
     is correct.
     """
     new_filename = effects.split_video(
         movie_path('testdata'), "00:00:04", "00:00:04")
     self.failUnless(
         effects.video_length(new_filename).startswith("00:00:04"))
     return new_filename
Пример #3
0
 def test_video_length(self):
     self.failUnlessEqual(effects.video_length(movie_path('testdata')),
                          "00:00:14.78")
Пример #4
0
 def test_split_video_no_duration(self):
     new_filename = effects.split_video(
         movie_path('testdata'), "00:00:04")
     self.failUnlessEqual(effects.video_length(new_filename), "00:00:11.14")
     return new_filename