# Similar Vid
Similar-vid is a library for finding similar frames between videos. It is written as a thin wrapper aroung the Decord and OpenCV libraries.
It was inspired by Netflix's "Skip Intro" feature which allows users to skip intro portions of a tv show.
# Table of Contents
+ [Dependencies](#dependencies)
+ [Installation](#installation)
+ [Usage](#usage)
+ [ToDo](#todos)
## Dependencies
Similar-vid depends on the following:
+ pillow
+ numpy
+ decord
+ imagehash
+ opencv-python
Fortunately, there's a Pipfile that contains virtual environment configurations as will be explained below.
## Installation
The most straightforward way to install the library is via pipenv:
1. Clone the repository
2. cd to the repository and install the dependencies using pipenv
3. activate the directory
```
git clone https://github.com/jahwi/similar-vid.git
cd similar-vid
(optionally install pipenv) pip install pipenv
pipenv install
pipenv shell
```
Alternatively, you can install the dependencies above manually using pip.
```
pip install pillow numpy decord opencv-python imagehash
```
## Usage
[Using the CLI](#the-cli)
[Using Similar-vid within other python projects](#using-similar-vid-within-other-python-projects)
1. [Loading and Matching](#1-loading-and-matching)
2. [Saving hashes and match data for future use](#2-saving-hashes-and-match-data-for-future-use)
3. [Loading saved hashes into fields](#3-loading-saved-hashes-into-fields)
4. [Using Aliases](#4-using-aliases)
### The CLI
Within the project is also a cli wrapper around the library. It is the most straightforward way to use Similar-vid.
```
similar_cli.py "path_to_refrence_video_or_hash" "path_to_other_video another_file_path yet_another_video_file_path"
```
## Using Similar-Vid within other python projects
### 1. Loading and Matching
The `Similar` class' `match` method compares frames between a reference video and an array of at least one other video.
```python
# import the class
from similar_vid.similar_secs import Similar
if __name__=="__main__":
# The library uses multiprocessing, so protect the entry point
# load videos
video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])
# match videos in comp_arr against reference video
video_task.match()
# print matches
print(video_task.matches)
```
### 2. Saving hashes and match data for future use
The library also provides a `save` function, which is a wrapper around the `json.dumps` method of the `json` library. It allows saving fields of the `Similar` class to a json file for future use. These can then be reloaded as will be discussed in `3. Loading saved hashes into fields`.
```python
# import the class
from similar_vid.similar_secs import Similar, save
if __name__=="__main__":
# load videos
video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])
# save the video's fields for future use
save(video_task.ref, path_to_output_file.json) # field holds the reference video hash
save(video_task.comp, path_to_another_output_file.json) # field holds the hashes of the comparision array
```
### 3. Loading saved hashes into fields
After saving fields using the `save` function, the `load` function allows loading saved hashes into fields.
```python
# import the class
from similar_vid.similar_secs import Similar, load
if __name__=="__main__":
# load videos via hashes
video_task = Similar() # first, declare an empty instance
video_task.ref = load(path_to_ref_video_hash.json) # then edit the fields directly
video_task.comp = load(path_to_comp_videos_hash.json)
# It can then be matched, as usual
video_task.match()
print(video_task.matches)
# You can also add individual hashfiles to the comp_array
video_task.comp.append(load(path_to_a_hashed_video.json))
```
### 4. Using Aliases
The library assigns aliases to videos. The reference video has an alias named `ref`, while the videos to be compared against are named `compare_n`, where `n` is the zero-indexed position of the video in the array. The library provides a method `get_by_alias` which allows selecting class objects by their aliases. Additionally, the class has a field, named `aliases` which shows the list of aliases in use for that instance.
```python
# import the class
from similar_vid.similar_secs import Similar
if __name__=="__main__":
# load videos
video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])
reference_by_alias = video_task.get_by_alias("ref") # selects the reference video object, if it exists.
# The above is equivalent to:
reference_directly = video_task.ref
# list aliases, if any
print(video_task.aliases)
```
### TODOs
1. Add ability to compare videos files to hashes directly..
Raw data
{
"_id": null,
"home_page": "https://github.com/supermakc/similar-vid",
"name": "similar-vid",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "video similar skip intro",
"author": "Maxim Baryshev",
"author_email": "supermakc@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/07/e1/7bee99bd97fe3054f06e03a54d2e12e16b894527eef9c2cdb8d2a9367a37/similar_vid-0.0.11.tar.gz",
"platform": null,
"description": "# Similar Vid\n\nSimilar-vid is a library for finding similar frames between videos. It is written as a thin wrapper aroung the Decord and OpenCV libraries.\nIt was inspired by Netflix's \"Skip Intro\" feature which allows users to skip intro portions of a tv show.\n\n# Table of Contents\n+ [Dependencies](#dependencies)\n+ [Installation](#installation)\n+ [Usage](#usage)\n+ [ToDo](#todos)\n\n## Dependencies\nSimilar-vid depends on the following:\n+ pillow\n+ numpy\n+ decord\n+ imagehash\n+ opencv-python\n\nFortunately, there's a Pipfile that contains virtual environment configurations as will be explained below.\n\n## Installation\nThe most straightforward way to install the library is via pipenv:\n1. Clone the repository\n2. cd to the repository and install the dependencies using pipenv\n3. activate the directory\n\n```\ngit clone https://github.com/jahwi/similar-vid.git\ncd similar-vid\n(optionally install pipenv) pip install pipenv\npipenv install\npipenv shell\n```\n\nAlternatively, you can install the dependencies above manually using pip.\n```\npip install pillow numpy decord opencv-python imagehash\n```\n\n## Usage\n[Using the CLI](#the-cli)\n\n[Using Similar-vid within other python projects](#using-similar-vid-within-other-python-projects)\n1. [Loading and Matching](#1-loading-and-matching)\n2. [Saving hashes and match data for future use](#2-saving-hashes-and-match-data-for-future-use)\n3. [Loading saved hashes into fields](#3-loading-saved-hashes-into-fields)\n4. [Using Aliases](#4-using-aliases)\n\n### The CLI\nWithin the project is also a cli wrapper around the library. It is the most straightforward way to use Similar-vid.\n```\nsimilar_cli.py \"path_to_refrence_video_or_hash\" \"path_to_other_video another_file_path yet_another_video_file_path\"\n```\n\n## Using Similar-Vid within other python projects\n### 1. Loading and Matching\nThe `Similar` class' `match` method compares frames between a reference video and an array of at least one other video.\n\n```python\n# import the class\nfrom similar_vid.similar_secs import Similar\n\nif __name__==\"__main__\":\n # The library uses multiprocessing, so protect the entry point\n \n # load videos\n video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])\n\n # match videos in comp_arr against reference video\n video_task.match()\n\n # print matches\n print(video_task.matches)\n\n```\n\n### 2. Saving hashes and match data for future use\nThe library also provides a `save` function, which is a wrapper around the `json.dumps` method of the `json` library. It allows saving fields of the `Similar` class to a json file for future use. These can then be reloaded as will be discussed in `3. Loading saved hashes into fields`.\n\n```python\n# import the class\nfrom similar_vid.similar_secs import Similar, save\n\nif __name__==\"__main__\":\n\n # load videos\n video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])\n\n # save the video's fields for future use\n save(video_task.ref, path_to_output_file.json) # field holds the reference video hash\n save(video_task.comp, path_to_another_output_file.json) # field holds the hashes of the comparision array\n```\n\n### 3. Loading saved hashes into fields\nAfter saving fields using the `save` function, the `load` function allows loading saved hashes into fields.\n\n```python\n# import the class\nfrom similar_vid.similar_secs import Similar, load\n\nif __name__==\"__main__\":\n\n # load videos via hashes\n video_task = Similar() # first, declare an empty instance\n video_task.ref = load(path_to_ref_video_hash.json) # then edit the fields directly\n video_task.comp = load(path_to_comp_videos_hash.json)\n\n # It can then be matched, as usual\n video_task.match()\n print(video_task.matches)\n\n # You can also add individual hashfiles to the comp_array\n video_task.comp.append(load(path_to_a_hashed_video.json))\n```\n\n### 4. Using Aliases\nThe library assigns aliases to videos. The reference video has an alias named `ref`, while the videos to be compared against are named `compare_n`, where `n` is the zero-indexed position of the video in the array. The library provides a method `get_by_alias` which allows selecting class objects by their aliases. Additionally, the class has a field, named `aliases` which shows the list of aliases in use for that instance.\n\n```python\n# import the class\nfrom similar_vid.similar_secs import Similar\n\nif __name__==\"__main__\":\n\n # load videos\n video_task = Similar(ref=path_to_reference_video, comp_arr=[path_to_other_video_1, path_to_other_video_2, path_to_other_video_3])\n\n reference_by_alias = video_task.get_by_alias(\"ref\") # selects the reference video object, if it exists.\n\n # The above is equivalent to:\n reference_directly = video_task.ref\n\n # list aliases, if any\n print(video_task.aliases)\n```\n\n### TODOs\n1. Add ability to compare videos files to hashes directly..\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Similar-vid is a library for finding similar frames between videos",
"version": "0.0.11",
"project_urls": {
"Homepage": "https://github.com/supermakc/similar-vid"
},
"split_keywords": [
"video",
"similar",
"skip",
"intro"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "51f534ec11fff5386c31c2a082b78cb60951ab3ef4481046472fa773450201f3",
"md5": "fe455accd4d64af3f79f879af3317294",
"sha256": "b73d34e9c6ac68736d88ca8faeecc5d28a18ea0ddc6274ded66668e22ee800e1"
},
"downloads": -1,
"filename": "similar_vid-0.0.11-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe455accd4d64af3f79f879af3317294",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 8867,
"upload_time": "2023-11-30T17:11:21",
"upload_time_iso_8601": "2023-11-30T17:11:21.520677Z",
"url": "https://files.pythonhosted.org/packages/51/f5/34ec11fff5386c31c2a082b78cb60951ab3ef4481046472fa773450201f3/similar_vid-0.0.11-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "07e17bee99bd97fe3054f06e03a54d2e12e16b894527eef9c2cdb8d2a9367a37",
"md5": "e2a77ce5dd8abd9f6f9c72eca246ecd1",
"sha256": "e804b7ac002d6b5a6d2764437430efdc81a731c23d3fb60ba95f85bcd52ab350"
},
"downloads": -1,
"filename": "similar_vid-0.0.11.tar.gz",
"has_sig": false,
"md5_digest": "e2a77ce5dd8abd9f6f9c72eca246ecd1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8958,
"upload_time": "2023-11-30T17:11:23",
"upload_time_iso_8601": "2023-11-30T17:11:23.132792Z",
"url": "https://files.pythonhosted.org/packages/07/e1/7bee99bd97fe3054f06e03a54d2e12e16b894527eef9c2cdb8d2a9367a37/similar_vid-0.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-30 17:11:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "supermakc",
"github_project": "similar-vid",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "similar-vid"
}