2 Star 1 Fork 0

yangyxd / video_downloader

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

x64 视频下载器

使用 ffmpeg 进行视频下载。可以显示下载进度。

video_down.dll 可以中实现了具体的功能,可供第三方使用(如 flutter )

FFMPEG 下载

Flutter 中使用 video_down.dll 示例

使用 FFI 方式调用 video_down.dll

////// ffmpeg 处理
typedef _DownloadM3U8N = Uint64 Function(
    Pointer<ffi.Utf16> url, Pointer<ffi.Utf16> outFile, Pointer onState, Uint32 timeout);
typedef _DownloadM3U8D = int Function(
    Pointer<ffi.Utf16> url, Pointer<ffi.Utf16> outFile, Pointer onState, int timeout);

typedef _StopDownloadM3U8N = Void Function(Uint64 handle);
typedef _StopDownloadM3U8D = void Function(int handle);

typedef _GetDownloadM3U8StatusN = Int32 Function(Uint64 handle, Pointer<Uint32> recv, Pointer<Uint32> total);
typedef _GetDownloadM3U8StatusD = int Function(int handle, Pointer<Uint32> recv, Pointer<Uint32> total);

class FFMpegWin {
  static DynamicLibrary? _library;
  static Pointer<void> nil = Pointer.fromAddress(0);

  static void windowsInit() {
    if (_library != null) return;
    const dll = "video_down.dll";
    try {
      _library = DynamicLibrary.open(dll);
    } catch (e) {
      stderr.writeln('Failed to load $dll');
      rethrow;
    }
  }

  /// 转换下载好的本地 m3u8 文件为 mp4
  /// 
  /// 处理结果:-1 任务不存在, 0 初始化中, 1 下载中,2 下载成功完成,3 下载超时结束,4 未知原因下载失败
  static Future<int> localM3u8ToMP4(String indexFile, String outFile) async {
    if (Platform.isWindows) {
      windowsInit();
    } else {
      return -1;
    }
    final downloadM3U8 = _library!.lookupFunction<_DownloadM3U8N, _DownloadM3U8D>("DownloadM3U8");
    final getDownState = _library!.lookupFunction<_GetDownloadM3U8StatusN, _GetDownloadM3U8StatusD>("GetDownloadM3U8Status");
    // final stopDownloadM3U8 = _library!.lookupFunction<_StopDownloadM3U8N, _StopDownloadM3U8D>("StopDownloadM3U8");
    final Pointer<ffi.Utf16> url = indexFile.toNativeUtf16();
    final Pointer<ffi.Utf16> out = outFile.toNativeUtf16();
    final Pointer<Uint32> recv = ffi.malloc.call<Uint32>();
    final Pointer<Uint32> total = ffi.malloc.call<Uint32>();
    int result = 0;
    try {
      final handle = downloadM3U8(url, out, nil as dynamic, 60000);
      if (handle != 0) {
        while (true) {
          await Utils.sleep(300);
          // 获取下载状态: -1 任务不存在, 0 初始化中, 1 下载中,2 下载成功完成,3 下载超时结束,4 未知原因下载失败
          result = getDownState(handle, recv, total);
          if (result > 1 || result == -1) break;
        }
      }
    } finally {
      ffi.malloc.free(url);
      ffi.malloc.free(out);
      ffi.malloc.free(recv);
      ffi.malloc.free(total);
    }
    return result;
  }

}
MIT License Copyright (c) 2022 yangyxd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于 ffmpeg 实现视频下载和转码为 mp4 展开 收起
Pascal
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/yangyxd/video_downloader.git
git@gitee.com:yangyxd/video_downloader.git
yangyxd
video_downloader
video_downloader
master

搜索帮助