rezoo / movis

Python library for video editing, presentation video generation, motion graphics, shader art coding, and other video production tasks
https://rezoo.github.io/movis/
MIT License
350 stars 21 forks source link

webm ffmpeg flags seem to not be right? #32

Closed elijahsgh closed 10 months ago

elijahsgh commented 10 months ago

Code:

import movis as mv

scene = mv.layer.Composition(size=(1080, 1900), duration=4.0)
scene.write_video("output.webm")

Output:

[webm @ 0x6e9a600] Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
  1%|█▎       

Is this my version of ffmpeg or...? I'm not sure how to solve this.

rezoo commented 10 months ago

I haven’t run it myself, but I suspect the issue might be with the flags passed to ffmpeg. The essence of write_video is that it calls imageio-ffmpeg for rendering, but the flags for webm are probably incorrect. I will verify this later, so please wait a bit

elijahsgh commented 10 months ago

I was trying to poke around a bit but I'm not sure what the problem is. Here are the flags output:

FFMPEG COMMAND:
/home/user/projects/movis-playground/.venv/lib/python3.11/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2 -y -f rawvideo -vcodec rawvideo -s 1080x1900 -pix_fmt rgba -r 30.00 -i - -an -vcodec libx264 -pix_fmt yuv420p -v error /home/user/projects/movis-playground/output.webm
rezoo commented 10 months ago

Ah, I see. Since WebM does not support h264 but uses vp9, try specifying the codec like this:

scene.write_video("output.webm", codec="libvpx-vp9")

Also, as movies use (W, H) instead of (H, W), I think scene = mv.layer.Composition(size=(1920, 1080), duration=4.0) would probably be appropriate.

elijahsgh commented 10 months ago

Worked perfectly. Thanks! The vertical resolution was intended for vertically oriented social media shares.