My code generates a series of svg images as text. Now I want to save them as an animated video.
Here is a MWE.
svgtxt =
"""
<svg width="100%" height="100%" viewBox="30 57 1102 582">
<g style="stroke:#f00; stroke-width:5;">
<path fill="#D7DDDF" d="M476,257 L135,257 L411,57 Z"/>
<path fill="#D2DFE4" d="M857,381 L751,57 L1027,257 Z"/>
<path fill="#D9E0E1" d="M240,581 L135,257 L30,581 Z"/>
<path fill="#B7B9B9" d="M476,257 L751,57 L411,57 Z"/>
<path fill="#D0DEE2" d="M856,381 L1132,581 L1027,257 Z"/>
</g>
</svg>
"""
display("image/svg+xml", svgtxt)
Now I want to save this svg to a video as frames. (Based on this post.)
(In reality I will have a yielding function that will keep returning different svgs at each call.)
open(`ffmpeg -loglevel warning -y -f rawvideo -pix_fmt rgb24 -s:v 1200x1200 -r 30 -i pipe:0 -vf "transpose=0" -pix_fmt yuv420p test.mp4`, "w") do out
for i = 1:300
write(out, svgtxt) # How to change svgtxt to a valid RGB buffer?
end
end
gives
pipe:0: corrupt input packet in stream 0
[rawvideo @ 0x55d5ac91e040] Invalid buffer size, packet size 115200 < expected frame_size 4320000
Error while decoding stream #0:0: Invalid argument
failed process: Process(`ffmpeg -loglevel warning -y -f rawvideo -pix_fmt rgb24 -s:v 1200x1200 -r 30 -i pipe:0 -vf transpose=0 -pix_fmt yuv420p test.mp4`, ProcessExited(69)) [69]