Created
October 25, 2019 13:21
-
-
Save papr/161c622ff50422f4044ef422eb207e7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import av # pip install av\n", | |
| "import numpy as np # pip install numpy\n", | |
| "import pandas as pd # pip install pandas\n", | |
| "%matplotlib inline" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def mean_fps(df):\n", | |
| " return 1.0 / df.diff().mean()\n", | |
| "\n", | |
| "def pts_dataframe(path):\n", | |
| " cont = av.open(path)\n", | |
| " stream = cont.streams.video[0]\n", | |
| " packet_pts = [pack.pts for pack in cont.demux(stream)]\n", | |
| " df = pd.DataFrame(packet_pts, columns=[\"packet_pts\"])\n", | |
| " df.packet_pts *= stream.time_base\n", | |
| " cont.close()\n", | |
| " return df" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": { | |
| "scrolled": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Effective FPS world_timestamps.csv: 29.61100354989063\n", | |
| "Effective FPS world.mp4: 60.0\n", | |
| "Effective FPS SL102world.mp4: 29.611004509264397\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "external_timestamps = \"world_timestamps.csv\"\n", | |
| "original = \"world.mp4\"\n", | |
| "exported = \"SL102world.mp4\"\n", | |
| "\n", | |
| "ts = pd.read_csv(external_timestamps)\n", | |
| "print(f\"Effective FPS {external_timestamps}: {mean_fps(ts).values[0]}\")\n", | |
| "\n", | |
| "for file in (original, exported):\n", | |
| " print(f\"Effective FPS {file}: {mean_fps(pts_dataframe(file)).values[0]}\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.7.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment