Media playback is unsupported on your device Media caption It had been feared the Javan warty pig had become extinct

Scientists have captured the first footage in the wild of one of the world's rarest - and ugliest - pigs.

The Javan warty pig is under such threat from hunting and habitat loss that conservationists surveying its habitat believed it might already have been driven to extinction.

Camera traps have now revealed that small populations survive in Java's increasingly fragmented forests.

The team says its aim now is to protect the rare animals' habitat.

The survey was led by Dr Johanna Rode-Margono from Chester Zoo, who said she and her colleagues were "thrilled" to see that the pigs were still there.

Image caption Motion-activated camera traps captured the images of the shy, endangered animals

The last study of these lowland forested areas was back in 2004 and revealed a "serious decline" in the population of the species.

"We were worried that all or most would have disappeared," she told BBC News.

Human-pig conflict

While these hairy, warty-faced beasts may not be Java's most photogenic residents, Dr Rode-Margono says they fulfil an important role in the forest's ecology - tilling the soil and spreading seeds as they forage.

And in Java, Indonesia's most crowded island, they are also emblematic of the burgeoning human pressure on the country's tropical forest.

The pigs are losing habitat to deforestation for agricultural and urban development, but are also coming into direct conflict with humans. The animals are considered pests and often hunted because they raid crops.

"Hunting for sport is also a problem," says Dr Rode-Margono, "and the species may be hybridising with European wild boar." That could result in the species being bred into extinction.

Fighting for the forests

Image copyright Victoria Gill

Image caption Most lowland forest in Java has been cleared for building and agriculture

Out of seven areas the team surveyed - using hidden, motion-activated cameras - only three had Javan warty pigs.

"That means the threat is ongoing and if we don't do anything, more and more populations will disappear," said Dr Rode-Margono. "This is a big red flag."

One wildlife centre in Java has started a captive breeding programme for the Javan warty pigs, and the scientists hope to identify some areas where these animals could be released and protected in the wild.

Image caption Captive-bred pigs could be released into the wild if the threats to their survival can be tackled

"There is still hope," Dr Rode-Margono told BBC News. "If we can manage to design some effective conservation projects, maybe we can keep them.

"For me," she added, "they are not ugly - they are beautiful.

"And everything in our ecosystem is connected - every tree, every plant, every animal. They depend on each other.

"If something breaks away, something else [could] break away, and that's a chain reaction where we can't foresee what will happen."

Follow Victoria on Twitter