ffmpeg_helper_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package ffmpeg_helper
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  4. "io/ioutil"
  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. f := NewFFMPEGHelper()
  11. bok, ffmpegInfo, err := f.GetFFMPEGInfo(videoFile)
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. if bok == false {
  16. t.Fatal("GetFFMPEGInfo = false")
  17. }
  18. subArgs, audioArgs := f.getAudioAndSubExportArgs(videoFile, ffmpegInfo)
  19. println(len(subArgs), len(audioArgs))
  20. }
  21. func readString(filePath string) string {
  22. bytes, err := ioutil.ReadFile(filePath)
  23. if err != nil {
  24. return ""
  25. }
  26. return string(bytes)
  27. }
  28. func Test_parseJsonString2GetFFMPEGInfo(t *testing.T) {
  29. testDataPath := "../../../TestData/ffmpeg"
  30. testRootDir, err := my_util.CopyTestData(testDataPath)
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. type args struct {
  35. videoFileFullPath string
  36. input string
  37. }
  38. tests := []struct {
  39. name string
  40. args args
  41. want bool
  42. subs int
  43. audios int
  44. }{
  45. {name: "R&M S05E10", args: args{videoFileFullPath: "123", input: readString(filepath.Join(testRootDir, "R&M S05E10-video_stream.json"))},
  46. want: true, subs: 1, audios: 1},
  47. {name: "千与千寻", args: args{videoFileFullPath: "123", input: readString(filepath.Join(testRootDir, "千与千寻-video_stream.json"))},
  48. want: true, subs: 2, audios: 3},
  49. }
  50. f := NewFFMPEGHelper()
  51. for _, tt := range tests {
  52. t.Run(tt.name, func(t *testing.T) {
  53. got, got1 := f.parseJsonString2GetFFProbeInfo(tt.args.videoFileFullPath, tt.args.input)
  54. if got != tt.want {
  55. t.Errorf("parseJsonString2GetFFProbeInfo() got = %v, want %v", got, tt.want)
  56. }
  57. if len(got1.AudioInfoList) != tt.audios || len(got1.SubtitleInfoList) != tt.subs {
  58. t.Fatal("parseJsonString2GetFFProbeInfo result List < 1")
  59. }
  60. })
  61. }
  62. }
  63. func TestFFMPEGHelper_ExportAudioArgsByTimeRange(t *testing.T) {
  64. audioFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"
  65. subFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_2.srt"
  66. startTimeString := "0:1:27"
  67. timeLeng := "28.2"
  68. f := NewFFMPEGHelper()
  69. _, _, timeRange, err := f.ExportAudioAndSubArgsByTimeRange(audioFullPath, subFullPath, startTimeString, timeLeng)
  70. if err != nil {
  71. println(timeRange)
  72. t.Fatal(err)
  73. }
  74. }
  75. func TestFFMPEGHelper_GetAudioInfo(t *testing.T) {
  76. audioFullPath := "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"
  77. f := NewFFMPEGHelper()
  78. bok, duration, err := f.GetAudioInfo(audioFullPath)
  79. if err != nil || bok == false {
  80. t.Fatal(err)
  81. }
  82. println(duration)
  83. }