ctypes

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:

#!/usr/bin/python
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_register_all()
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

Referencias:

3 Comments »

  1. AtotCype said,

    December 11, 2017 @ 21:01 pm

    http://buymrxviagrarxonline.com
    cialis viagra
    buying viagra online
    women in viagra commercials
    viagra for sale

  2. Get A Loan said,

    December 11, 2017 @ 21:17 pm

    loan loan loan payday loans online

  3. no credit check loans said,

    December 11, 2017 @ 21:39 pm

    payday loans no credit check
    cash loans no credit check
    payday loans for bad credit
    loans for bad credit
    payday loans no credit

  4. Quick Loan said,

    December 11, 2017 @ 21:42 pm

    advance cash payday loan loans online bad credit advance cash payday loan easy loans

  5. RdnkkylHoodo said,

    December 11, 2017 @ 22:05 pm

    https://onlineloansdkan.com/payday loan cash advance [url=https://onlineloansdkan.com/]cash advance loan[/url] 500 payday loans cash advance definition

  6. impesee said,

    December 11, 2017 @ 22:09 pm

    http://buymrxviagrarxonline.com
    viagra and cialis
    generic viagra
    viagra triangle bars
    order viagra online

  7. Lloydvef said,

    December 11, 2017 @ 22:19 pm

    prescription drugs online without doctor
    canadian pharmacies shipping to usa
    Online Drugstores
    top rated canadian pharmacies online
    online pharmacy

  8. laverdaddesnuda.com said,

    December 11, 2017 @ 22:38 pm

    I have been exploring for a little for any high-quality articles or weblog posts in this kind
    of space . Exploring in Yahoo I finally stumbled upon this website.
    Reading this information So i’m satisfied to exhibit that I’ve an incredibly good uncanny feeling I discovered exactly what I needed.
    I so much definitely will make sure to do not overlook this website and give it a glance regularly.

  9. AndroForce X10 said,

    December 11, 2017 @ 22:40 pm

    Very nice post. I just stumbled upon your blog and wanted to say
    that I’ve really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again very soon!

  10. elbow support band said,

    December 11, 2017 @ 22:42 pm

    It is easily our favorite tennis elbow brace.

  11. ed drugs said,

    December 11, 2017 @ 22:44 pm

    cheapest levitra prices
    ed drugs
    levitra sale canada

  12. misledia said,

    December 11, 2017 @ 22:50 pm

    http://cialisbxonlinerx.com
    emedicine viagra cialis pills
    buy cialis online
    cialis soft online
    buy cialis

  13. Jamesenula said,

    December 11, 2017 @ 22:52 pm

    buy essay buy essays online buy essays online https://buyessays.us.com – buy an essays

  14. FamybfEroli said,

    December 11, 2017 @ 23:17 pm

    http://cialisonlinemane.com/ cialis 20mg tablets [url=http://cialisonlinemane.com/]order cialis online[/url] daily cialis tadalafil cialis

  15. Payday Loan Online said,

    December 11, 2017 @ 23:51 pm

    cash advance payday advance loans cash advance lenders online payday loans instant approval

  16. Ralavant said,

    December 12, 2017 @ 00:01 am

    cheap cialis
    order daily cialis pills online
    http://calismdmrxonline.com.com
    official site cialis pills
    generic cialis online

  17. Joeenula said,

    December 12, 2017 @ 00:24 am

    quick payday loans with bad credit quick cash loans quick cash loans bad credit fast loans in 1 hour

  18. Lloydvef said,

    December 12, 2017 @ 01:04 am

    Legitimate Canadian Mail Order Pharmacies
    top rated canadian pharmacies online
    online prescriptions
    [url=http://canadaunmfgb.com/#]canadian pharmacies shipping to usa[/url]
    lloyds pharmacy online

  19. VbsfyUsaste said,

    December 12, 2017 @ 01:27 am

    http://genericviagracelak.com/ ordering viagra online [url=http://genericviagracelak.com/]viagra for sale[/url] viagra on line generic viagra

  20. Injergo said,

    December 12, 2017 @ 01:34 am

    buy generic cialis
    cheap cialis soft tabs
    http://calismdmrxonline.com.com
    cialis generic cheap
    generic cialis online

  21. free musically followers said,

    December 12, 2017 @ 02:16 am

    With this Blackberry spy software you will not be left in the dark.

    This computer software installs discreetly and no matter who is working with the cell phone
    they will not detect the cell phone monitoring software installed.
    Today, I and Bianca have become best friends again.

  22. MsbtAsperb said,

    December 12, 2017 @ 02:36 am

    http://viagraonlineakenc.com/herbal uk viagra [url=http://viagraonlineakenc.com/]canadian pharmacies[/url] natural alternative viagra order viagra online

  23. encoGs said,

    December 12, 2017 @ 02:37 am

    cheap cialis
    real cialis pills
    http://calismdmrxonline.com.com
    no prescription cialis online pharmacy
    cheap cialis

  24. DonaldAwaiz said,

    December 12, 2017 @ 02:43 am

    блок контейнер север м

    https://general-energo.ru/ – мобильные дэс

  25. PatrickGlync said,

    December 12, 2017 @ 02:44 am

    сафоновский электромашиностроительный завод сайт

    компактная установка с дизельным насосом ju6h-uf-50

  26. Patricktub said,

    December 12, 2017 @ 02:44 am

    ул.нижегородская д 32 стр.15

    пс 200 квт

  27. chaturbate hack token online said,

    December 12, 2017 @ 02:47 am

    Much has been said within the affect of the media channels
    on chaturbate hack.

  28. sportowefakty zuzel 1 liga said,

    December 12, 2017 @ 02:48 am

    Awesome things here. I am very glad to look your post.
    Thank you a lot and I’m having a look ahead to touch you.
    Will you kindly drop me a e-mail?

  29. walking war robots oro gratis said,

    December 12, 2017 @ 02:48 am

    You should not worry in regards to the recreation sources as can generate this cash with the assistance of
    our Strolling War Robots cheats tool of free gold, VIP, and silver.

  30. chatting apps like kik said,

    December 12, 2017 @ 02:48 am

    Android TV has improved over the previous couple of years,
    but it’s still the black sheep of the streaming media player class.

  31. www.otohasardanis.com said,

    December 12, 2017 @ 02:50 am

    Retro-modern is the design world’s comfort food.

  32. Clarkkance said,

    December 12, 2017 @ 02:50 am

    Legitimate Canadian Mail Order Pharmacies
    canadian pharmacies online
    no 1 canadian pharcharmy online
    canadian pharmacies
    reputable canadian online pharmacies

  33. Jeffreyzet said,

    December 12, 2017 @ 04:03 am

    viagra canada
    top rated canadian pharmacies online
    canada drugs
    canadian pharmacies shipping to usa
    List of Safe Online Pharmacies

  34. fraulgax said,

    December 12, 2017 @ 04:38 am

    generic cialis online
    generic cialis buy
    http://calismdmrxonline.com.com
    prometrium allergy cialis pills
    cheap cialis online

  35. William said,

    December 12, 2017 @ 04:44 am

    Today, Garcinia cambogia extract is expanded for its fruit in exotic environments around
    the globe, consisting of Southeast Asia, southern India, and west
    as well as main Africa.

  36. Rag Games said,

    December 12, 2017 @ 05:04 am

    I was recommended this blog by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty.
    You’re amazing! Thanks!

  37. Paulo Enzo Gabriel said,

    December 12, 2017 @ 05:26 am

    Estа é uma tragédia գue varias ρessoas passam. https://www.kiwibox.com/aciaciratfu1975/blog/entry/142542019/it-helps-in-improving-blood-circulation-helps-in-better-d/

  38. 玖富娱乐 said,

    December 12, 2017 @ 05:27 am

    玖富娱乐

    Nightly build

  39. Bandar Bola Piala Dunia 2018 said,

    December 12, 2017 @ 05:49 am

    Heya i’m for the primary time here. I found this board and I in finding It truly useful & it helped me out a lot.
    I am hoping to offer one thing back and help others like you helped me.

  40. https://www.pinterest.com/cacuocbongda8live/ said,

    December 12, 2017 @ 05:56 am

    Heya i’m for the first time here. I came across this
    board and I find It truly useful & it helped me out a lot.
    I hope to give something back and aid others like you aided
    me.

  41. Clarkkance said,

    December 12, 2017 @ 06:52 am

    online pharmacies in usa
    canadian pharmacies shipping to usa
    drugstore online
    [url=http://canadaunmfgb.com/#]canadian pharmacies online[/url]
    discount pharmacy

  42. VbsfyUsaste said,

    December 12, 2017 @ 07:08 am

    http://genericviagracelak.com/ try viagra for free [url=http://genericviagracelak.com/]order viagra online[/url] viagra samples free buy viagra

  43. RdnkkylHoodo said,

    December 12, 2017 @ 07:23 am

    https://onlineloansdkan.com/pls payday loan store [url=https://onlineloansdkan.com/]instant payday loans[/url] payday loans no faxing no credit checks cash advance now

  44. Saiprog said,

    December 12, 2017 @ 07:52 am

    buy cheap cialis
    lasix and viagra cialis generic
    http://calismdmrxonline.com.com
    buy cialis online canada canadian pharmacy
    generic cialis online

  45. Matthewtiele said,

    December 12, 2017 @ 08:26 am

    резистивный нагрузочный модуль

    нагрузочные модули

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...