、。
On the train, I didn't recognize him at first.
Literal
Train [of-の] inside [location-で], first [for-a-while-のうちは] he [copula-だ] [quotative-と] didn't-understand.
最初のうちは ('at first, initially') is a set phrase — 最初 + のうち + は — marking the opening stretch of time. 彼だとわからない ('didn't understand it was him') is a quotative structure with と + わかる: when the content of recognition/understanding is a proposition, it's framed with と. A natural construction for describing delayed recognition.