调整FFmpeg参数

This commit is contained in:
zlzw 2024-11-22 17:27:29 +08:00
parent a466ddfb68
commit 41d3dec536
3 changed files with 24 additions and 12 deletions

View File

@ -120,6 +120,9 @@ public class LiveService {
long videoTime = FFmpegUtils.getVideoTime(videoFile);
long startTime = Long.parseLong(videoId);
long endTime = Long.parseLong(videoId) + videoTime;
if(endTime==0){
endTime=System.currentTimeMillis();
}
return database.getGiftInfo(startTime, endTime);
}

View File

@ -177,13 +177,13 @@ public class LiveVideoDownloadService {
database = new BiliLiveDatabase(config);
try {
var keyframe = roomInfo.getKeyframe();
if(!StringUtils.hasText(keyframe)){
keyframe= roomInfo.getUserCover();
if (!StringUtils.hasText(keyframe)) {
keyframe = roomInfo.getUserCover();
}
HttpDownloadUtils.download(new HttpDownloadUtils.Builder().setUrl(keyframe)
.setPath(rootPath.getAbsolutePath())
.setFileName("poster.jpg"));
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
saveLiveInfo(roomInfo);
@ -257,8 +257,16 @@ public class LiveVideoDownloadService {
// .withNotSymbolParam("-progress", "-")
.withNotSymbolParam("-threads", "8")
.withNotSymbolParam("-c:v", "copy")
.withNotSymbolParam("-fflags","+genpts")
.withNotSymbolParam("-y", "");
.withNotSymbolParam("-fflags", "+genpts")
.withNotSymbolParam("-y", "")
//-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2
.withNotSymbolParam("-reconnect", "1")
.withNotSymbolParam("-reconnect_at_eof", "1")
.withNotSymbolParam("-reconnect_streamed", "1")
.withNotSymbolParam("-reconnect_delay_max", "2")
.withNotSymbolParam("-loglevel", "error")
// .withNotSymbolParam("-progress",new File("cache",config.getRoomId()+".txt").getAbsolutePath()); //输出进度日志,暂时没啥用
;
if (ck != null) {
builder = builder.withParam("-cookies", cookie);
}
@ -300,7 +308,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"));
}
}
@ -376,12 +384,12 @@ public class LiveVideoDownloadService {
}
}
liveDatabase.close();
if(videoInfo != null) {
if (videoInfo != null) {
File videoFile = new File(videoInfo.getPath().replace(".flv", ".mp4"));
if(!videoFile.exists()){
videoFile=new File(videoInfo.getPath());
if (!videoFile.exists()) {
videoFile = new File(videoInfo.getPath());
}
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath,videoFile , ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, videoFile, ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
System.out.println(ffmpeg.getCommand());
ffmpeg.start(new DownloadInterface() {
@Override
@ -396,7 +404,7 @@ public class LiveVideoDownloadService {
}
public static void main(String[] args) {
LiveVideoDownloadService service=new LiveVideoDownloadService();
LiveVideoDownloadService service = new LiveVideoDownloadService();
String play = service.getVideoPlay("17961", "1730363029293");
System.out.println(play);
}

View File

@ -155,6 +155,7 @@ public class FFmpegUtils extends AbsVideoRecord {
* @param video 视频文件
* @return 毫秒
*/
@Deprecated
public static long getVideoTime(File video) {
String ffprobe = ConfigTools.load(ConfigTools.CONFIG, "ffprobe", String.class);
String exec = ffprobe + " -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 \"" + video.getAbsolutePath() + "\"";
@ -172,7 +173,7 @@ public class FFmpegUtils extends AbsVideoRecord {
return (long) (Double.parseDouble(data) * 1000);
} catch (Exception e) {
Log.e(e);
throw new RuntimeException(e);
return 0;
}
}