|
| 1 | +""" |
| 2 | + @file |
| 3 | + @brief Utility to determine which sample rates divide evenly by which frame rates |
| 4 | + @author Jonathan Thomas <[email protected]> |
| 5 | +
|
| 6 | + @section LICENSE |
| 7 | +
|
| 8 | + Copyright (c) 2008-2020 OpenShot Studios, LLC |
| 9 | + (http://www.openshotstudios.com). This file is part of |
| 10 | + OpenShot Video Editor (http://www.openshot.org), an open-source project |
| 11 | + dedicated to delivering high quality video editing and animation solutions |
| 12 | + to the world. |
| 13 | +
|
| 14 | + OpenShot Video Editor is free software: you can redistribute it and/or modify |
| 15 | + it under the terms of the GNU General Public License as published by |
| 16 | + the Free Software Foundation, either version 3 of the License, or |
| 17 | + (at your option) any later version. |
| 18 | +
|
| 19 | + OpenShot Video Editor is distributed in the hope that it will be useful, |
| 20 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | + GNU General Public License for more details. |
| 23 | +
|
| 24 | + You should have received a copy of the GNU General Public License |
| 25 | + along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>. |
| 26 | + """ |
| 27 | + |
| 28 | +import os |
| 29 | +import math |
| 30 | +import openshot |
| 31 | +from src.classes import info |
| 32 | + |
| 33 | +# Try to get the security-patched XML functions from defusedxml |
| 34 | +try: |
| 35 | + from defusedxml import minidom as xml |
| 36 | +except ImportError: |
| 37 | + from xml.dom import minidom as xml |
| 38 | + |
| 39 | + |
| 40 | +all_fps = [] |
| 41 | +all_rates = [8000.0, 11025.0, 16000.0, 22050.0, 44100.0, 48000.0, |
| 42 | + 88200.0, 96000.0, 176400.0, 192000.0, 3528000.0, 384000.0] |
| 43 | + |
| 44 | +# Loop through all profiles (include any FPS used in OpenShot) |
| 45 | +for file in os.listdir(info.PROFILES_PATH): |
| 46 | + filepath = os.path.join(info.PROFILES_PATH, file) |
| 47 | + profile = openshot.Profile(filepath) |
| 48 | + fps_num = profile.info.fps.num |
| 49 | + fps_den = profile.info.fps.den |
| 50 | + fps = float(fps_num) / float(fps_den) |
| 51 | + if fps not in all_fps: |
| 52 | + all_fps.append(fps) |
| 53 | + |
| 54 | +# Loop through all export presets (include any sample rates used in OpenShot) |
| 55 | +for file in os.listdir(info.EXPORT_PRESETS_PATH): |
| 56 | + filepath = os.path.join(info.EXPORT_PRESETS_PATH, file) |
| 57 | + xmldoc = xml.parse(filepath) |
| 58 | + sampleRate = float(xmldoc.getElementsByTagName("samplerate")[0].childNodes[0].nodeValue) |
| 59 | + if sampleRate not in all_rates: |
| 60 | + all_rates.append(sampleRate) |
| 61 | + |
| 62 | +# Display all common fps and sample rates |
| 63 | +print("---------------------------------") |
| 64 | +print("Common Sample Rates / Common FPS") |
| 65 | +print("---------------------------------") |
| 66 | +print("FPS: %s" % sorted(all_fps)) |
| 67 | +print("Sample Rates: %s" % sorted(all_rates)) |
| 68 | +print("---------------------------------") |
| 69 | +print("GOOD = Sample rate evenly divisible by frame rate") |
| 70 | +print("BAD = Sample rate NOT evenly divisible by frame rate") |
| 71 | +print("---------------------------------\n") |
| 72 | + |
| 73 | +print("(Sample Rate / FPS) = Samples Per Frame") |
| 74 | +print("---------------------------------") |
| 75 | +for fps in sorted(all_fps): |
| 76 | + for rate in sorted(all_rates): |
| 77 | + samples_per_frame = rate / fps |
| 78 | + has_remainder = math.fmod(rate, fps) |
| 79 | + if not has_remainder: |
| 80 | + # Print good case with rounding to 2 digits |
| 81 | + print("GOOD:\t%s / %.2f =\t%d" % (rate, fps, samples_per_frame)) |
| 82 | + else: |
| 83 | + # Print bad case, without rounding the samples per frame |
| 84 | + print("BAD:\t%s / %.2f =\t%s.%s" % |
| 85 | + (rate, fps, str(samples_per_frame).split('.')[0], str(samples_per_frame).split('.')[1][:2])) |
0 commit comments