Assuming that you have undecoded AIS data (something in the following form: "!AIVDM,1,1,,A,13u?etPv2;0n:dDPwUM1U1Cb069D,0*24"), you need to:
1) decode the message,
2) check the message type and keep only those that contain data relevant for trajectories (in your case probably types 1,2,3 and 5),
3) identify the fields you need (e.g. MMSI, longitude, latitude, speed) and retrieve the values.
1:
If you are unfamiliar with AIS format you can use the following link:
http://catb.org/gpsd/AIVDM.html
Also, if you don't want to write decoder yourself, there are free online versions. Not all cover all AIS message types, but majority decodes the ones you need. You may try the following:
https://rl.se/aivdm
https://www.aggsoft.com/ais-decoder.htm
2:
You need to check AIS documentation to identify the message type you need. Types 1, 2 and 3 are for position report and you can use those to retrieve MMSI (unique identifier of a ship), its latitude, longitude, speed and some others.
Perhaps type 5 might also be of interest to you as it contains static and voyage related data.
3:
Once you know which messages you are goind to use, follow the format to extract the fields you need.