erika 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45d8d0b1b383dabfbe114468726f7b3fd4022eca
4
+ data.tar.gz: a444565a356de5c902255faf42e0ffc935773aca
5
+ SHA512:
6
+ metadata.gz: 14899f1f711b380f4ecdf3d16f3776e628278f3bd6e636c7e6ca80f0c74403bbfa50d7b03ea74066e7aa3a509748d95c573882354f1257a88adae1f8480a8dcb
7
+ data.tar.gz: 3d47a83a903cee2db82d7f23378a03ab2d78d991c5ae30581911761dd3e77f7834bc8df1b29fd866b72b05055c0690065809547772e42784128f4c33865c9030
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /.idea/
13
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hotline.shiva@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gem 'pry'
3
+ # Specify your gem's dependencies in erika.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ erika (0.1.0)
5
+ thor (~> 0.20.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ pry (0.12.2)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ rake (13.0.1)
17
+ rspec (3.5.0)
18
+ rspec-core (~> 3.5.0)
19
+ rspec-expectations (~> 3.5.0)
20
+ rspec-mocks (~> 3.5.0)
21
+ rspec-core (3.5.3)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-expectations (3.5.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.5.0)
26
+ rspec-mocks (3.5.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-support (3.5.0)
30
+ thor (0.20.3)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 2.0)
37
+ erika!
38
+ pry
39
+ rake (~> 13.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Shiva Bhusal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # video-generator
2
+ This is tested in macOS Mojave `10.14.6 (18G87)`
3
+
4
+ ## Installation
5
+ Please make sure you install `FFMPEG` library in your machine before using this gem.
6
+
7
+
8
+ ```bash
9
+ gem install erika
10
+
11
+ ```
12
+ ## Requirements
13
+ ### FFMPEG
14
+ A complete, cross-platform solution to record, convert and stream audio and video.
15
+ #### MacOSx
16
+ ```bash
17
+ brew install ffmpeg
18
+ ```
19
+
20
+ #### Ubuntu
21
+ ```bash
22
+ apt-get install ffmpeg
23
+ ```
24
+
25
+
26
+ ## Usage
27
+ To compile images in `~/pictures/birthday`, you need to make sure files are named in proper order.
28
+ I recommend you to prefix the files with number like
29
+ ```
30
+ - 0 My first birthday.jpg
31
+ - 1 My second birthday.jpg
32
+ - 2 My second birthday.jpg
33
+ - 3 My third birthday.jpg
34
+ ```
35
+
36
+ single command to compile
37
+ ```bash
38
+ cd ~/pictures
39
+
40
+ erika g -s birthday -o mybirthday.mp4
41
+
42
+ # This will generate video called `mybirthday.mp4`
43
+ ```
44
+
45
+ ## Options
46
+ ```bash
47
+  erika help g
48
+ Usage:
49
+ erika g
50
+
51
+ Options:
52
+ -o, [--output=OUTPUT] # Output path; where to generate output movie
53
+ -s, [--source=SOURCE] # Input path; folder path where the images are located
54
+ -a, [--audio=AUDIO] # Audio path; the path to bg audio
55
+ -t, [--transition-duration=TRANSITION_DURATION] # Transition animation duration between two images
56
+ -S, [--slide-duration=SLIDE_DURATION] # Slide duration between two images
57
+
58
+ Generate movie
59
+
60
+ ```
61
+ Example:-
62
+
63
+ ```ruby
64
+ erika g -s happy -S=5 -t=4 -o=opt/mymovie.mp4
65
+
66
+ ```
67
+
68
+ ## How Slide Animation is implemented
69
+ Creating intermediate mpeg's for each image and then concatenate them
70
+ all into a `video`.
71
+
72
+ **For example**, say you have `5` images; you would run this for each one of the
73
+ images to create the intermediate mpeg's with a fade in at the beginning and a fade out at the end.
74
+
75
+ ```bash
76
+ ffmpeg -y -loop 1 -i <your-image> -vf "fade=t=in:st=0:d=0.5,fade=t=out:st=4.5:d=0.5" -c:v mpeg2video -t 5 -q:v 1 image-1.mpeg
77
+ ```
78
+
79
+ where `t` is the duration, or time, of each image. Once you have all of these mpeg's, you use
80
+ ffmpeg's concat command to combine them all into an `mp4`.
81
+
82
+ ```bash
83
+ ffmpeg -y -i image-1.mpeg -i image-2.mpeg -i image-3.mpeg -i image-4.mpeg -i image-5.mpeg -filter_complex '[0:v][1:v][2:v][3:v][4:v] concat=n=5:v=1 [v]' -map '[v]' -c:v libx264 -s 1280x720 -aspect 16:9 -q:v 1 -pix_fmt yuv420p output.mp4
84
+ ```
85
+
86
+ ## Components Used
87
+ - get Image dimension
88
+ - [https://stackoverflow.com/a/32824749/3437900](https://stackoverflow.com/a/32824749/3437900)
89
+ - [https://askubuntu.com/a/577431](https://askubuntu.com/a/577431)
90
+ - IMAGE SCALING
91
+ - [https://www.bogotobogo.com/FFMpeg/ffmpeg_image_scaling_jpeg.php](https://www.bogotobogo.com/FFMpeg/ffmpeg_image_scaling_jpeg.php)
92
+ - FFMPEG filters
93
+ - [https://ffmpeg.org/ffmpeg-filters.html#subtitles-1](https://ffmpeg.org/ffmpeg-filters.html#subtitles-1)
94
+
95
+ - Resizing and padding image
96
+ - [https://superuser.com/a/991412](https://superuser.com/a/991412)
97
+
98
+ - Capturing STD Streams to prevent logs being cluttered
99
+ - [https://ruby-doc.org/stdlib-1.9.3/libdoc/open3/rdoc/Open3.html#method-c-capture3](https://ruby-doc.org/stdlib-1.9.3/libdoc/open3/rdoc/Open3.html#method-c-capture3)
100
+ - Animation in Slide Transition
101
+ - [https://stackoverflow.com/questions/30974848/animation-between-images-using-ffmpeg](https://stackoverflow.com/questions/30974848/animation-between-images-using-ffmpeg)
102
+ - [https://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg/834035#834035](https://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg/834035#834035)
103
+ - Image to Video Guide FFMPEG
104
+ - [https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence](https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence)
105
+ - Repeat Audio and generate a new audio file
106
+ - [https://stackoverflow.com/a/8017021/3437900](https://stackoverflow.com/a/8017021/3437900)
107
+ - Add Subtitles to the video
108
+ - [https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo](https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo)
109
+
110
+ https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player/1136305#1136305
111
+ https://trac.ffmpeg.org/wiki/Concatenate
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "erika"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config.yml ADDED
@@ -0,0 +1,33 @@
1
+ slide_duration: 5 # sec
2
+ slide_animation: cross-fade
3
+ slide_animation_duration: 3
4
+ audio: library/bensound-ukulele.mp3
5
+ source: 'images'
6
+ prefix: hello.jpg
7
+ suffix: thankyou.jpg
8
+ file_types:
9
+ - jpg
10
+ - jpeg
11
+ - png
12
+ output:
13
+ filename: output/movie.mp4
14
+ resolution: 1920x1080 #‘hd1080’
15
+ height: 1080
16
+ aspect_ratio: 16:9
17
+ width: 1920
18
+ frame_rate: '1/30' #‘sntsc’ '1/5'
19
+
20
+ caption:
21
+ show: true
22
+ font: "HeadLineA Regular"
23
+ font_color: "&H3300ff&"
24
+ font_size: 30 #px
25
+ animation: slide-left
26
+
27
+ # The first frame
28
+ title:
29
+ show: true
30
+ font-family: Times New Roman
31
+ font-color: red
32
+ font-size: 30px;
33
+ animation: slide-left
data/erika.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "erika/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "erika"
7
+ spec.version = Erika::VERSION
8
+ spec.authors = ["Shiva Bhusal"]
9
+ spec.email = ["hotline.shiva@gmail.com"]
10
+
11
+ spec.summary = "Erika - A CLI Based slideshow generator"
12
+ spec.description = "Generate Slideshow video from images using single command with animation"\
13
+ "Its simple to use and highly configurable."
14
+ spec.homepage = "https://shivab.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = 'https://github.com/shivabhusal/erika-slideshow'
21
+ spec.metadata["changelog_uri"] = 'https://github.com/shivabhusal/erika-slideshow'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "thor", "~> 0.20.0"
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
data/exe/erika ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pry'
3
+ require 'thor'
4
+
5
+ # Adding the lib directory to the Load Path of Ruby
6
+ $:.unshift File.expand_path("../../lib", __FILE__)
7
+ require 'overrides/hash'
8
+ $erika_options = {}
9
+ class Options < Thor
10
+ desc "g", "Generate movie"
11
+ method_option :output,
12
+ :aliases => "-o",
13
+ :desc => "Output path; where to generate output movie"
14
+ method_option :source,
15
+ :aliases => "-s",
16
+ :desc => "Input path; folder path where the images are located"
17
+ method_option :audio,
18
+ :aliases => "-a",
19
+ :desc => "Audio path; the path to bg audio"
20
+ method_option :transition_duration,
21
+ :aliases => "-t",
22
+ :desc => "Transition animation duration between two images"
23
+ method_option :slide_duration,
24
+ :aliases => "-S",
25
+ :desc => "Slide duration between two images"
26
+ def g
27
+ # $erika_options.merge({output_dir: File.expand_path(options[:o])}) if options[:o]
28
+ # $erika_options.merge({source_dir: File.expand_path(options[:s]),
29
+ # source_files: ''}) if options[:s]
30
+ # $erika_options.merge({audio: File.expand_path(options[:a])}) if options[:a]
31
+
32
+ $erika_options = options.to_o
33
+ require 'erika'
34
+ erika = Erika::SlideShow.new
35
+ erika.start
36
+ end
37
+ end
38
+
39
+
40
+ Options.start(ARGV)
@@ -0,0 +1,9 @@
1
+ class Erika
2
+ class Audio
3
+ attr_accessor :full_path
4
+
5
+ def initialize full_path: Erika::Config.audio
6
+ @full_path = full_path
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,60 @@
1
+ class Erika
2
+
3
+ class << self
4
+ # @return [dir, file]
5
+ def _get_output_info_from(data, options)
6
+ if options.output
7
+ file_part = options.output.split('/').last
8
+
9
+ if !file_part.include?('.')
10
+ [File.expand_path(options.output),
11
+ File.expand_path("#{options.output}/#{data['output']['filename'].split('/').last}")]
12
+ elsif file_part.include?('.')
13
+ [File.expand_path(options.output.split('/')[0 .. -2].join('/')),
14
+ File.expand_path(options.output)]
15
+ end
16
+ else
17
+ [File.expand_path(data['output']['filename'].split('/')[0 .. -2].join('/')),
18
+ File.expand_path(data['output']['filename'])]
19
+ end
20
+ end
21
+ end
22
+
23
+ Config = begin
24
+ config_file_path = File.absolute_path('../../config.yml', __dir__).to_s
25
+ data = Psych.load_file(config_file_path)
26
+ root = `pwd`.chomp
27
+
28
+ output_dir, output_file = _get_output_info_from(data, $erika_options)
29
+
30
+ source = $erika_options.source ? File.expand_path($erika_options.source) : "#{root}/#{data['source']}"
31
+ audio = $erika_options.audio ? File.expand_path($erika_options.audio) : File.expand_path('../../../library/bensound-ukulele.mp3', __FILE__)
32
+
33
+ source_files = "#{source}/*.{#{data['file_types'].join(',')}}"
34
+ data.merge({
35
+ no_of_images: Dir[source_files].count,
36
+ output_dir: output_dir,
37
+ output_file: output_file,
38
+ source_files: source_files,
39
+ audio: audio,
40
+ slide_duration: $erika_options.slide_duration.to_f || data['slide_duration'],
41
+ slide_animation: $erika_options.transition_duration.to_f || data['slide_animation'],
42
+ }).to_o
43
+ end
44
+
45
+ TempRoot = File.expand_path('~/erika') # home
46
+ Default = {
47
+ temp: {
48
+ dir: TempRoot + '/tmp',
49
+ image_dir: TempRoot + '/tmp/images',
50
+ video_dir: TempRoot + '/tmp/videos',
51
+ image_path: TempRoot + '/tmp/images/%05d.jpg',
52
+ video_path: TempRoot + '/tmp/videos/%05d.mp4',
53
+ video_list: TempRoot + '/tmp/videos/list.txt',
54
+ filename: TempRoot + "/tmp/temp_video.mp4",
55
+ audio_filename: TempRoot + "/tmp/temp_audio.mp3",
56
+ subtitle_filename: TempRoot + "/tmp/subtitle.srt"
57
+ }
58
+ }.to_o
59
+
60
+ end
@@ -0,0 +1,83 @@
1
+ class Erika
2
+ class Image
3
+ attr_accessor :filename, :full_path, :index
4
+ attr_reader :video, :temp_path, :caption, :title, :formatted_index
5
+
6
+ def initialize filename: '', full_path: '', index: 0
7
+ @filename, @full_path, @index = filename, full_path, index
8
+ @title = filename.sentence_case
9
+ @formatted_index = '%05d' % index
10
+ @temp_path = "#{Erika::Default.temp.image_dir}/#{formatted_index}.jpg"
11
+ _gen_caption_
12
+ end
13
+
14
+ # Chainable method
15
+ def resize_move_to_temp
16
+ cmd = [
17
+ ['ffmpeg'],
18
+ ['-i', full_path.shell_escape],
19
+ ['-vf', _scaling_params_],
20
+ [@temp_path]
21
+ ].flatten.join(' ')
22
+
23
+ Erika::Runner.(cmd)
24
+
25
+ self
26
+ end
27
+
28
+ def create_video
29
+ @video = Erika::Video.new(image: self).save
30
+ end
31
+
32
+ private
33
+
34
+ def _scaling_params_
35
+ %Q{"scale=#{Erika::Config.output.width}:#{Erika::Config.output.height}:force_original_aspect_ratio=decrease,pad=#{Erika::Config.output.width}:#{Erika::Config.output.height}:(ow-iw)/2:(oh-ih)/2"}
36
+ end
37
+
38
+ # 1
39
+ # 00:00:01,600 --> 00:00:04,200
40
+ # English (US)
41
+ #
42
+ # 2
43
+ # 00:00:05,900 --> 00:00:07,999
44
+ # This is a subtitle in American English
45
+ def _gen_caption_
46
+ start_time = _formatted_time(index * Erika::Config.slide_duration) # Seconds
47
+ end_time = _formatted_time((index + 1) * Erika::Config.slide_duration) # Seconds
48
+ @caption = [
49
+ '',
50
+ index + 1,
51
+ "#{start_time} --> #{end_time}",
52
+ title,
53
+ ''
54
+ ]
55
+ end
56
+
57
+
58
+ def _formatted_time(sec)
59
+ hour = sec / 3600
60
+ min = (sec - hour * 3600) / 60
61
+ sec = sec - min * 60
62
+ [hour, min, sec].map { |x| '%02d' % x }.join(':') + ',000'
63
+ end
64
+
65
+ # def resize_images
66
+ # prepare_tmp_dir
67
+ #
68
+ # # Rescale and Pad the images to the center of the frame selected in Erika::Config.yml file
69
+ # Dir[Erika::Config.source_files].sort.each_with_index do |file, index|
70
+ #
71
+ # output_filename = output_file(file, formatted_index)
72
+ #
73
+ #
74
+ # # create_video_for(output_filename, index)
75
+ #
76
+ # end
77
+ #
78
+ # # File.write(Erika::Default.temp.subtitle_filename, subtitles.join("\n"))
79
+ # end
80
+
81
+ end
82
+ end
83
+
@@ -0,0 +1,21 @@
1
+ class Erika
2
+ class Runner
3
+ class << self
4
+ def call(cmd)
5
+ puts '-' * 100
6
+ puts cmd
7
+ puts '-' * 100
8
+ stdo, stde, process = Open3.capture3(cmd)
9
+ _display_error(stde) if stde.length > 0
10
+ stdo
11
+ end
12
+
13
+ private
14
+ def _display_error(stde)
15
+ puts ('-' * 47) + ' Error ' + ('-' * 46)
16
+ puts stde
17
+ puts '-' * 100
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ class Erika
2
+ class SlideShow
3
+ attr_accessor :images
4
+
5
+ def initialize
6
+ prepare_tmp_dir
7
+ @images = []
8
+
9
+ # Gen subtitles
10
+ _images_
11
+ end
12
+
13
+ def start
14
+ Video.merge(images)
15
+
16
+ _gen_subtitle_file_
17
+
18
+ Video.new(full_path: Erika::Default.temp.filename).mix()
19
+ end
20
+
21
+ private
22
+
23
+ def _gen_subtitle_file_
24
+ File.write(Erika::Default.temp.subtitle_filename, images.map(&:caption).join("\n"))
25
+ end
26
+
27
+ def _images_
28
+ Dir[Erika::Config.source_files].sort.each_with_index do |file, index|
29
+ full_path = File.absolute_path(file, __dir__)
30
+ filename = file.split('/').last.split('.').first
31
+ image = Erika::Image.new(filename: filename, full_path: full_path, index: index)
32
+ image.resize_move_to_temp.create_video
33
+ images << image
34
+ end
35
+ end
36
+
37
+
38
+ def prepare_tmp_dir
39
+ cmds = [
40
+ %Q{rm -r "#{Erika::TempRoot}"},
41
+ %Q{rm -r "#{Erika::Default.temp.dir}"},
42
+ %Q{rm -r "#{Erika::Config.output_dir}"},
43
+
44
+ %Q{mkdir "#{Erika::TempRoot}"},
45
+ %Q{mkdir "#{Erika::Default.temp.dir}"},
46
+ %Q{mkdir "#{Erika::Default.temp.image_dir}"},
47
+ %Q{mkdir "#{Erika::Default.temp.video_dir}"},
48
+
49
+ %Q{mkdir "#{Erika::Config.output_dir}"},
50
+ ]
51
+
52
+ cmds.each { |cmd| Erika::Runner.(cmd) }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ class Erika
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,89 @@
1
+ class Erika
2
+ class Video
3
+ attr_accessor :image
4
+ attr_reader :temp_path, :full_path
5
+
6
+ def initialize image: nil, full_path: ''
7
+ @image = image
8
+ @full_path = full_path
9
+ @temp_path = "#{Erika::Default.temp.video_dir}/#{image&.formatted_index}.mp4"
10
+ end
11
+
12
+ def mix(audio: Erika::Audio.new)
13
+ length_of_video = Erika::Config.slide_duration * Erika::Config.no_of_images.to_f
14
+ length_of_audio = Erika::Runner.(%Q{ffprobe -i #{Erika::Config.audio} -show_format -v quiet | sed -n 's/duration=//p'}).chomp.to_f
15
+ num_of_loops = (length_of_video / length_of_audio).ceil
16
+
17
+ if length_of_video > length_of_audio
18
+ # Generate a new audio file looped so that it can cover the video fully
19
+ cmd = %Q{ffmpeg -lavfi "amovie=#{audio.full_path}:loop=#{num_of_loops }" #{Erika::Default.temp.audio_filename}}
20
+ Erika::Runner.(cmd)
21
+ else
22
+ Erika::Runner.("cp #{audio.full_path} #{Erika::Default.temp.audio_filename}")
23
+ end
24
+
25
+ # ffmpeg has the promising -loop_input flag, but it doesn't support audio inputs yet.
26
+ # Add Background Music to the Slideshow
27
+ cmd = [
28
+ ['ffmpeg'],
29
+ ['-y'],
30
+ ['-i', full_path], # video file as 0th input
31
+ ['-i', Erika::Default.temp.audio_filename], # audio file as 1st input
32
+ [%Q{-vf "subtitles=#{Erika::Default.temp.subtitle_filename}:force_style='Fontsize=#{Erika::Config.caption.font_size},FontName=#{Erika::Config.caption.font},PrimaryColour=#{Erika::Config.caption.font_color}'"}],
33
+ ['-map', '0:v'], # Selects the video from 0th input
34
+ ['-map', '1:a'], # Selects the audio from 1st input
35
+ ['-ac', '2'], # Audio channel manipulation https://trac.ffmpeg.org/wiki/AudioChannelManipulation
36
+ ['-shortest'], # will end the output file whenever the shortest input ends.
37
+ [%Q{"#{Erika::Config.output_file}"}]
38
+ ].flatten.join(' ')
39
+
40
+ Erika::Runner.(cmd)
41
+ end
42
+
43
+ def save
44
+
45
+ # def _create_video_
46
+ # filename = image.split('/').last.split('.').first
47
+ later_start_time = Erika::Config.slide_duration - Erika::Config.slide_animation_duration
48
+ earlier_start_time = 0
49
+
50
+ if image.index == 0
51
+ # no fading in beginning, but fadeout at end
52
+ transition = %Q{fade=t=out:st=#{later_start_time}:d=#{Erika::Config.slide_animation_duration}}
53
+ elsif image.index == Erika::Config.no_of_images - 1
54
+ # the should be fading in beginning, but no fadeout at end
55
+ transition = %Q{fade=t=in:st=#{earlier_start_time}:d=#{Erika::Config.slide_animation_duration}}
56
+ else
57
+ transition = %Q{fade=t=in:st=#{earlier_start_time}:d=#{Erika::Config.slide_animation_duration},fade=t=out:st=#{later_start_time}:d=#{Erika::Config.slide_animation_duration}}
58
+ end
59
+ filter = %Q{"#{transition}"}
60
+
61
+ cmd = [
62
+ ['ffmpeg'],
63
+ ['-y', ''],
64
+ ['-loop', '1'],
65
+ ['-i', image.temp_path],
66
+ ['-vf', filter],
67
+ ['-c:v', 'mpeg2video'],
68
+ ['-t', Erika::Config.slide_duration],
69
+ ['-q:v', '1'],
70
+ ['-b:a 32k'],
71
+ [%Q{"#{temp_path}"}]
72
+ ].join(' ')
73
+
74
+ Erika::Runner.(cmd)
75
+ end
76
+
77
+ class << self
78
+ def merge(images)
79
+ images.each do |image|
80
+ cmd = %Q{echo file '#{image.formatted_index}.mp4' >> #{Erika::Default.temp.video_list}}
81
+ Erika::Runner.(cmd)
82
+ end
83
+
84
+ cmd = %Q{ffmpeg -y -f concat -safe 0 -i #{Erika::Default.temp.video_list} -c copy #{Erika::Default.temp.filename}}
85
+ Erika::Runner.(cmd)
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/erika.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'open3'
2
+ require 'psych'
3
+ require 'pry'
4
+
5
+ require 'overrides/hash'
6
+ require 'overrides/string'
7
+
8
+ require 'erika/version'
9
+ require 'erika/config'
10
+ require 'erika/audio'
11
+ require 'erika/video'
12
+ require 'erika/image'
13
+ require 'erika/runner'
14
+ require 'erika/slideshow'
15
+
@@ -0,0 +1,6 @@
1
+ #Convert Hash to OpenStruct recursively
2
+ class Hash
3
+ def to_o
4
+ JSON.parse to_json, object_class: OpenStruct
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+
2
+ class String
3
+ def titleize
4
+ self.split.each { |x| x.capitalize! }.join(' ')
5
+ end
6
+
7
+ def sentence_case
8
+ self.split('.').first.gsub(/\W/, ' ').split(/(\A[\d]*[^a-zA-Z])/).last
9
+ end
10
+
11
+ def shell_escape
12
+ %Q{"#{self}"}
13
+ end
14
+ end
Binary file
data/script.yml ADDED
@@ -0,0 +1,6 @@
1
+ # If this file is empty, all the images in `images` folder will be played in sequence
2
+ # If script-config is only provided for `5`th index image, then only the config provided will
3
+ # will apply for the `5`th indexed image, other images will have default settings
4
+ 0:
5
+ caption: Picture Title
6
+ font-size: 40px
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erika
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Shiva Bhusal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Generate Slideshow video from images using single command with animationIts
70
+ simple to use and highly configurable.
71
+ email:
72
+ - hotline.shiva@gmail.com
73
+ executables:
74
+ - erika
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - config.yml
90
+ - erika.gemspec
91
+ - exe/erika
92
+ - lib/erika.rb
93
+ - lib/erika/audio.rb
94
+ - lib/erika/config.rb
95
+ - lib/erika/image.rb
96
+ - lib/erika/runner.rb
97
+ - lib/erika/slideshow.rb
98
+ - lib/erika/version.rb
99
+ - lib/erika/video.rb
100
+ - lib/overrides/hash.rb
101
+ - lib/overrides/string.rb
102
+ - library/bensound-ukulele.mp3
103
+ - script.yml
104
+ homepage: https://shivab.com
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ homepage_uri: https://shivab.com
110
+ source_code_uri: https://github.com/shivabhusal/erika-slideshow
111
+ changelog_uri: https://github.com/shivabhusal/erika-slideshow
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.5.2.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Erika - A CLI Based slideshow generator
132
+ test_files: []