【问题标题】:Downloading a video from youtube and convert to MP4从 youtube 下载视频并转换为 MP4
【发布时间】:2019-08-15 23:44:02
【问题描述】:

我创建了一个脚本来下载一个 youtube 视频并从中提取每个时期的图像

截屏视频

def screenshotvideo(url, interval, id, fullduration, title, quality):
    interval = int(interval)
    parsed_t = isodate.parse_duration(fullduration)
    durationseconds=parsed_t.total_seconds()
    iterat=int(durationseconds/int(interval))
    for i in range(0, iterat):
        print(str(id))
        print(str(i))
        print(str(i*interval))
        part(url, time.strftime('%H:%M:%S', time.gmtime(int(i*interval))), "00:00:01", title+"-"+str(id), quality)

部分

def part(url, starttime, duration, name, quality):
    f = os.popen("ffmpeg $(youtube-dl -f "+quality+" -g '"+url+"' | sed 's/.*/-ss "+starttime+" -i &/') -t "+duration+" -c copy "+name+".mp4")
    now = f.read()
    print(now)
    f = os.popen("ffmpeg -i "+name+".mp4 -ss 00:00:00 -vframes 1 "+name+".jpg")
    now = f.read()
    print(now)
    f = os.popen("rm -rf "+name+".mp4")
    now = f.read()
    print(now)

所以我在第一个 ffmpeg 命令中遇到了以下错误

[mp4 @ 0x55d537f64240] 在流 #0 中找不到编解码器 vp8 的标记,容器当前不支持编解码器。

无法为输出文件 #0 写入标头(编解码器参数不正确?):参数无效

【问题讨论】:

  • 仅供参考,大多数 YouTube 视频已经以 MP4 格式提供 - 在这种情况下,您不必进行任何转换。

标签: python ffmpeg youtube-dl


【解决方案1】:

错误很明显:

容器目前不支持编解码器。

使用支持 vp8 的其他容器,例如 webm 或 mkv。

【讨论】:

    【解决方案2】:

    答案接近szatmary answer,但我需要下载mp4格式的视频,所以我要做的就是编辑第一个命令

    ffmpeg $(youtube-dl -f "+quality+" -g '"+url+"' | sed 's/.*/-ss "+starttime+" -i &/') -t "+duration+" -c:v libx264 "+name+".mp4
    

    之后,我每次都想从视频中保存的图像文件名出现其他错误。

    所以这是我找到的最终解决方案:

    def screenshotvideo(url, interval, id, fullduration, title, quality):
        interval = int(interval)
        parsed_t = isodate.parse_duration(fullduration)
        durationseconds=parsed_t.total_seconds()
        iterat=int(durationseconds/int(interval))
        for i in range(0, iterat):
            print(str(id))
            print(str(i))
            print(str(i*interval))
            part(url, time.strftime('%H:%M:%S', time.gmtime(int(i*interval))), "00:00:01", title+"-"+str(id), quality, i)
    
    
    def part(url, starttime, duration, name, quality, i):
        f = os.popen("ffmpeg $(youtube-dl -f "+quality+" -g '"+url+"' | sed 's/.*/-ss "+starttime+" -i &/') -t "+duration+" -c:v libx264 "+name+".mp4")
        now = f.read()
        print(now)
        f = os.popen("ffmpeg -i "+name+".mp4 -ss 00:00:00 -vframes 1 "+name+"_"+str(i)+".jpg")
        now = f.read()
        print(now)
        f = os.popen("rm -rf "+name+".mp4")
        now = f.read()
        print(now)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2022-11-02
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多