{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"from math import log\n\n# loss1 - None\nloss1 = -1/4000 * (174 * log(174/1477) + (1477 - 174) * log(1 - 174/1477))\n\n\n# loss2 - 16:9\n# cd == '1/48000':\nloss2_1 = -1/4000 * (1407 * log(1407/1873) + (1873 - 1407) * log(1 - 1407/1873))\n# cd == else:\nloss2_2 = -1/4000 * (156 * log(156/206) + (206 - 156) * log(1 - 156/206))\n\n\n# loss3 - 9:16\n# cd == '1/48000':\nloss3_1 = -1/4000 * (70 * log(70/178) + (178 - 70) * log(1 - 70/178))\n# cd == else:\nloss3_2 = -1/4000 * (182 * log(182/241) + (241 - 182) * log(1 - 182/241))\n\n\n# others\nothers = -1/4000 * (11 * log(11/25) + 14 * log(14/25))\n\nscore = loss1 + loss2_1 + loss2_2 + loss3_1 + loss3_2 + others\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Public LB score: ', int(score * 100000) / 100000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport glob\nimport os\nimport subprocess as sp\nimport tqdm.notebook as tqdm\nfrom collections import defaultdict\nimport json\n\n! tar xvf \"../input/ffmpeg/ffmpeg-git.tar.xz\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def check_output(*popenargs, **kwargs):\n    closeNULL = 0\n    try:\n        from subprocess import DEVNULL\n        closeNULL = 0\n    except ImportError:\n        import os\n        DEVNULL = open(os.devnull, 'wb')\n        closeNULL = 1\n\n    process = sp.Popen(stdout=sp.PIPE, stderr=DEVNULL, *popenargs, **kwargs)\n    output, unused_err = process.communicate()\n    retcode = process.poll()\n\n    if closeNULL:\n        DEVNULL.close()\n\n    if retcode:\n        cmd = kwargs.get(\"args\")\n        if cmd is None:\n            cmd = popenargs[0]\n        error = sp.CalledProcessError(retcode, cmd)\n        error.output = output\n        raise error\n    return output\n\ndef ffprobe(filename):\n    \n    command = [\"../working/ffmpeg-git-20191209-amd64-static/ffprobe\", \"-v\", \"error\", \"-show_streams\", \"-print_format\", \"xml\", filename]\n\n    xml = check_output(command)\n    \n    return xml\n\ndef get_markers(video_file):\n\n    xml = ffprobe(str(video_file))\n    \n    found = str(xml).find('display_aspect_ratio')\n    if found >= 0:\n        ar = str(xml)[found+22:found+26]\n    else:\n        ar = None\n        \n    found = str(xml).find('\"audio\" codec_time_base')\n    if found >= 0:\n        cd = str(xml)[found+25:found+32]\n    else:\n        cd = None\n    \n    return ar, cd","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"video_file = '/kaggle/input/deepfake-detection-challenge/test_videos/bfjsthfhbd.mp4'\nget_markers(video_file)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}