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

Export videos in .mpeg4 #67

Open
Ipuch opened this issue Jan 24, 2022 · 7 comments
Open

Export videos in .mpeg4 #67

Ipuch opened this issue Jan 24, 2022 · 7 comments

Comments

@Ipuch
Copy link
Contributor

Ipuch commented Jan 24, 2022

Hello,

It would be great features to:

  1. export in mpeg4.
  2. Export a video directly from command lines.
  3. Get the same frame rate when two or more phases are in the same OCP.
@pariterre
Copy link
Member

Hi @Ipuch

export in mpeg4.

mpeg4 won't be possible... In general, messing with codec is enough to want to kill yourself haha! We will stick with non proprietary format (ogv) and people can reformat if needed.

Export a video directly from command lines.

It is obviously already possible to run in command line (as a button is just a fancy way to call a command line :) )

Get the same frame rate when two or more phases are in the same OCP.

bioviz is unfortunately agnostic of this "phase concept". This is solely bioptim based... To have the same framerate, you must use do it in bioptim (which has already this feature implemented)

@Ipuch
Copy link
Contributor Author

Ipuch commented Jan 24, 2022

@EveCharbie and @mickaelbegon

@EveCharbie
Copy link
Contributor

export in mpeg4.
can't we do something like this : https://askubuntu.com/questions/12182/how-can-i-convert-an-ogv-file-to-mp4 + https://stackoverflow.com/questions/32714579/ffmpeg-converts-anything-to-mp4 ?
Get the same frame rate when two or more phases are in the same OCP.
I think what we would like is to have the option to give bioviz a time vector and a Q matrix matching together so that the frame rate of the recorded video is approximately fixed at the real time. (I think I saw a sleep command that we could play with, but I would have to look again).

@pariterre
Copy link
Member

can't we do something like this : https://askubuntu.com/questions/12182/how-can-i-convert-an-ogv-file-to-mp4 + https://stackoverflow.com/questions/32714579/ffmpeg-converts-anything-to-mp4 ?

Yep, but these as bash command lines. That is exactly as if the user would open a terminal and type them in. This means ffmpeg must be installed first. The GUI wrapper in Linux is WinFF which you may be already aware of.
This is not a portable solution (nor that it is an actual Python solution). And again, it relies on the presence of codecs for both the container (.mp4, .mov, .Whatever) and the format (MPEG-4). Codecs are insanely complex to deal with. I strongly advice against anything towards this. Get a OGV (non-proprietary file) and then use ffmpeg (or any other tool) to convert locally. It can even be done automatically if needed.

Frame rate

Sleeping would do nothing. The frame rate is solely based on the amount of frame you record for a particular time period. For instance, if you hit "record" twice at each frame, you have a video which is twice slower. You however maybe can change the frame rate of the actual video (not sure about that). But it is going to be hard to decide what you should do or not.

My advice, the video is currently 30fps (if I recall well), therefore resample using animate in bioptim

@pariterre
Copy link
Member

Turns out, it wasn't accessible (it was defined in private methods), and that I needed this as the same time ;)
So #68 added the capability to record from command line as such:

import bioviz
import numpy as np

# This should be real data
all_q = np.random.rand(n_dof, n_frames)  # n_dof is the number of dof of the model

# Load a bioviz handler
b = bioviz.Viz("model_path.bioMod")
b.resize(1920, 1080)  # Make it nice and big

b.start_recording("save_path")
for q in all_q:
    b.set_q(q)
    b.add_frame()  # Add a frame to the video
b.stop_recording()

# Close the window
b.quit()

@Ipuch
Copy link
Contributor Author

Ipuch commented Jan 26, 2022

is it possible to specify a view angle ? :)

@pariterre
Copy link
Member

There is no direct API for this, but the vtk renderer is actually public. So you can get the camera like this:

cam = b.vtk_window.ren.GetActiveCamera()
cam.SetPosition(x, y, z)
cam.SetRoll(angle)
b.refresh_window()  # This is not necessary, but you won't visually see the changes

Please refer to the VTK documentation for further help

@Ipuch Ipuch changed the title Export videos in .mpeg4 and export a video directly from command line. Export videos in .mpeg4 Jun 22, 2022
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

3 participants