{"id":13535801,"url":"https://github.com/jinyu121/video2frame","last_synced_at":"2026-01-17T05:47:28.050Z","repository":{"id":85684394,"uuid":"164187881","full_name":"jinyu121/video2frame","owner":"jinyu121","description":"Yet another easy-to-use tool to extract frames from videos, for deep learning and computer vision.","archived":false,"fork":false,"pushed_at":"2019-11-09T13:33:41.000Z","size":90,"stargazers_count":131,"open_issues_count":0,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-02T09:22:47.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinyu121.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-05T06:16:45.000Z","updated_at":"2024-07-27T11:11:00.000Z","dependencies_parsed_at":"2023-07-06T14:45:08.336Z","dependency_job_id":null,"html_url":"https://github.com/jinyu121/video2frame","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinyu121%2Fvideo2frame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinyu121%2Fvideo2frame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinyu121%2Fvideo2frame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinyu121%2Fvideo2frame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinyu121","download_url":"https://codeload.github.com/jinyu121/video2frame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222791943,"owners_count":17038320,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T09:00:27.672Z","updated_at":"2026-01-17T05:47:28.005Z","avatar_url":"https://github.com/jinyu121.png","language":"Python","funding_links":[],"categories":["References","Python"],"sub_categories":["Extract Features"],"readme":"# video2frame\n\nVideo2frame is also an easy-to-use tool to extract frames from video.\n\n## Why this tool\n\n[Forwchen's vid2frame tool](https://github.com/forwchen/vid2frame) is great, but I am always confused by their parameters. At the same time, I also want to add something I need to the tool. \n\nSo I re-wrote the code. And now, it is a new wheel. It is hard to make a PR since I changed the code style. \n\n## How to use\n\n1. ### Establish the environment\n    \n    We recommend using [conda](https://conda.io/) to establish the environment. Just using \n    \n    ```sh\n    conda env create -f install/conda-environment.yml\n    ```\n    \n    You can also do it manually. This project relays on the following packages:\n    \n    - Python\n    - FFmpeg\n    - Python packages (can be installed using `pip install -r install/pip-requirements.txt`)\n        + h5py\n        + lmdb\n        + numpy\n        + easydict\n        + tqdm\n    \n1. ### Make the annotation json file\n    \n    The json file should like\n    \n    ```json\n    {\n        \"meta\": {\n            \"class_num\": 2,\n            \"class_name\": [\n                \"class_1\",\n                \"class_2\"\n            ]\n        },\n        \"annotation\": {\n            \"label1_abcdefg\": {\n                \"path\": \"path/to/the/video/file_1.mp4\",\n                \"class\": 1\n            },\n            \"label2_asdfghj\": {\n                \"path\": \"path/to/the/video/file_2.mp4\",\n                \"class\": 2\n            }\n        }\n    }\n    ```\n    \n1. ### Extract frames using `video2frame.py`\n    \n    #### Examples\n    \n    + Using the default options:\n     \n        ```sh\n        python video2frame.py dataset.json\n        ```\n        \n    + Specify the output file name:\n    \n        ```sh\n        python video2frame.py dataset.json --db_name my_dataset\n        ```\n        \n    + Using lmdb rather than hdf5:\n    \n        ```sh\n        python video2frame.py dataset.json --db_type LMDB\n        ``` \n        or \n        ```sh\n        python video2frame.py dataset.json --db_name my_dataset.lmdb\n        ```\n        \n    + Random clip 5 seconds:\n    \n        ```sh\n        python video2frame.py dataset.json --duration 5.0\n        ```\n        \n    + Get 3 video clips with a length of 5 seconds:\n    \n        ```sh\n        python video2frame.py dataset.json --clips 3 --duration 5.0 \n        ```\n    \n    + Resize the frames to 320x240:\n        \n        ```sh\n        python video2frame.py dataset.json --resize_mode 1 --resize 320x240\n        ```\n    \n    + Keep the aspect ration, and resize the shorter side to 320:\n    \n        ```sh\n        python video2frame.py dataset.json --resize_mode 2 --resize S320\n        ```\n    \n    + Keep the aspect ration, and resize the longer side to 240:\n    \n        ```sh\n        python video2frame.py dataset.json --resize_mode 2 --resize L240\n        ```\n        \n    + Extract 5 frames per second:\n    \n        ```sh\n        python video2frame.py dataset.json --fps 5\n        ```\n    \n    + Uniformly sample 16 frames per video:\n    \n        ```sh\n        python video2frame.py dataset.json --sample_mode 1 --sample 16\n        ```\n    \n    + Randomly sample 16 frames per video:\n    \n        ```sh\n        python video2frame.py dataset.json --sample_mode 2 --sample 16\n        ```\n        \n    + Use 16 threads to speed-up:\n    \n        ```sh\n        python video2frame.py dataset.json --threads 16\n        ```\n    \n    + Resize the frames to 320x240, extract one frame every two seconds, uniformly sample 32 frames per video, and using 20 threads:\n    \n        ```sh\n        python video2frame.py dataset.json \\\n            --resize_mode 1 \\ \n            --resize 320x240 \\\n            --fps 0.5 \\\n            --sample_mode 1 \\\n            --sample 32 \\\n            --threads 20\n        ```\n        \n    #### All parameters\n    \n    ```text\n    usage: video2frame.py [-h] [--db_name DB_NAME]\n                          [--db_type {LMDB,HDF5,FILE,PKL}] [--tmp_dir TMP_DIR]\n                          [--clips CLIPS] [--duration DURATION]\n                          [--resize_mode {0,1,2}] [--resize RESIZE] [--fps FPS]\n                          [--sample_mode {0,1,2,3}] [--sample SAMPLE]\n                          [--threads THREADS] [--keep]\n                          annotation_file\n    \n    positional arguments:\n      annotation_file       The annotation file, in json format\n    \n    optional arguments:\n      -h, --help            show this help message and exit\n      --db_name DB_NAME     The database to store extracted frames (default: None)\n      --db_type {LMDB,HDF5,FILE,PKL}\n                            Type of the database (default: HDF5)\n      --tmp_dir TMP_DIR     Temporary folder (default: /tmp)\n      --clips CLIPS         Num of clips per video (default: 1)\n      --duration DURATION   Length of each clip (default: -1)\n      --resize_mode {0,1,2}\n                            Resize mode\n                              0: Do not resize\n                              1: 800x600: Resize to WxH\n                              2: L600 or S600: keep the aspect ration and scale the longer/shorter side to s (default: 0)\n      --resize RESIZE       Parameter of resize mode (default: None)\n      --fps FPS             Sample the video at X fps (default: -1)\n      --sample_mode {0,1,2,3}\n                            Frame sampling options\n                              0: Keep all frames\n                              1: Uniformly sample n frames\n                              2: Randomly sample n continuous frames\n                              3: Randomly sample n frames\n                              4: Sample 1 frame every n frames (default: 0)\n      --sample SAMPLE       How many frames (default: None)\n      --threads THREADS     Number of threads (default: 0)\n      --keep                Do not delete temporary files at last (default: False)\n    ```\n    \n## Tools\n\n1. `video_folder_to_json.py`\n\n    A json generator where the videos are arranged in this way:\n\n    ```text\n    root/swimming/xxx.mp4\n    root/swimming/xxy.avi\n    root/swimming/xxz.flv\n    \n    root/dancing/123.mkv\n    root/dancing/nsdf3.webm\n    root/dancing/asd932_.mov\n    ``` \n1. `something_to_json.py`\n    \n    A json generator that converts the `Something-Something` dataset.\n\n1. `ucf101_to_json.py`\n\n    A json generator that converts the `UCF101` dataset.\n\n## Examples\n\n1. `pytorch_skvideo_dataset.py`\n\n    Get frames using `skvideo` package, when training and evaluating. It is OKay when your batch size is small, and your CPUs are powerful enough.\n\n1. `pytorch_lmdb_video_dataset.py`\n\n    A PyTorch `Dataset` example to read LMDB dataset.\n\n1. `pytorch_hdf5_video_dataset.py`\n\n    A PyTorch `Dataset` example to read HDF5 dataset.\n    \n    __ALWAYS ENSURE `num_workers=0` OR `num_workers=1` OF YOUR DATA LOADER.__\n\n1. `pytorch_pkl_video_dataset.py`\n\n    A PyTorch `Dataset` example to read pickle dataset.\n    \n1. `pytorch_file_video_dataset.py`\n\n    A PyTorch `Dataset` example to read image files dataset.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinyu121%2Fvideo2frame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinyu121%2Fvideo2frame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinyu121%2Fvideo2frame/lists"}