openshottest.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/usr/bin/env python3
  2. import openshot
  3. import sys
  4. fname=None
  5. if len(sys.argv)<=1:
  6. print('not enough parameters')
  7. fname="full.mp4"
  8. # sys.exit()
  9. if fname is None:
  10. fname=sys.argv[1]
  11. head= openshot.FFmpegReader("/home/jared/logo_audio.mp4")
  12. head.Open() # Open the reader
  13. # Create an FFmpegReader
  14. #r = openshot.FFmpegReader("/var/video/6320757395.mp4")
  15. r = openshot.FFmpegReader("/var/video/"+fname)
  16. r.Open() # Open the reader
  17. r.DisplayInfo() # Display metadata
  18. col=openshot.Color()
  19. col.red=openshot.Keyframe(16)
  20. col.green=openshot.Keyframe(254)
  21. col.blue=openshot.Keyframe(5)
  22. #ck=openshot.ChromaKey(col, openshot.Keyframe(120))
  23. ck=openshot.ChromaKey(col, openshot.Keyframe(170))
  24. #ck.Layer(2)
  25. #ck.End(60)
  26. # Set up Writer
  27. #w = openshot.FFmpegWriter("/var/video/s1/6320757395.mp4")
  28. w = openshot.FFmpegWriter("/var/video/s1/"+fname)
  29. #w.SetAudioOptions(True, "libmp3lame", r.info.sample_rate, r.info.channels, r.info.channel_layout, 128000)
  30. #w.SetAudioOptions(True, "libmp3lame", 44100, 1, r.info.channel_layout, 128000)
  31. #w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 128000)
  32. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  33. #w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  34. # openshot.Fraction(1, 1), False, False, 3000000)
  35. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  36. openshot.Fraction(1, 1), False, False, 3000000)
  37. w.info.metadata["title"] = "ChoozMo"
  38. w.info.metadata["artist"] = "ChoozMo"
  39. w.info.metadata["album"] = "ChoozMo"
  40. w.info.metadata["year"] = "2021"
  41. w.info.metadata["description"] = "ChoozMo"
  42. w.info.metadata["comment"] = "ChoozMo"
  43. w.info.metadata["comment"] = "ChoozMo"
  44. w.info.metadata["copyright"] = "copyright ChoozMo!"
  45. # Open the Writer
  46. w.Open()
  47. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  48. t.Open()
  49. c0 = openshot.Clip(head)
  50. c0.Layer(1)
  51. c0.Position=openshot.Keyframe(0)
  52. c0.Start=openshot.Keyframe(0)
  53. t.AddClip(c0)
  54. #lower = openshot.QtImageReader("/home/jared/tests/libopenshot/examples/back.png")
  55. #lower = openshot.QtImageReader("/home/jared/Wav2Lip-master/person.png")
  56. lower = openshot.QtImageReader("/home/jared/bk.jpg")
  57. c1 = openshot.Clip(lower)
  58. c1.has_audio=openshot.Keyframe(0)
  59. c1.Layer(2)
  60. c1.Position(3.03)
  61. c1.Start=0
  62. t.AddClip(c1)
  63. subtitle = openshot.FFmpegReader("/home/jared/subtitle.mov")
  64. subtitle.Open() # Open the reader
  65. c2 = openshot.Clip(r)
  66. #c2.has_audio=openshot.Keyframe(0)
  67. #c2.channel_filter=openshot.Keyframe(-1)
  68. #c2.channel_mapping=openshot.Keyframe(-1)
  69. c2.crop_x=openshot.Keyframe(0.14)
  70. #c2.crop_y=openshot.Keyframe(1.0)
  71. #c2.crop_height=openshot.Keyframe(1.0)
  72. c2.crop_width=openshot.Keyframe(0.69)
  73. #c2.location_x=openshot.Keyframe(0.18)
  74. c2.location_x=openshot.Keyframe(0.35)
  75. c2.location_y=openshot.Keyframe(0.05)
  76. c2.scale_x=openshot.Keyframe(0.55)
  77. c2.scale_y=openshot.Keyframe(0.55)
  78. c2.Position(3.03)
  79. c2.AddEffect(ck)
  80. c2.Layer(3)
  81. #c2.Position=openshot.Keyframe(10)
  82. t.AddClip(c2)
  83. c5 = openshot.Clip(subtitle)
  84. c5.Position(3.03)
  85. c5.location_x=openshot.Keyframe(-0.03)
  86. c5.location_y=openshot.Keyframe(0.1)
  87. c5.Layer(4)
  88. t.AddClip(c5)
  89. txt1 = openshot.QtImageReader("/var/txt/title.png")
  90. c_txt1 = openshot.Clip(txt1)
  91. c_txt1.has_audio=openshot.Keyframe(0)
  92. c_txt1.Layer(7)
  93. c_txt1.Position(3.5)
  94. c_txt1.location_x=openshot.Keyframe(0.22)
  95. #c_txt1.location_y=openshot.Keyframe(0.02)
  96. c_txt1.location_y=openshot.Keyframe(0.68)
  97. c_txt1.Start=0
  98. t.AddClip(c_txt1)
  99. bg1 = openshot.QtImageReader("/var/txt/bg1.jpg")
  100. c_bg1 = openshot.Clip(bg1)
  101. c_bg1.has_audio=openshot.Keyframe(0)
  102. c_bg1.Layer(6)
  103. c_bg1.Position(3.5)
  104. c_bg1.scale_x=openshot.Keyframe(0.65)
  105. c_bg1.scale_y=openshot.Keyframe(0.65)
  106. c_bg1.location_x=openshot.Keyframe(-0.18)
  107. c_bg1.location_y=openshot.Keyframe(-0.08)
  108. c_bg1.Start=0
  109. t.AddClip(c_bg1)
  110. #c3 = openshot.Clip(r2)
  111. #c3.Layer(4)
  112. #c3.has_video=openshot.Keyframe(0)
  113. #c3.has_audio=openshot.Keyframe(1)
  114. #c3.volume=openshot.Keyframe(1)
  115. #t.AddClip(c3)
  116. for n in range(800):
  117. # print(n, end=" ", flush=1)
  118. f=t.GetFrame(n)
  119. w.WriteFrame(f)
  120. # Grab 30 frames from Reader and encode to Writer
  121. #for frame in range(100):
  122. # f = r.GetFrame(frame)
  123. # w.WriteFrame(f)
  124. # Close out Reader & Writer
  125. w.Close()
  126. r.Close()
  127. print("Completed successfully!")