Forward error correction (FEC) has been widely used in today's communication systems, implemented by electronics. For optical communications, on-the-fly optical processing is highly desired for reduced optical-electrical-optical (OEO) conversions, so as to reduce the latency and cost. In this work, we present a proof-of-concept study of an optical FEC encoding method based on optical matrix computing by wavelength-division multiplexing (WDM) with time-wavelength interleaved manipulation. The optical FEC encoder realized by optical fiber devices features nearly equivalent net encoding gain compared with the theoretical electrical encoder. The experimental results indicate effective error correction, with 2-dB net gain in on-off keying (OOK) transmission at 20 Gb/s, supporting the realization of transmission-computing-merged systems. Meanwhile, the proposed method also supports the whole realization of FEC with both encoding and decoding.