Image copyright Youtube Image caption Gavin Long left an extensive social media trail

The man who shot dead three police officers in the US city of Baton Rouge has been identified as a black military veteran who released a series of videos railing against the treatment of African-Americans by police.

Gavin Long was killed in a gun battle with police on Sunday, on what was his 29th birthday.

Long served in the US Marines from 2005-2010, including a seven-month Iraq tour in 2008. He attained the rank of sergeant and received several awards, including the Marine Corps Good Conduct Medal.

More recently he appears to have tried to reinvent himself as a self-help guru.

On the website Convoswithcosmo.com, registered to Long, he describes himself as a "freedom strategist, mental game coach, nutritionist, author and spiritual advisor".

Media playback is unsupported on your device Media caption Barack Obama: 'Attacks on police are an attack on all of us'

AFP reported that Long had his name legally changed to Cosmo Ausar Setepenra last year, claiming to have Native American ancestry.

On the site, Cosmo says he travelled extensively in Africa, where he was taught by "native spiritual practitioners and elder holistic healers". Books written by Cosmo Setepenra are still available on Amazon.

But it is the long trail of social media postings linked to Long that will be most closely scrutinised by investigators.

"Let's go with the numbers, let's go with the history. 100% of revolutions, of victims fighting their oppressors... have been successful through fighting back, through bloodshed," he says in a YouTube video published on 10 July.

"Zero have been successful over simply protesting. It has never worked and it never will. You gotta fight back."

Image copyright @ConvosWithCosmo Image caption Long was a prolific user of social media, writing under a pseudonym

He posted an earlier video, now taken down, describing himself as a former Christian and a Nation of Islam member, but he then repeatedly stated he had no affiliation to any group.

"I thought my own thoughts, I made my own decisions," he says. "I'm the one who's gotta listen to the judgment."

In one tweet, Long wrote that Micah Johnson, who shot dead five US police officers in Dallas, was "one of us! My Religion is Justice". Like Long, Johnson was an army veteran.

The authorities are yet to comment on Long's motive. At least one of the officers he killed was black.

Long was married for two years and studied briefly at the University of Alabama. His home in Kansas City, Missouri, was searched by police.

A final tweet from his account reads: "Just bc you wake up every morning doesn't mean that you're living. And just bc you shed your physical body doesn't mean that you're dead."