This commit is contained in:
2024-11-22 16:02:11 +08:00
parent 23d4deb72e
commit a466ddfb68
8 changed files with 94 additions and 128 deletions

View File

@@ -1,76 +0,0 @@
package com.yutou.bilibili.Tools;
import com.yutou.common.utils.AppTools;
import com.yutou.common.utils.Log;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class FFmpegUtils {
private static final List<File> nowFFmpegList = new ArrayList<>();
public static int add(String ffmpeg, File file, File out) {
if (nowFFmpegList.contains(file)) {
return 2;
}
if (file.getName().contains("ffmpeg")) {
return 1;
} else {
startFFmpeg(ffmpeg, file, out);
}
return 0;
}
private synchronized static void startFFmpeg(String ffmpeg, File file, File out) {
if (nowFFmpegList.contains(file)) {
return;
}
nowFFmpegList.add(file);
new Thread(new Runnable() {
@Override
public void run() {
try {
if (!out.exists()) {
out.mkdirs();
}
String exec = String.format(
"%s -i \"%s\" -c:v copy -y \"%s\" ",
ffmpeg,
file.getAbsolutePath(),
out.getAbsolutePath() + File.separator + file.getName());
Log.i(exec);
Process process = ProcessUtils.exec(ffmpeg, "-i", file.getAbsolutePath(), "-c:v", "copy", "-y", out.getAbsolutePath() + File.separator + file.getName());
InputStream inputStream = process.getErrorStream();
byte[] bytes = new byte[1024];
while (inputStream.read(bytes) > -1) {
}
inputStream.close();
AppTools.copyFileToName(out.getAbsolutePath() + File.separator + file.getName(), file.getParent() + File.separator, file.getName().replace(".mp4", "_ffmpeg.mp4"), true);
file.delete();
new File(out.getAbsolutePath() + File.separator + file.getName()).delete();
} catch (Exception e) {
Log.e(e);
}
nowFFmpegList.remove(file);
}
}).start();
}
public static void main(String[] args) {
File file = new File("D:\\ieda\\bilibili\\live\\2021-03-20\\[2021-03-20 003537]1064046.mp4");
int i = -1;
while (i != 1) {
i = add("D:\\ffmpeg-4.3.1-2020-11-19-full_build\\bin\\ffmpeg.exe", file.getAbsoluteFile(), new File("ffmpeg_out"));
Log.i(i);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
Log.e(e);
}
}
Log.i("转码完成");
}
}

View File

@@ -97,6 +97,10 @@ public class LiveDanmuService {
long videoTime = FFmpegUtils.getVideoTime(videoFile);
long startTime = Long.parseLong(videoId);
long endTime = Long.parseLong(videoId) + videoTime;
// videoTime = 0;
if (videoTime == 0) {
endTime = System.currentTimeMillis();
}
List<LiveDanmuDatabaseBean> danmuList = liveDatabase.getOfTime(DateFormatUtils.getInstance().format(startTime), DateFormatUtils.getInstance().format(endTime), LiveDanmuDatabaseBean.class);
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(DateFormatUtils.getInstance().format(startTime), DateFormatUtils.getInstance().format(endTime), LiveSuperChatDatabaseBean.class);
for (LiveDanmuDatabaseBean bean : danmuList) {
@@ -104,7 +108,7 @@ public class LiveDanmuService {
danmus.getDanmu().add(danmu);
}
for (LiveSuperChatDatabaseBean bean : superChatList) {
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime,bean);
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean);
danmus.getSuperChat().add(superChat);
}

View File

@@ -257,6 +257,7 @@ public class LiveVideoDownloadService {
// .withNotSymbolParam("-progress", "-")
.withNotSymbolParam("-threads", "8")
.withNotSymbolParam("-c:v", "copy")
.withNotSymbolParam("-fflags","+genpts")
.withNotSymbolParam("-y", "");
if (ck != null) {
builder = builder.withParam("-cookies", cookie);
@@ -299,7 +300,7 @@ public class LiveVideoDownloadService {
videoDatabaseBean.setRoomInfoJson(JSONObject.toJSONString(roomInfo));
videoDatabaseBean.setStartTime(new Date());
database.addLiveInfo(videoDatabaseBean);
LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo"));
// LiveInfoNfoTools.saveLiveInfoNfo(roomInfo, rootPath.getAbsolutePath(), new File(savePath).getName().replace(".flv", ".nfo"));
}
}