安卓端利用ffmpeg合并b站新版m4s缓存文件说明

1.安装ffmpeg

下载软件termux安装完成打开软件输入 根据提示输入y键盘回车然后等待下载安装完成

 pkg install ffmpeg

等出现$符号后输入ffmpeg键盘回车确定,可以看到如下结果即表示安装完成

$ ffmpeg
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Android (5220042 based on r346389c) clang version 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf643d27dbca1bb228957008617) (https://android.googlesource.com/toolchain/llvm 3c393fe7a7e13b0fba4ac75a01aa683d7a5b11cd) (based on LLVM 8.0.7svn)
  configuration: --arch=aarch64 --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang --cxx=aarch64-linux-android-clang++ --cross-prefix=aarch64-linux-android- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --disable-lzma --enable-cross-compile --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libfreetype --enable-libvorbis --enable-libopus --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvpx --enable-shared --enable-libsoxr --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --enable-neon
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'
$

2.找到b站的视频文件缓存目录

此处目录路径可以使用软件 复制路径到剪切板 快速复制路径

/storage/emulated/0/Android/data/tv.danmaku.bili/download/XXXXXX/X/XXX/或
/sdcard/Android/data/tv.danmaku.bili/download/XXXXXX/X/XXX/

我们在里面看到一串数字,进去文件夹我们可以看到三个文件其中

video.m4s audio.m4s index.json

那么这里的video.m4s和audia.m4s就是我们需要合并的音频和视频了

3.开始合并

回到termux软件界面输入进入到b站缓存目录

cd /storage/emulated/0/Android/data/tv.danmaku.bili/download/XXXXXX/X/XXX/或
cd /sdcard/Android/data/tv.danmaku.bili/download/XXXXXX/X/XXX/

接着输入

ffmpeg -i video.m4s -i audio.m4s -c copy /sdcard/文件名.mp4(自行选择合并保存位置)
ffmpeg -i video.m4s -i audio.m4s -c copy 文件名.mp4(即保存文件到缓存目录)

执行后看到以下内容ffmpeg会自动识别音频和视频并进行合并

$ cd /storage/emulated/0/Android/data/tv.danmaku.bili/download/XXXXXX/X/XXX/
$ ffmpeg -i video.m4s -i audio.m4s -c copy 文件名.mp4
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Android (5220042 based on r346389c) clang version 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf643d27dbca1bb228957008617) (https://android.googlesource.com/toolchain/llvm 3c393fe7a7e13b0fba4ac75a01aa683d7a5b11cd) (based on LLVM 8.0.7svn)
  configuration: --arch=aarch64 --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang --cxx=aarch64-linux-android-clang++ --cross-prefix=aarch64-linux-android- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --disable-lzma --enable-cross-compile --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libfreetype --enable-libvorbis --enable-libopus --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvpx --enable-shared --enable-libsoxr --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --enable-neon
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.m4s':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: avc1iso5dsmsmsixdash
    encoder         : Lavf57.71.100
    description     : Packed by Bilibili XCoder v2.0.2
  Duration: 00:03:28.20, start: 0.000000, bitrate: 5678 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 99 kb/s, 25 fps, 25 tbr, 16k tbn, 50 tbc (default)
Metadata:
      handler_name    : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'audio.m4s':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: avc1iso5dsmsmsixdash
    encoder         : Lavf57.71.100
    description     : Packed by Bilibili XCoder v2.0.2
  Duration: 00:03:28.23, start: 0.080000, bitrate: 319 kb/s
    Stream #1:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 7 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to '文件名.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: avc1iso5dsmsmsixdash
    description     : Packed by Bilibili XCoder v2.0.2
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 99 kb/s, 25 fps, 25 tbr, 16k tbn, 16k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 7 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 3906 fps=0.0 q=-1.0 size=  116480kB time=00:02:36.12frame= 5205 fps=0.0 q=-1.0 Lsize=  152494kB time=00:03:28.17 bitrate=6001.0kbits/s speed= 252x
video:144273kB audio:8067kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.101180%
$

那么就表示文件合并完成,简单来说就是安装软件termux,然后安装ffmpeg利用ffmpeg来合并分段的视频和音频。本说明仅表示笔者发帖时可以合并成功,并不通用于复杂的网络环境,如有错误请自行解决,笔者只是半滴水的水平。

THE END