
快速构建大规模视频数据集的开源工具
video2dataset是一个开源工具,用于从视频URL快速创建大规模视频数据集。它支持多种输入输出格式和文件系统,可在12小时内处理1000万个视频。该工具提供增量模式、分布式处理和Weights & Biases集成,适合机器学习训练等场景。其灵活的API和配置选项让用户能够精细控制数据处理流程。
Easily create large video dataset from video urls. Can download and package 10M videos in 12h on a single 16 core machine.

If you believe in making reusable tools to make data easy to use for ML and you would like to contribute, please join the DataToML chat.
If you would like to contribute to video2dataset, please read CONTRIBUTE.md
pip install video2dataset
Or from source via
git clone https://github.com/iejMac/video2dataset cd video2dataset pip install -e .
On Mac, replace 'decord' with 'eva_decord' in requirements.txt. For details, see https://github.com/dmlc/decord/issues/213.
First get some video urls and metadata (all supported sites by yt-dlp). For example lets save this small animal video dataset to a csv file called videos.csv
url,caption https://www.youtube.com/watch?v=od_PmtmMDV0,Driving to the banana store https://www.youtube.com/watch?v=8FhGOV7fs64,Polar bear eating https://www.youtube.com/watch?v=TReCLbmhlMs,Cat scared of printer https://www.dailymotion.com/video/x29ryo7,Cat and owl playing
Then, run the tool:
video2dataset --url_list="videos.csv" --url_col="url" --caption_col="caption" --output_folder="dataset"
If you go into the output folder you should see a nice small video dataset stored with all relevant metadata.
Here are some more concrete examples of video2dataset usage.
The WebVid dataset is a high quality video-text of 10M stock videos. It can be easily downloaded and stored using one video2dataset command, to perform the same on the train split (much larger) you just need to swap out the csv file and update the distribution params to something more beefy. Here's an example config that adjusts the default config for slurm distribution (so we can use many nodes to download it quickly).
video2dataset is designed such that you can chain together runs to re-process your downloaded data since webdataset is a valid input_format. Here's an example - with the WebVid data you downloaded in the previous example you can also run this script which will compute the optical flow for each video and store it in metadata shards (shards which only have the optical flow metadata in them). You can also run this script which will take those videos and perform resizing, fps downsampling, cut detection, and clipping and also store that in a new dataset. We make sure that the content in shards with the same IDs is the same across re-processing runs. Furthermore, if clipping is not performed shard IDs and sample IDs are exactly the same since clipping is the only transformation that changes the sample IDs i.e. if sample 000 is clipped into 3 clips they will be split into 000_000, 000_001, 000_002.
Once you download some chunk of WebVid (or any video dataset) you can load it using our dataloader like in this example. Try it out.
Whenever we do a large dataset processing job we document them in dataset examples as many existing datasets are unique and might require special procesing or the authors just don't specify the best ways of getting the data. Thanks to this we can all share the most efficient ways of processing large video/audio datasets!
The tool will automatically download the urls and store them with the format:
output-folder
├── 00000{.ext if output_format != files, can be tar, parquet, tfrecord, etc.}
| ├── 00000.mp4
| ├── 00000.txt
| ├── 00000.json
| ├── 00001.mp4
| ├── 00001.txt
| ├── 00001.json
| └── ...
| ├── 10000.mp4
| ├── 10000.txt
| ├── 10000.json
├── 00001.ext
| ├── 10001.mp4
| ├── 10001.txt
| ├── 10001.json
│ ...
...
with each number being the position in the input table or the input sample ID. The subfolders avoid having too many files in a single folder. If captions are provided, they will be saved as 0.txt, 1.txt, etc. (matching the ID of the sample they belong to). This can then easily be fed into machine learning training or any other use case.
Also .json files named 0.json, 1.json,... are saved with these keys:
Also a .parquet file will be saved with the same name as the subfolder/tar files containing these same metadata. It can be used to analyze the results efficiently.
.json files will also be saved with the same name suffixed by _stats, they contain stats collected during downloading (download time, number of success, ...)
video2dataset support several formats. There are trade off for which to choose:
The module exposes a single function video2dataset which takes the same arguments as the command line tool:
url_list: list of input urls - can be any of the supported input formats
(csv, parquet, braceexpand tar paths etc.)
output_folder: Desired location of output dataset (default = "dataset")
output_format: Format of output dataset, can be (default = "files")
- files, samples saved in subdirectory for each shard (useful for debugging)
- webdataset, samples saved in tars (useful for efficient loading)
- parquet, sampels saved in parquet (as bytes)
- tfrecord, samples saved in tfrecord (as bytes)
- dummy, does not save (useful for benchmarks)
input_format: Format of the input, can be (default = "csv")
- txt, text file with a url in each line
- csv, csv file with urls, (and captions + metadata)
- tsv, tsv - || -
- tsv.gz, - || - but compressed gzip
- json, loads urls and metadata as json
- parquet, loads urls and metadata as parquet
- webdataset, usually braceexpand format of mutliple paths to tars to re-process
encode_formats: Dict that specifies what extension each modality should use (default = "{'video': 'mp4'}")
f.e. {"video": "mp4", "audio": "m4a"}
stage: String that tells video2dataset what stage of processing is being performed. Can be (default = 'download')
WARNING: To be depracated soon (this information should be deduced based on config)
- download, when input is some tabular format and data must be downloaded first
- subset, tar files are already written and we would like to re-process (input_format == "webdataset")
- optical_flow, tar files are written and we woudl like to compute optical_flow and save to md shards
url_col: Column in input (if has columns) that contains the url (default = "url")
caption_col: Column in input (if has columns) that contains captions (to be written as txt) (default = None)
clip_col: Column in input (if has columns) that contains timeframes of clips for how to split video (default = None)
save_additional_columns: List of column names to save to json component of a sample (defualt = None)
enable_wandb: Whether or not to log info to wandb (default = False)
wandb_project: Name of wandb project to log runs to (default = "video2dataset")
incremental_mode: Decides how to handle restarting, Can be (default = "incremental")
- incremental, checks which shards are done and skips those
- overwrite, deletes and reprocesses shards as it goes
max_shard_retry: Maximum amount of attempts to retry a failed shard (default = 1)
tmp_dir: Path to temporary directory on your file system (default = "/tmp")
config: Path to your config of choice or the config itself (more info on configs in API doc) (default = "default")
These arguments give coarse control over input/output "shape" of the dataset. For finer control of subsamplers, distribution, reading, and storage see the more detailed API.md doc.
If we want to download a large amount of YouTube videos with video2dataset we can specify some parameters and also extract useful metadata as well. For directions on how to do so please see this example.
If a first download got interrupted for any reason, you can run again with --incremental "incremental" (this is the default) and using the same output folder , the same number_sample_per_shard and the same input urls, and video2dataset will complete the download.
Thanks to fsspec, video2dataset supports reading and writing files in many file systems.
To use it, simply use the prefix of your filesystem before the path. For example hdfs://, s3://, http://, or gcs://.
Some of these file systems require installing an additional package (for example s3fs for s3, gcsfs for gcs).
See fsspec doc for all the details.
If you need specific configuration for your filesystem, you may handle this problem by using the fsspec configuration system that makes it possible to create a file such as .config/fsspec/s3.json and have information in it such as:
{ "s3": { "client_kwargs": { "endpoint_url": "https://some_endpoint", "aws_access_key_id": "your_user", "aws_secret_access_key": "your_password" } } }
Which may be necessary if using s3 compatible file systems such as minio. That kind of configuration also work for all other fsspec-supported file systems.
video2dataset supports several distributors.
multiprocessing is a good option for downloading on one machine, and as such it is the default. Pyspark lets video2dataset use many nodes, which makes it as fast as the number of machines. It can be particularly useful if downloading datasets with more than a billion image. Here's an example for how we used pyspark distributed mode to download 40M videos with metadata. If you have access to a slurm cluster it is more comfortable to use than pyspark but not everyone does.
In order to use video2dataset with pyspark, you will need to do this:
pip install pysparkdistributor: pyspark in your configsubjob_size: 1000 option in your config. This is the number of videos to download in each subjob. Increasing it will mean a longer time of preparation to put the feather files in the temporary dir, a shorter time will mean sending less shards at a time to the pyspark job.By default a local spark session will be created. You may want to create a custom spark session depending on your specific spark cluster.
As stated at the top of the README - video2dataset is capable of downloading 10M videos in 12h. For more details on end2end performance please see specific runs in dataset examples as there are nuances to video (how long it is, where it comes from etc.). For example it takes considerably longer to pul videos from youtube than just mp4 links (compare WebVid.md to VideoCC.md). Each example should have a "Performance" statement at the bottom which should contain info about download/processing performance (video/s, Mb/s) along with a cost estimate on popular cloud infrastructure.
For information about video2dataset subsampler speed please check out the benchmark suite which contains code that produces performance numbers for subsamplers, over a grid of parameters, on a given architecture. It also contains a json file with some results we produced. This can be used to estimate costs of big runs and also to optimize the subsamplers. NOTE: cost can drastically vary based on chosen subsampler configuration.
If you pass the --enable_wandb=True parameter then performance metrics will be logged to Weights & Biases

In addition, most frequent errors are logged for easier debugging

Other features are available:
When running the script for the first time, you can decide to either associate your metrics to your account or log them anonymously.
You can also log in (or create an account) before by running wandb login.
Either locally, or in gitpod (do export PIP_USER=false there)
Setup a virtualenv:
python3 -m venv .env source .env/bin/activate pip install -e .
to run tests:
pip install -r requirements-test.txt
then
make lint make test
You can use make black to reformat the code
python -m pytest -x -s -v tests -k "dummy" to run a specific test
@misc{kilian-2023-video2dataset, author = {Maciej Kilian, Romain Beaumont, Daniel Mendelevitch, Sumith Kulal, Andreas Blattmann}, title = {video2dataset: Easily turn large sets of video urls to a video dataset}, year = {2023}, publisher = {GitHub}, journal = {GitHub repository}, howpublished =


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理 响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写 作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号