openshottest.py 3.3 KB

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