Skip to content

Commit

Permalink
fix: 修复视频视频消音视频卡顿的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
iiheng committed May 26, 2024
1 parent eebf0cc commit 2a14ffe
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ assets/ffmpeg.exe
*.ipr
*.iws
.idea/
*.flv

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
Expand Down
23 changes: 22 additions & 1 deletion lib/view/bililive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_windows/webview_windows.dart';
import 'package:url_launcher/url_launcher.dart';

class BililivePage extends StatefulWidget {
const BililivePage({Key? key}) : super(key: key);
Expand Down Expand Up @@ -38,7 +39,27 @@ class _BililivePageState extends State<BililivePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BiliLive'),
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('BiliLive - 免费开源工具'),
IconButton(
icon: const Icon(Icons.link),
onPressed: () async {
const url = 'https://github.com/hr3lxphr6j/bililive-go';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
// 如果无法启动 URL,可以在这里添加处理逻辑
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('无法打开链接')),
);
}
},
),
],
),
),
body: Stack(
children: <Widget>[
Expand Down
13 changes: 12 additions & 1 deletion lib/view/censorship_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class _CensorshipPageState extends State<CensorshipPage> {

String videoDir = File(_videoPath).parent.path;
String videoName = File(_videoPath).uri.pathSegments.last;
String intermediateFileName =
'$videoDir/${videoName.split('.').first}_merged.${videoName.split('.').last}';
String outputFileName =
'$videoDir/${videoName.split('.').first}_消音后.${videoName.split('.').last}';

Expand All @@ -157,13 +159,22 @@ class _CensorshipPageState extends State<CensorshipPage> {
await outputFile.delete();
}

// 合并视频
String concatCmd =
'-f concat -safe 0 -i $concatFileName -c copy $outputFileName';
'-f concat -safe 0 -i $concatFileName -c copy $intermediateFileName';
String concatResult =
await FFmpegHandler.executeFFmpeg(concatCmd.split(' '));
print(concatResult);

// 跳过前十秒
String trimCmd =
'-y -ss 10 -accurate_seek -i $intermediateFileName -c copy -avoid_negative_ts 1 $outputFileName';
String trimResult = await FFmpegHandler.executeFFmpeg(trimCmd.split(' '));
print(trimResult);

// 清理临时文件
concatFile.deleteSync();
File(intermediateFileName).deleteSync();
}

Future<void> cleanUpTempFiles(List<String> tempFiles) async {
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <desktop_drop/desktop_drop_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
Expand All @@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
screen_retriever
url_launcher_linux
window_manager
)

Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import desktop_drop
import ffmpeg_kit_flutter
import screen_retriever
import shared_preferences_foundation
import url_launcher_macos
import wakelock_macos
import window_manager

Expand All @@ -17,6 +18,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FFmpegKitFlutterPlugin.register(with: registry.registrar(forPlugin: "FFmpegKitFlutterPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
64 changes: 64 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,70 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.2.6"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "17cd5e205ea615e2c6ea7a77323a11712dffa0720a8a90540db57a01347f9ad9"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.3.2"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "7068716403343f6ba4969b4173cbf3b84fc768042124bc2c011e5d782b24fe89"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.3.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.2.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: fff0932192afeedf63cdd50ecbb1bc825d31aed259f02bb8dba0f3b729a5e88b
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.3"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.1"
uuid:
dependency: transitive
description:
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.1+2
version: 1.0.2+3

environment:
sdk: '>=3.2.5 <4.0.0'
Expand Down Expand Up @@ -49,6 +49,7 @@ dependencies:
flutter_adaptive_scaffold: ^0.1.10+2
wakelock: ^0.4.0
webview_windows: ^0.4.0
url_launcher: ^6.2.6

dev_dependencies:
flutter_test:
Expand All @@ -75,6 +76,8 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/ffmpeg.exe
- assets/bililive-windows-amd64.exe
- assets/config.yml
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <desktop_drop/desktop_drop_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <webview_windows/webview_windows_plugin.h>
#include <window_manager/window_manager_plugin.h>

Expand All @@ -19,6 +20,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WebviewWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WebviewWindowsPlugin"));
WindowManagerPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
permission_handler_windows
screen_retriever
url_launcher_windows
webview_windows
window_manager
)
Expand Down

0 comments on commit 2a14ffe

Please sign in to comment.