Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Let MovieFileWriter save temp files in a new dir#11860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
fredrik-1 wants to merge1 commit intomatplotlib:masterfromfredrik-1:frame_dir

Conversation

fredrik-1
Copy link
Contributor

Another try to get the animation module to work better. The reason for these changes are that they make it possible to create videos of animations with a low frame rate to work in video players like the VLC player. This can be done by changing the output frame rate to a higher value by for example usingextra_args=['-r', '25'] orextra_args=['-vf', 'fps=25'].

The changes in this pr:

  • deleted-vframes in ffmpeg file writer because it is usually unnecessary and make it impossible to change the output frame rate.
  • made theMovieFileWriter save the temporary files in a new directory to avoid the possible problem that the writer reads old files.
  • made it possible to not have anything exceptextra_args after the-i temp_files by not using a codec ifcodec=''. This is not really necessary but gives more freedom and might be useful for someone.

@@ -542,6 +549,9 @@ def cleanup(self):
self._temp_names)
for fname in self._temp_names:
os.remove(fname)
folder = os.path.split(fname)[0]
if folder is not '':
shutil.rmtree(folder, ignore_errors=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Isn't it dangerous to simply delete a (possibly non-empty) folder from the user's disk? I guess we don't want to have people saying "Matplotlib sucks, it just deleted all my data without warning".

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good point. That code is definitely dangerous. I have changed toos.rmdir now.

One problem is that I believe thatos.rmdir sometimes don't remove empty directory's on windows for some reason. It seems to work for me now and it is possible that it doesn't happen that often and never in this application.

@fredrik-1fredrik-1force-pushed theframe_dir branch 3 times, most recently from22a9d12 to380104aCompareAugust 16, 2018 10:10
Copy link
Contributor

@dopplershiftdopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In general, putting the frames in a directory is a good idea and something I should have done awhile ago.

Only a few minor changes.

'''
self.fig = fig
self.outfile = outfile
if dpi is None:
dpi = self.fig.dpi
self.dpi = dpi
self._adjust_frame_size()
root, _ = os.path.splitext(outfile)
if frame_dir is None:
for i in itertools.count():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thinktempfile.mkdtemp would be more straightforward here.

folder = os.path.split(fname)[0]
if folder is not '':
try:
os.rmdir(folder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should really only delete the directory ifwe created it. Right now the user could pass us an existing directory, and this code would remove it when done.

@@ -597,7 +613,10 @@ class FFMpegBase(object):

@property
def output_args(self):
args = ['-vcodec', self.codec]
if self.codec is not '':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this would be better as:

args= []ifself.codec:args.extend(['-vcodec',self.codec])


frame_dir : str or None, optional
Directory where the temporary files are saved. None means that a
new directory is created and '' means that no temporary directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not sure it's necessary to document'' as an option; given that we're eliminatingvframes below, I'm not sure we want people doing it.

@@ -665,8 +684,7 @@ def _args(self):
# Returns the command line parameters for subprocess to use
# ffmpeg to create a movie using a collection of temp images
return [self.bin_path(), '-r', str(self.fps),
'-i', self._base_temp_name(),
'-vframes', str(self._frame_counter)] + self.output_args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Eliminatingvframes is only ok because we're putting frames in a temp directory by default, IMO. The original intent behind addingvframes was to handle a problem where users got stale frames in their animation if they changed the number of frames.

@jklymakjklymak added this to thev3.1 milestoneAug 16, 2018
@fredrik-1
Copy link
ContributorAuthor

Made the suggested changes.

@anntzer
Copy link
Contributor

See also#3536 for what was one of my first PRs to matplotlib :p
I think nowadays I'd suggest using TemporaryDirectory instead, it's more robust wrt. interpreter shutdown.

@jklymak
Copy link
Member

@fredrik-1 did you want to proceed w/ this? We are trying to tag 3.1 soonish...

@jklymakjklymak modified the milestones:v3.1.0,v3.2.0Mar 3, 2019
@jklymakjklymak added the stale labelMar 3, 2019
@jklymak
Copy link
Member

Thanks a lot for the contribution. I'm going to close this as having had no action for quite a while. OTOH, if there is still a community that wants this, please feel free to re-open, with my apologies!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ImportanceOfBeingErnestImportanceOfBeingErnestImportanceOfBeingErnest left review comments

@dopplershiftdopplershiftdopplershift requested changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.2.0
Development

Successfully merging this pull request may close these issues.

5 participants
@fredrik-1@anntzer@jklymak@dopplershift@ImportanceOfBeingErnest

[8]ページ先頭

©2009-2025 Movatter.jp