openshottest.py 4.1 KB

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