alexjc / shadertoy-render

Render a ShaderToy script directly to a video file.
BSD 3-Clause "New" or "Revised" License
238 stars 39 forks source link

Problems with numpy version number <1.8 #1

Closed chaosink closed 9 years ago

chaosink commented 9 years ago

I can watch the effect. But when it's over nothing is created.

alexjc commented 9 years ago

It's automatically created and overwritten based on the command line argument.

Do you have ffmpeg installed in your path?

chaosink commented 9 years ago

Yes, I have installed ffmpeg.

chaosink commented 9 years ago
➜  shadertoy-render git:(master) ✗ ffmpeg -h      
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
  configuration: 
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
Hyper fast Audio and Video encoder
chaosink commented 9 years ago

I downloaded the tarball which is of the newest version from the official website and compiled it.

alexjc commented 9 years ago

What command line are you using exactly, and what's the size of the output file you specify?

chaosink commented 9 years ago
➜  shadertoy-render git:(master) ✗ python shadertoy-render.py Seascape.glsl Seascape.mp4 
➜  shadertoy-render git:(master) ✗ python shadertoy-render.py Seascape.glsl Seascape.mp4 --size 1920x1080 --duration 5.0 --rate 60

It seems that the option --duration 5.0 has no effect.

alexjc commented 9 years ago

Is the Seascape.mp4 file ever created?

alexjc commented 9 years ago

The only idea I have is for you to disable -loglevel panic in the call of ffmpeg and see what the error is, if there is any.

chaosink commented 9 years ago

There is no Seascape.mp4 in the directory before. Here are more information of the procedure.

➜  shadertoy-render git:(master) ✗ ls
docs  glsl  LICENSE  README.rst  Seascape.glsl  shadertoy-render.py
➜  shadertoy-render git:(master) ✗ python shadertoy-render.py Seascape.glsl Seascape.mp4 --size 1920x1080 --duration 5.0 --rate 10
WARNING: Traceback (most recent call last):
  File "shadertoy-render.py", line 167, in <module>
    canvas.app.run()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/application.py", line 123, in run
    return self._backend._vispy_run()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 194, in _vispy_run
    self._vispy_process_events()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 188, in _vispy_process_events
    win._on_draw()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 407, in _on_draw
    self._vispy_canvas.events.draw(region=None)  # (0, 0, w, h))
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 436, in __call__
    self._invoke_callback(cb, event)
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 452, in _invoke_callback
    self, cb_event=(cb, event))
  << caught exception here: >>
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 448, in _invoke_callback
    cb(event)
  File "shadertoy-render.py", line 104, in on_draw
    self._stdout.write(framebuffer.tobytes())
AttributeError: 'numpy.ndarray' object has no attribute 'tobytes'
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> for DrawEvent
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 2
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 3
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 4
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 5
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 6
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 7
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 8
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 9
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 10
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f6cb1f7cc50>> repeat 20
➜  shadertoy-render git:(master) ✗ ls
docs  glsl  LICENSE  README.rst  Seascape.glsl  shadertoy-render.py
➜  shadertoy-render git:(master) ✗ 
chaosink commented 9 years ago

Here is the information after disabling -loglevel panic.

➜  shadertoy-render git:(master) ✗ python shadertoy-render.py Seascape.glsl Seascape.mp4 --size 1920x1080 --duration 5.0 --rate 10
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
  configuration: 
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
WARNING: Traceback (most recent call last):
  File "shadertoy-render.py", line 167, in <module>
    canvas.app.run()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/application.py", line 123, in run
    return self._backend._vispy_run()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 194, in _vispy_run
    self._vispy_process_events()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 188, in _vispy_process_events
    win._on_draw()
  File "/usr/local/lib/python2.7/dist-packages/vispy/app/backends/_glfw.py", line 407, in _on_draw
    self._vispy_canvas.events.draw(region=None)  # (0, 0, w, h))
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 436, in __call__
    self._invoke_callback(cb, event)
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 452, in _invoke_callback
    self, cb_event=(cb, event))
  << caught exception here: >>
  File "/usr/local/lib/python2.7/dist-packages/vispy/util/event.py", line 448, in _invoke_callback
    cb(event)
  File "shadertoy-render.py", line 104, in on_draw
    self._stdout.write(framebuffer.tobytes())
AttributeError: 'numpy.ndarray' object has no attribute 'tobytes'
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> for DrawEvent
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 2
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 3
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 4
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 5
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 6
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 7
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 8
ERROR: Invoking <bound method RenderingCanvas.on_draw of <RenderingCanvas (Glfw) at 0x7f22a5e5ec50>> repeat 9
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, bitrate: 663552 kb/s
    Stream #0:0: Video: rawvideo (RGBA / 0x41424752), rgba, 1920x1080, 663552 kb/s, 10 tbr, 10 tbn, 10 tbc
Unknown encoder 'libx264'
➜  shadertoy-render git:(master) ✗ 
chaosink commented 9 years ago

I googled Unknown encoder 'libx264' and ffmpeg libx264 and found this: How to quickly compile FFmpeg with libx264 (x264, H.264).

So I recompiled ffmpeg with ./configure --enable-gpl --enable-libx264. This time the MP4 file appeared, however I couldn't play it using VLC which said unable to identify the input format. And I also found that no matter how long a shader runs, the MP4 file is always 262 bytes.

Here is the information of encoding:

Input #0, rawvideo, from 'pipe:':
  Duration: N/A, bitrate: 884736 kb/s
    Stream #0:0: Video: rawvideo (RGBA / 0x41424752), rgba, 1280x720, 884736 kb/s, 30 tbr, 30 tbn, 30 tbc
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x2fb9ba0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x2fb9ba0] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0x2fb9ba0] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'Seascape.mp4':
  Metadata:
    encoder         : Lavf56.36.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1280x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.41.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
frame=    0 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
alexjc commented 9 years ago

The libx264 things should be resolved. There's one bug left in this project:

AttributeError: 'numpy.ndarray' object has no attribute 'tobytes`

I'll check what it's supposed to be, maybe toarray.

alexjc commented 9 years ago

Try getting latest including my fix [de66a57f1c]. Playing the output video with VLC should work fine!

You can also use --verbose parameter to display ffmpeg output without hacking the source.

chaosink commented 9 years ago

I updated numpy to 1.9.2 and now it works perfectly.

The problem about duration that I posed does't exist actually. I mistook it.

Many thanks for your problem solving!

alexjc commented 9 years ago

The duration problem may have been related to the exception above.

Great, closing the ticket!