acfun怎么下载视频,acfun视频

  

  一. 软件介绍:   

  

  MPV是一款免费、开源、跨平台的多媒体播放软件。它有丰富的功能、简洁紧凑的界面和没有广告,整体认知度等同于Windows上的PotPlayer. 相对于PotPlayer它最大的特点是跨平台,支持动态lua脚本解析.可高度定制化.市面上不少流行的播放器使用的内核其实也都是MPV,因此对它毫无疑问。   

  

  MPV通过配置文件提供了丰富的配置参数,对于批量配置相当方便,同时提供了事件处理接口。因此,我们可以自定义lua事件函数,并将快捷键绑定到该函数上,以便在观看视频时,方便地在键盘上按几个字符,直接完成一系列处理。官网链接如下:   

  

  mpv.iompv.io/   

  

  在这篇文章中,我们解释了如何使用mpv播放器来实现边看边编辑视频的效果。有的同学可能会说,编辑软件有这些基本功能,不是吗?没错,但是你要知道MPV可以直接做同样的工作,而且没有专业剪辑软件那么复杂。况且这只是我们学习MPV的第一课。我会在接下来的文章中向您介绍更多其他强大的功能。如果你有兴趣,请先同意或者关注我.哈哈(*)。(*)   

  

  当然,在本文中,我们实现对在线的视频免下载,直接进行剪辑处理,常见的如爱优腾/B站/YouTuBe,及任何其它能拿到视频播放地址的视频,具体怎么去拿地址很简单的,不用去写代码的...详见后文.本地磁盘的视频更不用提,绝对可以的!在这里会依赖一些其他的软件功能,但它们都很简单,没有什么大问题。   

  

  二. 示例操作步骤:   

  

  本文演示环境为: (MacOS)   

  

  1.下载mpv及基本配置   

  

  # ##1.安装home brew # # # # # # # # # # # # # # # # # # # # # # # # # # # #如果你已经安装了$/bin/zsh-c ' $(curl-fssl https://gitee . com/Cun kai/home brew cn/raw/master/home brew . sh)' # #方案2 :https://blog.csdn.net/Mr_Yang__/article/details/8131203 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 2。 将brew的来源修改为国内来源$ CD ' $ home brew/brew . git $ CD ' $(brew-repo)/Library/Taps/home brew/home brew-core ' $ git remoteset-urlrorigin https://mirrors . tuna . Tsinghua . edu.cn/git/home brew/home brew-core . git $ brew更新# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #查看$ MPV-version MPV 0.33.1版权所有2000-2020 # MPV的默认配置文件$ ls-a/usr/local/cellar/MPV/0 . 33 . 1/share/doc/MPV/. input . conf MPV . conf restore-old-bindings . conf。   

录放置自己的配置(优先级比系统默认配置高)$ mkdir -p ~/.config/mpv/scripts## 拷贝一份系统配置至自己的配置目录$ cp -r -/usr/local/Cellar/mpv/0.33.1/share/doc/mpv/*  ~/.config/mpv/################### 拷贝## 说明:## 所有的*.lua脚本放在scripts目录中,mpv打开时会自动加载并解析## 在~/.config/mpv/input.conf中添加快捷键信息## 在~/.config/mpv/mpv.conf中配置mpv播放器信息## 进入自己的配置目录,修改配置文件$ cd ~/.config/mpv/#################2.配置视频剪辑功能

  

下载mpv-video-cutter 项目,解压并拷贝内容至~/.config/mpv/scripts,下载github地址链接为:

  

## 安装ffmpeg$ brew install ffmpeg## 下载并解压git clone https://github.com/rushmj/mpv-video-cutter.git## 拷贝解压内容至如下目录~/.config/mpv/scripts其它更详细的说明,请参考如下的作者链接:

  

GitHub - rushmj/mpv-video-cutter: cut video and concat automaticallygithub.com/rushmj/mpv-video-cutter

  

拷贝后结果为如下框选,总共就3个文件

  

  

3.实现在线截取支持

  

原作者的脚本在使用mpv播放本地视频进行操作剪辑时完全正常,作者也只测试了本地,我自己测试了对线上播放视频的剪辑功能,添加了注释以及为了满足部分功能,作了些兼容修改.所以如果你要实现线上视频剪辑的话请用我的脚本覆盖一下你从GitHub 上下载的文件,如果你只是本地视频剪辑使用,可以忽略这一步! 拷贝操作时只要用如下c_concat.sh文件覆盖同名就行:

  

#### 文件名称:c_concat.sh 拷贝如下:####cp c_concat.sh  ~/.config/mpv/scripts #### 下面为sh文件内容: 经测试:支持优酷/B站/爱奇艺/其它站点*m3u8源#output a run.sh that real cut and concat the file#use ffmpeg,thanks for its developerif < "$1" = "" > || < "$2" = "" > || < "$3" = "" >thenecho "please input paramenter:$1,$2,$3"exit 2fitime_pairs_txt=$1 # txt file that contain time suits for trim## 格式: local file: ~/super_star.mp4 | web file: http://cdn.ali.upcs.com/hud/zzz_yyyy_mm.mp4?a=b&c=222 | m388 ts: http://cdn.ali.upcs.com/hud/zzz_yyyy/mm/m3u8?a=b&c=222 input=$2 # 待处理视频完整路径 #input=${input//' '/' '}input=`printf %q "$input"`output='date "+%Y_%m_%d_%H_%M_%S"' # 剪辑后输出文件名前缀dir_name=.cut_video  # 用于临时使用的目录dir_path=$3 # 剪辑后输出文件保存目录sh_dir=$4  # 脚本工作路径IFS=$'/' f=($2) # 对待处理视频的完整路径进行/分割file_name=${f<${#f<*>}-1>}  # /后分割得到文件名称## add by likey## 参考: https://blog.csdn.net/weixin_30363981/article/details/97631778http_schemal="http:" https_schemal="https:"echo "----------begin:----------"echo "input name:$input"echo "file name:$file_name"## 如果请求web网页资源,并为http或https协议# if << $input == *$http_schemal* || $input == *$https_schemal* >>if << $input =~ "$http_schemal" || $input =~ "$https_schemal" >>then    echo "request web resource!"## 添加refererreferer_str=$''if << $input =~ "iqiyi.com" >>then# referer_str="-headers Referer:https://www.iqiyi.com/"echo ">>>暂未对爱奇艺设置referer!"elif << $input =~ "bilivideo.com" >>thenreferer_str="-headers Referer:https://www.bilibili.com/"echo ">>>已经添加到 B 站:referer!"else# referer_str='-headers Referer:https://www.xxxx.com/'echo ">>>input输入流的站点未识别!"fiecho $referer_str##  丢弃包括?后的内容file_name=${file_name%%?*}## 分割headers中多个参数,不然有警告:No trailing CRLF found in HTTP header. Adding it.st_headers=$referer_str ## 要用正则换成每次对应请求的域名,这里暂时直接写死了,因为除了B站,其它站点似乎不受影响st_user_agent=$'-user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.76 " '# st_user_agent_m=$' -user_agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 " 'else    echo "request local resource!"st_headers=$''st_user_agent=$''st_user_agent_m=$''fi## 如文件名不含.号,则不是本地文件和远程文件直链,而是网页ts视频流if << $file_name != *$'.'* >>thenecho "hint: maybe online stream, please use you-get tool to get a direct remote media file  ......."## 设置返回视频格式为mp4及指定一个最终的合并文件名,更改后缀名为mp4不然m3u8下载的多个ts流无法合并转换成功file_format=$"mp4"file_name=$"m3u8_out_compact.mp4"## 如果请求文件是.m3u8后缀,更改后缀名为mp4不然可能无法转换成功elif << $file_name == *$'.m3u8'*  || $file_name == *$'.m4s'* || $file_name == *$'.ts'* >>thenfile_format=$"mp4"file_name="${file_name}.mp4"else## 带文件后缀(非.mu38流)的真实视频地址echo "direct file name: $file_name"fi#file_name=${file_name//' '/' '}IFS=$'.' t=($file_name)file_format=${t<${#t<*>}-1>}echo  "file name:$file_name, file format:$file_format"# cat $time_pairs_txt | while read line# do#  IFS=',' seg=($line)#  left=${seg<0>}#  right=${seg<1>}#  echo "left:$left,right:$right"# doneecho "dir_path for save_file:$dir_path"## add by likey 设置视频统一的输出路径,不然默认会放置在本地文件同目录下,(注意:Web网页请求时地址要处理,不然报错,因为传入的目录是一长串网址)dir_path=$'/Users/Likey/mpv-www-gen'eval cd "$sh_dir"echo "sh_dir for script:`pwd` "echo "cd "$dir_path"" > run.shecho "mkdir $dir_name" >> run.shIFS=$'' a=(`eval cat $time_pairs_txt`)num=${#a<@>}for  i  in  ${!a<@>};doIFS=',' seg=(${a})left=${seg<0>}right=${seg<1>}duration=$(echo "scale=2;$right-$left" |bc)# echo "<$i>left:$left,right:$right"#gen a new run.sh# if < $i = 0 ># then# echo "echo "file 'clip$i.mkv'" >>$dir_name/concat.txt" >run.sh# fiecho "ffmpeg $st_headers $st_user_agent -ss $left -i $input -t $duration  $dir_name/clip$i.$file_format" >>run.sh#echo "ffmpeg -y -accurate_seek -ss $left  -t $duration -i $input -c  copy -avoid_negative_ts 1 $dir_name/clip$i.$file_format" >>run.shecho "echo "file 'clip$i.$file_format'" >>$dir_name/concat.txt" >>run.shdone# if < $num == 1 ># then#    echo "cp mode"#    #echo "cp clip0.mkv ../"`$output`"_cat_$file_name" >>run.sh# else#    echo "concat mode"#    #echo "ffmpeg -f concat -i $dir_name/concat.txt -c copy "`$output`"_cat_$file_name" >>run.sh# fi## 如果只提取了单段视频,直接拷贝至放置目录,否则要用ffmpeg合并一次if < $num == 1 >then   echo "only single clip extract, use cp mode"   echo "cp $dir_name/clip0.$file_format "`$output`_cut_$file_name"" >>run.shelse   echo "multi clip extracts, use concat mode"   echo "ffmpeg -f concat -i $dir_name/concat.txt -c copy "`$output`_cut_$file_name"" >>run.shfiecho "rm -rf $dir_name" >>run.shecho "echo script_dir:`pwd`" >>run.shecho "echo -----ok!-----" >>run.shchmod +x run.shecho "-----run.sh has generated!-----"4.获取视频播放地址

  

mpv 播放器内置了youtube-dl引擎,可以直接拉到大部分的在线视频流,所以我们只要把浏览器上的地址拿过来就可以,如: mpv 视频网址url, 如果出现 mpv 不支持,播放不了的情况,我们可以使用IDM软件及Downie软件来获取流,同时可以使用you-get annie youtube-dl tampermonkey插件来获取.

  

#### 方法1:## 借助 IDM Downie4 等工具, 这种方法功能最强大,使用上也最为方便,建议使用#### 方法2:  ## 开源及轻量级的方案,很方便批量和定制化,如支持B站列表多集的批量获取及下载you-get -u  视频页浏览器urlannie -i  视频页浏览器urlyoutube-dl -F  视频页浏览器url#### 方法3: ## 使用tampermonkey插件 / FDM / 迅雷等中文说明 soimort/you-get Wiki (github.com)github.com/soimort/you-get/wiki/%E4%B8%AD%E6%96%87%E8%AF%B4%E6%98%8E

  

iawia002/annie: Fast, simple and clean video downloader (github.com)github.com/iawia002/annie

  

youtube-dlyoutube-dl.org/

  

如下,直接用tampermonkey插件 bilibili哔哩哔哩下载助手插件 - B站下载助手 Chrome插件,bilibili哔哩哔哩下载助手插件 - B站下载助手 谷歌浏览器插件下载_安装_教程-扩展迷 (extfans.com) 来实现第三方地址解析:

  

  

三. 查看测试效果:

  

接下来打开mpv播放器来测试一下:

  

## 终端执行:$ mpv "https://www.bilibili.com/video/BV17B4y1A7Fv" ## B站$ mpv "https://v.youku.com/v_show/id_XNTEzMTkzMzE4NA==.html" ## 优酷$ mpv "~/super_star.mp4"  ## 本地文件## 提示:cookies信息可用浏览器调试|fiddler|wireshark查看,或用annie -d查看:$ annie -i -d http://www.bilibili.com/video/av20088587############## 第三方解析地址测试:################ mpv直接播放mpv "https://upos-sz-mirrorcoso1.bilivideo.com/upgcxcode/06/25/326162506/326162506_nb2-1-80.flv?e=ig8euxZM2rNcNbTMhbUVhoMj7wNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1618889010&gen=playurlv2&os=coso1bv&oi=977184500&trid=b9140b6dd61d4ea382ce3e4d4d5b8cf3u&platform=pc&upsig=b1c7225718f2d5cf81c38165eda223d6&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=456220830&orderid=0,3&agrr=0&logo=80000000"  --referrer='https://www.bilibili.com' --no-ytdl## ffmpeg下载ffmpeg -headers $'Referer:http://www.bilibili.com/y:2' -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.76 "  -ss 3.323 -i https://upos-sz-mirrorcoso1.bilivideo.com/upgcxcode/06/25/326162506/326162506_nb2-1-80.flv?e=ig8euxZM2rNcNbTMhbUVhoMj7wNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1618889010&gen=playurlv2&os=coso1bv&oi=977184500&trid=b9140b6dd61d4ea382ce3e4d4d5b8cf3u&platform=pc&upsig=b1c7225718f2d5cf81c38165eda223d6&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=456220830&orderid=0,3&agrr=0&logo=80000000 -t 3.280  .cut_video/clip0.flv

  

接着我们只要在mpv播放器中通过按键盘字母C键来选定: 开始 ->结束,开始 ->结束多个视频播放时间段即可,确定后按下字母O键,mpv播放器会执行导出.如果要删除并重选,可以按 R 键来操作,其它更多用法请参考上面的GitHub链接.

  

如下所示: 在终端会实时显示相关的信息,在脚本目录会生成一个run.sh文件,其实原理就是获取了多次按C键选定的时间区域,然后使用了ffmpeg工具来提取了视频.最终再使用ffmpeg进行了合并.

  

如下图:终端上会显示具体的信息:

  

mpv处理并生成run.sh文件

  

Likey@Laptop scripts % pwd         /Users/Likey/.config/mpv/scriptsLikey@Laptop scripts % ls README.mdc_concat.shcutter.luatempCodeRunnerFile.luatest.shautoload.luac_concat2.shrun.shtest.luatime_pairs.txtLikey@Laptop scripts % cat ./run.sh cd "/Users/Likey/mpv-www-gen"mkdir .cut_videoffmpeg -headers Referer:http://www.bilibili.com/ -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.76 "  -ss 1.803 -i http://upos-hz-mirrorakam.akamaized.net/upgcxcode/06/25/326162506/326162506_nb2-1-80.flv?e=ig8euxZM2rNcNbTMhbUVhoMj7wNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNC8xNEVE9EKE9IMvXBvE2ENvNCImNEVEK9GVqJIwqa80WXIekXRE9IMvXBvEuENvNCImNEVEua6m2jIxux0CkF6s2JZv5x0DQJZY2F8SkXKE9IB5QK==&deadline=1618939426&gen=playurl&nbs=1&oi=804330220&os=akam&platform=pc&trid=c480ac64f3554ff89735c2db8f551509&uipk=5&upsig=50d548dc4f5907be43bc22ae9952cf51&uparams=e,deadline,gen,nbs,oi,os,platform,trid,uipk&hdnts=exp=1618939426~hmac=7c02aa37e8c2dd3d6045995eba48c2f68667da704f31b5006467d3398f6d2e8a&mid=0 -t 3.080  .cut_video/clip0.flvecho "file 'clip0.flv'" >>.cut_video/concat.txtffmpeg -headers Referer:http://www.bilibili.com/ -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.76 "  -ss 9.963 -i http://upos-hz-mirrorakam.akamaized.net/upgcxcode/06/25/326162506/326162506_nb2-1-80.flv?e=ig8euxZM2rNcNbTMhbUVhoMj7wNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNC8xNEVE9EKE9IMvXBvE2ENvNCImNEVEK9GVqJIwqa80WXIekXRE9IMvXBvEuENvNCImNEVEua6m2jIxux0CkF6s2JZv5x0DQJZY2F8SkXKE9IB5QK==&deadline=1618939426&gen=playurl&nbs=1&oi=804330220&os=akam&platform=pc&trid=c480ac64f3554ff89735c2db8f551509&uipk=5&upsig=50d548dc4f5907be43bc22ae9952cf51&uparams=e,deadline,gen,nbs,oi,os,platform,trid,uipk&hdnts=exp=1618939426~hmac=7c02aa37e8c2dd3d6045995eba48c2f68667da704f31b5006467d3398f6d2e8a&mid=0 -t 6.880  .cut_video/clip1.flvecho "file 'clip1.flv'" >>.cut_video/concat.txtffmpeg -f concat -i .cut_video/concat.txt -c copy "`date "+%Y_%m_%d_%H_%M_%S"`_cut_326162506_nb2-1-80.flv"rm -rf .cut_videoecho ----- ok! -----echo script_dir:/Users/Likey/.config/mpv/scriptsrun.sh文件里具体内容

  

最终生成的文件路径是通过c_concat.sh定义的,你可以按自己的需求改一下,如果不改默认是生成在本地视频文件所在的目录下,但为了方便整体管理和支持网页视频的剪辑,强烈建议你要在磁盘上创建一个目录并设置至以下参数. 我设置的是Users/Likey/mpv-www-gen路径:

  

  

打开Users/Likey/mpv-www-gen路径 ,我们看到,视频已经生成了,并可以成功打开.

  

  

四. 相关参考资料:

  

There is no god. Wonderful new world!fspark.me/archives/Linux-mpv-bilibili-bangumi-you-get.html#toc-2you-get%E8%8E%B7%E5%8F%96%E8%A7%A3%E6%9E%90%E5%9C%B0%E5%9D%80

  

User Scripts mpv-player/mpv Wiki (github.com)github.com/mpv-player/mpv/wiki/User-Scripts

  

rushmj/mpv-video-cuttergithub.com/rushmj/mpv-video-cutter

  

### 分流及分集的处理# flv分集:you-get -p "mpv --referrer='https://www.bilibili.com' --merge-files" https://www.bilibili.com/video/BV1ah41127s7 --playlist# m4s分集:you-get -p "mpv --merge-files" http://www.acfun.cn/v/ac3262317# m3u8线上流拉取:you-get -u https://www.acfun.cn/v/ac3262317 -playlists # 其它有价值的参考https://github.com/mpv-player/mpv/issues/1178https://stackoverflow.com/questions/49343174/can-ffmpeg-concatenate-files-from-a-different-domainhttps://superuser.com/questions/692990/use-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4感谢以上的作者! 本文结束...

  

补充链接:一只小胖子:MPV播放器系列(二)-完成课堂笔记5 赞同 2 评论文章

  

我是一只热爱学习的小胖子,如果你也热爱学习,并且对SuperMemo感兴趣,欢迎转发和评论!

相关文章