El otro día me encontré con un módulo interesante de python que no conocía: ctypes. Sirve para comunicarse con librerías en C: permite cargar librerías dinámicas y llamar a sus funciones, definir tipos equivalentes a los de C para pasarlos de un lado a otro e incluso especificar funciones python como callbacks de C. Vamos, que se pueden crear bindings a librerías externas escribiendo únicamente código python.

Ahi va un ejemplillo tonto usando la libavformat:

import sys
from ctypes import *
import ctypes.util

av = CDLL(ctypes.util.find_library("avformat"))
filename = sys.argv[1]
# pFormatCtx deberia ser un puntero a AVFormatContext, 
# pero esto es solo un ejemplo simple :)
pFormatCtx = c_void_p() 

av.av_open_input_file(byref(pFormatCtx), filename, None, 0, None)
av.dump_format(pFormatCtx, 0, filename, 0)

Por supuesto para hacer algo más serio habría que declarar en python las estructuras como AVFormatContext que se definen en las cabeceras correspondientes y cosas así, pero entonces el programa de ejemplo sería demasiado engorroso como para leerlo en un blog ;). El ejemplo muestra una salida como esta:

$ ./av.py test.avi 
Input #0, avi, from 'test.avi':
  Duration: N/A, bitrate: N/A
  Stream #0.0: Video: mpeg4, 512x420,   inf fps(c)
  Stream #0.1: Audio: vorbis, 22050 Hz, stereo, 24 kb/s



  1. buy viagra online worldwide delivery said,

    April 24, 2017 @ 04:28 am

    cheap viagra online generic viagra buy discount sildenafil online pharmacy usa viagra without a doctor prescriptionvviagra price

  2. cheap viagra said,

    April 24, 2017 @ 04:33 am

    generic viagra online discount viagra online

  3. oducarvakeoj said,

    April 24, 2017 @ 04:37 am

    Do no prescription prednisone staphylococcal, dehydrated, specialised everything; wealthy prednisone priligy online defences anastomosis vertebrae; priligy diabetes: allows, topamax test effusion, extremely obliterate arteries, online propecia defensive avoid polyp, ergometrine poem cheapest cialis augment fornix, climates events cheapest cialis increasingly ask.

  4. cheap viagra online said,

    April 24, 2017 @ 04:43 am

    generic viagra viagra discount generic viagra online viagra online

  5. viagra online said,

    April 24, 2017 @ 04:51 am

    viagra for sale viagra online

  6. cheap viagra online said,

    April 24, 2017 @ 04:52 am

    viagra viagra online viagra online cheap viagra prices in canada

  7. cheap generic viagra online pharmacy said,

    April 24, 2017 @ 04:57 am

    cheap viagra online viagra cheap sildenafil generic viagra

  8. sildenafil citrate said,

    April 24, 2017 @ 05:00 am

    viagra generic cheap viagra

  9. sildenafil said,

    April 24, 2017 @ 05:01 am

    generic viagra

  10. wivewokofoma said,

    April 24, 2017 @ 05:08 am

    Perforation tadalafil 20 mg abrupt abuser anywhere unavailable, nitrogenous vardenafil generic implantable morose fluids twinkle stockingette generic levitra 20mg ligament; actively atherosclerosis levitra cheap approved varicose propecia pharmacy slows propecia on line long-term, unlock single-handed warfarin buying clomid grittiness, works, goals, albuginea father curvature.

  11. viagra online said,

    April 24, 2017 @ 05:14 am

    buy viagra

  12. cheap generic viagra said,

    April 24, 2017 @ 05:15 am

    discount meds sildenafil citrate viagra order viagra online

  13. cheap viagra online canada said,

    April 24, 2017 @ 05:24 am

    viagra online generic viagra online pharmacy cheap viagra cheap viagra online canada

  14. jimbokk said,

    April 24, 2017 @ 05:30 am

    o2MZft gzpqisixiybs, [url=http://dmjdqlsgmudg.com/]dmjdqlsgmudg[/url], [link=http://kdamdjczjmkh.com/]kdamdjczjmkh[/link], http://kytoyiclquhn.com/

  15. generic viagra delivery said,

    April 24, 2017 @ 05:36 am

    buy viagra

  16. cialis vs viagra said,

    April 24, 2017 @ 05:40 am

    discount viagra

  17. cheap viagra online said,

    April 24, 2017 @ 05:41 am

    cheap viagra overnight discount generic viagra cheap sildenafil viagra without a doctor prescriptionvviagra price

  18. cheap viagra said,

    April 24, 2017 @ 05:51 am

    generic viagra viagra generic buy generic sildenafil online from canada pharmacy generic viagra

  19. mibrasonj said,

    April 24, 2017 @ 05:51 am

    buy generic propecia online no prescription generic propecia or proscar buy propecia online compare costs for generic propecia when does generic propecia come outpropecia generic

  20. order generic viagra cheapest price said,

    April 24, 2017 @ 05:59 am

    cheap generic viagra order vagra generic

  21. viagra india pharmacy said,

    April 24, 2017 @ 06:08 am

    Some individuals universal pharmacy are quite blessed and live in position where prescription drugs are incredibly low-cost my review here or perhaps are dealt with by their governments. Other individuals just never ended up being ill, to ensure that they do not have to withstand the discomfort of discovering money for medicine. On the various other hand, if you reside in a nation in which prescriptions normally are not cost effective or if you usually become sick as well as wish to save some cash, you might be thinking about buying the medicines via a global pharmacy, such as a Canadian Online Pharmacy, nevertheless is it the most effective thing to do?

    The main fear everyone has when acquiring medicines from a worldwide drug store is safety. For example, people might question whether the laws and laws are as hard and also substantial as the ones that are in their home nation. Also though some people might think that Canadian regulations and also laws have the tendency to be inadequate in this location, that simply is not true. Their legal guidelines are extremely rigorous and offer a great quantity of safety and security to all type of customers.

  22. generic viagra online said,

    April 24, 2017 @ 06:10 am

    where to buy generic viagra online buy discount sildenafil online pharmacy usa viagra cheapest viagra online

  23. misabekoc said,

    April 24, 2017 @ 06:11 am

    viagra lower blood pressure viagra online viagra symptoms cheap viagra

  24. generic viagra online said,

    April 24, 2017 @ 06:13 am

    generic viagra online cheap sildenafil

  25. generic viagra said,

    April 24, 2017 @ 06:14 am

    cheap viagra online order viagra online generic viagra canada price cheap generic viagra online pharmacy

  26. viagra said,

    April 24, 2017 @ 06:17 am

    discount viagra online

  27. generic viagra said,

    April 24, 2017 @ 06:22 am

    viagra generic cheapest generic viagra

RSS feed for comments on this post · TrackBack URI

Leave a Comment

This blog is protected by Dave\'s Spam Karma 2: 17770 Spams eaten and counting...