You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python下载浏览器全屏显示的指定Archive.org视频

使用Python下载Archive.org指定时间段的视频

方法1:利用yt-dlp(推荐,简单高效)

yt-dlp是一款功能强大的视频下载工具,原生支持解析Archive.org的视频资源,还能直接按指定时间段切割下载。

操作步骤:

  1. 安装依赖工具
    用pip安装yt-dlp:

    pip install yt-dlp
    

    另外需要单独安装ffmpeg(用于视频切割与编码),根据你的操作系统下载对应版本并配置到系统环境变量中。

  2. 编写Python调用代码

    import yt_dlp
    
    # 目标视频链接
    target_url = "https://archive.org/embed/KTVU_20221120_180000_FOX_News_Sunday?start=1620&end=1680"
    # 下载配置
    download_options = {
        'outtmpl': 'fox_news_segment.mp4',  # 输出文件名
        'format': 'best',  # 选择最高质量的音视频合并格式
        # 调用ffmpeg处理视频切割
        'download_ranges': yt_dlp.utils.download_range_func(None, [(1620, 1680)]),
        'postprocessors': [{
            'key': 'FFmpegVideoConvertor',
            'preferedformat': 'mp4',
        }]
    }
    
    with yt_dlp.YoutubeDL(download_options) as ydl:
        ydl.download([target_url])
    

方法2:手动解析源地址+Requests下载(适合自定义场景)

如果不想依赖第三方下载工具,可以手动解析Archive.org的视频元数据,获取真实下载链接后,再用ffmpeg切割指定片段。

操作步骤:

  1. 解析视频真实下载地址
    Archive.org的元数据接口为https://archive.org/metadata/{视频标识},其中视频标识是你链接里的KTVU_20221120_180000_FOX_News_Sunday。

    import requests
    import json
    
    video_identifier = "KTVU_20221120_180000_FOX_News_Sunday"
    metadata_api = f"https://archive.org/metadata/{video_identifier}"
    response = requests.get(metadata_api)
    video_metadata = json.loads(response.text)
    
    # 筛选最高质量的MPEG4格式视频源
    real_video_url = None
    for file_item in video_metadata['files']:
        if file_item['format'] == 'MPEG4' and file_item['source'] == 'original':
            real_video_url = f"https://archive.org/download/{video_identifier}/{file_item['name']}"
            break
    
    if not real_video_url:
        raise ValueError("未找到可用的视频源地址")
    
  2. 下载完整视频并切割片段

    import subprocess
    
    # 流式下载完整视频
    with requests.get(real_video_url, stream=True) as res:
        res.raise_for_status()
        with open('full_video.mp4', 'wb') as f:
            for chunk in res.iter_content(chunk_size=8192):
                f.write(chunk)
    
    # 用ffmpeg切割1620秒到1680秒的片段
    subprocess.run([
        'ffmpeg', '-i', 'full_video.mp4',
        '-ss', '1620', '-to', '1680',
        '-c:v', 'copy', '-c:a', 'copy',
        'fox_news_segment.mp4'
    ], check=True)
    

注意事项:

  • 确保网络可正常访问Archive.org
  • 方法1的yt-dlp无需下载完整视频,直接按时间段截取,更节省带宽
  • ffmpeg是视频切割的必需工具,需保证其可在命令行直接调用

内容的提问来源于stack exchange,提问作者Mateo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 17:30:44