Since the question of how Tolkien envisioned the tunes of his songs is covered elsewhere, I'm going to focus here on the differences between the singing we hear in the films, and what we read in the text.
There's actually a fair bit of diegetic singing in the films. It's mostly accurate (though there's much more verse in the books), but in a couple of places they either introduce new singing or change the words of the tune.
The Hobbit trilogy
There's only four diegetic songs/poems here:
"Blunt the Knives", performed by the Dwarves in Bag End to annoy Bilbo, is largely the same as in the book:
Chip the glasses and crack the plates!
Blunt the knives and bend the forks!
That's what Bilbo Baggins hates-
Smash the bottles and burn the corks!
Cut the cloth and tread on the fat!
Pour the milk on the pantry floor!
Leave the bones on the bedroom mat!
Splash the wine on every door!
Dump the crocks in a boiling bawl;
Pound them up with a thumping pole;
And when you've finished, if any are whole,
Send them down the hall to roll!
That's what Bilbo Baggins hates!
The Hobbit Chapter 1: "An Unexpected Party"
The film omits the final line from the book, which is "So, carefully! carefully with the plates!"
"Misty Mountains", the Dwarven lament that was in all the trailers, is mostly taken from a song in the text; in the film, they sing a slightly-modified version of the second refrain, and the middle of the second verse (in the book, the full song is three verses, interspersed with three variations on the refrain):
Far over the misty mountains cold
To dungeons deep and caverns old
We must away ere break of day
To claim our long-forgotten gold.
[...]
The pines were roaring on the height,
The winds were moaning in the night.
The fire was red, it flaming spread;
The trees like torches biased with light,
The Hobbit Chapter 1: "An Unexpected Party"
In the film, the line "To claim our long-forgotten gold." is sung as "To find our long-forgotten gold."
Moreover, both songs appear at about the same time: in Bilbo's house, after dinner.
"Bofur's Song", which Bofur sings to liven up the party at Rivendell (possibly in the extended edition only, I confess I cannot remember). This doesn't appear in The Hobbit, but does appear in Fellowship of the Ring; it's the song Frodo sings in Bree that ultimately gets him discovered by Strider; Bofur sings the start, and then a few lines cherry-picked from the middle:
There is an inn, a merry old inn
beneath an old grey hill,
And there they brew a beer so brown
That the Man in the Moon himself came down
one night to drink his fill.
The ostler has a tipsy cat
that plays a five-stringed fiddle;
And up and down he runs his bow,
Now squeaking high, now purring low,
now sawing in the middle.
[...]
So the cat on his fiddle played hey-diddle-diddle,
a jig that would wake the dead:
He squeaked and sawed and quickened the tune,
While the landlord shook the Man in the Moon:
'It's after three!' he said.
The Fellowship of the Ring Book I Chapter 9: "At the Sign of the Prancing Pony"
The full song is obviously much longer, comprising a total of thirteen verses.
In the extended edition of Desolation of Smaug, Bard recites "the prophecy of Durin's folk":
Bard: The Lord of silver fountains, the King of carven stone; The King Beneath the Mountain shall come into his own.
The Desolation of Smaug (2013)
This prophecy is a slight reshuffling of the first verse of a longer song from the book:
The King beneath the mountains,
The King of carven stone,
The lord of silver fountains
Shall come into his own!
The Hobbit Chapter 10: "A Warm Welcome"
In the book this is sung to Thorin's party by the people of Lake-town after they arrive in the town and are (reluctantly) welcomed by the Master.
Fellowship of the Ring
Bilbo's walking song, which he hums to himself when leaving Bag End (and which Gandalf hums to himself coming into Bag End) is the most obvious, and taken directly from the book:
The Road goes ever on and on
Down from the door where it began.
Now far ahead the Road has gone,
And I must follow, if I can
The Fellowship of the Ring Book I Chapter 1: "A Long-expected Party"
Gandalf's humming of the song is not in the books, but Bilbo's is; in both versions he sings a little of it (the full song is much longer) when leaving Bag End after the party
In the extended edition, Merry and Pippin sing a song, that's a mashed up version of two different songs from the book; "The Drinking Song", sung by Pippin and Sam on the way to Crickhollow:
Ho! Ho! Ho! to the bottle I go
To heal my heart and drown my woe.
Rain may fall and wind may blow,
And many miles be still to go,
Fellowship of the Ring Book I Chapter 4: "A Short Cut to Mushrooms"
And "The Bath Song", sung by Pippin when he's having a bath at the house in Crickhollow:
O! Sweet is the sound of falling rain,
and the brook that leaps from hill to plain;
but better than rain or rippling streams
Fellowship of the Ring Book I Chapter 5: "A Conspiracy Unmasked"
Pippin's final line is an invention of the film.
Strider sings a portion of "The Lay of Leithian", the words of which are taken from the text (though, according to the Annotated Score, translated into Sindarin by David Salo):
Tinúviel the elven-fair,
Immortal maiden elven-wise,
About him cast her shadowy hair
And arms like silver glimmering.
Fellowship of the Ring Book I Chapter 11: "A Knife in the Dark"
Unsurprisingly, Aragorn sings much more of the song in the book; the film limits itself only to the final four lines of the eighth stanza, while in the text Aragorn sings nine full stanzas (eight lines each)
In the text, this takes place after the first night at Weathertop. This is fairly accurate to the timeframe of the movies, though not the exact circumstances, where it's sung in the Midgewater Marshes the night before the encounter with the Ringwraiths.
"Lament for Gandalf" occurs exactly when you'd expect, but the words aren't given in the text, except for a single line (also used in the film):
Mithrandir, Mithrandir sang the Elves, O Pilgrim Grey!
Fellowship of the Ring Book II Chapter 7: "The Mirror of Galadriel"
Per the Annotated Score, the lyrics to the Elvish lament were written by Philippa Boyens and Howard Shore; the English lyrics are as follows:
O Olórin whom in time past
The West-lords sent
To guard the East-lands
Of Maiar, the Ever-wise
Why did you depart from
A country which you loved?
Mithrandir, Mithrandir O pilgrim grey
You will not wander the green earth
Your journey in darkness, ended.
The bonds cut, the spirit rent
The Flame of Anor from earth departed
A great light, blown out.
The Music of the Lord of the Rings Films Part 1: The Fellowship of the Ring The Annotated Score Texts "Lament for Gandalf"
Sam's contribution, however, remains unchanged from the text.
The Two Towers
It's debatable whether this is a song, but Gollum has a couple of rhyming lines during their trek through the Dead Marshes, avoiding Frodo's questioning about his past:
Frodo: Gandalf told me you were one of the River Folk.
Gollum: Cold be heart and hand and bone. Cold be travellers far from home
Frodo: He said your life was a sad story.
Gollum: They do not see what lies ahead, when sun has failed and moon is dead.
The Two Towers (2002)
These lines are adapted from the song of the Barrow-wights from Fellowship:
Cold be hand and heart and bone,
and cold be sleep under stone:
never mare to wake on stony bed,
never, till the Sun fails and the Moon is dead.
In the black wind the stars shall die,
and still on gold here let them lie,
till the dark lord lifts his hand
over dead sea and withered land.
Fellowship of the Ring Book I Chapter 8: "Fog on the Barrow-Downs"
In the extended edition, Treebeard recites some Entish poetry to Merry and Pippin while taking them to his home. The words are a combination of some lines from a song given to Bregalad in the book:
O rowan fair, upon your hair how white the blossom lay!
O rowan mine, I saw you shine upon a summer's day,
[...]
Upon your head how golden-red the crown you bore aloft!
The Two Towers Book III Chapter 4: "Treebeard"
And some lines from the Song of the Entwives, sung by Treebeard in the book:
Beneath the roof of sleeping leaves the dreams of trees unfold; When woodland halls are green and cool, and wind is in the West, Come back to me! Come back to me, and say my land is best!
The Two Towers Book III Chapter 4: "Treebeard"
In the films, this takes place while Treebeard is taking Merry and Pippin to his home, which is also when Treebeard sings the Song of the Entwives in the book. Bregalad's song comes later in the text, when Bregalad (Quickbeam) the Ent is entertaining the hobbits during Entmoot.
Gollum sings a song about fish while fishing in the Forbidden Pool, the lines of which are taken from a song he does sing in the book, while passing through the dead marshes1:
But stream and pool
is wet and cool
[...]
We only wish
to catch a fish,
so juicy-sweet!
The Two Towers Book IV Chapter 2: "The Passage of the Marshes"
At the Forbidden Pool in the book, Gollum is not singing but muttering curses to himself:
Frodo crept forward, using his hands Gollum-like to feel his way and to steady himself. The rocks were for the most part flat and smooth but slippery. He halted listening. At first he could hear no sound but the unceasing rush of the fall behind him. Then presently he heard, not far ahead, a hissing murmur.
'Fissh, nice fissh. White Face has vanished, my precious, at last, yes. Now we can eat fish in peace. No, not in peace, precious. For Precious is lost; yes, lost. Dirty hobbits, nasty hobbits. Gone and left us, gollum; and Precious is gone. Only poor Sméagol all alone. No Precious. Nasty Men, they'll take it, steal my Precious. Thieves. We hates them. Fissh, nice fissh: Makes us strong. Makes eyes bright, fingers tight, yes. Throttle them, precious. Throttle them all, yes, if we gets chances. Nice fissh. Nice fissh!'
The Two Towers Book IV Chapter 6: "The Forbidden Pool"
In preparation for the Battle of Helm's Deep, Théoden recites a line to Gamling:
Théoden: Where is the horse and the rider? Where is the horn that was blowing? They have passed like rain on the mountains. Like wind in the meadow.The days have gone down in the west. Behind the hills, into shadow.
The Two Towers (2002)
This verse is some cherry-picked lines from a longer song sung by Aragorn much earlier in the book, when Gandalf and the Three Walkers pass the burial mounds of the Lords of the Mark, on their way into Edoras:
Where now the horse and the rider? Where is the horn that was blowing?
Where is the helm and the hauberk, and the bright hair flowing?
Where is the hand on the harpstring, and the red fire glowing?
Where is the spring and the harvest and the tall corn growing?
They have passed like rain on the mountain, like a wind in the meadow;
The days have gone down in the West behind the hills into shadow.
Who shall gather the smoke of the dead wood burning,
Or behold the flowing years from the Sea returning?
The Two Towers Book III Chapter 6: "The King of the Golden Hall"
Interesting to note is that the lines not spoken by Théoden are used (translated into Old English by David Salo) in a piece titled "The Call" which is used, among other places, when Théoden decides to mount a charge against the Uruk-hai, shortly before Gandalf and Éomer's timely arrival.
Return of the King
Merry and Pippin sing "The Green Dragon" in the post-Hornburg victory celebration, after the confrontation with Saruman. This scene and its song is a pure invention of the films; per The Annotated Score, the lyrics were written by Fran Walsh and Philippa Boyens:
You can search far and wide.
You can drink the whole town dry.
But you’ll never find a beer so brown
As the one we drink in our home town.
But you’ll never find a beer so brown
As the one we drink in our home town.
You can keep your fancy ales.
You can drink them by the flagon.
But the only brew for the brave and true
Comes from the Green Dragon.
The Music of the Lord of the Rings Films Part 3: The Return of the King The Annotated Score Texts "The Green Dragon"
Arwen recites part of Bilbo's poem about Aragorn when convincing Elrond to reforge Narsil; the words of this verse are firsts seen in Gandalf's letter to the hobbits at Bree, introducing them to Aragorn:
From the ashes a fire shall be woken,
A light from the shadows shall spring;
Renewed shall be blade that was broken,
The crownless again shall be king.
Fellowship of the Ring Book I Chapter 9: "Strider"
The full poem from the text is longer (the film only uses the final four of eight lines, and is spoken aloud at the Council of Elrond by its author, Bilbo.
However, the scene itself does not appear in the book; Narsil is reforged before the Fellowship leaved Rivendell.
Pippin sings "Edge of Night" for Denethor's amusement. The words are taken piecemeal from a Walking Song, sung by Frodo, Sam, and Pippin on the road to Crickhollow:
Home is behind, the world ahead,
And there are many paths to tread
Through shadows to the edge of night,
Until the stars are all alight.
[...]
Mist and twilight, cloud and shade,
Away shall fade! Away shall fade!
Fellowship of the Ring Book I Chapter 3: "Three is Company"
The film modifies the final two lines, becoming:
Mist and shadows, cloud and shade:
All shall fade, all shall fade.
Return of the King (2003)
The scene itself is taken from the book, but Pippin is spared having to sing:
Can you sing?'
'Yes,' said Pippin. 'Well, yes, well enough for my own people. But we have no songs fit for great halls and evil times, lord. We seldom sing of anything more terrible than wind or rain. And most of my songs are about things that make us laugh; or about food and drink, of course.'
'And why should such songs be unfit for my halls, or for such hours as these? We who have lived long under the Shadow may surely listen to echoes from a land untroubled by it? Then we may feel that our vigil was not fruitless, though it may have been thankless.'
Pippin's heart sank. He did not relish the idea of singing any song of the Shire to the Lord of Minas Tirith, certainly not the comic ones that he knew best; they were too, well, rustic for such an occasion. He was however spared the ordeal for the present. He was not commanded to sing.
Return of the King Book V Chapter 4: "The Siege of Gondor"
However, the scene takes place somewhat earlier than in the film; in the film, the next we see of Denethor is when Faramir is carried into the city. In the book, it takes place shortly before Denethor dresses down Faramir for losing Osgiliath
At his coronation, Aragorn sings a few lines of Elvish. This does happen in the book (even the words are the same, though there's no indication he sings them in the text), but they happen slightly earlier in the book:
Et Eärello Endorenna utúlien. Sinome maruvan ar Hildinyar tenn' Ambar-metta!
Return of the King Book VI Chapter 5: "The Steward and the King"
In the book, they are said before Gandalf places the crown on Aragorn's head, not after.
1 Thanks to Yorik in comments for reminding me of this