从youtube下载视频并转换为MP4

问题描述 投票:3回答:2

我创建了一个脚本来下载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)

所以我在第一个qazxsw poi命令中得到以下错误

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

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

python ffmpeg youtube-dl
2个回答
5
投票

错误很明显:

容器中当前不支持编解码器。

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


1
投票

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

szatmary answer

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

所以这是我发现的最终解决方案:

ffmpeg $(youtube-dl -f "+quality+" -g '"+url+"' | sed 's/.*/-ss "+starttime+" -i &/') -t "+duration+" -c:v libx264 "+name+".mp4
© www.soinside.com 2019 - 2024. All rights reserved.