GithubHelp home page GithubHelp logo

MoviePy fixes ? about videogrep HOT 10 CLOSED

antiboredom avatar antiboredom commented on September 27, 2024
MoviePy fixes ?

from videogrep.

Comments (10)

antiboredom avatar antiboredom commented on September 27, 2024

Thank you so much for all of this! Extremely helpful. And of course thank you for MoviePy - it's really wonderful.

On Jun 20, 2014, at 12:17 PM, Zulko [email protected] wrote:

Hi there,

First: bravo ! It's a very cool project, and it made my day !

I noticed that your script videogrep.py uses MoviePy in a way that could be improved, so here are a few remarks.

Remark 1

For every video segment assembled in create_supercut, you create a clip by calling VideoFileClip. This is bad, as every time you call VideoFileClip, MoviePÿ creates a new FFMPEG process to communicate with the file, and it takes 10-20 Mo of RAM. If you have 30 segments inside the same video file, you should call VideoFileClip one time only on this video file, then cut different subclips from that one instance.

Remark 2

The function concatenate ignores the starting and ending times specified by the set_start and set_end functions, actually it will recompute these times (like what you did with your cumulative 'time' variable).

Putting remarks 1 and 2 together, here is how I would have implemented your create_supercut (note that I separate the 'padding addition' from the actual video editing):

def create_supercut(composition, outputfile, padding):

print ("Creating clips.")

# add padding when necessary
for (clip, nextclip) in in zip(composition, composition[1:]):
    if ( ( nextclip['file'] == clip['file'] ) and
         ( nextclip['start'] < clip['end'] )):
        nextclip['start'] += padding
    duration = end - start

# put all clips together:
all_filenames = set([c['file'] for c in composition)
videofileclips = dict([(f, VideoFileClip(f)) for f in all_filenames])
cut_clips = [videofileclips[ c['file']  ].subclip(c['start'], c['end'])
                   for c in composition]     
final_clip = concatenate( cut_clips)
final_clip.to_videofile(outputfile)

Now some minor remarks:

Minor remark 1

In my examples I often use

from moviepy.editor import *
but for long scripts it is a little frowned upon, your scripts we be better understandable if you state what you import

from moviepy.editor import VideoFileClip, concatenate
The moviepy.editor module is meant for editing videos "by hand" in an interactive way, so it loads a lot of things (and starts a PyGame session) and can slow down your program at the beginning. Write rather this (the program will only fetch what it needs):

from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.compositing.concatenate import concatenate
Minor remark 2

Apparently you have been a victim of the bug that makes that every time you generate a video file it creates an unwanted log file for the audio. I wasn't aware of this bug (it has been there in the last two months), but yesterday someone commited a fix for it, so the last version of MoviePy doesn't have it (no logfile is generated by default). So your 'cleaning' function is no longer needed.

Minor non-moviepy-related remarks

Maybe you should consider making a proper Python module (with a setup.py). This would come with advantages, like easy 'pip' install, automatic installation of the dependencies 'pattern' and 'moviepy' during the installation of videogrep, and automatic installation of the executable scripts like videogrep.py, so that they could be launched from anywhere, not just the folder where the script is.

Also, you could have a look at the python module "docopt", it makes the command line interface very easy to code and debug.

I hope this helped ! If you have any questions or request concerning MoviePy let me know.

Cheers !


Reply to this email directly or view it on GitHub.

from videogrep.

Zulko avatar Zulko commented on September 27, 2024

Hey !

I see you are getting more Github stars in a few days than MoviePy over it's one year of existence. I would be jealous but since MoviePy clearly benefited from the success of Videogrep I'd rather thank you !

I couldn't resist, I wrote a blog post with some more videogreping. In the post, I try to grep not only subtitles blocks, but the whole sentences where the expression appears, possibly spanning several subtitles blocks: this makes cleaner and more interesting cuts. I also make a lame attempt at greping single words (that is, cutting the scene tightly to keep just the word we are looking for). I don't know if you already tried this, but I thought you could be interested :)

from videogrep.

 avatar commented on September 27, 2024

I'd not heard of moviepy until I saw videogrep. Both are awesome tools. I've uploaded a python script called wordsworth, which does frequency analysis on text files. If you give it a subtitles file you can find out which are the most commonly occurring word, word pairs, triples and quads. I use it to find candidate search terms for videogrep.

from videogrep.

antiboredom avatar antiboredom commented on September 27, 2024

Hey @Zulko - love the blog post! Really great stuff.

As far as the stars thing goes it's pretty nuts. Your work totally made videogrep possible - and I really hope that more and more people will learn about & use MoviePy. Also, if you're in NY (or pass through at some point) let me know. Beers on me.

from videogrep.

shawnr avatar shawnr commented on September 27, 2024

@antiboredom @autonomoid @Zulko I love finding new troves of projects. This is a great example. I'm also new to MoviePy, but it's going in my toolkit!

from videogrep.

 avatar commented on September 27, 2024

I've just written a little tool that lets you check which codecs and file extensions your ffmpeg installation supports. Its currently in my fork. Let me know if this is something you want me to integrate into videogrep. This way you can do support checking at runtime.

https://github.com/autonomoid/videogrep/blob/master/ffmpeg_support.py

from videogrep.

antiboredom avatar antiboredom commented on September 27, 2024

@autonomoid that sounds really useful - perhaps it could be integrated into MoviePy itself? What do you think @Zulko?

from videogrep.

Zulko avatar Zulko commented on September 27, 2024

The best move would be to first change the default codec to 'libmp3lame' in Videogrep (and maybe in moviepy). Then yes you could integrate @automonoid's ffmpeg_support.py, that may come in handy if people still have issues.

On MoviePy's side, my focus it to clarify the errors returned when something goes wrong with FFMPEG. I still didn't push it online (getting error handling to work in a cross-platform and cross-version way is more difficult than it sounds in Python) but here is what you will get when it's done:

IOError: [Errno 32] Broken pipe
MoviePy error: FFMPEG encountered the following error while writing file testTEMP_MPY_to_videofile_SOUND.m4a:

Unknown encoder 'libfdk_aac'

MoviePy error: the audio export failed because FFMPEG didn't find the specified codec for audio  encoding (libfdk_aac). Please install this codec or change the codec when calling to_videofile or to_audiofile. For instance for mp3:
  >>> to_videofile('myvid.mp4', audio_codec='libmp3lame')

That should greatly help people understand the issue and fix the problems by themselves.

from videogrep.

shawnr avatar shawnr commented on September 27, 2024

That would be excellent error feedback, @Zulko!

from videogrep.

Zulko avatar Zulko commented on September 27, 2024

The error feedbacks are now better in moviepy, it should make debugging easier. And the default codec for audio is now libmp3lame. I hope this will help.

And if you guys want some more automatic cutting, here is a ~20 lines script which summarizes soccer videos based on the reactions of the crowd :)

from videogrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.