فهرست منبع

修复,时间轴校正 FFMPEG 导出失败的问题

Signed-off-by: allan716 <[email protected]>
allan716 3 سال پیش
والد
کامیت
7889bbc48e

+ 6 - 2
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx.go

@@ -70,8 +70,12 @@ func (s SubTimelineFixerHelperEx) Process(videoFileFullPath, srcSubFPath string)
 		return errors.New("SubTimelineFixerHelperEx.Process.GetFFMPEGInfo = false Subtitle -- " + videoFileFullPath)
 	}
 	// 内置的字幕,这里只列举一种格式出来,其实会有一个字幕的 srt 和 ass 两种格式都导出存在
-	// len(ffmpegInfo.SubtitleInfoList)
-	if len(ffmpegInfo.SubtitleInfoList) <= 0 {
+	if ffmpegInfo.SubtitleInfoList == nil || len(ffmpegInfo.SubtitleInfoList) <= 0 {
+
+		if ffmpegInfo.AudioInfoList == nil || len(ffmpegInfo.AudioInfoList) == 0 {
+			return errors.New("SubTimelineFixerHelperEx.Process.GetFFMPEGInfo Can`t Find SubTitle And Audio To Export -- " + videoFileFullPath)
+		}
+
 		// 如果内置字幕没有,那么就需要尝试获取音频信息
 		bok, ffmpegInfo, err = s.ffmpegHelper.GetFFMPEGInfo(videoFileFullPath, ffmpeg_helper.Audio)
 		if err != nil {

+ 12 - 0
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx_test.go

@@ -53,6 +53,18 @@ func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 				srcSubFPath:       "X:\\电影\\千与千寻 (2001)\\千与千寻 (2001) 1080p Opus.chinese(简英,zimuku).ass"},
 			wantErr: false,
 		},
+		{
+			name: "Red Notice (2021)", args: args{
+				videoFileFullPath: "X:\\电影\\Red Notice (2021)\\Red Notice (2021) WEBRip-1080p.mp4",
+				srcSubFPath:       "X:\\电影\\Red Notice (2021)\\Red Notice (2021) WEBRip-1080p.chinese(简,xunlei).default.ass"},
+			wantErr: false,
+		},
+		{
+			name: "The Last Duel (2021)", args: args{
+				videoFileFullPath: "X:\\电影\\The Last Duel (2021)\\The Last Duel (2021) WEBRip-1080p.mp4",
+				srcSubFPath:       "X:\\电影\\The Last Duel (2021)\\The Last Duel (2021) WEBRip-1080p.chinese(简,shooter).default.srt"},
+			wantErr: false,
+		},
 	}
 
 	s := NewSubTimelineFixerHelperEx(config.GetConfig().SubTimelineFixerConfig)

+ 51 - 8
internal/pkg/ffmpeg_helper/ffmpeg_helper.go

@@ -104,6 +104,33 @@ func (f *FFMPEGHelper) GetFFMPEGInfo(videoFileFullPath string, exportType Export
 		// 开始导出
 		// 构建导出的命令参数
 		exportAudioArgs, exportSubArgs := f.getAudioAndSubExportArgs(videoFileFullPath, ffMPEGInfo)
+
+		// 上面导出的信息,可能是 nil 参数,那么就直接把导出的 List 信息给置为 nil,让后续有依据可以跳出,不继续执行
+		if exportType == Subtitle {
+			if exportSubArgs == nil {
+				ffMPEGInfo.SubtitleInfoList = nil
+				return true, ffMPEGInfo, nil
+			}
+		} else if exportType == Audio {
+			if exportAudioArgs == nil {
+				ffMPEGInfo.AudioInfoList = nil
+				return true, ffMPEGInfo, nil
+			}
+		} else if exportType == SubtitleAndAudio {
+			if exportAudioArgs == nil || exportSubArgs == nil {
+				if exportAudioArgs == nil {
+					ffMPEGInfo.AudioInfoList = nil
+				}
+				if exportSubArgs == nil {
+					ffMPEGInfo.SubtitleInfoList = nil
+				}
+				return true, ffMPEGInfo, nil
+			}
+		} else {
+			log_helper.GetLogger().Errorln("GetFFMPEGInfo.getAudioAndSubExportArgs Not Support ExportType")
+			return false, nil, nil
+		}
+		// 上面的操作为了就是确保后续的导出不会出问题
 		// 执行导出,音频和内置的字幕
 		execErrorString, err := f.exportAudioAndSubtitles(exportAudioArgs, exportSubArgs, exportType)
 		if err != nil {
@@ -371,6 +398,8 @@ func (f *FFMPEGHelper) parseJsonString2GetAudioInfo(inputFFProbeString string) (
 // exportAudioAndSubtitles 导出音频和字幕文件
 func (f *FFMPEGHelper) exportAudioAndSubtitles(audioArgs, subArgs []string, exportType ExportType) (string, error) {
 
+	// 输入的两个数组,有可能是 nil
+
 	// 这里导出依赖的是 ffmpeg 这个程序,需要的是构建导出的语句
 	if exportType == SubtitleAndAudio {
 		execErrorString, err := f.execFFMPEG(audioArgs)
@@ -401,6 +430,9 @@ func (f *FFMPEGHelper) exportAudioAndSubtitles(audioArgs, subArgs []string, expo
 // execFFMPEG 执行 ffmpeg 命令
 func (f *FFMPEGHelper) execFFMPEG(cmds []string) (string, error) {
 
+	if cmds == nil || len(cmds) == 0 {
+		return "", nil
+	}
 	cmd := exec.Command("ffmpeg", cmds...)
 	buf := bytes.NewBufferString("")
 	//指定输出位置
@@ -450,18 +482,29 @@ func (f *FFMPEGHelper) getAudioAndSubExportArgs(videoFileFullPath string, ffmpeg
 		return nil, nil
 	}
 
-	for _, subtitleInfo := range ffmpegInfo.SubtitleInfoList {
+	if len(ffmpegInfo.SubtitleInfoList) == 0 {
+		// 如果没有,就返回空
+		subArgs = nil
+	} else {
+		for _, subtitleInfo := range ffmpegInfo.SubtitleInfoList {
 
-		f.addSubMapArg(&subArgs, subtitleInfo.Index,
-			filepath.Join(nowCacheFolderPath, subtitleInfo.GetName()+common.SubExtSRT))
-		f.addSubMapArg(&subArgs, subtitleInfo.Index,
-			filepath.Join(nowCacheFolderPath, subtitleInfo.GetName()+common.SubExtASS))
+			f.addSubMapArg(&subArgs, subtitleInfo.Index,
+				filepath.Join(nowCacheFolderPath, subtitleInfo.GetName()+common.SubExtSRT))
+			f.addSubMapArg(&subArgs, subtitleInfo.Index,
+				filepath.Join(nowCacheFolderPath, subtitleInfo.GetName()+common.SubExtASS))
+		}
 	}
+
 	// 音频导出的参数构建
 	audioArgs = append(audioArgs, "-vn")
-	for _, audioInfo := range ffmpegInfo.AudioInfoList {
-		f.addAudioMapArg(&audioArgs, audioInfo.Index,
-			filepath.Join(nowCacheFolderPath, audioInfo.GetName()+extPCM))
+	if len(ffmpegInfo.AudioInfoList) == 0 {
+		// 如果没有,就返回空
+		audioArgs = nil
+	} else {
+		for _, audioInfo := range ffmpegInfo.AudioInfoList {
+			f.addAudioMapArg(&audioArgs, audioInfo.Index,
+				filepath.Join(nowCacheFolderPath, audioInfo.GetName()+extPCM))
+		}
 	}
 
 	return audioArgs, subArgs

+ 1 - 0
internal/pkg/ffmpeg_helper/ffmpeg_info.go

@@ -153,6 +153,7 @@ func (f *FFMPEGInfo) isAudioExported(nowCacheFolder string) bool {
 			return true
 		}
 	}
+
 	return false
 }