ffmpeg_helper_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package ffmpeg_helper
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. )
  8. func TestGetFFMPEGInfo(t *testing.T) {
  9. //videoFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.mkv"
  10. videoFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
  11. //videoFile := "X:\\TestSeries\\Blade Runner - Black Lotus\\Season 1\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p.mkv"
  12. //videoFile := "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E10 - The Leap WEBDL-1080p.mkv"
  13. f := NewFFMPEGHelper()
  14. bok, ffmpegInfo, err := f.GetFFMPEGInfo(videoFile, Audio)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. if bok == false {
  19. t.Fatal("GetFFMPEGInfo = false")
  20. }
  21. subArgs, audioArgs := f.getAudioAndSubExportArgs(videoFile, ffmpegInfo)
  22. println(len(subArgs), len(audioArgs))
  23. }
  24. func readString(filePath string) string {
  25. bytes, err := os.ReadFile(filePath)
  26. if err != nil {
  27. return ""
  28. }
  29. return string(bytes)
  30. }
  31. func Test_parseJsonString2GetFFMPEGInfo(t *testing.T) {
  32. testDataPath := "../../../TestData/ffmpeg"
  33. testRootDir, err := my_util.CopyTestData(testDataPath)
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. type args struct {
  38. videoFileFullPath string
  39. input string
  40. }
  41. tests := []struct {
  42. name string
  43. args args
  44. want bool
  45. subs int
  46. audios int
  47. }{
  48. {name: "R&M S05E10", args: args{videoFileFullPath: "123", input: readString(filepath.Join(testRootDir, "R&M S05E10-video_stream.json"))},
  49. want: true, subs: 1, audios: 1},
  50. {name: "千与千寻", args: args{videoFileFullPath: "123", input: readString(filepath.Join(testRootDir, "千与千寻-video_stream.json"))},
  51. want: true, subs: 2, audios: 3},
  52. }
  53. f := NewFFMPEGHelper()
  54. for _, tt := range tests {
  55. t.Run(tt.name, func(t *testing.T) {
  56. got, got1 := f.parseJsonString2GetFFProbeInfo(tt.args.videoFileFullPath, tt.args.input)
  57. if got != tt.want {
  58. t.Errorf("parseJsonString2GetFFProbeInfo() got = %v, want %v", got, tt.want)
  59. }
  60. if len(got1.AudioInfoList) != tt.audios || len(got1.SubtitleInfoList) != tt.subs {
  61. t.Fatal("parseJsonString2GetFFProbeInfo result List < 1")
  62. }
  63. })
  64. }
  65. }
  66. func TestFFMPEGHelper_ExportAudioArgsByTimeRange(t *testing.T) {
  67. audioFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"
  68. subFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_2.srt"
  69. startTimeString := "0:1:27"
  70. timeLeng := "28.2"
  71. f := NewFFMPEGHelper()
  72. _, _, timeRange, err := f.ExportAudioAndSubArgsByTimeRange(audioFullPath, subFullPath, startTimeString, timeLeng)
  73. if err != nil {
  74. println(timeRange)
  75. t.Fatal(err)
  76. }
  77. }
  78. func TestFFMPEGHelper_GetAudioInfo(t *testing.T) {
  79. audioFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"
  80. f := NewFFMPEGHelper()
  81. bok, duration, err := f.GetAudioDurationInfo(audioFullPath)
  82. if err != nil || bok == false {
  83. t.Fatal(err)
  84. }
  85. println(duration)
  86. }
  87. func TestFFMPEGHelper_Version(t *testing.T) {
  88. f := FFMPEGHelper{}
  89. got, err := f.Version()
  90. if err != nil {
  91. t.Fatal(err)
  92. }
  93. println(got)
  94. }