41550

Best way of Getting Swf File Dimensions with Python

Question:

Edit:

I'm considering hexagonit, and swfTools. Does anyone have any other solutions, or insight? Edit:

New Question - how to solve this error: I tried using hexagonit.swfheader however I receive the error:

f = 'out/'+w+"/"+s+"/"+"theSwf/"+s data = hexagonit.swfheader.parse(f) File "/Library/Python/2.7/site-packages/hexagonit/swfheader/__init__.py", line 26, in parse signature = ''.join(struct.unpack('<3c', input.read(3))) struct.error: unpack requires a string argument of length 3

After tracing through this I found that the error occurs here:

def parse(input): """Parses the header information from an SWF file.""" need_close=False if hasattr(input, 'read'): input.seek(0) else: input = open(input, 'rb')* need_close=True <h2>* being where the error occurs.</h2>

I read: <a href="https://stackoverflow.com/questions/5136317/get-dimensions-from-a-flash-file-swf-in-pure-python" rel="nofollow">Get dimensions from a flash file (.swf) in pure-Python</a>

I have also tried using PIL and Pillow however I am under the impression that they compare images not swf files. I decompiled the swf file's I'm looking at along but also have the swf file itself.

I would like to know what size the file displays as (dimensions).

My first thought was to try using image size comparison.

<blockquote>

My issue with this is that some images that are used as assets in the swf are actually larger than the swf itself, otherwise I would use PIL to simply get the dimensions of the largest image asset (ex the background).

Secondly my other issue is that can equally compare svg and png files.. and Pillow and Pil to my knowledge do not handle svg files.

</blockquote>

My second idea was to search the actionscript code for the dimensions.

<blockquote>

Some files have in their action script something like 300x300 which denotes the size. Unfortunately after looking at most of the files I am working with do not which means this is largely unhelpful.

</blockquote>

My 3rd idea was to ignore the decompiled swf data and rather focus on the swf itself.

<blockquote>

I could in theory either try to find the dimensions in the byte code (or use a library that does this (which I need to find one as pip and pillow do not appear to work)) or I need to run the ad and then screenshot it and try to find where the ad starts and stops and calculate the pixels based on that. My problem with screens shotting it is that the image may blend into the background and make it hard if not impossible to get the correct dimensions, but more importantly many swfs cannot be played due to security if they are not played in the right url, etc.

</blockquote>

Thus I'm left with a dilemma. I think the best way to go about this would be to use the swf file itself.

Answer1:

Take a look at the official <a href="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/swf/pdf/swf-file-format-spec.pdf" rel="nofollow">SWF file format spec</a>. The dimension info you are looking for should be right near the beginning of the file. Take a look at the section "The SWF header"

The FrameSize field defines the width and height of the on-screen display. This field is stored as a RECT structure, meaning that its size may vary according to the number of bits needed to encode the coordinates. The FrameSize RECT always has Xmin and Ymin value of 0; the Xmax and Ymax members define the width and height (see Using bit values).

Recommend

  • Python : except OSError, e: [duplicate]
  • Why virtualenv relies on the global python instead of the local one, after being pulled?
  • input() - unexpected character after line continuation character
  • Named colors in tkinter
  • Binary response content, requests lib
  • How to install pillow on pypy
  • Add multiple pages to new PDF using PIL/Pillow
  • How to reduce image palette to specific colors?
  • Add dynamic html to fancy box
  • jQuery Sound
  • Unwanted border appearing on video element [closed]
  • Unable to show an image using python PIL Image.show
  • something like gimp “fuzzy select” in python/PIL
  • Finding the kth smallest item in an array using quicksort => expected running time?
  • Force a controller to always act as a proxy to a model in Ember
  • How does NodeAPI in Google Play Services work?
  • Tkinter nested mainloop
  • NuGet package restore consent without NuGet
  • Difficulties implementing the Hysteresis step of Canny Algorithm in Halide without define_extern fun
  • Using Python objects in C++
  • dc.js: Reducing rows in data table
  • drop duplicates pandas dataframe
  • Can an iframe pop up a Lightbox-style box?
  • record audio in HTML / js without Flash?
  • Disabling sound of embedded flash object with html
  • CSS how to fix an element to scroll horizontally with the page but not vertically?
  • Matplotlib save file as JPEG encoder error
  • Comparing user's facebook/twitter friends to site's users in Python/Django
  • How to request unsampled report from Google Analytics Management API using Google Apps Script?
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Where can I find tomesh.c?
  • How do I include a SWC in an AS2 Flash project?
  • How to get current document uri in XSLT?
  • HTTP/2 streams vs HTTP/1.1 connections
  • Syntax for setting draggablecursor property in google maps api
  • WOWZA + RTMP + HTML5 Playback?
  • GridView Sorting works once only
  • RestKit - RKRequestDelegate does not exist
  • How to get icons for entities from eclipse?
  • Running Map reduces the dimensions of the matrices