Synchronizing sound to a film or video can be a very complex as well as an exacting operation. (see Lip Sync) 

One may divide the operation into three activities, distinct but related: 

Recording location sound with picture.  Post production editing, dialogue replacement, sound effects, foley, music scoring, mixing.  Presentation systems for theatres, television, video cassette, CDROM, etc. 
Each of these activites raise different issues regarding synchronization but all depend on systems which allow for independent editing of picture or sound while maintaining frame accurate synchronization between the two. 
In the early part of the 20th century, motion pictures used a mechanical link between the film and sound medium. Motion picture film uses sprockets along side the image to advance the picture: it was a logical evolution to design sprocketed sound film to capture and reproduce audio and use mechanical links to keep the two systems in sync.  The emergence of an electronic medium (video) in the 1950's required the development of an electronic synchronization system or a virtual sprocket to keep magnetic tape systems locked together. Referred to as time code or SMPTE time code, it remains the primary method of synchronizing machines.