Inspirations for the story included Bergman's recurring nightmares, featuring a woman who took off her own face and an entity that walked on ceilings. Johan's description of being locked in a closet as a boy was based on Bergman's childhood. An external influence was Wolfgang Amadeus Mozart's "The Magic Flute", with the opera's character Papageno transformed into an evil Birdman. Bergman's interpretation of "The Magic Flute" is echoed through his character Lindhorst. Bergman credited German author E. T. A. Hoffmann as an additional major influence.