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

Create a MF4 file from CSV and AVI files #802

Open
LinusUng opened this issue Dec 21, 2022 · 7 comments
Open

Create a MF4 file from CSV and AVI files #802

LinusUng opened this issue Dec 21, 2022 · 7 comments

Comments

@LinusUng
Copy link

LinusUng commented Dec 21, 2022

Python version

('python=3.10.8 | packaged by conda-forge | (main, Nov 24 2022, 14:07:00) [MSC '
'v.1916 64 bit (AMD64)]')
'os=Windows-10-10.0.19044-SP0'
'numpy=1.23.5'
'asammdf=7.2.0'

Code

MDF version

4.00

Code snippet

#%% Imports
import pandas as pd
import logging
from asammdf import MDF
from os import listdir
from os.path import isfile, join

#%% Directories
csv_directory = "in/csvfile.csv"
avi_directory = "in/avifile.avi"
mf4_directory = "out/mf4file.mf4"

#%% Create empty mdf object
mdf  = MDF()

#%% Append data from csv file 
df_csv = pd.read_csv(csv_directory )
mdf.append(df_csv)

#%% Attach video 
with open(avi_directory , 'rb') as f:
        data = f.read()
        index = mdf.attach(data, file_name='front_camera.avi', compression=False, embedded=False)
        mdf.groups[-1].channels[-1].data_block_addr = index
        mdf.attachments[0].file_name = Path(str(mdf.attachments[0].file_name).replace("FROM_", "", 1))

#%% Save to mf4
mdf.save(mf4_directory)

Description

Hi all!

I have some vehicle data from CAN Bus written in csv and a synchronized video with matching number of frames. I would like to display both the signals and the associated video frames in a tool, which requires mf4 as input.
Therefore, I have setup the code above to convert csv files and avi files into mf4 format by recycling a similar issue #316.
The code does not trigger an error and appends the csv flawlessly to the mdf object, but it doesn't work for the avi attachment (neither size nor channel of mf4 output changes - the mf4 only contains signals from csv input). In debug mode I can see that the avi is successfully read to a binary file (data = b'RIFFX\xceM\x01AVI LIST\xec\x11\x00\x00hdrlavih8\x00\x00\x005\x82 ... ).

I'm quite new to this topic and am struggling to find documentation and threads to this kind of task.
Any help is highly appreciated!

@danielhrisca
Copy link
Owner

import pandas as pd
import logging
from asammdf import MDF
from asammdf.blocks.v4constants import CHANNEL_TYPE_SYNC, SYNC_TYPE_TIME
from os import listdir
from os.path import isfile, join

#%% Directories
csv_directory = "in/csvfile.csv"
avi_directory = "in/avifile.avi"
mf4_directory = "out/mf4file.mf4"

#%% Create empty mdf object
mdf  = MDF()

#%% Append data from csv file 
df_csv = pd.read_csv(csv_directory )
mdf.append(df_csv)

#%% Attach video 
with open(avi_directory , 'rb') as f:
        data = f.read()
        index = mdf.attach(data, file_name='front_camera.avi', compression=False, embedded=True)  # embedded attachment
        mdf.groups[-1].channels[-1].data_block_addr = index
        mdf.groups[-1].channels[-1].sync_type = SYNC_TYPE_TIME
        mdf.groups[-1].channels[-1].channel_type = CHANNEL_TYPE_SYNC
        mdf.attachments[0].file_name = Path(str(mdf.attachments[0].file_name).replace("FROM_", "", 1))

#%% Save to mf4
mdf.save(mf4_directory)

@LinusUng
Copy link
Author

Hi Daniel,

sorry for the late replay, but many thanks for your answer!
Your provided code works as intended and attaches an embedded video file, as you can see in the screenshot below.

2023-01-11_12h26_13

Unfortunately, this doesn't get me very far in terms of visualization videos within my tool. It seems that an additional channel is needed for this, which I did not point out in my original post - sorry about that. Is there also the possibility to add something like a multimedia or video channel to the existing signal channels?

Thank you in advance!

@danielhrisca
Copy link
Owner

Please send a demo file to see how the channels are stored

@LinusUng
Copy link
Author

Sorry, I can not share demo files because I have to follow protection of data privacy. I will attach some screenshots of the mdf file structure, which hopefully shows what you're asking for. As you can see, I'm navigating into the mdf file > groups > channels > channel 000:

Screenshots.pdf

This output is generated by your code snippet. I'm happy to share any other screenshots, if you need more information.

@Huluwala19
Copy link

@danielhrisca Hi Daniel, does the current asammdf gui supports displaying video or multimedia attachments? Thanks a lot.

@danielhrisca
Copy link
Owner

danielhrisca commented Oct 10, 2023

@danielhrisca Hi Daniel, does the current asammdf gui supports displaying video or multimedia attachments? Thanks a lot.

Video windows are not implemented

@Jubin2607
Copy link

is there a way to convert a pcap file to mf4

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

4 participants