快速构建大规模视频数据集的开源工具
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 pyspark
distributor: 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 =
AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满 足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效 制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号