It is still a great challenge to enhance the photocatalytic hydrogen production performance of photocatalysts. Herein, we used a simple two-step method to prepare layered graphitic carbon nitride (g-C3N4) porous nanostructures with much higher surface area by calcination of molecular crystals precursor assembled by hexadecyl trimethyl ammonium bromide (CTAB) and melamine. CTAB was found to act as the soft template and pore forming agent. CTAB and melamine firstly assembled together to form molecular crystals in hydrothermal conditions via electrostatic interaction. Then, after calcination, layered g-C3N4 porous nanostructures were formed. The as-prepared product exhibited almost 27.5-fold higher photocatalytic hydrogen generation than g-C3N4, which may be caused by the much higher surface area, faster separation rate of photogenerated hole-electron pairs and the narrowed band gap due to the carbon doping induced by the CTAB. This work provides a facile method for improving the performance of the hydrogen production of g-C3N4.