首先要解决的问题
1. youtube访问和导入
SM本身是提供直接获取youtube视频的功能的,限于国情,这项功能基本属于无用。经过尝试,通过方法访问youtube,导入后视频无法加载。故而,只能下载回来,再学习。但是,下载回来的视频是flv,SM不支持flv,所以,需要转换。
2. 视频下载(you-get[1])
you-get是一个基于python3的命令行程序,提供便利的方式来下载网络上的媒体信息。可下载流行网站之音视频,例如YouTube, Youku, bilibili等(完整见相关页面)。
2.1 安装
首先,系统需要安装python 3.x,具体的安装方式参考python官方。
然后,假设python3的安装一切妥当,打开cmd,输入:
$ pip3 install you-get
最后,验证是否成功:
$ you-get --version
you-get: version 0.4.1270, a tiny downloader that scrapes the web.
2.2 使用方法
首先,打开视频网站相关页面,复制链接。
然后,打开cmd,输入
you-get -i [link]
比如:
$ you-get -i https://www.bilibili.com/video/av24173069?from=search&seid=7585440769350719962
[ DEFAULT ] _________________________________
- format: flv720
container: flv
quality: 高清 720P
size: 12.3 MiB (12934297 bytes)
# download-with: you-get --format=flv720 [URL]
- format: flv480
container: flv
quality: 清晰 480P
size: 12.3 MiB (12881561 bytes)
# download-with: you-get --format=flv480 [URL]
- format: flv360
container: flv
quality: 流畅 360P
size: 10.9 MiB (11463215 bytes)
# download-with: you-get --format=flv360 [URL]
接着,根据需要,下载相应的清晰度:
$ you-get --format=flv360 https://www.bilibili.com/video/av24173069\?from\=search\&seid\=7585440769350719962
you-get: This is a multipart video. (use --playlist to download all parts.)
site: Bilibili
title: 【英语听力】Daily English Dictation 1-240 (Coach Shane)(更新中) (P1. 1)
stream:
- format: flv360
container: flv
quality: 流畅 360P
size: 10.9 MiB (11463215 bytes)
# download-with: you-get --format=flv360 [URL]
Downloading 【英语听力】Daily English Dictation 1-240 (Coach Shane)(更新中) (P1. 1).flv ...
100% ( 10.9/ 10.9MB)
├██████████████████████████████████████████████████████████████┤[1/1] 156 kB/s
Downloading 【英语听力】Daily English Dictation 1-240 (Coach Shane)(更新中) (P1. 1).cmt.xml ...
3. 格式转换(ffmpeg[2])
3.1 安装
ffmpe是一款跨平台的音视频转换软件,官网下载回来的是命令行软件。同样需要在终端内使用。
各个平台的安装参见官网,我用的是windows 10下的wsl,版本是ubuntu 18.04。安装方法如下:
打开wsl终端,输入:
$ sudo apt install ffmpeg
输入root密码,等待安装完成即可。
然后,验证安装:
$ ffmpeg -version
出现:
$ ffmpeg -version
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: ...
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
3.2 使用
ffmpeg的功能很强大,具体参见官网文档。我这里讲一下,基本的flv转MP4。
首先,定位到flv文件的文件夹。
然后,按住shift,同时右键,在弹出菜单选择打开linux shell。
接着输入:
$ ffmpeg -i input.flv output.mp4
等待转换完成即可。
同时也可以加入一些参数,这里我举一个例子,用来快速转换格式,基本上是秒转:
$ ffmpeg -i input.flv -vcodec copy -acodec copy output.mp4
考虑到省事,我写了个脚本,运行环境也是wsl,不过没有在其他电脑测试过。脚本调用ffmpeg进行格式转换,运行会要求填入文件夹的路径(我一般直接放到视频文件夹在运行,输入"."作为路径,省事),然后要求输入要转换的格式,比如mkv、flv,再根据提示输入希望转化出来的格式,比如MP4。代码复制粘贴,另存为后缀为py即可,名字随意:
import os, shlex, subprocess
def exec_command(file_name, input_file_extension, out_file_extenson):
if file_name.endswith(input_file_extension):
command = "ffmpeg -i %s -vcodec copy -acodec copy %s" % (file_name, file_name[:-3] + out_file_extenson)
arg = shlex.split(command)
print(arg)
exec_cmd = subprocess.call(arg)
file_dir = input("Where's the direction of work folder:")
input_file_extension = input("What's the extension of input files:")
output_file_extension = input("What's the extension of output files:")
file_list = os.listdir(file_dir)
for file_name in file_list:
exec_command(file_name, input_file_extension, output_file_extension)
4. 解决mci错误(安装K-Lite Codec Pack Standard[3])
官网下载exe安装包,默认安装即可,然后把默认视频播放器设置为windows media player,否则SM会出现mci错误。
SM 增量视频操作
[1]you-get of github
[2]ffmpeg website
[3]K-Lite Codec Pack Standard website