Reading ASF video

Hello Francois,

I am contacting you as i was wondering if it would be possible for Brainstorm to also support video as ASF format. Following code seems to be able to read and display the video well:

v =VideoReader('/NAS/Projects/90000129/Documentation/Data/PA11/Unknown Unknown.04.02.2022/05.02.2022/2/0/video/486212895228_1.asf')
figure;
currAxes =subplot(1,1,1)
while hasFrame(v)
vidFrame = readFrame(v);
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
pause(1/v.FrameRate);
end

Also, our system is outputing video as chunk of 40 minutes :

Exemple of a night recording :

486212895228_10.asf 486212895228_2.asf 486212895228_6.asf 486212895228.vid
486212895228_11.asf 486212895228_3.asf 486212895228_7.asf
486212895228_12.asf 486212895228_4.asf 486212895228_8.asf
486212895228_1.asf 486212895228_5.asf 486212895228_9.asf

with the file .vid indicating the order of the files:

[General]
Cut=0
Files=Video1,Video2,Video3,Video4,Video5,Video6,Video7,Video8,Video9,Video10,Video11,Video12
Start=05.02.2022 00:29:36,561
Markers=

[Video1]
FileName=486212895228_1.asf
Start=05.02.2022 00:29:36,561

[Video2]
FileName=486212895228_2.asf
Start=05.02.2022 01:09:41,598

[Video3]
FileName=486212895228_3.asf
Start=05.02.2022 01:49:46,463

[Video4]
FileName=486212895228_4.asf
Start=05.02.2022 02:29:51,324

[Video5]
FileName=486212895228_5.asf
Start=05.02.2022 03:09:55,977

[Video6]
FileName=486212895228_6.asf
Start=05.02.2022 03:50:01,94

[Video7]
FileName=486212895228_7.asf
Start=05.02.2022 04:30:05,951

[Video8]
FileName=486212895228_8.asf
Start=05.02.2022 05:10:10,742

[Video9]
FileName=486212895228_9.asf
Start=05.02.2022 05:50:15,843

[Video10]
FileName=486212895228_10.asf
Start=05.02.2022 06:30:20,919

[Video11]
FileName=486212895228_11.asf
Start=05.02.2022 07:10:25,467

[Video12]
FileName=486212895228_12.asf
Start=05.02.2022 07:50:30,722

In addition to reading .asf file; do you think we could import the entire folder and concatenate the videos?

Thanks a lot,
Edouard

I am contacting you as i was wondering if it would be possible for Brainstorm to also support video as ASF format.

Done: Add ASF in the video file formats · brainstorm-tools/brainstorm3@19cadef · GitHub

In addition to reading .asf file; do you think we could import the entire folder and concatenate the videos?

This is too specific for me to work on it, but if you want to work on this, there is maybe a simpler option than actually concatenating the files:

  • Add the .vid playlist as a file format in import_video.m
  • In import_video: add a block "READ PLAYLIST" around line 85
  • parse the .vid file to get a list of VideoFiles associated with a list of VideoStartList (the value that must be saved in the video link for it to be synchronized with the recordings)
1 Like

Hello;

So here is a solution if anyone needs to import ASF video from the SOMNO system or similar:

1/ Convert the asf videos to mp4 using FFmpeg:

For example :

ffmpeg -i 486214185234_1.asf -c:v libx264 -strict -2 486214185234_1.mp4
ffmpeg -i 486214185234_2.asf -c:v libx264 -strict -2 486214185234_2.mp4
ffmpeg -i 486214185234_3.asf -c:v libx264 -strict -2 486214185234_3.mp4

2/ Create a file listing the videos:

file '486214185234_1.mp4'
file '486214185234_2.mp4'
file '486214185234_3.mp4'

3/ Concatenate the videos:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4

The video can then be imported in Brainstorm as explained here: https://neuroimage.usc.edu/brainstorm/Tutorials/Epileptogenicity#Video-EEG

note: the conversion to mp4 might not be necessary as brainstorm support asf video; it is however more practical to have mp4 than asf :slight_smile:

More info here:
https://lists.ffmpeg.org/pipermail/ffmpeg-user/2019-January/042853.html
https://trac.ffmpeg.org/wiki/Concatenate

Edit: in case you have a lot of videos, the following script can help:


#!/bin/bash

in_folder=$1
out_folder=$2
out_name=$3


sorted_files=$(find "$in_folder/" -type f -name '*.asf' | sort -V)

for f in $sorted_files
do

    echo "Converting file: '$f'"
    echo "file '$f'" >> $in_folder/mylist.txt; 
 
    ffmpeg -i $f -c:v libx264 -strict -2 "${f%.asf}.mp4"

 done

 ffmpeg -f concat -safe 0   -i "$in_folder/mylist.txt" -c:v  copy "$2/$3"

2 Likes