Skip to content

Instantly share code, notes, and snippets.

@jagedn
Created March 30, 2020 06:14
Show Gist options
  • Save jagedn/7dd11ce2b12c54390b973c168b058397 to your computer and use it in GitHub Desktop.
Save jagedn/7dd11ce2b12c54390b973c168b058397 to your computer and use it in GitHub Desktop.
Descarga las cámaras de tráfico de Madrid para poder construir un mp4 con ella posteriormente
import groovy.util.slurpersupport.GPathResult
new File("madrid").deleteDir()
new File("madrid").mkdirs()
xml = 'http://informo.munimadrid.es/informo/tmadrid/CCTV.kml'.toURL().getText("ISO-8859-1")
xml = xml.substring(xml.indexOf('<')) // el kml tiene caracteres erróneos al principio, así es Madrid
kml = new XmlSlurper().parseText(xml).declareNamespace("xmlns":"http://earth.google.com/kml/2.2")
kml.Document.Placemark.sort{
it.ExtendedData.Data[1].Value.text()
}.eachWithIndex{ item, idx->
String description = item.description.text()
String url = description.split(' ').find{ it.startsWith('src=')}.substring(4)
new File("madrid/madrid${idx}.jpg").bytes = url.toURL().bytes
}
@jagedn
Copy link
Author

jagedn commented Mar 30, 2020

Si tienes instalado groovy simplemente descarga el fichero madrid.groovy en un directorio y ejecuta:

groovy madrid.groovy

Si no tienes, o quieres instalar groovy, puedes ejecutarlo mediante docker:

docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy:latest groovy https://gist.githubusercontent.com/jagedn/7dd11ce2b12c54390b973c168b058397/raw/adcf37a02eef67bd4c4b5c5b2475baa653b04d55/madrid.groovy

El script creará una carpeta madrid y descargará todas las imágenes disponibles en ella.

Una vez descargadas podrás hacer un mp4 con todas ellas usando ffmpeg:

ffmpeg -framerate 1 -i madrid/madrid%d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p madrid.mp4

Ejemplo https://www.youtube.com/watch?v=POrXtao5IeQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment