module MultimediaParadise

#
#

require ‘multimedia_paradise/audio/audio_player/misc.rb’

#
#

require ‘multimedia_paradise/audio/audio_player/reset.rb’

#
#

require ‘multimedia_paradise/audio/audio_player/tab.rb’

#
#

Constants that are specific to class ExtractAudio are kept here.

#
#

require ‘multimedia_paradise/audio/genres/constants.rb’

#
#

MultimediaParadise::RemoveAudio

This small module can be used to remove audio from a given file.

Specific usage example:

MultimediaParadise::RemoveAudio[]
#
#
#

MultimediaParadise::Audio::WavToMp3

Convert a .wav file into a .mp3 file.

Usage example:

require 'multimedia_paradise/audio/wav_to_mp3.rb'
MultimediaParadise::Audio::WavToMp3.new
#

require ‘multimedia_paradise/audio/wav_to_mp3.rb’

#
#

require ‘multimedia_paradise/audio/waveform/constants.rb’

#
#

MultimediaParadise::Waveform::Log

The purpose of this class is to log and provide benchmarks.

This may be important for lengthy batch operations.

There may be other, better benchmark classes, but it is fairly trivial code - not mandatory to google for better solutions.

#

require ‘multimedia_paradise/audio/waveform/log.rb’

#
#

require ‘multimedia_paradise/base/colours.rb’

#
#

require ‘multimedia_paradise/base/commandline_arguments.rb’

#
#

require ‘multimedia_paradise/base/constants.rb’

#
#

Encoding-related code should be stored in this file here.

#
#

require ‘multimedia_paradise/base/misc.rb’

#
#

require ‘multimedia_paradise/base/namespace.rb’

#
#

require ‘multimedia_paradise/base/time.rb’

#
#

require ‘multimedia_paradise/commandline/menu.rb’

#
#

require ‘multimedia_paradise/constants/conversions.rb’

#
#

require ‘multimedia_paradise/constants/directory_constants.rb’

#
#

require ‘multimedia_paradise/constants/encodings.rb’

#
#

require ‘multimedia_paradise/constants/file_constants.rb’

#
#

require ‘multimedia_paradise/constants/namespace.rb’

#
#

require ‘multimedia_paradise/constants/newline.rb’

#
#

require ‘multimedia_paradise/constants/video_filetypes.rb’

#
#

MultimediaParadise::WebConstants

#

require ‘multimedia_paradise/constants/web_constants.rb’ include MultimediaParadise::WebConstants

#
#

Code in this .rb file has to do with converting multimedia formats, and thus will contain all kind of conversion-related aspects - but it can also be used for cutting, splitting etc.. of audio files, at the least for some of that.

If you want to use a wrapper over image-to-image manipulation then you should use another module/class though, perhaps even the project called image_paradise.

#

require ‘multimedia_paradise/toplevel_methods/conversions.rb’ MultimediaParadise.video_to_images

#
#

require ‘multimedia_paradise/ffmpeg/ffmpeg.rb’

#
#
#

require ‘multimedia_paradise/gui/gtk3/tag_mp3_files/connect_skeleton.rb’

#
#

require ‘multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb’

#
#

require ‘multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb’

#
#

MultimediaParadise::GUI::LibUI::ChangeMetadataWidget

#
#

MultimediaParadise::GUI::LibUI::CutMultimedia

#

require ‘multimedia_paradise/gui/libui/cut_multimedia/cut_multimedia.rb’ MultimediaParadise::GUI::LibUI::CutMultimedia.new

#
#

MultimediaParadise::GUI::Libui::Lyrics

#

require ‘multimedia_paradise/gui/libui/lyrics/lyrics.rb’ MultimediaParadise::GUI::Libui::Lyrics.new

#
#

MultimediaParadise::GUI::Libui::SimplePlayWidget

#

require ‘multimedia_paradise/gui/libui/simple_play_widget/simple_play_widget.rb’ MultimediaParadise::GUI::Libui::SimplePlayWidget.new

#
#

MultimediaParadise::GUI::Libui::TagMp3Files

#
#

MultimediaParadise::GUI::Libui::VideoPlayer

#
#

MultimediaParadise::GUI::Libui::WidgetIncreaseOrDecreaseAudio

#
#

MultimediaParadise::GUI::Libui::YoutubeChannels

#
#

MultimediaParadise::GUI::Libui::YoutubeDownloader

#
#

MultimediaParadise::GUI::ChangeMetadataWidget::Module

#

require ‘multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb’ include MultimediaParadise::GUI::ChangeMetadataWidgetModule

#
#

MultimediaParadise::GUI::CutMultimediaModule

#

require ‘multimedia_paradise/gui/shared_code/cut_multimedia/cut_multimedia_module.rb’ include MultimediaParadise::GUI::CutMultimediaModule

#
#

MultimediaParadise::GUI::InformationAboutAMp3FileModule

#

require ‘multimedia_paradise/gui/shared_code/information_about_a_mp3_file/information_about_a_mp3_file_module.rb’ include MultimediaParadise::GUI::InformationAboutAMp3FileModule

#
#

MultimediaParadise::GUI::Gtk::LyricsModule

#

require ‘multimedia_paradise/gui/shared_code/lyrics/lyrics_module.rb’ include ::MultimediaParadise::GUI::Gtk::LyricsModule

#
#

MultimediaParadise::GUI::Gtk::MultimediaConverterModule

This class contains a “multimedia_convert”, aka just a thin wrapper over ffmpeg.

Features that it should have:

- convert between .mp3, .wav, .ogg and so forth.
- allow conversions between .avi and .mpg and so forth.
- scrolling should be possible in the entry area, so we can select
  different audio files.
#

require ‘multimedia_paradise/gui/shared_code/multimedia_converter/multimedia_converter_module.rb’ include MultimediaParadise::GUI::Gtk::MultimediaConverterModule

#
#

MultimediaParadise::GUI::Gtk::MultimediaNotebookModule

#

require ‘multimedia_paradise/gui/shared_code/multimedia_notebook/multimedia_notebook_module.rb’ include ::MultimediaParadise::GUI::Gtk::MultimediaNotebookModule

#
#

MultimediaParadise::GUI::Gtk::PlayVideoFromMyCollectionModule

#

require ‘multimedia_paradise/gui/shared_code/play_video_from_my_collection/play_video_from_my_collection_module.rb’ include ::MultimediaParadise::GUI::Gtk::PlayVideoFromMyCollectionModule

#
#

MultimediaParadise::GUI::Gtk::PlaylistModule

This just provides a GUI wrapper over the commandline-based playlist functionality. I haven’t really improved on this much at all, though. It was added in January of 2021.

#

require ‘multimedia_paradise/gui/shared_code/playlist/playlist_module.rb’ include ::MultimediaParadise::GUI::Gtk::PlaylistModule

#
#

MultimediaParadise::GUI::SimplePlayWidgetModule

#

require ‘multimedia_paradise/gui/shared_code/simple_play_widget/simple_play_widget_module.rb’ include MultimediaParadise::GUI::SimplePlayWidgetModule

#
#

MultimediaParadise::GUI::Gtk::SoundEffectWidgetModule

#

require ‘multimedia_paradise/gui/shared_code/sound_effect_widget/sound_effect_widget_module.rb’ include ::MultimediaParadise::GUI::Gtk::SoundEffectWidgetModule

#
#

MultimediaParadise::GUI::TagMp3FilesModule

#

require ‘multimedia_paradise/gui/shared_code/tag_mp3_files/tag_mp3_files_module.rb’ include MultimediaParadise::GUI::TagMp3FilesModule

#
#

MultimediaParadise::GUI::Gtk::VideoEditorModule

#

require ‘multimedia_paradise/gui/shared_code/video_editor/video_editor_module.rb’ include ::MultimediaParadise::GUI::Gtk::VideoEditorModule

#
#

MultimediaParadise::GUI::Gtk::VideoPlayerModule

Some information was obtained from the following blog entry:

http://www.intransitione.com/blog/embedding-mplayer-in-a-pygtk-application/
#

require ‘multimedia_paradise/gui/shared_code/video_player/video_player_module.rb’ include ::MultimediaParadise::GUI::Gtk::VideoPlayerModule

#
#

require ‘multimedia_paradise/gui/shared_code/widget_increase_or_decrease_audio/widget_increase_or_decrease_audio_module.rb’ include ::MultimediaParadise::GUI::Gtk::WidgetIncreaseOrDecreaseAudioModule

#
#

MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule

The purpose of this class is to be able to download a remote youtube file, either via youtube-dl or some other way, and to automatically modify this downloaded video file.

Usage example:

require 'multimedia_paradise/youtube_downloader.rb'
MultimediaParadise::GUI::Gtk::YoutubeDownloader.new
#

require ‘multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb’ include ::MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule

#
#

require ‘multimedia_paradise/help/help.rb’

#
#

MultimediaParadise::LongFormatToMillisecondsConverter

Usage example:

MultimediaParadise::LongFormatToMillisecondsConverter.new
#

require ‘multimedia_paradise/misc/long_format_to_milliseconds_converter.rb’ MultimediaParadise.long_format_to_milliseconds(ARGV)

#
#

The input to this class must be in n milliseconds.

Usage example:

MultimediaParadise::MillisecondsToLongFormatConverter.new(ARGV)
#

require ‘multimedia_paradise/misc/milliseconds_to_long_format_converter.rb’ MultimediaParadise.milliseconds_to_long_format

#
#

This class shall be representative for all Chord objects.

#
#

This file will cut an audio file into 10 minutes each.

#

require ‘10_minutes_chop.rb’

#
#

This file will cut an audio file into 15 minutes each.

#

require ‘15_minutes_chop.rb’

#
#

This file will cut an audio file into 30 minutes each.

#

require ‘30_minutes_chop.rb’

#
#

This file will cut an audio file into minutes each.

#

require ‘5_minutes_chop.rb’

#
#

MultimediaParadise::StartLengthDuration

This simple class holds length, start and duration information.

ALL those values MUST be absolute (positive) values, all the time!

Every time you set @length, @start or @duration, you must invoke ensure_proper_values()

Span gives the total duration (from start + duration)

#

require ‘multimedia_paradise/multimedia/start_length_duration.rb’

#
#

require ‘multimedia_paradise/project/project.rb’ MultimediaParadise.project_yaml_dir?

#
#

MultimediaParadise::Sinatra

#

require ‘multimedia_paradise/sinatra/app.rb’ MultimediaParadise.start_sinatra MultimediaParadise.run_app

#
#

MultimediaParadise::EmbeddableInterface

The code in this file can be used to “embed” the functionality of MultimediaParadise in web-applications, in particular in sinatra.

This depends on the cyberweb project.

#

require ‘multimedia_paradise/sinatra/embeddable_interface.rb’ include MultimediaParadise::EmbeddableInterface

#
#

require ‘multimedia_paradise/toplevel_methods/chop_off_first_n_seconds.rb’

#
#

The idea for this file is to collect codec-related code.

#

require ‘multimedia_paradise/toplevel_methods/codecs.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/cut_from_to.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/e.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/esystem.rb’

#
#

Code in this file will deal with files and directories in general, including cd-related actions, removal of files, creation of files and so forth.

#

require ‘multimedia_paradise/toplevel_methods/files_and_directories.rb’ MultimediaParadise.chdir

#
#

require ‘multimedia_paradise/toplevel_methods/is_audio_file.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/is_on_roebe.rb’ MultimediaParadise.is_on_roebe?

#
#

require ‘multimedia_paradise/toplevel_methods/merge_multimedia_file.rb’

#

MultimediaParadise.merge_mp3(:default, ‘*mp3’) MultimediaParadise.merge_avi_files

#
#

require ‘multimedia_paradise/toplevel_methods/merge_these_videos.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/misc.rb’ MultimediaParadise.bitrate_of_this_song MultimediaParadise.verbose_analyse_this_mp3_file_for_id3_tags MultimediaParadise.return_video_codec_of_this_file

#
#

require ‘multimedia_paradise/toplevel_methods/output_directory.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/player_in_use.rb’

#
#

Internet-radio related code will reside in this file here.

#

require ‘multimedia_paradise/toplevel_methods/radio.rb’ MultimediaParadise.register_title_of_this_audio_file MultimediaParadise.title_of_the_audio_file?

#
#
#

require ‘multimedia_paradise/toplevel_methods/return_all_video_files.rb’ MultimediaParadise.return_all_video_files

#
#

require ‘multimedia_paradise/toplevel_methods/return_random_video_file_from_the_video_collection.rb’ MultimediaParadise.return_random_video

#
#

require ‘multimedia_paradise/toplevel_methods/return_screen_resolution.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/run_sys_command.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/set_title_of.rb’

#
#

This file will gather code that can be used to do a screencast on the xorg-server.

#

require ‘multimedia_paradise/toplevel_methods/screencast.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/subtitles.rb’ MultimediaParadise.remove_subtitles_from_this_video_file MultimediaParadise.embed_this_subtitle_onto_that_video

#
#
#

require ‘multimedia_paradise/toplevel_methods/to_mp4.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/total_duration.rb’

#
#

require ‘multimedia_paradise/toplevel_methods/video_dataset.rb’

#
#

require ‘multimedia_paradise/version/version.rb’

#
#

This is just a dummy namespace to use “Video” as the namespace here, within the MultimediaParadise project.

#

require ‘multimedia_paradise/video/video.rb’

#
#

MultimediaParadise::Video::Youtube

The idea for this module is to obtain information from youtube, such as the length/duration of a video. As I presently do not know how to do this, this is thus mostly a stub for future work.

#

Constants

ARRAY_HELP_OPTIONS
#

ARRAY_HELP_OPTIONS (help tag)

We will commonly respond to these help options here.

#
ARRAY_MULTIMEDIA_FILES
ARRAY_MULTIMEDIA_FILETYPES
#

MultimediaParadise::ARRAY_MULTIMEDIA_FILETYPES

Build an array that holds all multimedia filetypes. This is a merger between the video-filetypes and the audio-formats.

#
ARRAY_VIDEO_FILETYPES
#

MultimediaParadise::ARRAY_VIDEO_FILETYPES

Define which filetypes we will consider to be video-formats.

Store without ‘.’ character.

#
AUDIO_CHANNELS
#

AUDIO_CHANNELS

Most of the following constants come from the LAME documentation

#
AUDIO_DIRECTORY
AUDIO_FORMATS
#

MultimediaParadise::AUDIO_FORMATS

The file can usually be found here:

bl $MULTIMEDIA_PARADISE/yaml/audio_formats.yml
#
BASE_DIR
CARTOONS_DIRECTORY
#

CARTOONS_DIRECTORY

This constant is mildly deprecated. Prefer to use the method MultimediaParadise.cartoons_directory? instead.

#
COLOURS
#

COLOURS

#
CONFIGURATION_DIRECTORY
#

CONFIGURATION_DIRECTORY

#
CutAudio
#

Add two aliases next.

#
CutVideo
DEFAULT_VIDEO_BITRATE
#

DEFAULT_VIDEO_BITRATE

#
DEPOT_VIDEO
DIRECTORY_DATA_VIDEO
#

MultimediaParadise::DIRECTORY_DATA_VIDEO

This constant is always hardcoded.

#
DIRECTORY_TO_THE_LOCAL_SONGS
ENCODING_QUALITY
#

ENCODING_QUALITY

#
FILE_AUDIO_FORMATS
#

FILE_AUDIO_FORMATS

This constant has the file path towards the file called audio_formats.yml

#
FILE_IMAGE_FORMATS
#

FILE_IMAGE_FORMATS

This constant has the file path towards the file called audio_formats.yml

#
FILE_LYRICS
#

FILE_LYRICS

#
FILE_MUSIC_GENRES
#

FILE_MUSIC_GENRES

#
FILE_PLAYLIST
#

FILE_PLAYLIST

#
FILE_RADIO_IMAGE
#

FILE_RADIO_IMAGE

Denote where the image for the radio can be found.

#
FILE_RADIO_STATIONS
#

This clause is the default on my home system - and for most users too, I assume.

#
FILE_SONG_TAGS
#

FILE_SONG_TAGS

#
FILE_USAGE_EXAMPLES
#

FILE_USAGE_EXAMPLES

#
FILE_USE_THIS_VIDEO_PLAYER
#

FILE_USE_THIS_VIDEO_PLAYER

bl $MULTIMEDIA_PARADISE/yaml/use_this_video_player.yml

#
FILE_VIDEO_COLLECTION
#

FILE_VIDEO_COLLECTION

Use this constant to define your video collection.

On my home system this will be:

/home/x/DATA/VIDEO/yaml/video_collection.yml
#
FIVE_MINUTES
#

FIVE_MINUTES

#
HOME
HOME_DIR
HOME_DIRECTORY
HOME_DIRECTORY_OF_USER_X
#

HOME_DIRECTORY_OF_USER_X

#
IMAGE_FORMATS
#

MultimediaParadise::IMAGE_FORMATS

The file can usually be found here:

bl $MULTIMEDIA_PARADISE/yaml/image_formats.yml
#
ISO_ENCODING
#

ISO_ENCODING

#
LAST_UPDATE
#

LAST_UPDATE

The last update entry should be kept in the dd.mm.yyyy format.

#
LYRICS_YAML_FILE
#

LYRICS_YAML_FILE

#
MP3_BITRATES
#

MP3_BITRATES

#
MULTIMEDIA_PARADISE_DOC_DIR
#

MULTIMEDIA_PARADISE_DOC_DIR

#
MY_AUDIO_DIR
#

MY_AUDIO_DIR

This constant is really only useful on my home system.

It would point to a target such as “/home/x/DATA/AUDIO/”.

#
MY_DATA_DIR
#

MY_DATA_DIR

#
MY_VIDEO_DIRECTORY
N
#

N

#
NAMESPACE
#

NAMESPACE

#
PLAY_ZOOMED
#

MultimediaParadise::PLAY_ZOOMED

If this constant is set to true, then we will play in a zoomed way.

#
PROJECT_BASE_DIRECTORY
#

PROJECT_BASE_DIRECTORY

#
PROJECT_YAML_DIRECTORY
#

PROJECT_YAML_DIRECTORY

This constant points to the main yaml-directory of this project, but it may be better to use the method below this constant.

#
REALVIDS
REALVIDS_DIRECTORY
#

REALVIDS_DIRECTORY

#
REPLAY_GAIN
#

REPLAY_GAIN

#
SAMPLE_RATES
#

SAMPLE_RATES

#
SONG_DIR
TEN_MINUTES
#

TEN_MINUTES

#
TRY_TO_RENAME_THE_KDE_KONSOLE_TAB
#

MultimediaParadise::TRY_TO_RENAME_THE_KDE_KONSOLE_TAB

If true then we assume that we use the KDE konsole and that we can also rename a konsole-tab title.

#
TRY_TO_USE_UNICODE_SYMBOLS
#

MultimediaParadise::TRY_TO_USE_UNICODE_SYMBOLS

If the following constant is set to true then we will try to make use of unicode symbols, when applicable. This may aid in the process of displaying some multimedia icons on the commandline, for example.

#
USER_HOME_DIR
USE_THIS_ENCODING
#

USE_THIS_ENCODING

We default to the UTF-8 Encoding.

#
UTF_ENCODING
#

UTF_ENCODING

#
VBR_QUALITY
#

VBR_QUALITY

#
VERSION
#

VERSION

#
VIDEO_COLLECTION
VIDEO_DATASET
#

VIDEO_DATASET

#
WHICH_VIDEO_PLAYER_TO_USE
YOUR_EDITOR
#

MultimediaParadise::YOUR_EDITOR

#

Public Class Methods

add_this_song_to_the_playlist(i) click to toggle source
#

MultimediaParadise.add_this_song_to_the_playlist

#
# File lib/multimedia_paradise/audio/playlist/playlist.rb, line 1601
def self.add_this_song_to_the_playlist(i)
  ::MultimediaParadise::Playlist.add(i)
end
analyze_audio_stream( of_this_file ) click to toggle source
#

MultimediaParadise.analyze_audio_stream

This method will use ffmpeg in order to analyze the audio stream. A Hash will be returned, which will keep the decibel-score value.

For more documentation see the method MultimediaParadise.ffmpeg_analyze_audio_stream().

#
# File lib/multimedia_paradise/toplevel_methods/analyze_audio_stream.rb, line 21
def self.analyze_audio_stream(
    of_this_file
  )
  ffmpeg_analyze_audio_stream(of_this_file)
end
analyze_this_directory_for_id3_tags(i = Dir.pwd) click to toggle source
#

MultimediaParadise.analyze_this_directory_for_id3_tags

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 801
def self.analyze_this_directory_for_id3_tags(i = Dir.pwd)
  require 'id3lib'
  all_files = Dir["#{i}/*.mp3"]
  all_files.each {|this_mp3_file|
    verbose_analyse_this_mp3_file_for_id3_tags(this_mp3_file)
  }
end
any_to_mp3(this_file, to = '.mp3') click to toggle source
#

MultimediaParadise.any_to_mp3

Wrapper method. Converts any file to mp3 format. Right now it uses ffmpeg for this. This may be superior to the other variants actually.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 293
def self.any_to_mp3(this_file, to = '.mp3')
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
append_silence_to_this_song( add_this_delay = 5, work_on_these_songs = ['foobar.mp3'] ) click to toggle source
#

MultimediaParadise.append_silence_to_this_song

Note that this method currently depends on sox. Perhaps someone knows how to do so via ffmpeg; I don’t right now.

The first argument to this method is the delay, in n seconds. You can use a fraction, such as 0.25 here as well.

The second argument is the song, such as “bla.mp3”. This filename should exist.

The method will then simply add “silence” to the song at hand - it will append “silence”.

Usage examples:

MultimediaParadise.append_silence_to_this_song(5, 'foobar.mp3')
MultimediaParadise.append_silence_to_this_song(5, 'ack.mp3')
MultimediaParadise.append_silence_to_this_song(.027, 'foobar.mp3')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 382
def self.append_silence_to_this_song(
    add_this_delay      = 5,
    work_on_these_songs = ['foobar.mp3']
  )
  [work_on_these_songs].flatten.compact.each {|this_song|
    if File.exist? this_song
      cmd = "sox #{this_song} padded_#{this_song} pad 0 #{add_this_delay.to_f}"
      esystem cmd
    else
      e 'No file exists at '+this_song.to_s+'.'
    end
  }
end
array_commandline_arguments?() click to toggle source
#

MultimediaParadise.array_commandline_arguments?

#
# File lib/multimedia_paradise/commandline/menu.rb, line 31
def self.array_commandline_arguments?
  @array_commandline_arguments
end
au_to_wav( this_file, to = 'wav' ) click to toggle source
#

MultimediaParadise.au_to_wav

convert .au file to .wav file.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 529
def self.au_to_wav(
    this_file, to = 'wav'
  )
  ::MultimediaParadise.general_format_conversion(this_file, to: ot)
end
audio_info(i) click to toggle source
#

MultimediaParadise.audio_info

As of November 2013 this method makes use of ffprobe, from ffmpeg instead.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 594
def self.audio_info(i)
  if i.is_a? Array
    i.each {|entry| audio_info(entry) }
  else
    # cmd = 'sox '+i+' -e stat'
    cmd = 'ffprobe '+i
    run_sys_command cmd
  end
end
audio_player(options = nil) click to toggle source
#

MultimediaParadise.audio_player

We also want to use a simpler module-method for the audio player.

#
# File lib/multimedia_paradise/audio/audio_player/audio_player.rb, line 63
def self.audio_player(options = nil)
  MultimediaParadise::AudioPlayer.new(options)
end
available_video_files() click to toggle source
#

MultimediaParadise.available_video_files

This method will only return all video-files under ther ealvids directory.

#
# File lib/multimedia_paradise/toplevel_methods/return_all_video_files.rb, line 20
def self.available_video_files
  Dir["#{realvids_directory?}**"].select {|entry| is_a_video_file?(entry) }.sort
end
avi_to_flash(file) click to toggle source
#

MultimediaParadise.avi_to_flash

Convert an .avi file to flash format, i.e. to .flv. Right now we will simply use ffmpeg for this.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 520
def self.avi_to_flash(file)
  run_sys_command 'ffmpeg -i '+file+' '+file+'.flv'
end
avi_to_m4v( output_file = 'output.m4v', *input_files ) click to toggle source
#

MultimediaParadise.avi_to_m4v

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 429
def self.avi_to_m4v(
    output_file = 'output.m4v', *input_files
  )
  output_file = 'output.m4v' if output_file.nil?
  output_file = 'output.'+output_file unless output_file.include? '.'
  _  = 'ffmpeg '.dup
  _ << '-i '+input_files.join(' ')+' '
  _ << '-r 12.5 '
  _ << '-b 80 '
  _ << '-vcodec libxvid '
  _ << '-maxrate 80 '
  _ << '-bufsize 5 '
  _ << output_file
  run_sys_command _
end
bin_dir?() click to toggle source
#

MultimediaParadise.bin_dir?

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 41
def self.bin_dir?
  RbConfig::CONFIG['bindir'].to_s+'/' # Ensure trailing '/'.
end
bitrate_of_this_song(this_song) click to toggle source
#

MultimediaParadise.bitrate_of_this_song

This method will make use of ffmpeg’s ffprobe to query the bitrate of

    1. a .mp3 song. The return value is a String such as “192 kb/s”.

The commandline variant would be the following:

ffprobe foobar.mp3 2>&1 | grep Stream

Result:

Stream #0:0: Audio: mp3, 11025 Hz, mono, s16p, 32 kb/s

Usage example:

MultimediaParadise.bitrate_of_this_song('foobar.mp3') # => "192 kb"
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 292
def self.bitrate_of_this_song(this_song)
  use_this_regex = /(\d{1,3} ?kb)\/s/ # See: https://rubular.com/r/CfmHoK5w0goYpU
  if this_song.is_a? Array
    this_song = this_song.first
  end
  result = `ffprobe #{this_song} 2>&1 | grep Stream`.strip
  result = result.scan(use_this_regex).flatten.first.to_s
  return result
end
capture_screen(size_angabe = '1024x800') click to toggle source
#

MultimediaParadise.capture_screen

This captures a screen by using ffmpeg.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 756
def self.capture_screen(size_angabe = '1024x800')
  begin
    require 'capture_screen'
  rescue LoadError; end
  img_file = '$MY_TEMP/GRABBED_X11_screencast.mov'
  _ = CaptureScreen.new :dont_run_yet
  _.store_here = img_file
  _.size = size_angabe
  return _.main_string?
end
cartoons_directory?() click to toggle source
#

MultimediaParadise.cartoons_directory?

#
# File lib/multimedia_paradise/constants/directory_constants.rb, line 62
def self.cartoons_directory?
  CARTOONS_DIRECTORY
end
chdir(i) click to toggle source
#

MultimediaParadise.chdir

Use this method if you wish to change directory to another target directory.

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 86
def self.chdir(i)
  Dir.chdir(i) if File.directory? i
end
chop_into_segments_of_n_seconds_size( this_file, n_seconds = 60 ) click to toggle source
#

MultimediaParadise.chop_into_segments_of_n_seconds_size

Use this (audio) method to chop up an audio file into segments of n size. You could also use this on a video file, but the primary use of it is to chop up a large audio file into smaller audio files.

The first argument is the name (path) of the file that you wish to modify.

If only one argument is provided (the filename), then we will default to a duration of 60 seconds.

#
# File lib/multimedia_paradise/toplevel_methods/chop_into_segments_of_n_seconds_size.rb, line 25
def self.chop_into_segments_of_n_seconds_size(
    this_file, # <- Your target file that will be chopped up.
    n_seconds = 60
  )
  ffmpeg_chop_into_segments_of_n_seconds_size(this_file, n_seconds)
end
chop_off_first_five_minutes(of_this_file) click to toggle source
#

MultimediaParadise.chop_off_first_five_minutes

#
# File lib/multimedia_paradise/toplevel_methods/chop_off_first_five_minutes.rb, line 12
def self.chop_off_first_five_minutes(of_this_file)
  MultimediaParadise.chop_off_first_n_seconds(
    '5 minutes', of_this_file, :do_create_complementary_file
  )
end
chop_off_first_n_seconds( n_seconds = TEN_MINUTES, of_this_multimedia_file = ARGV, also_do_create_complementary_file = false ) click to toggle source
#

MultimediaParadise.chop_off_first_n_seconds

Use this method to chop off the first n seconds from a multimedia file.

By default, we will chop off the first 10 minutes.

This just wraps ffmpeg, such as:

ffmpeg -ss 0 -t 30 -i file.mp3 file.wav

Options explained:

-ss 0 - Start at 0 seconds
-t 30 - Capture 30 seconds (from 0, so 0:00 - 0:30). If you want 1 minute of audio, use -t 60.
file.mp3 - Input file
file.wav - output file

Specific usage example:

MultimediaParadise.chop_off_first_n_seconds(:default, '/Users/x/STUDIUM/UNI_WIEN/321015_Pathophysiologie/audio/01-Pathophysiologie-30.05.2016_Vormittag_Überlebenszeit_Apoptose.mp3')
#
# File lib/multimedia_paradise/toplevel_methods/chop_off_first_n_seconds.rb, line 44
def self.chop_off_first_n_seconds(
    n_seconds                         = TEN_MINUTES, # 10 minutes.
    of_this_multimedia_file           = ARGV,
    also_do_create_complementary_file = false
  )
  if of_this_multimedia_file.is_a? Array
    of_this_multimedia_file.each {|entry|
      chop_off_first_n_seconds(n_seconds, entry, also_do_create_complementary_file)
    }
  else
    case n_seconds
    when '10 minutes'
      n_seconds = TEN_MINUTES
    when '5 minutes'
      n_seconds = FIVE_MINUTES
    when :default
      n_seconds = TEN_MINUTES
    end
    case also_do_create_complementary_file
    when :do_create_complementary_file
      also_do_create_complementary_file = true
    end
    ffmpeg_command = 'ffmpeg -ss 0 -t '+n_seconds.to_s+' -i '+of_this_multimedia_file
    extname        = File.extname(of_this_multimedia_file)
    output_file    = of_this_multimedia_file.sub(/(#{extname})/, '_CHOPPED_AT_THE_START\\1')
    ffmpeg_command << ' '+output_file
    esystem ffmpeg_command
    # ===================================================================== #
    # Also create the "missing" part of the multimedia file, so that
    # we will end up with two files as a result.
    # ===================================================================== #
    if also_do_create_complementary_file
      e 'Now also creating the complementary file.'
      duration       = ::MultimediaParadise.return_duration_of_this_multimedia_file(of_this_multimedia_file) - n_seconds.to_f
      ffmpeg_command = 'ffmpeg -ss '+n_seconds.to_s+' -t '+duration.to_s+' -i '+of_this_multimedia_file
      extname        = File.extname(of_this_multimedia_file)
      output_file    = of_this_multimedia_file.sub(/(#{extname})/, '_CHOPPED_AT_THE_END\\1')
      ffmpeg_command << ' '+output_file
      e orange(ffmpeg_command)
      system ffmpeg_command
    end
  end
end
chop_off_first_ten_minutes(of_this_file) click to toggle source
#

MultimediaParadise.chop_off_first_ten_minutes

#
# File lib/multimedia_paradise/toplevel_methods/chop_off_first_ten_minutes.rb, line 12
def self.chop_off_first_ten_minutes(of_this_file)
  MultimediaParadise.chop_off_first_n_seconds(
    '10 minutes', of_this_file, :do_create_complementary_file
  )
end
chop_off_first_two_minutes(of_this_file) click to toggle source
#

MultimediaParadise.chop_off_first_two_minutes

#
# File lib/multimedia_paradise/toplevel_methods/chop_off_first_two_minutes.rb, line 14
def self.chop_off_first_two_minutes(of_this_file)
  MultimediaParadise.chop_off_first_n_seconds(
    '2 minutes', of_this_file, :do_create_complementary_file
  )
end
codec_conversion( of_this_input_file, use_this_codec = :libvorbis ) click to toggle source
#

MultimediaParadise.codec_conversion

This method can be used to convert, e. g. from a .mp3 file to a .ogg file. Note that this does not work right now (November 2020).

In raw ffmpeg this would be like so:

ffmpeg -i input.mp3 -c:a libvorbis output.ogg

Usage example:

MultimediaParadise.codec_conversion
#
# File lib/multimedia_paradise/toplevel_methods/codecs.rb, line 28
def self.codec_conversion(
    of_this_input_file,
    use_this_codec = :libvorbis
  )
  if of_this_input_file.is_a? Array
    of_this_input_file = of_this_input_file.join(' ').strip
  end
  output_file = of_this_input_file.
                sub(/#{File.extname(of_this_input_file)}/,'')+
                '.ogg'
  _ = 'ffmpeg -i '+of_this_input_file+' -c:a '+
       use_this_codec.to_s+
       output_file
  e
  esystem _
  e
end
compress_this_audio_file(this_audio_file) click to toggle source
#

MultimediaParadise.compress_this_audio_file

#
# File lib/multimedia_paradise/audio/compress.rb, line 89
def self.compress_this_audio_file(this_audio_file)
  MultimediaParadise::Compress.new(this_audio_file)
end
compress_this_ogg_file(i = 'foobar.ogg') click to toggle source
#

MultimediaParadise.compress_this_ogg_file

This method will use a sampling rate of 22050 Hz. This should be perfectly adequate for speech-related audio, but I also found it to work well when compressing a tetris.ogg file (for the game tetris).

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 817
def self.compress_this_ogg_file(i = 'foobar.ogg')
  _ = 'ffmpeg -i '+entry+' '\
      '-c:a libvorbis -ab 32k '\
      '-ar 22050'\
      ' OUTPUT_'+i
  e
  esystem _
  e
end
convert_these_images_into_a_video(*images) click to toggle source
#

MultimediaParadise.convert_these_images_into_a_video

This method can be used to “assemble” images into a video.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 560
def self.convert_these_images_into_a_video(*images)
  _ = 'ffmpeg -f image2 -i '+images.join(' ').strip+' video.mpg'
  esystem _
end
copy_and_merge_this_video_n_times( this_video, n_times = 3 ) click to toggle source
#

MultimediaParadise.copy_and_merge_this_video_n_times

This method will copy the given video; and then merge these copies.

#
# File lib/multimedia_paradise/toplevel_methods/copy_and_merge_this_video_n_times.rb, line 19
def self.copy_and_merge_this_video_n_times(
    this_video, n_times = 3
  )
  if this_video.is_a? Array
    this_video = this_video.join(' ').strip
  end
  n_times = 3 if n_times.nil? # <- Set the default here.
  array = []
  extname = File.extname(this_video)
  # ========================================================================= #
  # Create intermediate files next.
  # ========================================================================= #
  n_times.to_i.times {|number|
    this_new_video_file = 'foobar_'+this_video.sub(/#{extname}$/,'').to_s+
                          '_'+number.to_s+extname
    array << this_new_video_file
    copy_file(this_video, this_new_video_file)
  }
  # ========================================================================= #
  # Past this point we assume that the files were copied successfully.
  # We will next proceed to merge these files.
  # ========================================================================= #
  result = ::MultimediaParadise.merge_these_videos(
    array
  )
  return result
end
copy_bin_directory() click to toggle source
#

MultimediaParadise.copy_bin_directory

This method can be used to copy the content of the bin/ directory onto the current working directory.

Usage example from within ruby code:

require 'multimedia_paradise'; MultimediaParadise.copy_bin_directory
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 56
def self.copy_bin_directory
  file_installed_binaries = "#{MultimediaParadise.project_base_directory?}"\
                            "yaml/internal/installed_binaries.yml"
  mkdir('bin/')
  cd('bin/')
  if File.exist? file_installed_binaries
    e 'Making use of the file '+sfile(file_installed_binaries)+'.'
    install_these_binaries = YAML.load_file(file_installed_binaries)
    installation_directory = `gem env`.split("\n").select {|line| # Check for INSTALLATION DIRECTORY: /root/.gem
      line.include? 'INSTALLATION DIRECTORY:'
    }.first.
    scan(/INSTALLATION DIRECTORY: (.+)$/).flatten.first
    install_these_binaries.each {|entry|
      target = installation_directory+'/bin/'+entry
      if File.exist? target
        e "Copying the file #{target} into the current working "\
          "directory next."
        copy_file(target, Dir.pwd)
      else
        # ================================================================= #
        # Since as of January 2023 first try the bin_dir, before giving up.
        # ================================================================= #
        target = MultimediaParadise.bin_dir?+File.basename(entry)
        if File.exist? target
          e "Copying the file #{target} into the current working "\
            "directory next."
          copy_file(target, Dir.pwd)
        else
          no_file_exists_at(target)
        end
      end
    }
  end
end
copy_file(from, to) click to toggle source
#

MultimediaParadise.copy_file

#
# File lib/multimedia_paradise/toplevel_methods/copy_file.rb, line 14
def self.copy_file(from, to)
  FileUtils.cp(from, to)
end
copy_missing_video_files(i = ARGV.first) click to toggle source
#

MultimediaParadise.copy_missing_video_files

#
# File lib/multimedia_paradise/video/copy_missing_video_files.rb, line 285
def self.copy_missing_video_files(i = ARGV.first)
  MultimediaParadise::Video::CopyMissingVideoFiles.new(i)
end
copy_random_video(i) click to toggle source
#

MultimediaParadise.copy_random_video

#
# File lib/multimedia_paradise/video/copy_random_video.rb, line 90
def self.copy_random_video(i)
  MultimediaParadise::CopyRandomVideo.new(i)
end
correct_video_numbers(i) click to toggle source
#

MultimediaParadise.correct_video_numbers

#
# File lib/multimedia_paradise/video/correct_video_numbers.rb, line 270
def self.correct_video_numbers(i)
  MultimediaParadise::Video::CorrectVideoNumbers.new(i)
end
create_dvd( input_file = 'video.avi' ) click to toggle source
#

MultimediaParadise.create_dvd

This method can be used to create a DVD. The first argument should be the existing file that you wish to “turn” into a DVD.

Note that you need the program dvdauthor in order to make use of this method.

Invocation example:

MultimediaParadise.create_dvd '259_TheGreatDictator.avi'
#
# File lib/multimedia_paradise/video/create_dvd.rb, line 26
def self.create_dvd(
    input_file = 'video.avi'
  )
  output_mpg_file = 'dvd.mpg'
  e 'We will create a .mpg file called '+sfile(output_mpg_file)+'.'
  _ = 'ffmpeg -i '+input_file+' -aspect 16:9 -target pal-dvd '+output_mpg_file
  esystem(_)
  e 'Next adding this .mpg file ('+output_mpg_file+') to the project '\
    'via '+orange('dvdauthor')+':'
  _ = 'dvdauthor -o dvd/ -t '+output_mpg_file
  esystem(_)
  # ======================================================================= #
  # Use PAL next:
  # ======================================================================= #
  ENV['VIDEO_FORMAT'] = 'PAL'
  _ = 'dvdauthor -o dvd/ -T'
  esystem(_)
  e 'Next creating an .iso file using mkisofs:'
  iso_file = 'dvd.iso'
  _ = "mkisofs -dvd-video -o #{iso_file} dvd/"
  esystem(_)
  e 'All should be finished now! You can burn the file `'+iso_file+'`.'
end
create_m3u_playlist(i = :default_playlist) click to toggle source
#

MultimediaParadise.create_m3u_playlist

#
# File lib/multimedia_paradise/audio/create_m3u_playlist.rb, line 237
def self.create_m3u_playlist(i = :default_playlist)
  ::MultimediaParadise::CreateM3uPlaylist.new(i)
end
create_noise_profile( of_this_mp3_file ) click to toggle source
#

MultimediaParadise.create_noise_profile

Note that this method depends on the external program called “sox”.

Usage example:

MultimediaParadise.create_noise_profile('foobar.mp3')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 147
def self.create_noise_profile(
    of_this_mp3_file
  )
  array_results = []
  [of_this_mp3_file].flatten.compact.each {|work_on_this_mp3_file|
    work_on_this_mp3_file = File.absolute_path(work_on_this_mp3_file)
    filename_without_extension = work_on_this_mp3_file.delete_suffix('.mp3')
    this_profile_file_is_to_be_created = "noise_profile_based_on_#{File.basename(filename_without_extension)}"
    if File.exist?(this_profile_file_is_to_be_created) # Always remove old profiles.
      File.delete(this_profile_file_is_to_be_created)
    end
    cmd_to_run = "sox #{work_on_this_mp3_file} -n noiseprof #{this_profile_file_is_to_be_created}.profile"
    e cmd_to_run
    `#{cmd_to_run}`
    array_results << this_profile_file_is_to_be_created
  }
  return array_results
end
create_video_from_this_audio( this_audio_file = ARGV, use_this_image = 'CAT.png' ) click to toggle source
#

MultimediaParadise.create_video_from_this_audio

This method can turn a, for example, .mp3 file into a video with a static image.

The second argument should be the image that you wish to show for the video. If this image can NOT be found then the method will try to find any other image file in the current directory - this is the behaviour I needed, so it was added. Ideally provide the image, though.

#
# File lib/multimedia_paradise/toplevel_methods/create_video_from_this_audio.rb, line 25
def self.create_video_from_this_audio(
    this_audio_file = ARGV,
    use_this_image  = 'CAT.png'
  )
  if this_audio_file.is_a? Array
    this_audio_file.each {|entry|
      MultimediaParadise.create_video_from_this_audio(entry)
    }
  else
    unless File.exist? use_this_image
      e "No file called `#{use_this_image}` exists."
      e 'Trying to find any other image in this directory next.'
      all_image_files = Dir['*'].select {|entry| is_an_image_file?(entry) }
      # =================================================================== #
      # Must check whether it is empty or not.
      # =================================================================== #
      if all_image_files.empty?
        e 'No image could be found, thus no image was supplied. This is'
        e 'not allowed, so we exit here.'
        return
      else
        # ================================================================= #
        # Ok, use that image in this case - the first one.
        # ================================================================= #
        use_this_image = all_image_files.first.to_s
      end
    end
    output_file = this_audio_file.sub(/#{File.extname(this_audio_file)}/,'')+'.mp4'
    _ = 'ffmpeg -loop 1 '\
        '-i '+use_this_image.to_s+' '\
        '-i '+this_audio_file+' -c:a copy -c:v libx264 '\
        '-shortest '+output_file
    esystem(_)
  end
end
crop_this_video( i = 'input.mp4', output_file = 'output.mp4' ) click to toggle source
#

MultimediaParadise.crop_this_video

This method can be used to crop a particular video file, via ffmpeg.

The raw ffmpeg-command would go like something like this:

ffmpeg -i input.mp4 -filter:v "crop=out_w:out_h:x:y" output.mp4

These variables are:

 out_w is the width  of the output rectangle
 out_h is the height of the output rectangle
 x and y specify the top left corner of the output rectangle
 output.mp4 is the output file
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 867
def self.crop_this_video(
    i           = 'input.mp4',
    output_file = 'output.mp4'
  )
  [i].flatten.compact.each {|this_video_file|
    esystem 'ffmpeg -i '+
            this_video_file.to_s+
            ' -filter:v "crop=w:h:x:y" '+
            output_file.to_s
  }
end
cut_from_to( from_to_position = '', hash = {} ) click to toggle source
#

MultimediaParadise.cut_from_to

This method will make use of ffmpeg to cut out segments from a video file.

ffmpeg can respond to the -ss option to specify a start timestamp. The -t option can be used to specify the encoding duration.

One constraint is that the timestamps need to be in HH:MM:SS.xxx format; or in seconds.

The following example in plain ffmpeg skips the first 30 seconds, and then clips for at the least 10 seconds after that:

ffmpeg -ss 00:00:30.0 -i input.wmv -c copy -t 00:00:10.0 output.wmv

Input to this method should be in a format like this:

MultimediaParadise.cut_from_to('00:00:01-00:25:10',   this_file: 'Tales_from_the_crypt_S05E10_Came_the_Dawn_1993.mp4')
MultimediaParadise.cut_from_to('00:02:23 / 00:28:04', this_file: 'Tales_from_the_crypt_S05E10_Came_the_Dawn_1993.mp4')
#
# File lib/multimedia_paradise/toplevel_methods/cut_from_to.rb, line 57
def self.cut_from_to(
    from_to_position = '',
    hash             = {}
  )
  use_this_file = nil
  start_position = '00:00:00.0' # This is the starting position.
  duration       = nil
  if hash.is_a? String
    hash = { this_file: hash }
  end
  if from_to_position.is_a?(Hash) and hash.is_a?(Hash)
    hash.update(from_to_position)
    from_to_position = '' # And re-set to the old default again.
  end
  if hash.is_a?(Hash) and hash.has_key?(:this_file)
    # ===================================================================== #
    # Designate the file that is to be used next:
    # ===================================================================== #
    use_this_file = hash.delete(:this_file)
  end
  case use_this_file
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    use_this_file =
      'TALES_FROM_THE_CRYPT/Tales_from_the_crypt_S06E11_Surprise_Party.mkv'
  end
  if use_this_file.start_with? 'TALES_FROM_THE_CRYPT/'
    use_this_file = use_this_file.dup if use_this_file.frozen?
    use_this_file.sub!(
      Regexp.quote('TALES_FROM_THE_CRYPT/'),
      "#{HOME_DIRECTORY_OF_USER_X}VIDEO/Tales_from_the_crypt/"
    )
  end
  if hash.is_a? Hash
    if hash.has_key?(:to)
      duration = hash[:to]
    end
  end
  if from_to_position.is_a?(String) and from_to_position.frozen?
    from_to_position = from_to_position.dup
  end
  if use_this_file
    # ===================================================================== #
    # The input contains a valid file.
    # ===================================================================== #
    if File.exist? use_this_file
      _ = "ffmpeg -i #{use_this_file} -c copy".dup
      if from_to_position.is_a?(String)
        from_to_position.delete!(' ')
      end
      seek_this_token = '-' # <- This can be '-' or '/'.
      if from_to_position.is_a? String
        if from_to_position.include? '/'
          seek_this_token = '/'
        end
        if from_to_position.include?(seek_this_token)
          splitted = from_to_position.split(seek_this_token)
          start_position = splitted.first
          duration = splitted.last
        end
      end
      _ << " -ss #{start_position}"
      _ << " -t #{duration}"
      dirname = "#{File.dirname(use_this_file)}/".squeeze '/'
      output_file = dirname+'output_'+File.basename(use_this_file)
      _ << " #{output_file}"
      esystem _
      if File.exist? output_file
        e "Created file at `#{sfile(output_file)}`."
        return File.absolute_path(output_file) # And return it here, just to make this method more useful.
      end
    else
      e "No file exists at #{use_this_file}."
    end
  else
    e 'Please provide a valid file, via a key called '\
      ':this_file as part of the second argument '\
      '(which is a Hash).'
  end
end
decrease_volume( of_this_file, by_how_much = '0.5' ) click to toggle source
#

MultimediaParadise.decrease_volume

This should decrease audio volume, by using sox.

We do this by using the command –volume FACTOR.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 304
def self.decrease_volume(
    of_this_file,
    by_how_much = '0.5'
  )
  run_sys_command 'sox --volume '+
                   by_how_much+' '+of_this_file+' AUDIO_REDUCED_'+of_this_file 
end
delay_audio( this_file = ARGV, by = '3.85 seconds' ) click to toggle source
#

MultimediaParadise.delay_audio

This method will delay the audio of a video-file, by n-seconds.

The second argument to this method, ‘by`, handles that delay.

#
# File lib/multimedia_paradise/toplevel_methods/delay_audio.rb, line 19
def self.delay_audio(
    this_file = ARGV,
    by        = '3.85 seconds' # <- Input your delay here.
  )
  ffmpeg_delay_audio(this_file, by)
end
demultiplex(this_file) click to toggle source
#

MultimediaParadise.demultiplex

Demultiplex using tcdemux.

Ffmpeg should also allow it - this is an example for it:

ffmpeg -i source -map 0:a -c:a copy audioout -map 0:v -c:v copy videoout

Usage example:

MultimediaParadise.demultiplex('foo.mpg')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 478
def self.demultiplex(this_file)
  cmd  = 'tcdemux -i '.dup
  cmd << this_file
  cmd << ' -x ac3 > bla.ac3'
  run_sys_command cmd
end
denoise( input_file, lowpass_value = 3000, highpass_value = 200 ) click to toggle source
#

MultimediaParadise.denoise

This method attempts to remove noise from a multimedia file.

Note that this uses ffmpeg. Sox can also be used to filter away noise. The first argument is for the lowpass value; the second argument is for the highpass value.

The FFMPEG highpass filter is explained here:

https://ffmpeg.org/ffmpeg-filters.html#highpass
#
# File lib/multimedia_paradise/toplevel_methods/denoise.rb, line 25
def self.denoise(
    input_file,
    lowpass_value  = 3000,
    highpass_value =  200
  )
  ffmpeg_denoise(input_file, lowpass_value, highpass_value)
end
deshake(input_file = nil) click to toggle source
#

MultimediaParadise.deshake

This method can stabilize a video that was, for example, captured via a handheld camera while being quite shaky. The deshake-filter from ffmpeg helps remove camera shake from hand-holding a camera.

For more information look at this resource:

https://ffmpeg.org/ffmpeg-filters.html#deshake
#
# File lib/multimedia_paradise/toplevel_methods/deshake.rb, line 23
def self.deshake(input_file = nil)
  if input_file.is_a? Array
    input_file.each {|entry|
      deshake(entry)
    }
  else
    output_file = "output_#{input_file}"
    use_this_command = "ffmpeg -i #{input_file} -vf deshake #{output_file}"
    e
    e use_this_command
    e
    system use_this_command
  end
  
end
directory_to_the_local_songs?() click to toggle source
#

MultimediaParadise.local_audio_directory?

On my home system this will yield a string such as “/home/x/songs/”.

#
# File lib/multimedia_paradise/constants/directory_constants.rb, line 104
def self.directory_to_the_local_songs?
  DIRECTORY_TO_THE_LOCAL_SONGS
end
display_radio_stations() click to toggle source
#

MultimediaParadise.display_radio_stations

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 357
def self.display_radio_stations
  e sfile(
      FILE_RADIO_STATIONS
    )
end
display_warning(what_kind_of_warning) click to toggle source
#

MultimediaParadise.display_warning

Use this method when you wish to display a warning.

Usage example:

display_warning :lossy
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 823
def self.display_warning(what_kind_of_warning)
  case what_kind_of_warning
  when :lossy
    e 'Warning: Converting from one lossy format to another '\
      'lossy format.'
  end
end
e(i = '') click to toggle source
#

MultimediaParadise.e

#
# File lib/multimedia_paradise/toplevel_methods/e.rb, line 12
def self.e(i = '')
  puts i
end
eimportant(i) click to toggle source
#

MultimediaParadise.eimportant

#
# File lib/multimedia_paradise/colours/colours.rb, line 50
def self.eimportant(i)
  e ::MultimediaParadise.simp(i)
end
embed_this_subtitle_onto_that_video( this_subtitle, that_video ) click to toggle source
#

MultimediaParadise.embed_this_subtitle_onto_that_video

This method can be used to “attach” a subtitle to a particular video.

#
# File lib/multimedia_paradise/toplevel_methods/subtitles.rb, line 44
def self.embed_this_subtitle_onto_that_video(
    this_subtitle, that_video
  )
  output_file = 'output.mp4'
  _ = 'ffmpeg -i '+that_video+' -i '+this_subtitle+
      ' -c copy -c:s mov_text '+output_file
  e
  esystem _
  e
end
embeddable_interface() click to toggle source
#

MultimediaParadise.embeddable_interface

This method can be used to “embed” a fake-object that implements the module defined above.

#
# File lib/multimedia_paradise/sinatra/embeddable_interface.rb, line 373
def self.embeddable_interface
  object = Object.new
  object.extend(MultimediaParadise::EmbeddableInterface)
  return object
end
encode_this_video( i = ARGV, use_this_mode = :CRF ) click to toggle source
#

MultimediaParadise.encode_this_video

The default mode for this method is CRF, which stands for:

Constant Rate Factor

This method is similar to the following commandline:

ffmpeg -i input.avi -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
#
# File lib/multimedia_paradise/toplevel_methods/encode_this_video.rb, line 24
def self.encode_this_video(
    i = ARGV, use_this_mode = :CRF
  )
  [i].flatten.compact.each {|this_video|
    if File.exist? this_video
      output_filename = 'output_'+
                        this_video.
                        sub(/#{File.extname(this_video)}$/,'')+
                        '.mkv'
      case use_this_mode
      when :CRF, :default
        _ = 'ffmpeg -i '+this_video+' -c:v libx264 '\
            '-preset slow -crf 22 -c:a copy '+output_filename
        esystem _
      end
    else
      e 'No file exists at '+this_video+'.'
    end
  }
end
ensure_that_the_output_directory_exists( output_directory = MultimediaParadise.output_directory? ) click to toggle source
#

MultimediaParadise.ensure_that_the_output_directory_exists

We must make sure that the output directory exists, hence the check belove and the call to FileUtils.mkdir_p().

#
# File lib/multimedia_paradise/toplevel_methods/ensure_that_the_output_directory_exists.rb, line 17
def self.ensure_that_the_output_directory_exists(
    output_directory = MultimediaParadise.output_directory?
  )
  unless File.exist? output_directory
    FileUtils.mkdir_p(
      output_directory
    )
  end
end
esystem( i, optional_colour_to_use = nil ) click to toggle source
#

MultimediaParadise.esystem

The second argument can be like this:

colour: :slateblue

Currently only Hashes are supported like that.

#
# File lib/multimedia_paradise/toplevel_methods/esystem.rb, line 21
def self.esystem(
    i, optional_colour_to_use = nil
  )
  Signal.trap('SIGINT') { exit }
  i = i.dup if i.frozen?
  i.strip!
  display_this_string = i.dup
  if optional_colour_to_use
    if optional_colour_to_use.is_a?(Hash) and
       optional_colour_to_use.has_key?(:colour)
      use_this_colour = optional_colour_to_use[:colour]
      display_this_string = COLOURS.send(use_this_colour, display_this_string) 
    end
  end
  e display_this_string
  system i
end
extract_audio( i, optional_store_where = :default, &block ) click to toggle source
#

MultimediaParadise.extract_audio (extract tag)

Class method to extract audio from a given multimedia file.

Please note - we can not strip away any extensions from this method here, so we must ensure that the data passed to our method is sane before continuing. (The reason we cant yet strip away stuff is that other methods rely on the follow-up input/output)

To test this method, try:

require 'multimedia_paradise'; MultimediaParadise.extract_audio 'break-741.wmv'

An alternative way would be this:

ffmpeg -i Ivanhoe.avi audio.mp3

Most of the time we will use ffmpeg, but via mencoder we can also extract the audio.

Another usage example:

require 'multimedia_paradise'; x = MultimediaParadise.extract_audio('/Depot/j/Ozzy_Man.mkv'); pp x # => "/Depot/j/Ozzy_Man.mkv.mp3"
#
# File lib/multimedia_paradise/audio/extract_audio/extract_audio.rb, line 393
def self.extract_audio(
    i,
    optional_store_where = :default,
    &block
  )
  if i.is_a? Array
    i.each {|entry| # Recursive-call here.
      MultimediaParadise.extract_audio(entry, optional_store_where, &block)
    }
  else
    _ = ::MultimediaParadise::ExtractAudio.new(i, optional_store_where, &block)
    return _.file_location?
  end
end
extract_audio_from_until( this_file, from_start_pos = 30, duration = 30 ) click to toggle source
#

MultimediaParadise.extract_audio_from_until

Usage example:

MultimediaParadise.extract_audio_from_until('/Depot/j/foobar.mp4', 25, 35)
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 697
def self.extract_audio_from_until(
    this_file,
    from_start_pos = 30, 
    duration       = 30
  )
  this_file = File.absolute_path(this_file)
  base_dir = File.dirname(this_file)
  output_file = 'CLIPPED_'+File.basename(this_file)
  output_file = base_dir+'/'+output_file
  this_command = 'ffmpeg -y'+ # -y for "automatically overwrite".
                 ' -i '+this_file+' -ss '+from_start_pos.to_s+
                 ' -t '+duration.to_s+' '+output_file
  run_sys_command this_command
end
extract_images_from_this_video_file(*i) click to toggle source
#

MultimediaParadise.extract_images_from_this_video_file

This variant uses the default rate, which is 25 images per second.

Note that the method is named incorrectly; in the long run I may rename it (written in January 2020).

Usage example:

MultimediaParadise.extract_images_from_this_video_file('foobar.mp4')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 518
def self.extract_images_from_this_video_file(*i)
  i.flatten.each {|entry|
    _extension_to_use = File.extname(entry) # No longer in use.
    _ = 'ffmpeg '\
        '-i '+entry+
        ' %08d.png' #OUTPUT_'+entry.sub(/#{extension_to_use}$/,'')+
        # extension_to_use+
    e
    esystem _
    e
  }
end
extract_one_image_per_second( from_this_video_file = 'my_video.mpeg', frame_size_to_use = '75x75' ) click to toggle source
#

MultimediaParadise.extract_one_image_per_second

This method will extract one-image-per-second from a given input video file.

The first argument to this method should be the video file you are working with, such as ‘foobar.mp4’.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 540
def self.extract_one_image_per_second(
    from_this_video_file = 'my_video.mpeg',
    frame_size_to_use    = '75x75'
  )
  extension_to_use = File.extname(from_this_video_file)
  _ = 'ffmpeg -i '+from_this_video_file+
      ' -r 1 '+ # ← Specify the video-frame here, aka "1 image per second".
      '-s '+frame_size_to_use+
      ' OUTPUT_'+from_this_video_file.sub(/#{extension_to_use}$/,'')+
      extension_to_use
  e
  esystem _
  e
end
extract_video(this_file) click to toggle source
#

MultimediaParadise.extract_video

Extract the video portion using mencoder.

The return value will be the new filepath in question, or nil otherwise.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 797
def self.extract_video(this_file)
  new_file_location = nil
  if this_file.is_a? Array
    this_file = this_file.first # For now, we only use the first member.
  end
  name_of_the_extension = File.extname(this_file.delete('.'))
  output_file_name = 'video_extracted_from_'+
                     File.basename(this_file.sub(/\.avi$/,'')).
                     sub(/#{name_of_the_extension}$/,'')+'.avi'
  output_file_name = output_file_name.squeeze('.')
  _ = 'mencoder -idx -ovc copy -nosound '+this_file+' -o '+output_file_name
  run_sys_command _ if _
  new_file_location = output_file_name
  return new_file_location
end
ffmpeg_analyze_audio_stream( of_this_file ) click to toggle source
#

MultimediaParadise.ffmpeg_analyze_audio_stream

This method will use ffmpeg in order to analyze the audio stream.

A Hash will be returned by this method, which will keep the decibel-score value.

An example result can be seen next:

[Parsed_volumedetect_0 @ 0x1f32d80] n_samples: 20468176
[Parsed_volumedetect_0 @ 0x1f32d80] mean_volume: -15.9 dB
[Parsed_volumedetect_0 @ 0x1f32d80] max_volume: -0.9 dB
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_0db: 4
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_1db: 91
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_2db: 546
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_3db: 1906
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_4db: 6486
[Parsed_volumedetect_0 @ 0x1f32d80] histogram_5db: 36079

The Hash may then be like this:

{"/Depot/Audio/Sumo_Knockouts_2018.mp3"=> {:maximum_volume=>-0.9, :mean_volume=>-15.9}}
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 462
def self.ffmpeg_analyze_audio_stream(
    of_this_file
  )
  hash = {}
  of_this_file = [of_this_file].flatten.compact
  of_this_file.each {|this_file|
    hash[this_file] = {}
    _ = 'ffmpeg -i '+this_file+' -af "volumedetect" -f null /dev/null 2>&1'
    e
    result = `#{_}`
    max_volume_is = result.scan(/max_volume: (.+)$/).flatten.first.sub(/ dB/,'').to_f
    hash[this_file][:maximum_volume] = max_volume_is # in decibel, dB.
    mean_volume_is = result.scan(/mean_volume: (.+)$/).flatten.first.sub(/ dB/,'').to_f
    hash[this_file][:mean_volume] = mean_volume_is
  }
  hash
end
ffmpeg_chop_into_segments_of_n_seconds_size( this_file, n_seconds = 60 ) click to toggle source
#

MultimediaParadise.ffmpeg_chop_into_segments_of_n_seconds_size

Use this (audio) method to chop up an audio file into segments of n size. You could also use this on a video file, but the primary use of it is to chop up a large audio file into smaller audio files.

The first argument is the name (path) of the file that you wish to modify.

If only one argument is provided (the filename), then we will default to a duration of 60 seconds.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 333
def self.ffmpeg_chop_into_segments_of_n_seconds_size(
    this_file, # <- Your target file that will be chopped up.
    n_seconds = 60
  )
  if this_file
    this_file = this_file.dup if this_file.frozen?
    extname = File.extname(this_file)
    filename = this_file.sub(/#{extname}/,'')
    _ = 'ffmpeg -i '+this_file+' -f segment -segment_time '+n_seconds.to_s+' -c copy out_'+filename+'_%03d'+extname
    esystem(_)
  end
end
ffmpeg_chroma_subsampling(this_video) click to toggle source
#

MultimediaParadise.ffmpeg_chroma_subsampling

Chroma subsampling is the practice of encoding images by implementing less resolution for chroma information (i.e. color information) than for luma information (brightness information), taking advantage of the human visual system’s lower acuity for color differences than for luminance.

Note that yuv420p denotes 4:2:0 chroma subsampling.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 63
def self.ffmpeg_chroma_subsampling(this_video)
  esystem 'ffmpeg -i '+this_video+' -vf format=yuv420p output.mp4'
end
ffmpeg_convert_this_multimedia_file( input_file = 'input.mp3', output_file = :mkv ) { || ... } click to toggle source
#

MultimediaParadise.ffmpeg_convert_this_multimedia_file

This method can be used to convert a file from A to B, through ffmpeg.

Remember that the command ffmpeg -codecs will print every codec FFmpeg knows about.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 565
def self.ffmpeg_convert_this_multimedia_file(
    input_file  = 'input.mp3',
    output_file = :mkv #'output.ogg'
  )
  yielded = nil
  if block_given?
    yielded = yield
  end
  if File.exist? input_file
    case output_file
    when :mkv
      extname = File.extname(input_file)
      use_this_name = input_file.
                      sub(/#{extname}$/,'')
      output_file = use_this_name+'.mkv'
    end
    _ = "ffmpeg -i #{input_file}"
    case yielded
    # ===================================================================== #
    # === :copy_audio
    # ===================================================================== #
    when :copy_audio
      _ << ' -c:a copy' 
    # ===================================================================== #
    # === :libvorbis_audiostream
    # ===================================================================== #
    when :libvorbis_audiostream
      _ << ' -c:a libvorbis'
    # ===================================================================== #
    # === :vp9_codec
    # ===================================================================== #
    when :vp9_codec
      _ << ' -c:v vp9' 
    else
      if yielded.is_a? Hash
        # ================================================================= #
        # === :framerate
        # ================================================================= #
        if yielded.has_key? :framerate
          _ << " -r #{yielded.delete(:framerate)}"
        end
      end
    end
    _ << " #{output_file}"
    e _
    system _
  else
    e 'No file exists at '+input_file+'.'
  end
end
ffmpeg_deinterlace_this_video(this_video) click to toggle source
#

MultimediaParadise.ffmpeg_deinterlace_this_video

Deinterlacing is done generally on older videos or videos that had been used for broadcasting purposes to minimize the interlacing effect.

Yadif (“yet another deinterlacing filter”) is the name of the filter used by ffmpeg.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 77
def self.ffmpeg_deinterlace_this_video(this_video)
  esystem 'ffmpeg -i '+this_video+' -vf yadif output.mp4'
end
ffmpeg_delay_audio( this_file = ARGV, by = '3.85 seconds' ) click to toggle source
#

MultimediaParadise.ffmpeg_delay_audio

This method will delay the audio of a video-file, by n-seconds.

The second argument to this method, ‘by`, handles that delay.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 415
def self.ffmpeg_delay_audio(
    this_file = ARGV,
    by        = '3.85 seconds' # <- Input your delay here.
  )
  if this_file.is_a? Array
    this_file.each {|entry|
      ffmpeg_delay_audio(entry, by)
    }
  else
    by = by.to_s # Need a String past this point here.
    by.sub!(/ seconds/,'') if by.include? ' seconds' # Strip away ' seconds'.
    _ = 'ffmpeg -i "'+this_file+'"'.dup
    _ << ' -itsoffset '+by
    _ << ' -map 0:v -map 1:a -c copy'
    # ===================================================================== #
    # Next, determine the output-file.
    # ===================================================================== #
    _ << ' "OUTPUT_WITH_DELAYED_AUDIO_'+this_file+'"'
    esystem _
  end
end
ffmpeg_denoise( input_file, lowpass_value = 3000, highpass_value = 200 ) click to toggle source
#

MultimediaParadise.ffmpeg_denoise

This method attempts to remove noise from a multimedia file.

Note that this uses ffmpeg. Sox can also be used to filter away noise. The first argument is for the lowpass value; the second argument is for the highpass value.

The FFMPEG highpass filter is explained here:

https://ffmpeg.org/ffmpeg-filters.html#highpass
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 360
def self.ffmpeg_denoise(
    input_file,
    lowpass_value  = 3000,
    highpass_value =  200
  )
  if input_file.is_a? Array
    if input_file.empty?
      opn; e "Please provide at the least one file name to the method "\
             "#{sfancy(__method__.to_s+'()')}"
    else
      input_file.each {|entry|
        ffmpeg_denoise(entry, lowpass_value, highpass_value)
      }
    end
  else
    _ = 'ffmpeg -i '+input_file+' '
    _ << '-af "'
    _ << 'lowpass=f='+lowpass_value.to_s+','
    _ << 'highpass=f='+highpass_value.to_s
    _ << '" '
    _ << 'denoised_output_'+input_file.to_s
    esystem _
  end
end
ffmpeg_extract_audio( i = input.mkv, o = :ogg ) click to toggle source
#

MultimediaParadise.ffmpeg_extract_audio

This method will specifically use ffmpeg in order to extract the audio from a video or audio file.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 542
def self.ffmpeg_extract_audio(
    i = input.mkv, # The input filename.
    o = :ogg       # The output filename.
  )
  extname = File.extname(i)
  case o
  when :ogg
    use_this_name = i.
                    sub(/#{extname}$/,'')
    o = use_this_name+'.ogg'
  end
  esystem 'ffmpeg -i '+i+' -vn '+o
end
ffmpeg_flip_video_to_the_left(i) click to toggle source
#

MultimediaParadise.ffmpeg_flip_video_to_the_left

This toplevel-method can be used to flip a video to the left, that is, to rotate it by -90 degrees.

Strangely enough the number 2 denotes left-hand flipping (or, to remain in ffmpeg-parlance, this means “90°CounterClockwise” rotation).

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 531
def self.ffmpeg_flip_video_to_the_left(i)
  _ = "ffmpeg -i #{i} -vf transpose=2 flipped_to_the_left_#{i}"
  esystem _
end
ffmpeg_flip_video_to_the_right(i) click to toggle source
#

MultimediaParadise.ffmpeg_flip_video_to_the_right

This toplevel-method can be used to flip a video to the right, that is, to rotate it by +90 degrees.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 516
def self.ffmpeg_flip_video_to_the_right(i)
  _ = "ffmpeg -i #{i} -vf transpose=1 flipped_to_the_right_#{i}"
  esystem _
end
ffmpeg_horizontal_flip(this_video_file) click to toggle source
#

MultimediaParadise.ffmpeg_horizontal_flip

This method will make use of the video-filter called “hflip”.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 215
def self.ffmpeg_horizontal_flip(this_video_file)
  if this_video_file.is_a? Array
    this_video_file.each {|entry| horizontal_flip(entry) }
  else
    extname = File.extname(this_video_file)
    output_name = 'horizontal_flip_'+this_video_file.sub(/#{extname}/,'')+extname
    _ = 'ffmpeg -i '+this_video_file+' -vf "hflip" '+output_name
    esystem _
    output_name # <- Also return the output filename here.
  end
end
ffmpeg_increase_volume_of_this_audio_file( input_file, modify_volume_by_this_value = '5.0' ) click to toggle source
#

MultimediaParadise.ffmpeg_increase_volume_of_this_audio_file

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 255
def self.ffmpeg_increase_volume_of_this_audio_file(
    input_file,
    modify_volume_by_this_value = '5.0' # or 3.0 or 4.0 and so forth.
  )
  [input_file].flatten.compact.each {|this_file|
    _ = 'ffmpeg -i '+this_file+' -vcodec copy -af "volume='+modify_volume_by_this_value.to_s+
       '" output_'+this_file
    esystem _
  }
end
ffmpeg_query_the_audio_codec_of_this_file(i) click to toggle source
#

MultimediaParadise.ffmpeg_query_the_audio_codec_of_this_file

This method will return a String - the audio codec in use.

We will use ffmpeg for this and scan for an entry such as:

"    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)"

Many .mp4 files typically use the “aac” codec. .avi files on the other hand, are often using the mp3 codec for their audio data.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 162
def self.ffmpeg_query_the_audio_codec_of_this_file(i)
  # ======================================================================= #
  # See: https://rubular.com/r/8KrR1NTUq9hQU8
  # ======================================================================= #
  use_this_regex = /Audio: ([a-zA-Z0-9]{0,10})/
  result = []
  i = [i].flatten.map
  i.each {|this_file|
    _ = `ffmpeg -i #{this_file} 2>&1`.split("\n")
    _.select! {|line|
      line.include? ': Audio: '
    }
    _.map! {|entry|
      entry =~ use_this_regex
      $1.to_s.dup
    }
    result << _.first
  }
  result
end
ffmpeg_return_image_from_this_video_file( input_file = 'input.mp4', starting_position = 5, width_and_height_for_the_image = '480x270' ) click to toggle source
#

MultimediaParadise.ffmpeg_return_image_from_this_video_file

Invocation example:

MultimediaParadise.return_image_from_this_video_file()
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 39
def self.ffmpeg_return_image_from_this_video_file(
    input_file = 'input.mp4',
    starting_position = 5, # in n seconds
    width_and_height_for_the_image = '480x270'
  )
  esystem 'ffmpeg -i '+input_file+' -vframes 1 -an -s '+
          width_and_height_for_the_image.to_s+' '+
          '-y -ss '+
          starting_position.to_s+' output.jpg'
end
ffmpeg_rotate_this_video_file_by_90_degrees( this_video_file ) click to toggle source
#

MultimediaParadise.ffmpeg_rotate_this_video_file_by_90_degrees

This method can be used to rotate a video file by 90°. Sometimes smartphones create tilted videos, so this method can correct this distortion.

This can be fixed by using FFMPEG’s transpose filter. The transpose value will work in multiples of 90, so “1” means 90°.

Invocation example:

MultimediaParadise.ffmpeg_rotate_this_video_file_by_90_degrees('foo.mpg')
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 243
def self.ffmpeg_rotate_this_video_file_by_90_degrees(
    this_video_file
  )
  output_file = 'output_'+this_video_file+'.mp4' 
  _ = 'ffmpeg -i '+this_video_file+' -vf transpose=1 '+output_file
  esystem _
  output_file # <- And return the output file too.
end
ffmpeg_scale_this_video( this_video, optional_hash = {} ) click to toggle source
#

MultimediaParadise.ffmpeg_scale_this_video

This method can be used to scale (resize) a video.

The first argument should be the path to a local video file. If an Array is passed then this method will attempt to batch-process that given input (and assume that this input is an array of locally existing files).

Invocation examples:

MultimediaParadise.ffmpeg_scale_this_video('input.mp4', height: 320)
MultimediaParadise.ffmpeg_scale_this_video('input.mp4', height: 320, height: -1)
MultimediaParadise.resize('yo.mp4', height: 320)
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 98
def self.ffmpeg_scale_this_video(
    this_video, optional_hash = {}
  )
  if this_video.is_a? Array
    this_video.each {|entry| ffmpeg_scale_this_video(entry) }
  else
    use_this_as_output_file = 'output.mp4'
    cmd = ''.dup
    cmd << 'ffmpeg -i'
    cmd << " #{this_video}"
    # ===================================================================== #
    # Height and width must be determined before the next step. Set them to
    # nil first.
    # ===================================================================== #
    width = nil
    height = nil
    if optional_hash.is_a? Hash
      # ======================================================================= #
      # === :height
      # ======================================================================= #
      if optional_hash.has_key? :height
        height = optional_hash.delete(:height)
      end
      # ======================================================================= #
      # === :width
      # ======================================================================= #
      if optional_hash.has_key? :width
        width = optional_hash.delete(:width)
      end
    end
    if width.nil?
      width = 1080 # Currently hardcoded on purpose. Used to be 640 in the past.
    end
    if height.nil?
      height = -1
    end
    cmd << " -vf scale=#{width}:#{height}"
    if File.exist? use_this_as_output_file
      random_number = rand(100)+1 # Pick a "random" name for the file.
      use_this_as_output_file = "output#{random_number}.mp4"
    end
    # ===================================================================== #
    # Add the name of the output file next:
    # ===================================================================== #
    cmd << " #{use_this_as_output_file}"
    e
    esystem cmd
    e
  end
end
ffmpeg_slow_down_this_video_file( this_video_file = ARGV, pts_value_to_use = 2.0 ) click to toggle source
#

MultimediaParadise.ffmpeg_slow_down_this_video_file

This method can be used to slow down a video file.

FFmpeg will be doing this slow down action.

This uses the “setpts” video filter of ffmpeg, for the video stream at hand. The video stream can be changed without tampering with the audio stream. This is also the default modus operandi for this method here.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 492
def self.ffmpeg_slow_down_this_video_file(
    this_video_file  = ARGV,
    pts_value_to_use = 2.0
  )
  if this_video_file.is_a? Array
    this_video_file.each {|entry|
      ffmpeg_slow_down_this_video_file(entry, pts_value_to_use)
    }
  else
    # ===================================================================== #
    # To slow down a video, a  multiplier greater than 1 has to be used:
    # ===================================================================== #
    _ = "ffmpeg -i #{this_video_file} -filter:v \"setpts=#{pts_value_to_use}*PTS\" "\
        "OUTPUT_SLOWED_DOWN_VIDEO_#{this_video_file}"
    esystem _
  end
end
ffmpeg_start_screencast( use_this_screen_resolution = return_screen_resolution, output_filename = 'screencast', use_this_framerate = '25', use_this_video_codec = 'huffyuv' ) click to toggle source
#

MultimediaParadise.ffmpeg_start_screencast

This method can be used to “record” the desktop, by making use of x11grab and the huffyuv codec.

If more flexibility is required then this may be added at a later time.

Keep in mind that this will create HUGE files depending on the video codec in use - like 20 seconds may occupy 2 gigabytes for the lossless huffyuv codec.

If you wish to use different video or audio codecs, you can use these commandline flags:

-vcodec: video encoding codec
-acodec: audio encoding codec

To record the desktop only, one could use a commandline flag such as this one here:

ffmpeg -f x11grab -s 1366x768 -i :0.0 -r 25 -vcodec libx264 output.mkv
ffmpeg -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec huffyuv screencast.avi

For some useful links (should these persist), have a look at:

https://www.pcsuggest.com/linux-screen-recorder-ffmpeg/
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 295
def self.ffmpeg_start_screencast(
    use_this_screen_resolution = return_screen_resolution, # <- We will use the default screen-resolution here.
    output_filename            = 'screencast',
    use_this_framerate         = '25',
    use_this_video_codec       = 'huffyuv' # <- or libx264, for instance.
  )
  # ======================================================================= #
  # Must use a proper output-format. By default this will be .mkv,
  # although it could also be .avi.
  # ======================================================================= #
  unless output_filename.include? '.'
    output_filename = output_filename.dup if output_filename.frozen?
    output_filename << '.mkv'
  end
  _ = 'ffmpeg -f x11grab -r '+
      use_this_framerate.to_s+' -s '
  _ << use_this_screen_resolution+' '
  _ << ' -i :0.0 '
  _ << '-vcodec '+use_this_video_codec+' '
  #_ << '-f alsa -i hw:0 '
  _ << ' '+output_filename
  esystem _
end
ffmpeg_to_mp4(*these_files) click to toggle source
#

MultimediaParadise.ffmpeg_to_mp4

This method can be used to convert any video to a .mp4 format, by making use of ffmpeg.

The input to this method should be the files that you wish to convert into the .mp4 format.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 22
def self.ffmpeg_to_mp4(*these_files)
  output_file = 'foobar.mp4'
  _ = 'ffmpeg -i '+[these_files].flatten.compact.join(' ')+
      ' -vcodec copy -acodec copy '+
      output_file
  esystem _
  return output_file
end
ffmpeg_use_lame_codec( this_video_file ) click to toggle source
#

MultimediaParadise.ffmpeg_use_lame_codec

Use this method if you quickly want to replace one audio codec with another - in this context the lame (liblame) audio codec.

The input should be a locally existing video file. The -acodec value will be libmp3lame.

The input to this method should be an existing video file.

#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 396
def self.ffmpeg_use_lame_codec(
    this_video_file
  )
  this_video_file = [this_video_file].flatten.compact
  this_video_file.each {|video_file|
    output_file = "output_#{File.basename(video_file)}"
    _ = 'ffmpeg -i "'+video_file+
        '" -vcodec copy -acodec libmp3lame "'+output_file+'"'
    esystem _
  }
end
ffmpeg_vertical_flip(this_video_file) click to toggle source
#

MultimediaParadise.ffmpeg_vertical_flip

This method will make use of the video-filter called “vflip”. A vertical flip will flip the video from head-to-bottom, so people will suddenly appear as if they are hanging from the ceiling. :)

Invocation example:

MultimediaParadise.ffmpeg_vertical_flip '/Depot/Video/Reallife/O.J.Simpson_TV_News_etwa_1995.avi'
#
# File lib/multimedia_paradise/ffmpeg/ffmpeg.rb, line 196
def self.ffmpeg_vertical_flip(this_video_file)
  if this_video_file.is_a? Array
    this_video_file.each {|entry| ffmpeg_vertical_flip(entry) }
  else
    extname = File.extname(this_video_file)
    base_dir = File.dirname(this_video_file)
    filename = File.basename(this_video_file)
    output_name = base_dir+'/vertical_flip_'+filename.sub(/#{extname}/,'')+extname
    _ = 'ffmpeg -i '+this_video_file+' -vf "vflip" '+output_name
    esystem _
    output_name # <- Also return the output name here.
  end
end
file_does_not_exist(file) click to toggle source
#

MultimediaParadise.file_does_not_exist

Use this method when reporting that a file does not exist (or was not found).

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 610
def self.file_does_not_exist(file)
  e "No file exists at `#{sfile(file)}`."
end
file_duration_of(i) click to toggle source
#

MultimediaParadise.file_duration_of

This method will return, as number, the file duration of e. g. an audio file. Other than that it is silent, so it will not output anything on the commandline.

Usage example:

require 'multimedia_paradise/multimedia/file_duration.rb'

MultimediaParadise.duration? '/home/x/songs/WetWetWet_Loveisallaround.mp3'
MultimediaParadise.length_of?('/home/x/songs/Veracocha_CarteBlancha.mp3')
#
# File lib/multimedia_paradise/audio/file_duration/file_duration.rb, line 583
def self.file_duration_of(i)
  duration = ::MultimediaParadise::FileDuration.new(i) {
    :be_quiet_and_we_may_not_exit
  }.duration?
  return duration
end
file_lyrics() click to toggle source
#

MultimediaParadise.file_lyrics

#
# File lib/multimedia_paradise/constants/file_constants.rb, line 28
def self.file_lyrics
  FILE_LYRICS
end
file_radio_stations() click to toggle source
#

MultimediaParadise.file_radio_stations

#
# File lib/multimedia_paradise/constants/file_constants.rb, line 106
def self.file_radio_stations
  FILE_RADIO_STATIONS
end
file_tales_from_the_crypt() click to toggle source
#

MultimediaParadise.file_tales_from_the_crypt

#
# File lib/multimedia_paradise/constants/file_constants.rb, line 162
def self.file_tales_from_the_crypt
  "#{MultimediaParadise.project_yaml_dir?}tales_from_the_crypt/tales_from_the_crypt.yml"
end
file_tv_channels() click to toggle source
#

MultimediaParadise.file_tv_channels

This method will return a String such as:

"/usr/lib/ruby/site_ruby/3.0.0/multimedia_paradise/yaml/tv_channels/tv_channels.yml"
#
# File lib/multimedia_paradise/constants/file_constants.rb, line 155
def self.file_tv_channels
  "#{PROJECT_YAML_DIRECTORY}tv_channels/tv_channels.yml"
end
file_video_collection?() click to toggle source
#

MultimediaParadise.file_video_collection?

Easier toplevel-method to find out where the file storing all local videos is kept at.

The file path returned by this method would typically be at:

/home/x/DATA/VIDEO/yaml/video_collection.yml
#
# File lib/multimedia_paradise/constants/file_constants.rb, line 140
def self.file_video_collection?
  FILE_VIDEO_COLLECTION
end
filter_for_video_files(array) click to toggle source
#

MultimediaParadise.filter_for_video_files

This filter will only return video files.

#
# File lib/multimedia_paradise/toplevel_methods/is_video_file.rb, line 51
def self.filter_for_video_files(array)
  array.select {|entry| is_video_file?(entry) }
end
filter_for_video_files_from( this_directory ) click to toggle source
#

MultimediaParadise.filter_for_video_files_from

This method accepts as input an Array. That array will then be filtered to include ONLY video files.

#
# File lib/multimedia_paradise/toplevel_methods/is_video_file.rb, line 35
def self.filter_for_video_files_from(
    this_directory
  )
  if this_directory.is_a?(String) and File.directory?(this_directory)
    this_directory = Dir["#{this_directory}/*"]
  end
  this_directory.select {|entry|
    is_video_file? entry
  }
end
find_this_video( i, be_silent_or_be_verbose = :be_verbose ) click to toggle source
#

MultimediaParadise.find_this_video

Usage examples:

result = MultimediaParadise.find_this_video('glad')
result = MultimediaParadise.find_this_video('24')
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 421
def self.find_this_video(
    i,
    be_silent_or_be_verbose = :be_verbose
  )
  _ = MultimediaParadise::FindVideo.new(i, be_silent_or_be_verbose)
  return _.find_video
end
flash_to_mp4(input_file = 'input.flv') click to toggle source
#

MultimediaParadise.flash_to_mp4

Do flash .flv to .mp4 conversion.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 400
def self.flash_to_mp4(input_file = 'input.flv')
  if File.exist? input_file
    cmd  = 'ffmpeg '
    cmd << '-i '+input_file+' '
    cmd << '-an output.mp4  '
    run_sys_command cmd
  end
end
flash_to_mpg( input_file = 'jokes.flv', output_file = 'jokes.mpg' ) click to toggle source
#

MultimediaParadise.flash_to_mpg

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 265
def self.flash_to_mpg(
    input_file  = 'jokes.flv',
    output_file = 'jokes.mpg'
  )
  if File.exist? input_file
    cmd = 'ffmpeg -i '
    cmd << input_file
    cmd << ' -ab 56 -ar 22050 -b 500 -s 320×240 '
    cmd << output_file
    run_sys_command cmd
  end
end
flip_video_to_the_left(i) click to toggle source
#

MultimediaParadise.flip_video_to_the_left

This toplevel-method can be used to flip a video to the left, that is, to rotate it by -90 degrees.

It will tap into ffmpeg for this task.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 701
def self.flip_video_to_the_left(i)
  ffmpeg_flip_video_to_the_left(i)
end
flip_video_to_the_right(i) click to toggle source
#

MultimediaParadise.flip_video_to_the_right

This toplevel-method can be used to flip a video to the right, that is, to rotate it by +90 degrees.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 711
def self.flip_video_to_the_right(i)
  ffmpeg_flip_video_to_the_right(i)
end
for_ipod() click to toggle source
#

MultimediaParadise.for_ipod

Convert to ipod.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 619
def self.for_ipod
  cmd = 'mencoder -ovc raw -ofps 15 -oac pcm '.dup
  cmd << '-vf scale=176:-2,expand=176:132,format=bgr16 input.file '
  cmd << '-o output.avi'
end
general_format_conversion( input_file, target_file ) { || ... } click to toggle source
#

MultimediaParadise.general_format_conversion

Use ffmpeg here in a simplified manner through this method, in order to convert one format to another one.

Simply provide the input file as the first argument to this method, and the desired target file as the second argument. See the following usage examples for how to use this method specifically.

Usage examples:

MultimediaParadise.general_format_conversion('foo.wav','foo.mp3')
MultimediaParadise.convert('foobar.mp3', to: 'wav')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 73
def self.general_format_conversion(
    input_file,  # Such as 'foobar.wav'.
    target_file, # Such as 'foobar.mp3'.
    &block
  )
  if input_file.is_a? Array
    input_file.each {|entry|
      general_format_conversion(entry, target_file, &block)
    }
  else
    if target_file.is_a? Hash
      # =================================================================== #
      # === :to
      #
      # Allow support for the ":to" keyword.
      # =================================================================== #
      if target_file.has_key? :to
        target_file = target_file.delete(:to)
      end
    end
    # ===================================================================== #
    # The variable target_file may be a symbol. Check this first.
    #
    # We work on the target_file first.
    # ===================================================================== #
    case target_file.to_s
    # ===================================================================== #
    # === to_webm
    # ===================================================================== #
    when /^to(_|-)?webm$/i,
         /webm$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.webm'
    # ===================================================================== #
    # === to_ogg
    # ===================================================================== #
    when /^to(_|-)?ogg$/i,
         /ogg$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.ogg'
    # ===================================================================== #
    # === to_aac
    # ===================================================================== #
    when /^to(_|-)?aac$/i,
         /\.?aac$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.aac'
    # ===================================================================== #
    # === to_dv
    # ===================================================================== #
    when /^to(_|-)?dv$/i,
         /\.?dv$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.dv'
    # ===================================================================== #
    # === to_wav
    # ===================================================================== #
    when /^to(_|-)?wav$/i,
         /wav$/i,
         '2wav'
      target_file = input_file.gsub(File.extname(input_file), '')+'.wav'
    # ===================================================================== #
    # === to_mp3
    # ===================================================================== #
    when /^to(_|-)?mp3$/i,
         /mp3$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.mp3'
    # ===================================================================== #
    # === to_mp3
    # ===================================================================== #
    when /^to(_|-)?mp3$/i,
         /mp3$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.mp3'
    # ===================================================================== #
    # === to_opus
    # ===================================================================== #
    when /^to(_|-)?opus$/i,
         /opus$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.opus'
    # ===================================================================== #
    # === to_wv
    # ===================================================================== #
    when /^to(_|-)?wv$/i,
         /wv$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.wv'
    # ===================================================================== #
    # === to_wma
    # ===================================================================== #
    when /^to(_|-)?wma$/i,
         /wma$/i
      target_file = input_file.gsub(File.extname(input_file), '')+'.wma'
    end unless target_file.to_s.include?('/')
    # ===================================================================== #
    #          ^^^ here we assume the second argument to be like this: /Depot/j/yodel.wav
    # ===================================================================== #
    # ===================================================================== #
    # The "target_file" variable may be something such as '.wma'
    # In this case, the file name is missing. We fix this problem
    # by using the real name of the input_file as output format.
    # ===================================================================== #
    if target_file.start_with? '.'
      if input_file.include? '.'
        target_file = input_file[0, input_file.index('.')]+target_file
      end
    end if target_file.respond_to? :start_with?
    target_file = rds(target_file)
    target_file = File.absolute_path(target_file)
    if File.exist? input_file
      cliner {
        please_be_patient(
          input_file, 'to '+File.extname(target_file)+' format'
        )
        ::MultimediaParadise.display_warning(:lossy)
      }
      # =================================================================== #
      # By default we will use ffmpeg, but this can be changed to sox or
      # any other toolkit.
      # =================================================================== #
      _ = "#{::MultimediaParadise.use_this_binary_for_conversions?} -y ".dup
      _ << " -i #{input_file} "
      # =================================================================== #
      # Do some ad-hoc clean up next.
      # -ac means audio_channel
      # =================================================================== #
      if target_file.end_with?('.opus')
        _ << '" -ar 48000 -ac 2 -acodec libopus -ab 256k '
      elsif target_file.end_with?('.ogg')
        _ << ' -acodec libvorbis -aq 60 '
      end
      if block_given?
        yielded = yield
        if yielded.is_a? Hash
          # =============================================================== #
          # === :bitrate_to_use
          # =============================================================== #
          if yielded.has_key? :bitrate_to_use
            # -b:a will convert the audio bitrate to be exactly that value.
            _ << ' -b:a '+yielded[:bitrate_to_use].to_s+'k'
          end
        end
      end
      _ << " #{target_file}"
      _.squeeze!(' ')
      run_sys_command _
      # =================================================================== #
      # Since as of August 2016, we will return the path to the newly
      # generated file.
      # =================================================================== #
      return target_file.to_s
    else
      file_does_not_exist(input_file)
    end
  end
end
generate_sine_tone( n_seconds = 5 ) click to toggle source
#

MultimediaParadise.generate_sine_tone

Generate a n-second sine tone.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 321
def self.generate_sine_tone(
    n_seconds = 5
  )
  output_file = 'output.wav'
  esystem 'sox -n '+output_file+' synth '+n_seconds.to_s+' sine 440'
  return output_file
end
generate_sine_tone_sweep( n_seconds = 5 ) click to toggle source
#

MultimediaParadise.generate_sine_tone_sweep

Generate a n-second sine tone sweep.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 334
def self.generate_sine_tone_sweep(
    n_seconds = 5
  )
  output_file = 'output.wav'
  esystem 'sox -n '+output_file+' synth '+n_seconds.to_s+' sine 0:800'
  return output_file
end
has_this_video_file?(this_file) click to toggle source
#

MultimediaParadise.has_this_video_file?

This method can be used to query whether there is a video registered with the given name.

This method will return a boolean value, true/false.

o It will return true  if the video file is registered.
o It will return false if the video file is NOT registered.

Usage examples:

result_has_this_video_file = MultimediaParadise.has_this_video_file?('Glad')
result_has_this_video_file = MultimediaParadise.has_this_video_file?('Gladd')
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 460
def self.has_this_video_file?(this_file)
  result = MultimediaParadise.find_this_video(this_file, :be_silent)
  if result.is_a? Hash
    if result.empty?
      result = false
    else
      result = true
    end
  elsif result.is_a? Array
    result = true unless result.empty?
  end
  return result
end
high_quality_transcoding_of_this_video_file(this_video_file) click to toggle source
#

MultimediaParadise.high_quality_transcoding_of_this_video_file

This method can be used for high-quality transcoding of a given input video file.

  • C:V is the video codec of choice

  • preset is the compression preset (in this case slow for higher

    quality compression)
  • CRF is the Constant Rate Factor, which preserves an overall level of quality throughout the file by adjusting each frame’s bitrate based on the given quality level. The higher the CRF, the lower the overall quality level.

  • The video filter flag (-vf) is used to call FFMPEG’s pre-bundled video filters.

  • yadif (Yet Another Deinterlacing Filter) deinterlaces an interlaced input, as progressive video is not only easier to compress and most current computer monitors and televisions are progressive scan.

  • When encoding with H.264/MPEG-4 AVC, the audio format used is AAC (Advanced Audio Coding); in order to enable FFMPEG’s experimental, native AAC encoder.

  • -strict -2 needs to be added to the command.

  • An external library such as libfaac can also be used, and -strict -2 can be omitted.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 591
def self.high_quality_transcoding_of_this_video_file(this_video_file)
  output_file = 'OUTPUT_'+this_video_file.
                sub(/#{File.extname(this_video_file)}$/,'')+'.mp4'
  _ = 'ffmpeg -i '+this_video_file+' -c:v libx264 -preset slow '\
      '-crf 18 -vf yadif -strict -2 '+
      output_file
  e
  esystem _
  e
end
horizontal_flip(this_video_file) click to toggle source
#

MultimediaParadise.horizontal_flip

This method will make use of the video-filter called “hflip”.

#
# File lib/multimedia_paradise/toplevel_methods/flip_and_rotate.rb, line 35
def self.horizontal_flip(this_video_file)
  ffmpeg_horizontal_flip(this_video_file)
end
identify_video(this_file) click to toggle source
#

MultimediaParadise.identify_video

Use this to identify a given video or audio file.

Another way would be this:

mplayer -vo null -ao null -frames 0 -identify POP_America_TheLastUnicorn.mp3

You will have to parse this lateron.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 613
def self.identify_video(this_file)
  cmd = "ffmpeg -i #{this_file}"
  e
  e cmd
  e
  result = `{cmd}`
  return result
end
images_to_video(img = 'img%d.jpg') click to toggle source
#

MultimediaParadise.images_to_video

Notice that %d is replaced by the image number in question.

Usage example:

MultimediaParadise.images_to_video
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 419
def self.images_to_video(img = 'img%d.jpg')
  frames_per_second = '5'
  img = img.join(' ') if img.is_a? Array
  cmd = 'ffmpeg -r '+frames_per_second+' -b '+DEFAULT_VIDEO_BITRATE.to_s+' -i '+img+' output.mp4'
  run_sys_command cmd
end
increase_volume( of_this_file, by_how_much = '2.0' ) click to toggle source
#

MultimediaParadise.increase_volume

Increase the volume of an audio file using sox with this method.

We do this by using the command –volume FACTOR.

A value of 0.9 would mean a new audio file with 90% volume of the original file. 2.0 would mean 200% of the volume.

Note that this method depends on sox, which in turn has limitations. For instance, sox can not handle .mp4 files. In the long run I may have to switch to ffmpeg, but for now this method will stay as it is. (In the future perhaps an additional argument has to denote which toolkit we will use.)

Usage examples:

MultimediaParadise.increase_volume 'Mittwoch_14.10.2015.mp3'
MultimediaParadise.increase_volume '/Depot/j/CLIPPED_foobar.mp4', '1.5'
MultimediaParadise.increase_volume '/Depot/j/ack.mp3', '1.5'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 735
def self.increase_volume(
    of_this_file,
    by_how_much = '2.0'
  )
  of_this_file = File.absolute_path(of_this_file)
  unless by_how_much.is_a? String
    by_how_much = by_how_much.to_f.to_s
  end
  extname = File.extname(of_this_file) # This will result in e. g. ".mp4".
  run_sys_command 'sox --volume '+
                   by_how_much+' '+
                   of_this_file+' '+
                   of_this_file.delete_suffix(extname)+
                   'AUDIO_GAINED_'+extname 
end
increase_volume_of_this_audio_file( input_file, modify_volume_by_this_value = '5.0' ) click to toggle source
#

MultimediaParadise.increase_volume_of_this_audio_file

The method method MultimediaParadise.increase_volume_of_this_audio_file can boost the volume of an audio file, by making use of sox or ffmpeg.

Sox is currently the default, whereas ffmpeg is used if the input given ends with ‘db’, which is short for decibel. The latter variant allows you to just input an increase or decrease in decibel.

The sox command can modify the audio volume, up or down, using the -v flag, followed by a multiplier. The following example doubles (x2) the audio volume of a file.

sox -v 2.0 original-music.ogg louder-music.ogg
#
# File lib/multimedia_paradise/toplevel_methods/increase_volume_of_this_audio_file.rb, line 28
def self.increase_volume_of_this_audio_file(
    input_file,
    modify_volume_by_this_value = '5.0' # or 3.0 or 4.0 and so forth.
  )
  unless input_file.is_a? Array
    input_file = [input_file]
  end
  if modify_volume_by_this_value.to_s.downcase.end_with? 'db'
    ffmpeg_increase_volume_of_this_audio_file(
      input_file, modify_volume_by_this_value
    )
  else
    case modify_volume_by_this_value # case tag
    when '1/4', :one_fourth,'25%'
      modify_volume_by_this_value = 0.25
    end
    # ======================================================================= #
    # Batch-process the Array next.
    # ======================================================================= #
    input_file.each {|this_file|
      value = modify_volume_by_this_value.to_s
      output_file = "modified_file_by_v#{value}_#{this_file}"
      _ = 'sox -v '+value+
          ' '+this_file+' '+output_file
      esystem _
    }
  end
end
is_a_multimedia_file?(i) click to toggle source
#

MultimediaParadise.is_a_multimedia_file?

Determine whether a given file is a multimedia file or whether it is not.

Usage example:

MultimediaParadise.is_a_multimedia_file? 'foobar.avi'
#
# File lib/multimedia_paradise/toplevel_methods/is_a_multimedia_file.rb, line 22
def self.is_a_multimedia_file?(i)
  i = File.extname(i).delete('.') if i
  ARRAY_MULTIMEDIA_FILETYPES.include? i
end
is_audio_file?(i) click to toggle source
#

MultimediaParadise.is_audio_file?

This method will return true or false depending on whether the input is assumed to be an audio file or whether it is not.

#
# File lib/multimedia_paradise/toplevel_methods/is_audio_file.rb, line 17
def self.is_audio_file?(i)
  _ = false
  extname = File.extname(i).delete('.') # Will be something such as "mp3".
  case extname
  when *AUDIO_FORMATS
    _ = true
  end
  return _
end
is_image_file?(i) click to toggle source
#

MultimediaParadise.is_image_file?

This method will return true or false depending on whether the input is assumed to be an image file or whether it is not.

#
# File lib/multimedia_paradise/toplevel_methods/is_image_file.rb, line 17
def self.is_image_file?(i)
  _ = false
  extname = File.extname(i).delete('.') # Will be something such as "mp3".
  case extname
  when *IMAGE_FORMATS
    _ = true
  end
  return _
end
is_on_roebe?() click to toggle source
#

MultimediaParadise.is_on_roebe?

#
# File lib/multimedia_paradise/toplevel_methods/is_on_roebe.rb, line 13
def self.is_on_roebe?
  ENV['IS_ROEBE'] == '1'
end
is_video_file?(i) click to toggle source
#

MultimediaParadise.is_video_file?

This method will return true or false depending on whether the input is assumed to be a video file or whether it is not.

#
# File lib/multimedia_paradise/toplevel_methods/is_video_file.rb, line 17
def self.is_video_file?(i)
  _ = false
  extname = File.extname(i).delete('.')
  case extname
  when *ARRAY_VIDEO_FILETYPES
    _ = true
  end
  return _
end
load_yaml(i) click to toggle source
#

MultimediaParadise.load_yaml

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 678
def self.load_yaml(i)
  YAML.load_file(i)
end
long_format_to_milliseconds(i = ARGV) click to toggle source
#

MultimediaParadise.long_format_to_milliseconds

#
# File lib/multimedia_paradise/misc/long_format_to_milliseconds_converter.rb, line 169
def self.long_format_to_milliseconds(i = ARGV)
  MultimediaParadise::LongFormatToMillisecondsConverter.new(i).result?
end
loop_this_video(this_video = 'foobar.webm', n_times = '5x') click to toggle source
#

MultimediaParadise.loop_this_video

This method can be used to loop a video, via ffmpeg.

A commandline variant for this would look as follows:

ffmpeg -stream_loop 3 -i  Tata.webm   -c copy output.webm
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 26
def self.loop_this_video(this_video = 'foobar.webm', n_times = '5x')
  result = []
  [this_video].flatten.compact.each {|work_on_this_video_file|
    n_times = n_times.to_s.delete('x').sub(/ times/,'')
    output_file = "output_#{work_on_this_video_file}"
    result << output_file
    cmd = "ffmpeg -stream_loop #{n_times} -i #{work_on_this_video_file} -c copy #{output_file}"
    esystem cmd
  }
  return result
end
m4a_to_mp3(this_file, to = '.mp3') click to toggle source
#

MultimediaParadise.m4a_to_mp3

From .m4a audio to a .mp3 file.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 283
def self.m4a_to_mp3(this_file, to = '.mp3')
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
menu(i) click to toggle source
#

MultimediaParadise.menu (menu tag)

#
merge_avi_files( *these_avi_files ) click to toggle source
#

MultimediaParadise.merge_avi_files

This method can be specifically used to merge several .avi files together. The input to this method should come in the form of .avi files.

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 124
def self.merge_avi_files(
    *these_avi_files
  )
  these_avi_files = [these_avi_files].flatten.compact
  if these_avi_files.empty?
    these_avi_files = Dir['*.avi'] # Try to find .avi files in this case.
  end
  cmd = 'ffmpeg -i "concat:'+
         these_avi_files.join('|')+
         '" -c copy output.avi'
  e
  e cmd
  e
  system cmd
end
merge_flv( output_file = 'output.flv', *input_files ) click to toggle source
#

MultimediaParadise.merge_flv

Merge .flv files. Uses mencoder right now.

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 318
def self.merge_flv(
    output_file = 'output.flv', *input_files
  )
  _  = 'mencoder -forceidx -oac mp3lame -ovc copy'.dup
  _ << ' -o '+output_file
  _ << ' '+input_files.join(' ')
  run_sys_command _
end
merge_m4v( output_file = nil, input_files = [] ) click to toggle source
#

MultimediaParadise.merge_m4v

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 143
def self.merge_m4v(
    output_file = nil,
    input_files = []
  )
  output_file = 'output.m4v' # The input is .m4v, so the output should also be .mp4.
  we_created_these_temporary_video_files = ''
  input_files.each_with_index {|input_file, index|
    temporary_video_file = 'temp'+index.to_s+'.ts'
    # ======================================================================= #
    # Next get rid of prior-existing temporary video files, in the
    # event that these exist.
    # ======================================================================= #
    File.delete(temporary_video_file) if File.exist? temporary_video_file
    we_created_these_temporary_video_files << temporary_video_file+'|'
    _ = 'ffmpeg -i '+input_file+' -c copy -bsf:v h264_mp4toannexb '+temporary_video_file
    esystem _, :colourize_output
  }
  if we_created_these_temporary_video_files.end_with? '|'
    we_created_these_temporary_video_files.chop!
  end
  _ = 'ffmpeg -i "concat:'+we_created_these_temporary_video_files+
      '" -c copy -bsf:a aac_adtstoasc '+output_file.to_s
  esystem _, :colourize_output
  if File.exist? output_file
    e 'Stored into the file '+sfile(output_file)+'.'
  end
end
merge_mov( output_file = 'output.mov', *input_files ) click to toggle source
#

MultimediaParadise.merge_mov

Use this to merge some .mov files. Hmm. For some reason mencoder makes this an .avi file.

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 107
def self.merge_mov(
    output_file = 'output.mov', *input_files
  )
  output_file << '.mov' unless output_file.end_with? '.mov'
  _  = 'mencoder -idx -forceidx -oac mp3lame -ovc xvid -xvidencopts fixed_quant=4'.dup
  _ << ' -o "'+output_file+'"'
  _ << ' '+input_files.join(' ')
  run_sys_command _
end
merge_mp3( output_file = 'output.mp3', *input_files ) click to toggle source
#

MultimediaParadise.merge_mp3

This method will merge a variable number of .mp3 files.

Could use an alternative too:

mp3wrap output.mp3 *mp3

In “pure” ruby however, try this:

require 'multimedia_multimedia'

MultimediaParadise.merge_mp3(:default, '*mp3')
#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 274
def self.merge_mp3(
    output_file = 'output.mp3', *input_files
  )
  case output_file
  # This entry point is for the default name.
  when nil, :default
    output_file = 'output.mp3'
  end
  output_file = 'output_'+output_file unless output_file.include? '.'
  output_file << '.mp3' unless output_file.end_with? 'mp3'
  input_files = Dir['*.mp3'] if input_files.first == '*mp3' # This is a shorthand notation for "get all mp3 files".
  if input_files.any? {|entry| entry.include? ' ' }
    input_files.map! {|entry| '"'+entry+'"'}
  end
  # ======================================================================= #
  # We could use either mpgtx or ffmpeg.
  # _  = 'mpgtx -j '
  # _ << '-o '+output_file
  # _ << ' '+input_files.join(' ')
  # ======================================================================= #
  _ = 'ffmpeg -i concat:'+input_files.join('\|')
  _ << " -acodec copy #{output_file}"
  run_sys_command _
  return output_file # And return this output file here as well.
end
merge_mp4( output_file = 'output.mp4', *input_files ) click to toggle source
#

MultimediaParadise.merge_mp4

Merge mp4 files. This is currently done using ffmpeg’s concat protocol.

Unfortunately, concatenating .mp4 files is not trivial and may require an intermediate step such as remuxing them to ts (mpegts) before then putting them together into a .mp4 file.

The concat protocol follows this rule:

ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg
#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 203
def self.merge_mp4(
    output_file = 'output.mp4',
    *input_files
  )
  input_files.flatten!
  # ======================================================================= #
  # Pad all input files next, to avoid "foo'bar.mp3" problems.
  # ======================================================================= #
  input_files.map! {|entry|
    entry = '"'+entry+'"' unless entry.start_with?('"')
    entry
  }

  MultimediaParadise.ensure_that_the_output_directory_exists # Our log-base directory must exist.
  output_file = 'output.mp4' if output_file.nil?
  output_file = 'output_'+output_file unless output_file.include? '.'
  output_file << '.mp4' unless output_file.end_with? 'mp4'
  output_file = '"'+output_file+'"' unless output_file.start_with?('"')
  File.delete(output_file) if File.exist? output_file # Don't want any backups.
  # ======================================================================= #
  # Ok now, the first step is to produce intermediate .ts files. Since
  # they are intermediate, we don't have to store them persistently.
  # We do this by iterating over our input_files Array first.
  # ======================================================================= #
  input_files.each_with_index {|the_input_mp4_file, index|
    index += 1
    _ = "ffmpeg -i #{the_input_mp4_file} -c copy -bsf:v h264_mp4toannexb -f mpegts"
    name_of_the_ts_file = MultimediaParadise.store_in_this_directory+'intermediate'+index.to_s+'.ts'
    # ======================================================================= #
    # We must kill old .ts files, just in case that they exist. This is
    # acceptable since it is a temporary directory anyway.
    # ======================================================================= #
    File.delete(name_of_the_ts_file) if File.exist? name_of_the_ts_file
    _ << ' '+name_of_the_ts_file
    e _
    system _
  }
  # ======================================================================= #
  # Ok, now we created the intermediate .ts files, so now we can apply
  # the concat protocol.
  # ======================================================================= #
  input_files = input_files.flatten.map.with_index {|entry, index|
    index += 1
    entry = MultimediaParadise.store_in_this_directory+'intermediate'+index.to_s+'.ts'
    entry
  }
  _  = 'ffmpeg -i "concat:'+input_files.join('|')+'" -c copy '
  _ << '  -bsf:a aac_adtstoasc '
  _ << output_file
  _.strip!
  esystem _
  if File.exist? output_file
    e "The file should now exist at `#{sfile(output_file)}`."
  end
end
merge_multimedia_file( input_files = nil, output_file = nil, extname = nil ) click to toggle source
#

MultimediaParadise.merge_multimedia_file (merge tag)

This method combines several multimedia-related actions, into one bundled method.

Do note that the input files come last in the various merge methods, but they do come first for the input to this method here.

The reason is that we can pass a variable amount to a method in ruby via the * syntax.

Usage example:

MultimediaParadise.merge_multimedia_file(ARGV)
#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 33
def self.merge_multimedia_file(
    input_files = nil, # This should be an Array.
    output_file = nil, # This should be a String.
    extname     = nil
  )

  require 'multimedia_paradise/conversions/conversions.rb'

  if input_files.is_a?(String) and input_files.include? '*'
    input_files = Dir[input_files]
  end
  input_files.flatten!
  # ======================================================================= #
  # Determine the extname to use next.
  # ======================================================================= #
  if extname.nil? and input_files.is_a?(Array) and !input_files.empty? 
    extname = File.extname(input_files.first)
  end

  extname = extname.to_s.delete('.')

  case extname # This will be a String, as determined above.
  # ======================================================================= #
  # === mp4
  # ======================================================================= #
  when 'mp4'
    eimportant(
      output_file = merge_mp4(output_file, input_files)
    )
  # ======================================================================= #
  # === mp3
  # ======================================================================= #
  when 'mp3' # Act on mp3 files here.
    eimportant(
      output_file = merge_mp3(output_file, input_files)
    )
  # ======================================================================= #
  # === ogg
  # ======================================================================= #
  when 'ogg'
    eimportant(
      output_file = merge_ogg(output_file, input_files)
    )
  # ======================================================================= #
  # === flv
  # ======================================================================= #
  when 'flv'
    eimportant(
      output_file = merge_flv(output_file, input_files)
    )
  # ======================================================================= #
  # === m4v
  # ======================================================================= #
  when 'm4v'
    eimportant(
      output_file = merge_m4v(output_file, input_files)
    )
  else
    output_file = ::MultimediaParadise.merge_these_videos(input_files)
  end
  return output_file
end
merge_ogg( output_file = 'output.ogg', *input_files ) click to toggle source
#

MultimediaParadise.merge_ogg (merge ogg files)

Use this method if you wish to merge some .ogg files together.

We presently use ffmpeg for this.

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 178
def self.merge_ogg(
    output_file = 'output.ogg', *input_files
  )
  input_files.flatten! # Flatten them.
  input_files = input_files.join('\|') if input_files.is_a? Array
  _  = 'ffmpeg -i concat:'+input_files # input_files are always an Array.
  _ << ' -acodec copy'
  _ << ' '+output_file
  run_sys_command _
end
merge_these_videos( *i ) click to toggle source
#

MultimediaParadise.merge_these_videos

This method can be used to merge multiple videos together. The “concat” option of ffmpeg will be used for this merge-action.

Ideally the video-files that are given as input to this method should all use the same resolution and the same frame rate.

There are several ways how to go about this. A simple one is to simply create a text-file that can then tell ffmpeg which files are to be merged together. This is the strategy that this method will presently (2018) pursue.

The ffmpeg-concact options are explained here:

https://trac.ffmpeg.org/wiki/Concatenate

Invocation examples:

MultimediaParadise.merge_these_videos('foo.mp4','bar.mp4')
MultimediaParadise.merge('foo.mp4','bar.mp4')
#
# File lib/multimedia_paradise/toplevel_methods/merge_these_videos.rb, line 37
def self.merge_these_videos(
    *i
  )
  i = [i].flatten.map(&:strip)
  e ::Colours.rev+
    ::Colours.steelblue(i.size.to_s)+
    ' video files will be merged next.'
  new_file_extension = nil
  # ======================================================================= #
  # We will store into the following text-file:
  # ======================================================================= #
  text_file = "#{log_directory?}file_that_keeps_track_of_the_videos.md"
  # ======================================================================= #
  # Make sure that the base directory exists:
  # ======================================================================= #
  unless File.directory?(File.dirname(text_file))
    mkdir(File.dirname(text_file))
  end
  File.delete(text_file) if File.exist? text_file
  name_of_the_output_file = 'merged_files_'.dup
  e 'The video files will be analyzed. A log file will be stored at:'
  e
  e "  #{sfile(text_file)}"
  e
  i.each {|this_video_file|
    # ===================================================================== #
    # We have to obtain the absolute file path:
    # ===================================================================== #
    this_video_file = File.absolute_path(this_video_file)
    File.open(text_file, 'a+') { |file|
      file.write("file #{this_video_file}\n")
    }
    raw_name = this_video_file.sub(/#{File.extname(this_video_file)}$/,'').dup
    name_of_the_output_file << File.basename(raw_name).delete('/')
    new_file_extension = File.extname(this_video_file).delete('.')
  }
  # ======================================================================= #
  # Ensure that the file name is not too long, thus truncating.
  # ======================================================================= #
  if name_of_the_output_file.size > 200
    name_of_the_output_file = name_of_the_output_file[0 .. 200]
  end
  name_of_the_output_file << '.'+new_file_extension
  name_of_the_output_file = '"'+name_of_the_output_file.
                            delete("'")+'"'
  # ======================================================================= #
  # Build up the string for ffmpeg next. The option -y is used to
  # overwrite automatically.
  # ======================================================================= #
  _ = 'ffmpeg '\
      '-y '\
      '-safe 0 '\
      '-f concat '\
      '-i '+text_file+
      ' -c copy '+name_of_the_output_file
  esystem _
  e
  e 'Ouput stored at:'
  e
  e "  #{sfile(name_of_the_output_file)}"
  e
  return name_of_the_output_file # <- And also return it here.
end
metadata_from_this_song(this_song) click to toggle source
#

MultimediaParadise.metadata_from_this_song

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 494
def self.metadata_from_this_song(this_song)
  MultimediaParadise::AudioTagReader[this_song]
end
milliseconds_to_long_format(i = ARGV) click to toggle source
#

MultimediaParadise.milliseconds_to_long_format

Usage example:

MultimediaParadise.milliseconds_to_long_format('15_05') # => "00:00:01,505"
#
# File lib/multimedia_paradise/misc/milliseconds_to_long_format_converter.rb, line 161
def self.milliseconds_to_long_format(i = ARGV)
  MultimediaParadise::MillisecondsToLongFormatConverter.new(i).result?
end
mkdir(i) click to toggle source
#

MultimediaParadise.mkdir

This method can be used to create a directory on the local computer system.

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 47
def self.mkdir(i)
  FileUtils.mkdir_p(i)
end
modify_year_of_audio_file(*i) click to toggle source
#

MultimediaParadise.modify_year_of_audio_file

Invoke this like so:

MultimediaParadise.modify_year_of_audio_file /Depot/j/foobar.mp3 2012
#
# File lib/multimedia_paradise/audio/modify_year_of_audio_file.rb, line 143
def self.modify_year_of_audio_file(*i)
  MultimediaParadise::Audio::ModifyYearOfAudioFile.new(i)
end
move_file(old, new) click to toggle source
#

MultimediaParadise.move_file

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 20
def self.move_file(old, new)
  FileUtils.mv(old, new)
end
mp3_to_aac( this_file, to = '.aac' ) click to toggle source
#

MultimediaParadise.mp3_to_aac

Convert from .mp3 to .aac format, using ffmpeg.

Usage example:

MultimediaParadise.to_aac('/Depot/jjj/foobar.mp3')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 841
def self.mp3_to_aac(
    this_file,
    to = '.aac'
  )
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
mp3_to_midi( input_file, output_file = 'ack.mid' ) click to toggle source
#

MultimediaParadise.mp3_to_midi

Convert mp3 to midi file using lame and waon. We need to do two steps because a single step is not yet enough.

I do not know presently (December 2021) whether ffmpeg allows mp3-to-midi conversions, but waon does, so let’s use that.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 376
def self.mp3_to_midi(
    input_file, output_file = 'ack.mid'
  )
  result = mp3_to_wav(input_file)
  cmd = 'waon -i '.dup
  cmd << result
  cmd << ' -o '+output_file
  run_sys_command cmd
end
mp3_to_ogg( this_file, to = '.ogg' ) click to toggle source
#

MultimediaParadise.mp3_to_ogg

Convert from .mp3 to .ogg format.

Usage example:

mp3_to_ogg 'foo.mp3'
MultimediaParadise.mp3_to_ogg('/Depot/j/output.mp3')
MultimediaParadise.to_ogg('/Depot/jjj/foobar.mp3')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 860
def self.mp3_to_ogg(
    this_file,
    to = '.ogg'
  )
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
mp3_to_opus(this_file, to = '.opus') click to toggle source
#

MultimediaParadise.mp3_to_opus

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 244
def self.mp3_to_opus(this_file, to = '.opus')
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
mp3_to_wav( i = '/Depot/j/foobar.mp3', to = 'wav' ) click to toggle source
#

MultimediaParadise.mp3_to_wav

This method will attempt to convert a .mp3 file to a .wav file.

Returns result as well.

Rather than use ffmpeg we could also use lame, such as via:

'lame --decode "'+i+'" "'+output_file+'"'

Usage example:

MultimediaParadise.mp3_to_wav('/Depot/j/foobar.mp3','/Depot/j/yodel.wav')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 659
def self.mp3_to_wav(
    i  = '/Depot/j/foobar.mp3',
    to = 'wav'
  )
  MultimediaParadise.convert(i, to: to)
end
mp4_to_mp3(a, b = '.mp3') click to toggle source
#

MultimediaParadise.mp4_to_mp3

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 228
def self.mp4_to_mp3(a, b = '.mp3')
  ::MultimediaParadise.general_format_conversion(a, b)
end
n_local_videos?( from_this_directory = realvids_directory? ) click to toggle source
#

MultimediaParadise.n_local_videos?

#
# File lib/multimedia_paradise/toplevel_methods/n_local_videos.rb, line 27
def self.n_local_videos?(
    from_this_directory = realvids_directory?
  )
  these_files = Dir["#{from_this_directory}*"].select {|entry|
    ::MultimediaParadise.is_video_file?(entry)
  } 
  n_local_videos_are_available = these_files.size
  return n_local_videos_are_available
end
normalize( this_file ) click to toggle source
#

MultimediaParadise.normalize

Normalize audio.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 359
def self.normalize(
    this_file
  )
  cmd  = 'normalize '
  cmd << this_file
  run_sys_command cmd
end
obtain_title_at_position(i) click to toggle source
#

MultimediaParadise.obtain_title_at_position

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 19
def self.obtain_title_at_position(i)
  result = VIDEO_DATASET[i.to_i]
  result = result['title'].to_s if result
  result
end
ogg_to_mp3(this_file, to = '.mp3') click to toggle source
#

MultimediaParadise.ogg_to_mp3

Convert .ogg files into .mp3 files.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 237
def self.ogg_to_mp3(this_file, to = '.mp3')
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
open_yaml_file( i = FILE_VIDEO_COLLECTION ) click to toggle source
#

MultimediaParadise.open_yaml_file

This will open my video collection.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 687
def self.open_yaml_file(
    i = FILE_VIDEO_COLLECTION
  )
  esystem "bluefish #{i}"
end
opnn( i = { namespace: NAMESPACE }, &block ) click to toggle source
#

MultimediaParadise.opnn

#
# File lib/multimedia_paradise/toplevel_methods/opn.rb, line 18
def self.opnn(
    i = { namespace: NAMESPACE }, &block
  )
  Opn.opn(i, &block) if Object.const_defined? :Opn
end
orange(i) click to toggle source
#

MultimediaParadise.orange

#
# File lib/multimedia_paradise/colours/colours.rb, line 57
def self.orange(i)
  return COLOURS.orange(i)
end
output_directory?() click to toggle source
#

MultimediaParadise.output_directory?

Query method over the class-instance variable called @output_directory.

We ensured through the setter that this will always end via a trailing ‘/’ token.

#
# File lib/multimedia_paradise/toplevel_methods/output_directory.rb, line 53
def self.output_directory?
  @output_directory
end
overlay_this_image_onto_that_video( this_image, that_video, duration_in_n_seconds = 3 ) click to toggle source
#

MultimediaParadise.overlay_this_image_onto_that_video

This method can be used to overlay an image over an existing local video file.

The options in use are as follows:

overlay=25:25: The image will be positioned 25px to the right and
               25px down, originating from the top left corner (0:0).

enable='between(t,0,20)': The overlay image will be shown from
                          00:00:00 to 00:00:20
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 411
def self.overlay_this_image_onto_that_video(
    this_image,
    that_video,
    duration_in_n_seconds = 3
  )
  _ = 'ffmpeg -y -i '+that_video+' '\
      '-i '+this_image+' -filter_complex "[0:v][1:v] '\
      'overlay=80:80:enable=\'between(t,0,'+
      duration_in_n_seconds.to_s+')\'" '\
      '-pix_fmt yuv420p -c:a copy '\
      'output.mp4'
  e
  esystem _
  e
end
overlay_two_audio_files( first, second ) click to toggle source
#

MultimediaParadise.overlay_two_audio_files

This method can merge in two audio files, usually .mp3 files.

The functionality depends on “sox”.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 236
def self.overlay_two_audio_files(
    first,
    second
  )
  output_file = 'output_file.mp3'
  esystem 'sox --combine mix '+
          first.to_s+
          ' '+
          second.to_s+
          ' '+
          output_file
end
permanently_use_this_video_player( i = :mpv ) click to toggle source
#

MultimediaParadise.set_array_commandline_arguments.permanently_use_this_video_player

#
# File lib/multimedia_paradise/commandline/menu.rb, line 62
def self.permanently_use_this_video_player(
    i = :mpv
  )
  i = i.to_s
  require 'save_file'
  _ = FILE_USE_THIS_VIDEO_PLAYER
  if File.exist? _ # Store into the proper file.
    e 'Storing into '+sfile(_)+'.'
    SaveFile.write_what_into(i,_)
    if is_on_roebe?
      _ = '/home/x/programming/ruby/src/'\
          'multimedia_paradise/lib/multimedia_paradise/yaml/'+
          File.basename(_)
      e 'Storing into '+sfile(_)+'.'
      SaveFile.write_what_into(i,_)
    end
  else
    e 'No file exists at '+_+'.'
  end
end
pid?() click to toggle source
#

MultimediaParadise.pid?

Keep track of the pid through this toplevel variable.

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 232
def self.pid?
  @pid
end
play_from_this_list(i = ARGV) click to toggle source
#

MultimediaParadise.play_from_this_list

#
# File lib/multimedia_paradise/multimedia/play_from_this_list.rb, line 155
def self.play_from_this_list(i = ARGV)
  ::MultimediaParadise::PlayFromThisList.new(i)
end
play_radio( remote_url = 'bbc3' ) click to toggle source
#

MultimediaParadise.play_radio

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 239
def self.play_radio(
    remote_url = 'bbc3'
  )
  unless remote_url.include? 'http'
    remote_url = return_radio_station_url_from_this_input(remote_url)
  end
  play_radio_from_this_url(remote_url)
end
play_radio_from_this_url( url = 'http://www.radioking.com/play/generationhit80', capture_into_this_file = nil ) { || ... } click to toggle source
#

MultimediaParadise.play_radio_from_this_url

This method can be used to play radio from a remote URL.

It will make use of Process.spawn rather than system(), because we need to return the PID.

The second argument to this method, if given, will log the captured stream into a local file. This depends on mpv mostly, and is a bit limited, so don’t expect too much of that feature.

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 57
def self.play_radio_from_this_url(
    url                    = 'http://www.radioking.com/play/generationhit80',
    capture_into_this_file = nil,
    &block
  )
  _ = video_player?
  # ======================================================================= #
  # === Handle blocks given to this method next
  # ======================================================================= #
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      # =================================================================== #
      # === :use_this_player
      # =================================================================== #
      if yielded.has_key? :use_this_player
        _ = yielded.delete(:use_this_player)
      end
    end
  end
  case _.to_s
  # ======================================================================= #
  # === mpv
  # ======================================================================= #
  when 'mpv'
    cmd_to_run = "mpv #{url}".dup
    if capture_into_this_file
      cmd_to_run << ' --stream-record="'+capture_into_this_file+'"'
    end
    e cmd_to_run
    # ===================================================================== #
    # The line below was in use until September 2020; it is kept in the
    # event that we wish to revert to it.
    #   pid = Process.spawn(cmd_to_run)
    # ===================================================================== #
    io_object = IO.popen(cmd_to_run, 'r+')
    pid = io_object.pid
    set_pid(pid) # Keep track of the pid here.
    io_object.each { |line|
      if line.start_with? ' icy-title: '
        register_title_of_this_audio_file(line)
      end
      e line
    }
    io_object.close
    return pid
  # ======================================================================= #
  # === mplayer
  # ======================================================================= #
  when 'mplayer'
    cmd_to_run = "mplayer #{url}".dup
    if capture_into_this_file
      cmd_to_run << ' -dumpstream -dumpfile "'+capture_into_this_file+'"'
    end
    e cmd_to_run
    pid = Process.spawn(cmd_to_run)
    set_pid(pid) # Keep track of the pid here.
    return pid
  else
    e "No video player that is known (#{_}). The "\
      "URL would have been: #{sfancy(url)}"
  end
end
play_random_file(i) click to toggle source
#

MultimediaParadise.play_random_file

#
# File lib/multimedia_paradise/video/play_random_file.rb, line 83
def self.play_random_file(i)
  MultimediaParadise::PlayRandomFile.new(i)
end
play_random_realvideo() click to toggle source
#

MultimediaParadise.play_random_realvideo

#
# File lib/multimedia_paradise/video/play_random_realvideo.rb, line 79
def self.play_random_realvideo
  ::MultimediaParadise::Video::PlayRandomRealvideo.new
end
play_random_simpsons_movie( n_times = 1 ) click to toggle source
#

MultimediaParadise.play_random_simpsons_movie

#
# File lib/multimedia_paradise/toplevel_methods/return_path_to_random_simpsons_video_file.rb, line 30
def self.play_random_simpsons_movie(
    n_times = 1
  )
  n_times.times {
    _ = return_path_to_random_simpsons_video_file
    esystem video_player?+' '+_
  }
end
play_simpsons(n_simpsons = 10) click to toggle source
#

MultimediaParadise.play_simpsons

#
# File lib/multimedia_paradise/video/mplayer_wrapper.rb, line 496
def self.play_simpsons(n_simpsons = 10)
  MultimediaParadise::MplayerWrapper.new('--simpsons='+n_simpsons.to_s)
end
play_video_file(i) click to toggle source
#

MultimediaParadise.play_video_file

#
# File lib/multimedia_paradise/video/video_player.rb, line 571
def self.play_video_file(i)
  if i.is_a? Array
    i.each {|entry| MultimediaParadise.play_video_file(entry) }
  else
    MultimediaParadise::VideoPlayer.new(i)
  end
end
player_in_use?() click to toggle source
#

MultimediaParadise.player_in_use?

Query which audio/video player is in use for this project.

#
# File lib/multimedia_paradise/toplevel_methods/player_in_use.rb, line 40
def self.player_in_use?
  @player_in_use
end
please_be_patient( file, optional_target_format = '' ) click to toggle source
#

MultimediaParadise.please_be_patient

Simply display a little message so the user can remain patient.

The second argument is an optional target-format message.

Usage example:

please_be_patient(file, 'to mp3 format')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 679
def self.please_be_patient(
    file, optional_target_format = ''
  )
  optional_target_format = optional_target_format.to_s
  optional_target_format << ' ' if optional_target_format.empty?
  opn; e 'Converting `'+::MultimediaParadise.sfile(file)+'` '+
          optional_target_format.strip+
         ' next, please be patient.'
end
project_base_dir?() click to toggle source
#

MultimediaParadise.project_base_dir?

#
# File lib/multimedia_paradise/project/project.rb, line 20
def self.project_base_dir?
  PROJECT_BASE_DIRECTORY
end
project_yaml_dir?() click to toggle source
#

MultimediaParadise.project_yaml_dir?

This may point to:

/home/Programs/Ruby/2.6.5/lib/ruby/site_ruby/2.6.0/multimedia_paradise/yaml/
#
# File lib/multimedia_paradise/project/project.rb, line 43
def self.project_yaml_dir?
  PROJECT_YAML_DIRECTORY
end
query_the_audio_codec_of_this_file(i) click to toggle source
#

MultimediaParadise.query_the_audio_codec_of_this_file

See the method MultimediaParadise.ffmpeg_query_the_audio_codec_of_this_file for a description of this method.

#
# File lib/multimedia_paradise/toplevel_methods/query_the_audio_codec_of_this_file.rb, line 15
def self.query_the_audio_codec_of_this_file(i)
  ffmpeg_query_the_audio_codec_of_this_file(i)
end
radio_stations?(i = FILE_RADIO_STATIONS) click to toggle source
#

MultimediaParadise.radio_stations?

The file that is used by this method by default is usually the one that is distributed via the MultimediaParadise project, called ‘radio/radio_stations.yml’.

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 128
def self.radio_stations?(i = FILE_RADIO_STATIONS)
  YAML.load_file(i)
end
random_video() click to toggle source
#

MultimediaParadise.random_video

#
# File lib/multimedia_paradise/video/random_video.rb, line 301
def self.random_video
  ::MultimediaParadise::Video::RandomVideo.new
end
rds(i = nil) click to toggle source
#

MultimediaParadise.rds

This method will replace ‘//’ with ‘/’.

#
# File lib/multimedia_paradise/toplevel_methods/rds.rb, line 12
def self.rds(i = nil)
  return '' if i.nil?
  i.squeeze '/'
end
read_meta_tags_of_this_file(i) click to toggle source
#

MultimediaParadise.read_meta_tags_of_this_file

#
# File lib/multimedia_paradise/multimedia/read_meta_tags.rb, line 165
def self.read_meta_tags_of_this_file(i)
  MultimediaParadise::ReadMetaTags.new(i)
end
realvids_directory?() click to toggle source
#

MultimediaParadise.realvids_directory?

This method is only really useful on my home setup. It will yield a String such as:

"/home/x/video/Realvids/"
#
# File lib/multimedia_paradise/constants/directory_constants.rb, line 45
def self.realvids_directory?
  REALVIDS_DIRECTORY
end
record_my_desktop() click to toggle source
#

MultimediaParadise.record_my_desktop

This is mostly an ad-hoc method.

#
# File lib/multimedia_paradise/toplevel_methods/start_screencast.rb, line 62
def self.record_my_desktop
  esystem 'ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -c:v libx264 -qp 0 -preset ultrafast capture.mkv'
end
register_title_of_this_audio_file(i) click to toggle source
#

MultimediaParadise.register_title_of_this_audio_file

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 208
def self.register_title_of_this_audio_file(i)
  @title_of_the_audio_file = nil # Always reset it here.
  use_this_regex = /^ icy-title: (.+)\n/
  if i and i.start_with?(' icy-title: ')
    i = i.scan(use_this_regex).flatten
    if i.is_a? Array
      i = i.first.to_s
    end
    @title_of_the_audio_file = i.strip
  end
end
remove_audio(i, &block) click to toggle source
#

MultimediaParadise.remove_audio

Also add a simpler API to remove audio. The input argument to this method should be a local file (typically a video-file) from which you wish to remove the audio.

Usage example:

MultimediaParadise.remove_audio '/Depot/jj/StarTrek_Nemesis.mp4'
#
# File lib/multimedia_paradise/audio/remove_audio.rb, line 90
def self.remove_audio(i, &block)
  RemoveAudio.remove_audio_from(i, &block)
end
remove_file(i) click to toggle source
#

MultimediaParadise.remove_file

Remove a given file, without any further checks.

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 30
def self.remove_file(i)
  File.delete(i) if File.exist?(i)
end
remove_last_second(this_audio_file) click to toggle source
#

MultimediaParadise.remove_last_second

#
# File lib/multimedia_paradise/audio/remove_last_second.rb, line 75
def self.remove_last_second(this_audio_file)
  MultimediaParadise::RemoveLastSecond.new(this_audio_file)
end
remove_metadata(from_this_file) click to toggle source
#

MultimediaParadise.remove_metadata

#
# File lib/multimedia_paradise/video/remove_metadata.rb, line 44
def self.remove_metadata(from_this_file)
  MultimediaParadise::Video::RemoveMetadata.new(from_this_file)
end
remove_noise( of_this_file = '*.mp3', this_rate = '3400' ) click to toggle source
#

MultimediaParadise.remove_noise

Use sox to remove noise stuff.

Usage example:

require 'multimedia_paradise'; MultimediaConversions.remove_noise('*.mp3')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 777
def self.remove_noise(
    of_this_file = '*.mp3', this_rate = '3400'
  )
  of_this_file = glob(of_this_file) if of_this_file.include? '*'
  if of_this_file.is_a? Array
    of_this_file.each {|entry|
      remove_noise(entry, this_rate)
    }
  else
    esystem 'sox '+of_this_file+' removed_noise_'+of_this_file+' lowp '+this_rate
  end 
end
remove_subtitles_from_this_video_file( this_video_file = 'foobar.mp4' ) click to toggle source
#

MultimediaParadise.remove_subtitles_from_this_video_file

This method can be used to remove a subtitle from a video file.

Typical commandline usage in ffmpeg would look like this:

ffmpeg -i video.mkv -vcodec copy -acodec copy -sn video-no-subs.mkv
#
# File lib/multimedia_paradise/toplevel_methods/subtitles.rb, line 22
def self.remove_subtitles_from_this_video_file(
    this_video_file = 'foobar.mp4'
  )
  if this_video_file.is_a? Array
    this_video_file = this_video_file.join(' ').strip
  end
  output_file = "output_video_without_subs_#{this_video_file}"
  _ = 'ffmpeg -i '+this_video_file.to_s+' -vcodec copy '\
      '-acodec copy '\
      '-sn '+
      output_file
  e
  esystem _
  e
end
rename(from, to) click to toggle source
#

MultimediaParadise.rename

This perform a rename-action, using mv.

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 63
def self.rename(from, to)
  if File.exist? from
    e rev+'Now renaming `'+sfile(from.to_s)+rev+'` to `'+sfile(to.to_s)+rev+'`.'
    FileUtils.mv(from, to)
  else
    e "#{rev}Can not rename `#{sfancy(from)}` as it does not exist."
  end
end
repeat_this_song_n_times( this_song = ARGV, n_times = 3 ) click to toggle source
#

MultimediaParadise.repeat_this_song_n_times

This will make use of sox and repeat a given song n times.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 347
def self.repeat_this_song_n_times(
    this_song = ARGV,
    n_times   = 3
  )
  [this_song].flatten.compact.each {|a_song|
    if File.exist? a_song
      esystem 'sox '+a_song+' repeated_song_'+a_song+' repeat '+n_times.to_s
    else
      no_file_exists_at(a_song)
    end
  }
end
report_duration_of(this_file) click to toggle source
#

MultimediaParadise.report_duration_of

This module-method will report in a compact way.

Usage example:

MultimediaParadise.report_duration_of('/Depot/Audio/foobar.mp3')
#
# File lib/multimedia_paradise/audio/file_duration/file_duration.rb, line 550
def self.report_duration_of(this_file)
  if this_file.is_a? Array
    this_file.each {|entry| report_duration_of(entry) }
  else
    _ = MultimediaParadise::FileDuration.new(this_file)
    _.report_duration(:compact)
  end
end
report_how_many_real_videos_are_stored( in_this_yaml_file = file_video_collection? ) click to toggle source
#

MultimediaParadise.report_how_many_real_videos_are_stored

This method will report how many “real” videos are stored in the file video_collection.yml, which is distributed as part of this gem. You can, however had, also specify your own .yml file, as first argument to this method.

To tap into this method, do issue:

mpa --n-videos?
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 195
def self.report_how_many_real_videos_are_stored(
    in_this_yaml_file = file_video_collection?
  )
  if File.exist? in_this_yaml_file
    dataset = YAML.load_file(in_this_yaml_file)
    e rev+
      'There are '+sfancy(dataset.keys.size)+' registered videos '+
      'in the file'
    e '`'+sfile(in_this_yaml_file)+'`.'
  else
    e 'Please supply an existing yaml file (.yml) to this method.'
  end
end
report_missing_id(i = :default_playlist) click to toggle source
#

MultimediaParadise.report_missing_id

#
# File lib/multimedia_paradise/audio/report_missing_id.rb, line 131
def self.report_missing_id(i = :default_playlist)
  ::MultimediaParadise::ReportMissingId.new(i)
end
report_missing_videos() click to toggle source
#

MultimediaParadise.report_missing_videos

#
# File lib/multimedia_paradise/commandline/menu.rb, line 38
def self.report_missing_videos
  _ = REALVIDS_DIRECTORY
  if File.directory? _
    local_files = Dir[_+'*'].select {|entry| is_a_video_file?(entry) }.sort.map {|entry|
      File.basename(entry).
      sub(/#{File.extname(entry)}$/,'')
    }
    all_titles = ::MultimediaParadise.return_all_video_files.map {|key, value|
      title = value['title']
      key.to_s.rjust(3,'0')+
      '_'+title.tr(' ','_')
    }
    local_files.each {|entry|
      if all_titles.include? entry
      else
        e rev+'No match found for '+sfancy(entry)+'.'
      end
    }
  end
end
report_missing_videos_in_the_yaml_file() click to toggle source
#

MultimediaParadise.report_missing_videos

#
# File lib/multimedia_paradise/video/report_missing_videos_in_the_yaml_file.rb, line 98
def self.report_missing_videos_in_the_yaml_file
  MultimediaParadise::Video::ReportMissingVideosInTheYamlFile.new
end
report_n_local_videos?() click to toggle source
#

MultimediaParadise.report_n_local_videos?

This is the method that will report how many videos are available.

#
# File lib/multimedia_paradise/toplevel_methods/n_local_videos.rb, line 42
def self.report_n_local_videos?
  opn; e 'There are '+sfancy(n_local_videos?.to_s)+' videos available '\
         'locally, at `'+sdir(realvids_directory?)+'`.'
  if is_on_roebe? and File.exist?(FILE_VIDEO_COLLECTION)
    dataset = YAML.load_file(FILE_VIDEO_COLLECTION)
    opn; e 'A total of '+sfancy(dataset.keys.size.to_s)+' videos are registered '\
           'in total in the file '+sfile('video_collection.yml')+'.'
  end
end
require_audio_files() click to toggle source
#

MultimediaParadise.require_audio_files

Batch-require all .rb files under audio/ files.

#
# File lib/multimedia_paradise/requires/require_audio_files.rb, line 17
def self.require_audio_files
  target = "#{project_base_directory?}audio/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/audio/#{File.basename(file)}"
    require this_file
  }
end
require_cut_multimedia_files() click to toggle source
#

MultimediaParadise.require_cut_multimedia_files

#
# File lib/multimedia_paradise/requires/require_audio_files.rb, line 65
def self.require_cut_multimedia_files
  target = "#{project_base_dir?}multimedia/cut_multimedia/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/multimedia/cut_multimedia/#{File.basename(file)}"
    require this_file
  }
end
require_extract_audio_files() click to toggle source
#

MultimediaParadise.require_extract_audio_files

#
# File lib/multimedia_paradise/requires/require_audio_files.rb, line 53
def self.require_extract_audio_files
  target = "#{project_base_dir?}audio/extract_audio/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/audio/extract_audio/#{File.basename(file)}"
    require this_file
  }
end
require_genre_files() click to toggle source
#

MultimediaParadise.require_genre_files

#
# File lib/multimedia_paradise/requires/require_audio_files.rb, line 41
def self.require_genre_files
  target = "#{project_base_dir?}audio/genre/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/audio/genre/#{File.basename(file)}"
    require this_file
  }
end
require_toplevel_methods_files() click to toggle source
#

MultimediaParadise.require_toplevel_methods_files

#
# File lib/multimedia_paradise/requires/require_toplevel_methods_files.rb, line 16
def self.require_toplevel_methods_files
  target = "#{MultimediaParadise.project_base_dir?}toplevel_methods/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/toplevel_methods/#{File.basename(file)}"
    require this_file
  }
end
require_video_files() click to toggle source
#

MultimediaParadise.require_video_files

#
# File lib/multimedia_paradise/requires/require_video_files.rb, line 16
def self.require_video_files
  target = "#{project_base_dir?}video/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/video/#{File.basename(file)}"
    require this_file
  }
end
require_waveform_files() click to toggle source
#

MultimediaParadise.require_waveform_files

#
# File lib/multimedia_paradise/requires/require_audio_files.rb, line 29
def self.require_waveform_files
  target = "#{project_base_dir?}audio/waveform/*.rb"
  these_files = Dir[target] # We will require these files here.
  these_files.each {|file|
    this_file = "multimedia_paradise/audio/waveform/#{File.basename(file)}"
    require this_file
  }
end
return_all_video_files() click to toggle source
#

MultimediaParadise.return_all_video_files

Use this method if you wish to return all video files registered in the main video_collection yaml file.

This will return a Hash that has entries similar to this one here:

275=>{"title"=>"Shaun Of The Dead", "genre"=>"Comedy", "addition_date"=>"21.12.2009", "language"=>"english"},
#
# File lib/multimedia_paradise/toplevel_methods/return_all_video_files.rb, line 35
def self.return_all_video_files
  _ = file_video_collection
  if File.exist? _
    begin
      YAML.load_file(_)
    rescue Psych::SyntaxError => error
      puts "Psych::SyntaxError for the file #{_} in the method "\
           "MultimediaParadise.return_all_video_files()"
      pp error
    end
  else
    {} # Or we will return an empty Hash.
  end
end
return_artist( i, report_classname = true ) click to toggle source
#

MultimediaParadise.return_artist

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 663
def self.return_artist(
    i,
    report_classname = true
  )
  i = i.to_s
  cmd =
    'ffprobe -loglevel error -show_entries format_tags=artist '\
    '-of default=noprint_wrappers=1:nokey=1 '+i
  result = `#{cmd}`.chomp
  return result
end
return_data_from_video_collection_file_for_this_entry(i) click to toggle source
#

MultimediaParadise.return_data_from_video_collection_file_for_this_entry

This method assumes a number as input, such as 1 or 2 and so forth.

Then, it will attempt to fetch the corresponding entry from the file “video_collection.yml”.

#
# File lib/multimedia_paradise/toplevel_methods/return_data_from_video_collection_file_for_this_entry.rb, line 19
def self.return_data_from_video_collection_file_for_this_entry(i)
  i = i.first if i.is_a? Array
  i = i.to_i # Must always work on an Integer past this point.
  # ======================================================================= #
  # Next, we have to load up the dataset from the yaml-file.
  # ======================================================================= #
  dataset = ::MultimediaParadise.return_all_video_files
  if dataset.has_key? i
    assumed_datased = dataset[i]
    return assumed_datased
  else
    nil # nil for "no result".
  end
end
return_duration_of_this_file(i) click to toggle source
#

MultimediaParadise.return_duration_of_this_file

#
# File lib/multimedia_paradise/audio/file_duration/file_duration.rb, line 562
def self.return_duration_of_this_file(i)
  return ::MultimediaParadise::FileDuration.return_duration_of_this_file(i)
end
return_duration_of_this_multimedia_file(i) click to toggle source
#

MultimediaParadise.return_duration_of_this_multimedia_file

This will simply return the number of seconds of a file, as Float.

#
# File lib/multimedia_paradise/toplevel_methods/return_duration_of_this_multimedia_file.rb, line 17
def self.return_duration_of_this_multimedia_file(i)
  i = i.first if i.is_a? Array
  _ = MultimediaParadise::FileDuration.new(i) { :be_quiet }
  _.duration?.to_f
end
return_filename_of_this_video_file(i) click to toggle source
#

MultimediaParadise.return_filename_of_this_video_file

Usage example:

result = MultimediaParadise.return_filename_of_this_video_file('24') # => "024_Convoy"
#
# File lib/multimedia_paradise/video/find_video/find_video.rb, line 437
def self.return_filename_of_this_video_file(i)
  _ = MultimediaParadise::FindVideo.new(i, :be_silent)
  array = _.find_video.flatten
  return array.last+'_'+array.first
end
return_full_name_for_video_at_this_position( position_of_the_video_file, use_this_extension = 'avi' ) click to toggle source
#

MultimediaParadise.return_full_name_for_video_at_this_position

Pass the position of the video file, such as ‘5’. Then we will return a full string such as “005_BowlingforColumbine”.

The second argument will be the name of the file extension in question.

#
# File lib/multimedia_paradise/toplevel_methods/return_full_name_for_video_at_this_position.rb, line 19
def self.return_full_name_for_video_at_this_position(
    position_of_the_video_file,
    use_this_extension = 'avi'
  )
  renamed_title = obtain_title_at_position(
    position_of_the_video_file.to_i
  ).to_s.delete(' ')
  unless use_this_extension.start_with? '.'
    use_this_extension = use_this_extension.dup if use_this_extension.frozen?
    use_this_extension.prepend '.'
  end
  # ======================================================================= #
  # We need to pad-up with leading numbers such as '0' and so on.
  # ======================================================================= #
  new_name = (position_of_the_video_file.to_s).rjust(3, '0')+
              '_'+renamed_title+use_this_extension
  return new_name
end
return_iso_encoding_of(i) click to toggle source
#

MultimediaParadise.return_iso_encoding_of

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 251
def self.return_iso_encoding_of(i)
  i = i.dup if i.frozen?
  i.force_encoding(ISO_ENCODING)
end
return_path_to_random_simpsons_video_file() click to toggle source
#

MultimediaParadise.return_path_to_random_simpsons_video_file

This method will return the full local path to a random simpsons video. This only works on my home system, though, as the directory structure is a very specific one.

#
# File lib/multimedia_paradise/toplevel_methods/return_path_to_random_simpsons_video_file.rb, line 21
def self.return_path_to_random_simpsons_video_file
  Dir[
    "#{CARTOONS_DIRECTORY}Simpsons-**/**"
  ].sample
end
return_radio_station_url_from_this_input( i, use_this_yaml_file = FILE_RADIO_STATIONS ) click to toggle source
#

MultimediaParadise.return_radio_station_url_from_this_input

This method will try to return a corresponding URL from the given input at hand.

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 262
def self.return_radio_station_url_from_this_input(
    i,
    use_this_yaml_file = FILE_RADIO_STATIONS
  )
  dataset = YAML.load_file(use_this_yaml_file)
  # ======================================================================= #
  # This file may contain umlauts. We could convert these into ISO
  # encoding, but since as of May 2019 we will default to UTF-8
  # anyway.
  # ======================================================================= #
  # dataset.each_pair {|key, value|
  #   hash[return_iso_encoding_of(key)] = value
  # }; dataset = hash
  i = i.to_s.delete('-').downcase
  i = case i
  # ======================================================================= #
  # === oe3
  # ======================================================================= #
  when 'oe3','ö3','o3'
    dataset['Hitradio Ö3']['url']
  # ======================================================================= #
  # === fm4
  # ======================================================================= #
  when 'fm4'
    dataset['FM4']['url']
  # ======================================================================= #
  # == orf-radio-wien
  # ======================================================================= #
  when /^-?-?orf(_|-)?radio(_|-)?wien$/i
    dataset['ORF Radio Wien']['url']
  # ======================================================================= #
  # === energy
  # ======================================================================= #
  when 'energy'
    dataset['Energy 104,2']['url']
  # ======================================================================= #
  # === trance
  # ======================================================================= #
  when 'trance'
    dataset['PulsRadio TRANCE']['url']
  # ======================================================================= #
  # === germany
  # ======================================================================= #
  when 'germany'
    dataset['Germany Radio']['url']
  # ======================================================================= #
  # === bbc1
  # ======================================================================= #
  when /^bbc1$/i
    dataset['BBC Radio 1']['url']
  # ======================================================================= #
  # === bbc2
  # ======================================================================= #
  when /^bbc2$/i
    dataset['BBC Radio 2']['url']
  # ======================================================================= #
  # === bbc4
  # ======================================================================= #
  when /^bbc4/i
    dataset['BBC Radio 4']['url']
  # ======================================================================= #
  # === kronehit
  # ======================================================================= #
  when 'kronehit'
    dataset['Kronehit Dance']['url']
  # ======================================================================= #
  # === oe1
  # ======================================================================= #
  when 'oe1','ö1'
    dataset['OE 1']['url']
  # ======================================================================= #
  # === radiowien
  # ======================================================================= #
  when /^radio(-|_| )?wien$/
    dataset['ORF Radio Wien']['url']
  # ======================================================================= #
  # === Magic FM Germany
  # ======================================================================= #
  when /^Magic(-|_| )?FM(-|_| )?Germany$/i
    dataset['Magic FM Germany']['url']
  # ======================================================================= #
  # === bbc3
  # ======================================================================= #
  when /^bbc3$/i,
       /^BBC(-|_| )?Radio(-|_| )?3$/i
    dataset['BBC Radio 3']['url']
  else
    i
  end
  i
end
return_random_video_file_from_the_video_collection( shall_we_notify_the_user_if_the_video_file_is_missing = false ) click to toggle source
#

MultimediaParadise.return_random_video_file_from_the_video_collection

This method will return a random video file from the video collection.

This can then be used to e. g. play said file.

Do note that for this to work, the file must exist at the target position - otherwise the method will return nil.

#
# File lib/multimedia_paradise/toplevel_methods/return_random_video_file_from_the_video_collection.rb, line 26
def self.return_random_video_file_from_the_video_collection(
    shall_we_notify_the_user_if_the_video_file_is_missing = false
  )
  case shall_we_notify_the_user_if_the_video_file_is_missing
  when :notify_when_missing
    shall_we_notify_the_user_if_the_video_file_is_missing = true
  end
  # ======================================================================= #
  # First, obtain the full collection.
  # ======================================================================= #
  _ = file_video_collection
  video_collection = YAML.load_file(_)
  keys = video_collection.keys
  sample_key = keys.sample
  target = video_collection[sample_key]['title'] # This is the sample.
  path = ::MultimediaParadise.realvids_directory?+'*'+target.tr(' ','*')+'*'
  result = Dir[path]
  if result.is_a?(Array) and (result.size > 1)
    # ===================================================================== #
    # This here may be the case for a two-member Array such
    # as ['058_IceAge.mp3','058_IceAge.avi']
    # ===================================================================== #
    result = is_video_file?(result)
  end
  if result.empty? and shall_we_notify_the_user_if_the_video_file_is_missing
    e 'No file could be found at '+path+'.'
  end
  if result.is_a? Array
    result = result.first
  end
  return result
end
return_random_video_that_exists() click to toggle source
#

MultimediaParadise.return_random_video_that_exists

#
# File lib/multimedia_paradise/toplevel_methods/return_random_video_file_from_the_video_collection.rb, line 62
def self.return_random_video_that_exists
  return Dir[::MultimediaParadise.realvids_directory?+'*'].select {|entry|
    MultimediaParadise.is_this_a_video_file?(entry)
  }.sample
end
return_screen_resolution() click to toggle source
#

MultimediaParadise.return_screen_resolution

This method will return the screen resolution, as String, such as in “1920x1080”.

This functionality presently depends on the program called “xrandr”.

#
# File lib/multimedia_paradise/toplevel_methods/return_screen_resolution.rb, line 18
def self.return_screen_resolution
  `xrandr`.split("\n").select {|line|
    line.include? '*+'
  }.first.strip.split('  ').first
end
return_ss_mm_hh() click to toggle source
#

MultimediaParadise.return_ss_mm_hh

This may return a string such as “16:35:07”.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 456
def self.return_ss_mm_hh
  ::Time.now.strftime('%H:%M:%S')
end
return_the_mpeg_layer_from_this_mp3_file(i) click to toggle source
#

MultimediaParadise.return_the_mpeg_layer_from_this_mp3_file

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 212
def self.return_the_mpeg_layer_from_this_mp3_file(i)
  cmd = "mpg123 -t #{i} 2>&1"
  result = `#{cmd}`
  splitted = result.split("\n")
  selected = splitted.select {|line|
    line.start_with? 'MPEG ' # Obtain the MPEG layer here.
  }.uniq
  result = selected.first # Pick the first result here.
  # ======================================================================= #
  # We may have to clean up that result a little bit still.
  # ======================================================================= #
  if result and result.include?(' ') and result.include?('III')
    result = result[0 .. (result.index('III')+2)]
  end
  return result
end
return_video_codec_of_this_file(i = ARGV) click to toggle source
#

MultimediaParadise.return_video_codec_of_this_file

This method will use ffmpeg’s ffprobe and return the video codec of the given file at hand.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 97
def self.return_video_codec_of_this_file(i = ARGV)
  if i
    if i.is_a? Array
      i = i.first
    end
    cmd = "ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 #{i}"
    result = `#{cmd}`
    return result
  end
end
rev() click to toggle source
#

MultimediaParadise.rev

#
# File lib/multimedia_paradise/colours/colours.rb, line 71
def self.rev
  if Object.const_defined? :Colours # The Colours namespace must be available.
    return ::Colours.rev # Or ::Colours::GREEN
  end
  ''
end
reverse_audio( this_file = 'output.wav' ) click to toggle source
#

MultimediaParadise.reverse_audio

Reverse an audio file.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 307
def self.reverse_audio(
    this_file = 'output.wav'
  )
  output_file = 'reversed_'+this_file
  cmd = 'sox -n '+this_file+' '+output_file+' reverse'
  run_sys_command cmd
  return output_file
end
rotate_this_video_file_by_90_degrees( this_video_file ) click to toggle source
#

MultimediaParadise.rotate_this_video_file_by_90_degrees

For a complete description of this method, please have a look at the method MultimediaParadise.ffmpeg_rotate_this_video_file_by_90_degrees

#
# File lib/multimedia_paradise/toplevel_methods/flip_and_rotate.rb, line 45
def self.rotate_this_video_file_by_90_degrees(
    this_video_file
  )
  ffmpeg_rotate_this_video_file_by_90_degrees(
    this_video_file
  )
end
run_app() click to toggle source
#

MultimediaParadise.run_app

#
# File lib/multimedia_paradise/sinatra/app.rb, line 305
def self.run_app
  MultimediaParadise::Sinatra.run!
end
run_sys_command( cmd, pad_the_output = true ) click to toggle source
#

MultimediaParadise.run_sys_command (sys tag, sys cmd)

Echo the command before running it via “.

#
# File lib/multimedia_paradise/toplevel_methods/run_sys_command.rb, line 14
def self.run_sys_command(
    cmd, pad_the_output = true
  )
  cmd = cmd.strip
  e if pad_the_output
  e cmd
  e if pad_the_output
  begin
    result = `#{cmd}` # Sigint event can happen here.
    return result
  rescue Errno::ENOENT => error
    e 'No such file exists. ('+error.to_s+')'
    return nil
  end
end
samplerate_of_this_song(this_song) click to toggle source
#

MultimediaParadise.samplerate_of_this_song

Usage example:

MultimediaParadise.samplerate_of_this_song('foobar.mp3') # => 44100
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 257
def self.samplerate_of_this_song(this_song)
  if this_song.is_a? Array
    this_song = this_song.first
  end
  result = `ffprobe -select_streams a -show_streams #{this_song} 2>&1`
  if result
    result = result.split("\n").select {|entry|
      entry.start_with? 'sample_rate'
    }.first.to_s
  end
  if result and result.include?('=')
    result = result.split('=').last
  end
  return result
end
scale_this_video( this_video, optional_hash = {} ) click to toggle source
#

MultimediaParadise.scale_this_video

For the documentation of this method, please look at the method called MultimediaParadise.scale_this_video().

#
# File lib/multimedia_paradise/toplevel_methods/scale_video.rb, line 17
def self.scale_this_video(
    this_video, optional_hash = {}
  )
  ffmpeg_scale_this_video(this_video, optional_hash)
end
sdir(i) click to toggle source
#

MultimediaParadise.sdir

#
# File lib/multimedia_paradise/colours/colours.rb, line 22
def self.sdir(i)
  COLOURS.sdir(i)
end
set_array_commandline_arguments(i) click to toggle source
#

MultimediaParadise.set_array_commandline_arguments

#
# File lib/multimedia_paradise/commandline/menu.rb, line 86
def self.set_array_commandline_arguments(i)
  @array_commandline_arguments = i
end
set_output_directory( i = :default ) click to toggle source
#

MultimediaParadise.set_output_directory

#
# File lib/multimedia_paradise/toplevel_methods/output_directory.rb, line 19
def self.set_output_directory(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = '/home/Temp/multimedia_paradise/'
  # ======================================================================= #
  # === :old_default
  # ======================================================================= #
  when :old_default
    i = '/Depot/Temp/multimedia_paradise/'
  end
  i << '/' unless i.end_with? '/' # Ensure a trailing '/' directory.
  @output_directory = i
end
set_pid(i) click to toggle source
#

MultimediaParadise.set_pid

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 201
def self.set_pid(i)
  @pid = i
end
set_player_in_use( i = :default ) click to toggle source
#

MultimediaParadise.set_player_in_use

#
# File lib/multimedia_paradise/toplevel_methods/player_in_use.rb, line 53
def self.set_player_in_use(
    i = :default
  )
  i = i.to_s.dup.strip # Make sure we have a String past this point.
  case i
  when 'default',''
    # ====================================================================== #
    # Determine the default video-player in use for the MultimediaParadise
    # project. A constant keeps track of this value. Since as of June
    # 2020 a .yml file exists, and it will be used if it is available
    # AND if we are on a roebe system..
    # ====================================================================== #
    if File.exist?(FILE_USE_THIS_VIDEO_PLAYER) and is_on_roebe?
      i = YAML.load_file(FILE_USE_THIS_VIDEO_PLAYER)
    else
      i = WHICH_VIDEO_PLAYER_TO_USE
    end
  end
  @player_in_use = i
end
set_the_aspect_ratio_of_this_video( this_video, use_this_aspect_ratio = '16:9' ) click to toggle source
#

MultimediaParadise.set_the_aspect_ratio_of_this_video

This method will set the aspect-ratio of a given video file, via ffmpeg. The commandline-flag for this is called -aspect.

Original example:

ffmpeg -i foo.mp4 -aspect 16:9 bar.mp4

Example for the MultimediaParadise namespace:

MultimediaParadise.set_the_aspect_ratio_of_this_video('foo.mpg')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 492
def self.set_the_aspect_ratio_of_this_video(
    this_video, use_this_aspect_ratio = '16:9'
  )
  extension_to_use = File.extname(this_video)
  cmd_to_use = 'ffmpeg -i '+this_video+' -aspect '+
               use_this_aspect_ratio+' output_'+
               this_video.sub(/#{extension_to_use}$/,'')+extension_to_use
  e
  e cmd_to_use
  e
  system cmd_to_use
end
set_title_of( these_audio_files = ARGV, use_this_title = nil ) click to toggle source
#

MultimediaParadise.set_title_of

This toplevel-method can be used specifically to set the title of a .mp3 or a .mp4 file or any other multimedia-file that allows for meta-data.

For some .mp3 files this requires re-encoding, since the total filesize will change (as the header will be at the beginning of the file, in order to allow for simpler streaming support).

The second argument to this method should be the title that we are going to use for the given multimedia file at hand.

#
# File lib/multimedia_paradise/toplevel_methods/set_title_of.rb, line 26
def self.set_title_of(
    these_audio_files = ARGV,
    use_this_title    = nil
  )
  [these_audio_files].flatten.compact.each {|this_audio_file|
    if use_this_title
      case use_this_title
      # =================================================================== #
      # === :automatic
      # =================================================================== #
      when :automatic
        extname = File.extname(this_audio_file)
        use_this_title = File.basename(this_audio_file).sub(/#{extname}$/,'')
      end
      new_filename = "output_#{File.basename(this_audio_file)}"
      # =================================================================== #
      # Build up our main command next, via ffmpeg:
      # =================================================================== #
      _ = 'ffmpeg -i '+
          this_audio_file+
          ' -metadata title="'+use_this_title+'" '\
          '-codec copy '+new_filename
      esystem _
      if File.exist? new_filename
        e "#{rev}Stored at `#{sfile(new_filename)}`."
      end
    end
  }
end
sfancy(i) click to toggle source
#

MultimediaParadise.sfancy

#
# File lib/multimedia_paradise/colours/colours.rb, line 29
def self.sfancy(i)
  COLOURS.sfancy(i)
end
sfile(i) click to toggle source
#

MultimediaParadise.sfile

#
# File lib/multimedia_paradise/colours/colours.rb, line 36
def self.sfile(i)
  COLOURS.sfile(i)
end
shell() click to toggle source
#

MultimediaParadise.shell

#
# File lib/multimedia_paradise/multimedia/interactive_shell.rb, line 76
def self.shell
  InteractiveShell.new
end
show_artist( i, report_classname = true ) click to toggle source
#

MultimediaParadise.show_artist

Use this for .mp3 files, via ffmpeg. It will show the artist.

Input should be a .mp3 file.

Usage example from within ruby code:

MultimediaParadise.show_artist('/Depot/Audio/YoutubeMix_VivaldisFourSeasons.mp3')
MultimediaParadise.show_artist('/Depot/Audio/Vivaldi_Concerto8.mp3')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 647
def self.show_artist(
    i, report_classname = true
  )
  result = MultimediaParadise.return_artist(i)
  if result.empty?
    opnn if report_classname
    e 'This file does not have any artist-tag.'
  else
    opnn if report_classname
    e "The artist is: #{simp(result)}"
  end
end
show_available_audio_formats() click to toggle source
#

MultimediaParadise.show_available_audio_formats

Use this method if you want to show the available (registered) audio formats.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 628
def self.show_available_audio_formats
  e; AUDIO_FORMATS.each {|entry|
    e "  - #{entry}" # It is ok to prepend the '-' since this is for display purposes.
  }; e
end
show_help() click to toggle source
#

MultimediaParadise.show_help

This method shows some of the options available through the commandline interface at bin/multimedia_paradise (mpa).

Commandline way to invoke this method is:

mpa --help
#
# File lib/multimedia_paradise/help/help.rb, line 22
def self.show_help
  e "#{rev}You can use the MultimediaParadise project in this manner:"
  e
  e '  '+simp($PROGRAM_NAME.to_s)+' foo.mp3 foo.wav'
  e
  e 'This would convert '+orange('foo.mp3')+' into '+orange('foo.wav')
  e
  e '  --formats              # Will list all available format-conversions.'
  e
  e '  --increase_volume file # Use this to increase the volume of an '\
    'audio file'
  e
  e '  --intro                # Display some intro-information'
  e
  e '  --extract-audio        # Use ffmpeg to extract the audio '\
    'from a video file'
  e
  e '  --store                # Store all available video files into '\
    'a local yaml file'
  e
  e 'There are more options available, though:'
  e
  e '  --radio?               # Show URLs to radio-stations for '\
    'use in e. g. '+orange('rhythmbox')
  e '  --cut-audio            # Start the libui-wrapper for '\
    'cutting multimedia files (such as a .mp3 file)'
  e
end
show_internet_radio_URLs( i = file_radio_stations, display_style = :default ) { || ... } click to toggle source
#

MultimediaParadise.show_internet_radio_URLs

This method will show various URLs to internet-radio. This depends on prior registration in a yaml file.

The first argument should provide an existing file to where the radio stations are registered. By default, MultimediaParadise will come with a file where some radio URL stations are registered.

The second argument controls how this dataset is displayed. The :default style means that we will use a long display format, with more newlines. This may be easier to read - but there is also a :compact variant, which will display the radio stations along with the registered URL in a compact manner, all on the same line. Do note that :in_a_compact_form is simply an alias to :compact.

To invoke this, do:

mparadise --radio-compact
mparadise --rhythmbox
#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 156
def self.show_internet_radio_URLs(
    i             = file_radio_stations,
    display_style = :default
  )
  # ======================================================================= #
  # First, load up the dataset from the given file.
  # ======================================================================= #
  dataset = YAML.load_file(i)
  e
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # This instructions will show the remote URL listing of radio
    # stations in a more compact version.
    # ===================================================================== #
    when :compact,
         :in_a_compact_form
      display_style = :compact
    end
  end
  dataset.each_pair {|name_of_the_radio_station_at_hand, value|
    result = '  '.dup
    if TRY_TO_USE_UNICODE_SYMBOLS and Object.const_defined?(:Roebe) and
       Roebe.respond_to?(:wheel_of_dharma)
      result << COLOURS.darkslateblue(Roebe.wheel_of_dharma+' ')
    end
    entry = value['url'] # Define "entry" here.
    properly_formatted_name_of_the_radio_station_at_hand =
      COLOURS.royalblue(
        (name_of_the_radio_station_at_hand+':').ljust(25)
      )
    result << properly_formatted_name_of_the_radio_station_at_hand
    unless display_style == :compact
      result << "\n"
    end
    result << '  '+sfancy("    #{entry}")
    e result
  }
  e
end
show_intro() click to toggle source
#

MultimediaParadise.show_intro

This will show some intro in how to use this project from the commandline.

#
# File lib/multimedia_paradise/help/help.rb, line 57
  def self.show_intro
intro = <<-EOF

  This is an introduction to the MultimediaParadise project.

  This project integrates audio and video related components.

  This here is a short introduction into some of the possibilities
  of the project.

EOF
    _ = ::MultimediaParadise::FILE_USAGE_EXAMPLES
    if File.exist? _ # Append the file only if it exists.
      intro << File.read(_) # Append the file content here.
    end
    e intro # Output the intro.
  end
shrink_quality_of_these_mp3_files(*array) click to toggle source
#

MultimediaParadise.shrink_quality_of_these_mp3_files

This method can be used to batch-shrink several .mp3 files in one go.

Usage example:

MultimediaParadise.shrink_quality_of_these_mp3_files(Dir['*.mp3'])
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 176
def self.shrink_quality_of_these_mp3_files(*array)
  array.flatten.each {|this_mp3_file|
    esystem "lame --mp3input -b 64 #{this_mp3_file}"
  }
end
simp(i) click to toggle source
#

MultimediaParadise.simp

#
# File lib/multimedia_paradise/colours/colours.rb, line 43
def self.simp(i)
  COLOURS.simp(i)
end
simple_play_widget() click to toggle source
#

MultimediaParadise.simple_play_widget

This method can be used if you simply want to return the widget, to then embed it into another ruby-gtk application.

#
# File lib/multimedia_paradise/gui/shared_code/simple_play_widget/simple_play_widget_module.rb, line 253
def self.simple_play_widget
  ::MultimediaParadise::GUI::Gtk::SimplePlayWidget.new
end
slow_down_this_video_file( this_video_file = ARGV ) click to toggle source
#

MultimediaParadise.slow_down_this_video_file

This method can be used to slow down a video file.

FFmpeg will be doing this slow down action.

This uses the “setpts” video filter of ffmpeg, for the video stream at hand. The video stream can be changed without tampering with the audio stream. This is also the default modus operandi for this method here.

#
# File lib/multimedia_paradise/toplevel_methods/slow_down_this_video_file.rb, line 23
def self.slow_down_this_video_file(
    this_video_file = ARGV
  )
  ffmpeg_slow_down_this_video_file(this_video_file)
end
sox_denoise( input_file = 'input.mp4', start_time = '00:00:00' ) click to toggle source
#

MultimediaParadise.sox_denoise

This is similar to MultimediaParadise.denoise() but it uses sox in addition to ffmpeg.

See the following link:

http://www.zoharbabin.com/how-to-do-noise-reduction-using-ffmpeg-and-sox/
#
# File lib/multimedia_paradise/toplevel_methods/denoise.rb, line 44
def self.sox_denoise(
    input_file = 'input.mp4',
    start_time = '00:00:00'
  )
  input_file = input_file.join(' ').strip if input_file.is_a? Array
  # ======================================================================= #
  # (1) Split audio and video streams into two separate files:
  # ======================================================================= #
  _ = "ffmpeg -i #{input_file} -qscale 0 -an output_file_#{input_file}" # Video stream.
  esystem _
  temp_audio_wav = 'output_file_'+input_file.sub(/\.mp4$/,'')+'.wav'
  _ = ' ffmpeg -i '+input_file+' -qscale 0 '+temp_audio_wav # Audio stream.
  esystem _
  # ======================================================================= #
  # (2) Generate a sample of noise from the audio of the file. Choose a
  # segment of the audio where there is no speech and only noise, e. g.
  # where the speaker was silent for a second.
  # ======================================================================= #
  output_wav_file = 'output_noiseaudio.wav'
  _ = 'ffmpeg -i '+input_file+' -vn -ss '+start_time+' -t 00:00:01 '+output_wav_file
  esystem _
  # ======================================================================= #
  # (3) Generate a noise profile in sox:
  # ======================================================================= #
  _ = 'sox '+output_wav_file+' -n noiseprof noise.prof'
  esystem _
  # ======================================================================= #
  # (4) Clean the noise samples from the audio stream:
  # ======================================================================= #
  _ = 'sox '+temp_audio_wav+' '+temp_audio_wav.sub(/\.wav$/,'')+'_tmpaud-clean.wav noisered noise.prof 0.21'
  esystem _
  # ======================================================================= #
  # (5) Change the 0.21 value above ^^^ to adjust the level of sensitivity
  # in the sampling rates (0.2-0.3 often provides the best result).
  # ======================================================================= #
  # (6) Merge audio and video streams back together:
  # ======================================================================= #
  _ = 'ffmpeg -i tmpaud-clean.wav -i tmpvid.mp4 -qscale 0 vid.mp4'
  esystem _
end
split_into_chunks_of_5_minutes( i = '*.mp4' ) click to toggle source
#

MultimediaParadise.split_into_chunks_of_5_minutes

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 445
def self.split_into_chunks_of_5_minutes(
    i = '*.mp4'
  )
  MultimediaParadise.split_into_chunks_of_n_minutes(i, 5)
end
split_into_chunks_of_n_minutes( this_video = '*.mp4', n_minutes = 5 ) click to toggle source
#

MultimediaParadise.split_into_chunks_of_n_minutes

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 430
def self.split_into_chunks_of_n_minutes(
    this_video = '*.mp4',
    n_minutes  = 5
  )
  this_video = this_video.first if this_video.is_a? Array
  _ = 'ffmpeg -i '+this_video+' -c copy -map 0 -segment_time '\
      '00:0'+n_minutes.to_s+':00 -f segment output%03d.mp4'
  e
  esystem _
  e
end
start_screencast( use_this_screen_resolution = return_screen_resolution, output_filename = 'screencast', use_this_framerate = '25', use_this_video_codec = 'huffyuv' ) click to toggle source
#

MultimediaParadise.start_screencast

This method can be used to “record” the desktop, by making use of x11grab and the huffyuv codec.

If more flexibility is required then this may be added at a later time.

Keep in mind that this will create HUGE files depending on the video codec in use - like 20 seconds may occupy 2 gigabytes for the lossless huffyuv codec.

If you wish to use different video or audio codecs, you can use these commandline flags:

-vcodec: video encoding codec
-acodec: audio encoding codec

To record the desktop only, one could use a commandline flag such as this one here:

ffmpeg -f x11grab -s 1366x768 -i :0.0 -r 25 -vcodec libx264 output.mkv
ffmpeg -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec huffyuv screencast.avi

For some useful links (should these persist), have a look at:

https://www.pcsuggest.com/linux-screen-recorder-ffmpeg/
#
# File lib/multimedia_paradise/toplevel_methods/start_screencast.rb, line 43
def self.start_screencast(
    use_this_screen_resolution = return_screen_resolution, # ← We will use the default screen-resolution here.
    output_filename            = 'screencast',
    use_this_framerate         = '25',     # ← This is the option -r to ffmpeg.
    use_this_video_codec       = 'huffyuv' # ← or libx264, for instance.
  )
  ffmpeg_start_screencast(
    use_this_screen_resolution,
    output_filename,
    use_this_framerate,
    use_this_video_codec
  )
end
start_the_libui_wrapper_over_cut_multimedia() click to toggle source
#

MultimediaParadise.start_the_libui_wrapper_over_cut_multimedia

#
# File lib/multimedia_paradise/commandline/menu.rb, line 93
def self.start_the_libui_wrapper_over_cut_multimedia
  require 'multimedia_paradise/gui/libui/cut_multimedia/cut_multimedia.rb'
  MultimediaParadise::GUI::LibUI::CutMultimedia.new
end
streamripper(i = nil) click to toggle source
#

MultimediaParadise.streamripper

#
# File lib/multimedia_paradise/audio/streamripper/streamripper_wrapper.rb, line 269
def self.streamripper(i = nil)
  MultimediaParadise::Audio::StreamripperWrapper.new(i)
end
stretch_audio( this_audio_file, by_this_factor = 1.2 ) click to toggle source
#

MultimediaParadise.stretch_audio

More than 1.0 means longer duration, less then 1.0 will shorten the song.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 490
def self.stretch_audio(
    this_audio_file,
    by_this_factor = 1.2
  )
  if this_audio_file.is_a? Array
    this_audio_file.each {|entry| stretch_audio(entry) }
  else
    cmd = 'sox '+this_audio_file+' '+this_audio_file+' stretch '+by_this_factor.to_s
    run_sys_command cmd
  end
end
title_of_the_audio_file?() click to toggle source
#

MultimediaParadise.title_of_the_audio_file?

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 223
def self.title_of_the_audio_file?
  @title_of_the_audio_file
end
to_avi_with_this_image(audio_file, image_file) click to toggle source
#

MultimediaParadise.to_avi_with_this_image

Easier toplevel-method to add a static image file to an audio file.

#
# File lib/multimedia_paradise/multimedia/convert_audio_to_video_with_image.rb, line 153
def self.to_avi_with_this_image(audio_file, image_file)
  MultimediaParadise::ConvertAudioToVideoWithImage.new(audio_file, image_file)
end
to_dv(a, b = '.dv') click to toggle source
#

MultimediaParadise.to_dv

This entry point will convert into “Digital Video” format.

Usage example:

MultimediaParadise.to_dv 'foobar.mp4'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 915
def self.to_dv(a, b = '.dv')
  ::MultimediaParadise.general_format_conversion(a, b)
end
to_flac(input_files) click to toggle source
#

MultimediaParadise.to_flac

Convert e. g. a .mp3 file into a .flac file.

#
# File lib/multimedia_paradise/toplevel_methods/to_flac.rb, line 14
def self.to_flac(input_files)
  [input_files].flatten.compact.each {|this_input_file|
    output_name = File.absolute_path(
      'output_'+File.basename(this_input_file).
      delete_suffix(File.extname(this_input_file))+'.flac'
    )
    e
    esystem "ffmpeg -i #{this_input_file} #{output_name}"
    e
  }
end
to_gif(i) click to toggle source
#

MultimediaParadise.to_gif

This method can be used to quickly turn an .avi file or a .mp4 file into an animated .gif.

The quality is pretty low, so this is not ideal, but if you have a use case for animated .gif files then this is one way to do so.

Usage example:

MultimediaParadise.to_gif('foobar.mp4')
#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 124
def self.to_gif(i)
  [i].flatten.compact.each {|this_video_file|
    _ = File.basename(this_video_file).
             delete_suffix(
               File.extname(this_video_file)
             )
    name_of_the_output_gif_file = "output_#{_}.gif"
    cmd = "ffmpeg -i #{this_video_file} -pix_fmt rgb8 #{name_of_the_output_gif_file}" # Or use 0rgb.
    esystem(cmd)
    return name_of_the_output_gif_file
  }
end
to_mkv(a, b = '.mkv') click to toggle source
#

MultimediaParadise.to_mkv

Usage example:

MultimediaParadise.to_mkv 'foobar.mp4'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 901
def self.to_mkv(a, b = '.mkv')
  ::MultimediaParadise.general_format_conversion(a, b)
end
to_mp3(*i) click to toggle source
#

MultimediaParadise.to_mp3

Simpler top-level API to convert the given input towards a .mp3 file.

#
# File lib/multimedia_paradise/audio/to_mp3.rb, line 130
def self.to_mp3(*i)
  MultimediaParadise::Audio::ToMp3.new(i)
end
to_mp4(*these_files) click to toggle source
#

MultimediaParadise.to_mp4

#
# File lib/multimedia_paradise/toplevel_methods/to_mp4.rb, line 14
def self.to_mp4(*these_files)
  File.absolute_path(
    ffmpeg_to_mp4(these_files)
  )
end
to_mp4_with_this_image(audio_file = 'slide1_audio.mp3', image_file = 'image.png') click to toggle source
#

MultimediaParadise.to_mp4_with_this_image

Easier toplevel-method to add a static image file to an audio file.

#
# File lib/multimedia_paradise/multimedia/convert_audio_to_video_with_image.rb, line 162
def self.to_mp4_with_this_image(audio_file = 'slide1_audio.mp3', image_file = 'image.png')
  MultimediaParadise::ConvertAudioToVideoWithImage.new(audio_file, image_file) { :to_mp4 }
end
to_ts() click to toggle source
#

MultimediaParadise.to_ts

This will batch-convert all .mp4 files into .ts files.

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 465
def self.to_ts
  files = Dir['*.mp4']
  files.each {|this_file|
    cmd = 'ffmpeg -i '+this_file+' -c copy '\
          '-bsf:v h264_mp4toannexb -f mpegts '+
          this_file.sub(/#{File.extname(this_file)}$/,'')+
          '.ts'

    esystem cmd
  }
end
to_vob(*i) click to toggle source
#

MultimediaParadise.to_vob

This method converts input to a .vob file, which is a file that is used for DVD-playback.

Usage example:

require 'multimedia_paradise/autoinclude'

to_vob 'Simpsons_Halloween_DasHaus.avi'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 458
def self.to_vob(*i)
  _ = 'ffmpeg -y -i '+i.join(' ')+' MERGED.vob'
  e _
  run_sys_command _
end
to_webm(a, b = '.webm') click to toggle source
#

MultimediaParadise.to_webm

Usage example:

MultimediaParadise.to_webm 'foobar.mp4'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 889
def self.to_webm(a, b = '.webm')
  ::MultimediaParadise.general_format_conversion(a, b)
end
total_duration(i = ARGF) click to toggle source
#

MultimediaParadise.total_duration

This method will attempt to determine the total duration, in n minutes right now. At a later time this may become more flexible but for now it will only work on minutes.

#
# File lib/multimedia_paradise/toplevel_methods/total_duration.rb, line 16
def self.total_duration(i = ARGF)
  _ = ''.dup # Build up our temporary String.
  if i.respond_to? :each_line
    i.each_line {|this_line|
      _ << this_line << "\n"
    }
  else
    _ << i
  end
  scanned_result = _.scan(/(\d{1,2}.\d{0,1}) minutes/)
  n_minutes = scanned_result.flatten.map {|line| line.to_f }.sum
  n_minutes
end
trim_audio(of_this_file) click to toggle source
#

MultimediaParadise.trim_audio

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 505
def self.trim_audio(of_this_file)
  e 'Start at how many seconds:'
  start_pos = $stdin.gets.chomp
  e 'Capture how many seconds?'
  duration = $stdin.gets.chomp
  cmd = 'sox '+of_this_file+' trim '+start_pos+' '+duration
  e cmd
end
try_to_find_a_match_for_a_similar_radio_station(i) click to toggle source
#

MultimediaParadise.try_to_find_a_match_for_a_similar_radio_station

This method will attempt to find a matching URL from the given input.

#
# File lib/multimedia_paradise/toplevel_methods/radio.rb, line 35
def self.try_to_find_a_match_for_a_similar_radio_station(i)
  i = i.to_s.downcase.delete(' ')
  all_radio_stations = MultimediaParadise.radio_stations?
  selection = all_radio_stations.select {|name_of_the_radio_station, remote_URL|
    name_of_the_radio_station.downcase.delete(' ').include? i
  }
  return selection
end
try_to_rename_kde_konsole_tab( new_title = '_', try_to_rename_the_kde_konsole_tab = TRY_TO_RENAME_THE_KDE_KONSOLE_TAB ) click to toggle source
#

MultimediaParadise.try_to_rename_kde_konsole_tab

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 830
def self.try_to_rename_kde_konsole_tab(
    new_title                         = '_',
    try_to_rename_the_kde_konsole_tab = TRY_TO_RENAME_THE_KDE_KONSOLE_TAB
  )
  if try_to_rename_the_kde_konsole_tab
    begin
      require 'roebe/requires/require_kde_konsole.rb'
    rescue LoadError
      e 'roebe/requires/require_kde_konsole.rb is not available'
    end
    if Object.const_defined?(:Roebe) and
       Roebe.respond_to?(:rename_konsole)
      Roebe.rename_konsole(new_title)
    end
  end
end
use_lame_codec( this_video_file ) click to toggle source
#

MultimediaParadise.use_lame_codec

Use this method if you quickly want to replace one audio codec with another - in this context the lame (liblame) audio codec.

The input should be a locally existing video file. The -acodec value will be libmp3lame.

The input to this method should be an existing video file.

#
# File lib/multimedia_paradise/toplevel_methods/use_lame_codec.rb, line 22
def self.use_lame_codec(
    this_video_file
  )
  ffmpeg_use_lame_codec(this_video_file)
end
use_this_binary_for_conversions?() click to toggle source
#

MultimediaParadise.use_this_binary_for_conversions?

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 46
def self.use_this_binary_for_conversions?
  @use_this_binary_for_conversions
end
verbose_analyse_this_mp3_file_for_id3_tags(this_mp3_file) click to toggle source
#

MultimediaParadise.verbose_analyse_this_mp3_file_for_id3_tags

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 741
def self.verbose_analyse_this_mp3_file_for_id3_tags(this_mp3_file)
  require 'id3lib'
  if this_mp3_file.is_a? Array
    this_mp3_file.each {|entry|
      verbose_analyse_this_mp3_file_for_id3_tags(entry)
    }
  else
    dataset = ID3Lib::Tag.new(this_mp3_file)
    e "#{::Colours.rev}"\
      "The .mp3 file is called: #{sfancy(this_mp3_file)}"
    if dataset.empty?
      e 'Has no id3-tags!'
    else
      # e 'Has some id3-tags.' # <- Dont report this in this case, though.
      # ===================================================================== #
      # Iterate through these entries next.
      # ===================================================================== #
      dataset.each_entry {|inner_hash|
        value = inner_hash[:text].to_s
        case inner_hash[:id]
        # =================================================================== #
        # === :TIT2
        # =================================================================== #
        when :TIT2
          e 'The title is: '+
             Colours.steelblue(value) unless value.empty?
        # =================================================================== #
        # === :TCON
        #
        # The genre.
        # =================================================================== #
        when :TCON
          e 'The genre is: '+
             Colours.steelblue(value) unless value.empty?
        # =================================================================== #
        # === :TYER
        #
        # The year.
        # =================================================================== #
        when :TYER
          e 'The year is: '+
             Colours.steelblue(value) unless value.empty?
        # =================================================================== #
        # === :TPE1
        #
        # The artist.
        # =================================================================== #
        when :TPE1
          e 'The artist is: '+
             Colours.steelblue(value) unless value.empty?
        end
      }
      # pp dataset # <- for debugging.
    end
  end
end
version?() click to toggle source
#

MultimediaParadise.version?

#
# File lib/multimedia_paradise/version/version.rb, line 24
def self.version?
  VERSION
end
vertical_flip(this_video_file) click to toggle source
#

MultimediaParadise.vertical_flip

This method will make use of the video-filter called “vflip”. A vertical flip will flip the video from head-to-bottom, so people will suddenly appear as if they are hanging from the ceiling. :)

Invocation example:

MultimediaParadise.vertical_flip '/Depot/Video/Reallife/O.J.Simpson_TV_News_etwa_1995.avi'
#
# File lib/multimedia_paradise/toplevel_methods/flip_and_rotate.rb, line 26
def self.vertical_flip(this_video_file)
  ffmpeg_vertical_flip(this_video_file)
end
video_duration( of_this_file, time_range = '00:30:00-00:35:00' ) click to toggle source
#

MultimediaParadise.video_duration

This method is a wrapper over the method called MultimediaParadise.cut_from_to(). It specifically uses the reversed arrangement of arguments, compared to that other method.

Specific usage example:

MultimediaParadise.video_duration(of_this_file, '00:30:00-00:35:00')
MultimediaParadise.video_duration('/home/x/studium/UNI_WIEN/321005_Grundlagen_der_Chemie/videos/DONE_Einheit_01_Grundlagen.mp4', '00:04:00-20:35:00')
#
# File lib/multimedia_paradise/toplevel_methods/cut_from_to.rb, line 27
def self.video_duration(
    of_this_file,
    time_range = '00:30:00-00:35:00'
  )
  MultimediaParadise.cut_from_to(time_range, of_this_file)
end
video_information(i) click to toggle source
#

MultimediaParadise.video_information

#
# File lib/multimedia_paradise/video/video_information.rb, line 433
def self.video_information(i)
  _ = MultimediaParadise::Video::VideoInformation.new(i)
  _.verbose_report(:do_not_report_the_namespace)
end
video_to_images( which_video = 'video.mpg', format_to_use = :default, framerate_to_use = 25 ) click to toggle source
#

MultimediaParadise.video_to_images

This method can, by leveraging “ffmpeg”, convert a video-file into a set of image-files.

The first argument to this method should be the filename of the video-file, such as “foobar.mp4” or “cool_movie.mkv”.

Right now the default target format for the images will be .jpg, but you could also use .png or any other image-format. This is the second argument to this method.

If you need a variant that works for bash (the shell), try this:

ffmpeg -i ack.mkv extracted_images_from_file_ack_%d.jpg

Or via the bin/video_to_images file:

video_to_images ack.mkv
videotoimages *.avi
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 559
def self.video_to_images(
    which_video      = 'video.mpg',
    format_to_use    = :default,
    framerate_to_use = 25
  )
  if format_to_use.frozen?
    format_to_use = format_to_use.dup
  end
  case format_to_use
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    format_to_use = '.jpg'
  end
  unless format_to_use.start_with? '.'
    format_to_use.prepend '.'
  end
  [which_video].flatten.compact.each {|this_video_file|
    cliner
    cmd = 'ffmpeg '+
          '-i '+this_video_file.to_s+' '+
          '-r '+framerate_to_use.to_s+
          ' extracted_images_from_the_movie_%d'+format_to_use
    run_sys_command cmd
    cliner
  }
end
vobmerge(*input_files) click to toggle source
#

MultimediaParadise.vobmerge

You must pass the vob files to merge to this method.

#
# File lib/multimedia_paradise/toplevel_methods/merge_multimedia_file.rb, line 305
def self.vobmerge(*input_files)
  _ = 'cat '.dup
  input_files = input_files.flatten
  input_files.each {|file| _ << "#{file} " }
  _ << ' > merged_'+File.basename(input_files.first) #.gsub(/\.vob/,'')
  run_sys_command _
end
watermark( videofile = nil, use_this_image_as_watermark = MultimediaParadise::Video::Watermark::USE_THIS_IMAGE_AS_WATERMARK ) click to toggle source
#

MultimediaParadise.watermark

The first argument shall be the video file that we wish to watermark.

The second argument shall be the path to the image that we will use for the watermark in question.

To use this method, try this:

MultimediaParadise.watermark('/Depot/Video/053_Muttertag.mp4')
#
# File lib/multimedia_paradise/video/watermark.rb, line 271
def self.watermark(
    videofile                   = nil,
    use_this_image_as_watermark =
      MultimediaParadise::Video::Watermark::USE_THIS_IMAGE_AS_WATERMARK
  )
  MultimediaParadise::Video::Watermark.new(
    videofile, use_this_image_as_watermark
  )
end
wav_to_midi( input_file, output_file = 'ack.mid' ) click to toggle source
#

MultimediaParadise.wav_to_midi

Convert wav to midi file using waon.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 253
def self.wav_to_midi(
    input_file, output_file = 'ack.mid'
  )
  cmd = 'waon -i '.dup
  cmd << input_file
  cmd << ' -o '+output_file
  run_sys_command cmd
end
wav_to_mp3( this_file, bitrate_to_use = 192, to = '.mp3' ) click to toggle source
#

MultimediaParadise.wav_to_mp3 (wav_to_mp3 conversion)

We convert a .wav file into a .mp3 file with this method here.

The second argument can be a hash such as:

:output => output?

Usage example:

MultimediaParadise.wav_to_mp3

Another way would be to use ffmpeg like so (-ab is the audio bitrate):

ffmpeg -i audio.wav -acodec mp3 -ab 192k audio.mp3

Usage example:

result = MultimediaParadise.wav_to_mp3 '/Depot/j/BOTY_2013_MorningOfOwlShowcase.mp3'
MultimediaParadise.wav_to_mp3 '/Depot/jj/Youtube2008_Soundmix.wav'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 346
def self.wav_to_mp3(
    this_file, bitrate_to_use = 192, to = '.mp3'
  )
  ::MultimediaParadise.general_format_conversion(this_file, to) {{
    bitrate_to_use: bitrate_to_use
  }}
end
wav_to_ogg( i = '/Depot/j/foobar.wav', to = 'ogg' ) click to toggle source
#

MultimediaParadise.wav_to_ogg

Perform a .wav to .ogg conversion through this method here.

Usage examples:

wav_to_ogg 'test.wav'
MultimediaParadise.wav_to_ogg('/Depot/j/foobar.wav','/Depot/j/yodel.ogg')
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 636
def self.wav_to_ogg(
    i  = '/Depot/j/foobar.wav',
    to = 'ogg'
  )
  MultimediaParadise.convert(i, to: to)
end
wav_to_opus(this_file, to = '.opus') click to toggle source
#

MultimediaParadise.wav_to_opus

Use this method to convert a .mp4 file into a .mp3 file.

We will use ffmpeg for this conversion.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 319
def self.wav_to_opus(this_file, to = '.opus')
  ::MultimediaParadise.general_format_conversion(this_file, to)
end
webm_to_mp3(a, b = '.mp3') click to toggle source
#

MultimediaParadise.webm_to_mp3

Usage example:

MultimediaParadise.webm_to_mp3 'Intermission_Six_Days-Jg9P3Z7ZCcE.f171.webm', '/Depot/j/yo.mp3'
#
# File lib/multimedia_paradise/conversions/conversions.rb, line 877
def self.webm_to_mp3(a, b = '.mp3')
  ::MultimediaParadise.general_format_conversion(a, b)
end
widget_increase_or_decrease_audio(i = ARGV) click to toggle source
#

MultimediaParadise.widget_increase_or_decrease_audio

#
# File lib/multimedia_paradise/gui/shared_code/widget_increase_or_decrease_audio/widget_increase_or_decrease_audio_module.rb, line 306
def self.widget_increase_or_decrease_audio(i = ARGV)
  return MultimediaParadise::GUI::Gtk::WidgetIncreaseOrDecreaseAudio.new(i)
end
yel(i) click to toggle source
#

MultimediaParadise.yel

#
# File lib/multimedia_paradise/colours/colours.rb, line 64
def self.yel(i)
  return COLOURS.yellow(i)
end

Public Instance Methods

cd(i)
Alias for: chdir
chdir(i) click to toggle source
#

chdir (cd tag)

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 76
def chdir(i)
  MultimediaParadise.chdir(i)
end
Also aliased as: cd, cd
cliner() click to toggle source
#

cliner

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 53
def cliner
  Cliner.cliner
end
delete_file(i)
Alias for: remove_file
entry_at_this_position(position) click to toggle source
#

entry_at_this_position

The input should be a number. This number is the video file at said position.

For instance, the argument 20 will obtain “A chinese ghost story”.

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 63
def entry_at_this_position(position)
  VIDEO_DATASET[position]
end
filter_for_video_files(i) click to toggle source
#

filter_for_video_files

#
# File lib/multimedia_paradise/toplevel_methods/is_video_file.rb, line 58
def filter_for_video_files(i)
  MultimediaParadise.filter_for_video_files(i)
end
flash_to_avi(file) click to toggle source
#

MultimediaParadise.flash_to_avi

Convert a .flv file to .avi.

#
# File lib/multimedia_paradise/conversions/conversions.rb, line 391
def flash_to_avi(file)
  run_sys_command "ffmpeg -i #{file} #{file}.avi"
end
glob(i) click to toggle source
#

glob

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 718
def glob(i)
  Dir[i]
end
map_number_to_videofile(i = '002') click to toggle source
#

map_number_to_videofile

Input a number, such as 001, which we will then use to find the videofile in question, and return the title.

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 45
def map_number_to_videofile(i = '002')
  _ = i.to_i
  if VIDEO_DATASET.has_key? _
    result = VIDEO_DATASET[_]['title']
    return result
  else
    i
  end
end
max_entries_registered?() click to toggle source
#

max_entries_registered?

This method will tell us how many video files we have registered.

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 72
def max_entries_registered?
  VIDEO_DATASET.keys.max
end
mkdir(i) click to toggle source
#

mkdir

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 54
def mkdir(i)
  MultimediaParadise.mkdir(i)
end
obtain_position_of(i)
obtain_title_at_position(i) click to toggle source
#

obtain_title_at_position

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 28
def obtain_title_at_position(i)
  MultimediaParadise.obtain_title_at_position(i)
end
rds(i) click to toggle source
#

rds

#
# File lib/multimedia_paradise/toplevel_methods/rds.rb, line 20
def rds(i)
  MultimediaParadise.rds(i)
end
remove_file(i) click to toggle source
#

remove_file

#
# File lib/multimedia_paradise/toplevel_methods/files_and_directories.rb, line 37
def remove_file(i)
  MultimediaParadise.remove_file(i)
end
Also aliased as: delete_file
return_all_video_files() click to toggle source
#

return_all_video_files

Return all video files that are defined in the file video_collection.yml.

#
# File lib/multimedia_paradise/toplevel_methods/return_all_video_files.rb, line 56
def return_all_video_files
  MultimediaParadise.return_all_video_files # Defined in this file here.
end
return_full_name_for_video_at_this_position(a = 1, b = 'avi') click to toggle source
#

return_full_name_for_video_at_this_position

This method may return a String such as ‘001_TheAnimatrix.avi’.

#
# File lib/multimedia_paradise/toplevel_methods/return_full_name_for_video_at_this_position.rb, line 43
def return_full_name_for_video_at_this_position(a = 1, b = 'avi')
  ::MultimediaParadise.return_full_name_for_video_at_this_position(a, b)
end
return_title_and_position_of(i) click to toggle source
#

return_title_and_position_of

#
# File lib/multimedia_paradise/toplevel_methods/video_dataset.rb, line 35
def return_title_and_position_of(i)
  VIDEO_DATASET[i.to_i]['title'].to_s if VIDEO_DATASET.has_key? i.to_i
end
Also aliased as: obtain_position_of
video_collection?() click to toggle source
#

video_collection?

#
# File lib/multimedia_paradise/toplevel_methods/misc.rb, line 725
def video_collection?
  ::MultimediaParadise.file_video_collection
end