Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when saving movie file #61

Open
ognancy4life opened this issue Jul 16, 2021 · 14 comments
Open

Error when saving movie file #61

ognancy4life opened this issue Jul 16, 2021 · 14 comments

Comments

@ognancy4life
Copy link

ognancy4life commented Jul 16, 2021

I'm getting an error when I try to save my xmovie file. The frames are showing up in the output_dir where they're supposed to, but the final save doesn't work. I do have ffmpeg installed and have used it successfully for other things.

mov = Movie(
SSH.sla.sel(
longitude=slice(0,150),
time=slice("2019-05-01", "2019-08-2")),
cmap='RdBu',
vmin=-.3, vmax=.3,
levels=41,
plotmethod='contourf',
extend='both'
)
mov.preview(30) # To preview a specific frame
mov.save(
output_dir + 'SLA2019_Saildrone_movie.mp4',
progress=True,
overwrite_existing=True,
verbose=True
)
! rm output_dir + frame_*.png

Yields the following error:

ValueError Traceback (most recent call last)
/var/folders/77/krt31b_92xg9grw6m3r25r380000mn/T/ipykernel_53094/1418684609.py in
11 )
12 mov.preview(30) # To preview a specific frame
---> 13 mov.save(
14 output_dir + 'SLA2019_Saildrone_movie.mp4',
15 progress=True,

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in save(self, filename, remove_frames, remove_movie, progress, verbose, overwrite_existing, parallel, parallel_compute_kwargs, framerate, ffmpeg_options, gif_palette, gif_resolution_factor, gif_framerate)
522
523 # Create movie
--> 524 combine_frames_into_movie(
525 dirname,
526 moviefile,

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in combine_frames_into_movie(sourcefolder, moviename, frame_pattern, remove_frames, verbose, ffmpeg_options, framerate)
209 sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options
210 )
--> 211 p = _check_ffmpeg_execute(command, verbose=verbose)
212
213 print("Movie created at %s" % (moviename))

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _check_ffmpeg_execute(command, verbose)
134 else:
135 try:
--> 136 p = _execute_command(command, verbose=verbose)
137 return p
138 except RuntimeError:

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _execute_command(command, verbose, error)
116 if out_check != "":
117 # only display 10 lines, this cant be that hard?
--> 118 sys.stdout.write(out)
119 sys.stdout.flush()
120 else:

~/opt/anaconda3/lib/python3.8/site-packages/ipykernel/iostream.py in write(self, string)
499
500 if not isinstance(string, str):
--> 501 raise ValueError(
502 "TypeError: write() argument must be str, not {type(string)}"
503 )

ValueError: TypeError: write() argument must be str, not {type(string)}

@jbusecke
Copy link
Owner

Hi @ognancy4life, thanks for raising this issue and sorry for the long wait. Could you post the version of ffmpeg that you are using?

@ognancy4life
Copy link
Author

Thanks for the reply, @jbusecke ! Here ya go:
ffmpeg version N-102789-g072788c46e Copyright (c) 2000-2021 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration:
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 1.102 / 59. 1.102
libavformat 59. 3.101 / 59. 3.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.102 / 8. 0.102
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100

@jbusecke
Copy link
Owner

Ughhh this is indeed a bit convoluted to debug. Can you try to set verbose=False and see if the movie gets created?

@jbusecke
Copy link
Owner

I think this error is just raised in this part of the code which is responsible for the printing the stdout to the notebook...

@ognancy4life
Copy link
Author

Same as above but with verbose=False yields this, which is why I switched to verbose=True :


RuntimeError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _check_ffmpeg_execute(command, verbose)
135 try:
--> 136 p = _execute_command(command, verbose=verbose)
137 return p

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _execute_command(command, verbose, error)
123 if p.returncode != 0:
--> 124 raise RuntimeError("Command %s failed" % command)
125 return p

RuntimeError: Command ffmpeg -r 15 -i "output/frame_%05d.png" -y -c:v libx264 -preset veryslow -crf 10 -pix_fmt yuv420p -r 15 "output/" failed

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
/var/folders/77/krt31b_92xg9grw6m3r25r380000mn/T/ipykernel_25142/4094402877.py in
15 # There is some kind of issue with xmovie.
16 # I raised it at #61
---> 17 mov.save(
18 output_dir,
19 'SLA2019_Saildrone_movie.mp4',

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in save(self, filename, remove_frames, remove_movie, progress, verbose, overwrite_existing, parallel, parallel_compute_kwargs, framerate, ffmpeg_options, gif_palette, gif_resolution_factor, gif_framerate)
522
523 # Create movie
--> 524 combine_frames_into_movie(
525 dirname,
526 moviefile,

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in combine_frames_into_movie(sourcefolder, moviename, frame_pattern, remove_frames, verbose, ffmpeg_options, framerate)
209 sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options
210 )
--> 211 p = _check_ffmpeg_execute(command, verbose=verbose)
212
213 print("Movie created at %s" % (moviename))

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _check_ffmpeg_execute(command, verbose)
137 return p
138 except RuntimeError:
--> 139 raise RuntimeError(
140 "Something has gone wrong. Use verbose=True to check if ffmpeg displays a problem"
141 )

RuntimeError: Something has gone wrong. Use verbose=True to check if ffmpeg displays a problem

@jbusecke
Copy link
Owner

Lol, that isnt the most helpful advice, huh?

Can you try to run ffmpeg -r 15 -i "output/frame_%05d.png" -y -c:v libx264 -preset veryslow -crf 10 -pix_fmt yuv420p -r 15 "output/" in the terminal? I feel there might be something wrong with the filename?

@jbusecke
Copy link
Owner

Can you pass an explicit string instead of `output_dir + 'SLA2019_Saildrone_movie.mp4' to test?

@ognancy4life
Copy link
Author

(base) MacBook-Pro-2:Saildrone_python williams$ ffmpeg -r 15 -i "output/frame_%05d.png" -y -c:v libx264 -preset veryslow -crf 10 -pix_fmt yuv420p -r 15 "output/"
ffmpeg version N-102789-g072788c46e Copyright (c) 2000-2021 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration:
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 1.102 / 59. 1.102
libavformat 59. 3.101 / 59. 3.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.102 / 8. 0.102
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
Unrecognized option 'preset'.
Error splitting the argument list: Option not found

@ognancy4life
Copy link
Author

And:

mov = Movie(
SSH.sla.sel(
longitude=slice(0,150),
time=slice("2019-05-01", "2019-08-2")
),
cmap='RdBu',
vmin=-.3, vmax=.3,
levels=41,
plotmethod='contourf',
extend='both'
)
mov.preview(30) # To preview a specific frame

mov.save(
'output/SLA2019_Saildrone_movie.mp4',
progress=True,
overwrite_existing=True,
verbose=False
)

100%
94/94 [01:05<00:00, 1.23it/s]

RuntimeError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _check_ffmpeg_execute(command, verbose)
135 try:
--> 136 p = _execute_command(command, verbose=verbose)
137 return p

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _execute_command(command, verbose, error)
123 if p.returncode != 0:
--> 124 raise RuntimeError("Command %s failed" % command)
125 return p

RuntimeError: Command ffmpeg -r 15 -i "output/frame_%05d.png" -y -c:v libx264 -preset veryslow -crf 10 -pix_fmt yuv420p -r 15 "output/SLA2019_Saildrone_movie.mp4" failed

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
/var/folders/77/krt31b_92xg9grw6m3r25r380000mn/T/ipykernel_25142/1961350411.py in
15 # There is some kind of issue with xmovie.
16 # I raised it at #61
---> 17 mov.save(
18 'output/SLA2019_Saildrone_movie.mp4',
19 progress=True,

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in save(self, filename, remove_frames, remove_movie, progress, verbose, overwrite_existing, parallel, parallel_compute_kwargs, framerate, ffmpeg_options, gif_palette, gif_resolution_factor, gif_framerate)
522
523 # Create movie
--> 524 combine_frames_into_movie(
525 dirname,
526 moviefile,

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in combine_frames_into_movie(sourcefolder, moviename, frame_pattern, remove_frames, verbose, ffmpeg_options, framerate)
209 sourcefolder, moviename, framerate, frame_pattern, ffmpeg_options
210 )
--> 211 p = _check_ffmpeg_execute(command, verbose=verbose)
212
213 print("Movie created at %s" % (moviename))

~/opt/anaconda3/lib/python3.8/site-packages/xmovie/core.py in _check_ffmpeg_execute(command, verbose)
137 return p
138 except RuntimeError:
--> 139 raise RuntimeError(
140 "Something has gone wrong. Use verbose=True to check if ffmpeg displays a problem"
141 )

RuntimeError: Something has gone wrong. Use verbose=True to check if ffmpeg displays a problem

@jbusecke
Copy link
Owner

This suggests to me that there is something incompatible with the version of ffmpeg you have installed. Could you try to install a new version via conda/mamba?

$conda install -c conda-forge ffmpeg

@ognancy4life
Copy link
Author

OK, I installed that version of ffmpeg and ran it a few ways:

  1. with output_dir, 'SLA2019_Saildrone_movie.mp4' and I still got that error "ValueError: TypeError: write() argument must be str, not {type(string)}" and no video.
  2. with output_dir + 'SLA2019_Saildrone_movie.mp4' and still got the error "ValueError: TypeError: write() argument must be str, not {type(string)}" but it made the video!
  3. with just 'SLA2019_Saildrone_movie.mp4' and no directory. still gives the error "ValueError: TypeError: write() argument must be str, not {type(string)}" and produces the video but not where I want it.
  4. with 'output/SLA2019_Saildrone_movie.mp4' gives the error "ValueError: TypeError: write() argument must be str, not {type(string)}" but it made the video!

So, it's working but with an error. Thanks and let me know if you want me to try anything else to help diagnose the issue!

@jbusecke
Copy link
Owner

Ooof that is frustrating, sorry. These were all run with 'verbose=True'?

I think this is then purely an issue with printing the ffmpeg output to the notebook, since 2.-4. produce a video.

  1. I wouldnt expect to work, because we need a full filename as one string.

@ognancy4life
Copy link
Author

No worries here! Thanks for your help! I am running this in a notebook so it's fine, I can just skip past the error. Would this type of error interrupt a .py script if someone were running that way?

@jbusecke
Copy link
Owner

Good question. I dont thing so? But that would need some testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants