fourMs / MGT-python

Musical Gestures Toolbox for Python
https://www.uio.no/ritmo/english/research/labs/fourms/downloads/software/musicalgesturestoolbox/mgt-python/index.html
GNU General Public License v3.0
52 stars 11 forks source link

Time in trimmed videos #279

Closed alexarje closed 1 year ago

alexarje commented 1 year ago

I often use the skip function to shorten video duration and thereby improve processing speed. However, the challenge is when running an audio process on a trimmed video, then the time shown in the waveform, spectrogram, etc. refers to the trimmed version, not the real time version. For example, this spectrogram is made from a 10-minute long video where I have used skip=5 in a previous step:

image

Perhaps it would be possible to store information about time and skipping somewhere? Then one can choose to have the real time shown underneath the graph.

joachimpoutaraud commented 1 year ago

I have added the possibility to plot the original time on audio representations when the frames of a video file have been skipped beforehand. To do so, I stored the original duration of the file in the video metadata using FFmpeg. This is a bit of a hack but it works. Basically, if the video file is preprocessed with skipped frames, a tag will be automatically added to the metadata of the video file in order to store the original time of the video and to be able to reuse it afterwards. This is a bit of a hack because it is not feasible to properly add a new 'duration' metadata section in FFmpeg, so the variable is stored under the title key in the FFmpeg metadata.

That way, it is possible to retrieve the original time value afterwards and plot a shortened waveform, spectrogram, tempogram, etc. with the original time on the x axis. By default, the parameter original_time is set to True if a video has been shortened, but it is possible to set it to False in order to get the real time of the shortened video. More information on the source code.