
Recherche avancée
Médias (1)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
Autres articles (111)
-
Script d’installation automatique de MediaSPIP
25 avril 2011, parAfin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
La documentation de l’utilisation du script d’installation (...) -
Que fait exactement ce script ?
18 janvier 2011, parCe script est écrit en bash. Il est donc facilement utilisable sur n’importe quel serveur.
Il n’est compatible qu’avec une liste de distributions précises (voir Liste des distributions compatibles).
Installation de dépendances de MediaSPIP
Son rôle principal est d’installer l’ensemble des dépendances logicielles nécessaires coté serveur à savoir :
Les outils de base pour pouvoir installer le reste des dépendances Les outils de développements : build-essential (via APT depuis les dépôts officiels) ; (...) -
Activation de l’inscription des visiteurs
12 avril 2011, parIl est également possible d’activer l’inscription des visiteurs ce qui permettra à tout un chacun d’ouvrir soit même un compte sur le canal en question dans le cadre de projets ouverts par exemple.
Pour ce faire, il suffit d’aller dans l’espace de configuration du site en choisissant le sous menus "Gestion des utilisateurs". Le premier formulaire visible correspond à cette fonctionnalité.
Par défaut, MediaSPIP a créé lors de son initialisation un élément de menu dans le menu du haut de la page menant (...)
Sur d’autres sites (5113)
-
How do I get videos to upload using ruby on rails carrierwave-video ?
9 juillet 2016, par EricUpdated as of July 9, 2016
I tried to follow the instructions on the github website for the video uploader process using carrierwave-video gem but get an error that says the file or directory mmpeg -i doesn’t exist.
The upload path for images functions correctly, just not the video one.
I have added all of the following code necessary to help solve the error and minified as much as i possibly could.
Video uploader code using carrierwave
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
storage :file
version :mp4 do
process :encode_video => [:mp4, resolution: "100x100"]
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
endHere is the movie controller code that handles uploading of videos
class MoviesController < ApplicationController
include MoviesHelper
def index
mode "index"
end
def show
mode "show"
end
def new
mode "new"
end
def edit
mode "edit"
end
def create
mode "create"
end
def update
mode "update"
end
def destroy
mode "destroy"
end
def review
mode "review"
end
def approve
mode "approve"
end
def deny
mode "deny"
end
endHere is the model data for the movie that goes with it
class Movie < ActiveRecord::Base
attr_accessible :created_on, :description, :maintenance, :reviewed, :subplaylist_id, :title, :user_id, :video, :remote_video_url
belongs_to :user
belongs_to :subplaylist
mount_uploader :video, VideoUploader
endHere is where the movie is supposed to be displayed but it is not working
<% provide(:title, "Movie: Where movies are made!") %>
<% provide(:keywords, "movies, video") %>
<% provide(:description, "This is the place where users showcase their wonderful video talent.") %>
<p><%= notice %></p>
<h1 class="pageheader"><%= @movie.title %></h1>
<br />
<p class="pagetext"><%= video_tag(@movie.video_url.to_s, controls: true, class: "imagebox") %></p>
<p class="pagetext"><%= @movie.description %></p>
<p class="pagetext">Created on: <%= @movie.created_on.strftime("%B-%d-%Y") %></p>
<p class="pagetext">Owner: <%= getType(@movie.user) %><%= link_to @movie.user.vname, user_path(@movie.user) %></p>
<br />
<p class="pagetext"><%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @movie.subplaylist) %></p>Here is where the movie new action is
<% provide(:title, "Movie: Create new movies here!") %>
<% provide(:description, "New movies are uploaded only to the site when the movie gets approved.") %>
<h1 class="pagetextheader">New movie</h1>
<%= render 'form' %>
<p class="pagetext"><%= link_to 'Back', mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist) %></p>Here is where the movies forum parameters are
<%= form_for([@subplaylist, @movie], :html=>{:multipart => true}) do |f| %>
<% if @movie.errors.any? %>
<div>
<h2><%= pluralize(@movie.errors.count, "error") %> prohibited this movie from being saved:</h2>
<ul>
<% @movie.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<br />
<div class="pagetext">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="pagetext">
<%= f.file_field :video %>
</div>
<div class="pagetext">
<%= f.label :remote_video_url, "or video URL" %><br />
<%= f.text_field :remote_video_url %>
</div>
<div class="pagetext">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="pagetext">
<%= f.submit %>
</div>
<br />
<% end %>Here is the movies helper code
module MoviesHelper
def mode(type)
code = auto_logout
if(code == true)
sign_out
redirect_to root_path
else
#Check if Maintenance is turned_on
allmode = Maintenancemode.find_by_id(1)
moviemode = Maintenancemode.find_by_id(19)
mode_turned_on = (allmode.maintenance_on || moviemode.maintenance_on)
#Determine if any maintenance is on
if(mode_turned_on)
#Determine if we are a regular user
regularUser = (!current_user || !current_user.admin?)
if(regularUser)
#Determine which maintenance mode is on
if(allmode.maintenance_on)
redirect_to maintenance_path
else
redirect_to movies_maintenance_path
end
else
switch type
end
else
switch type
end
end
end
private
def getType(user)
if(user.admin)
value = "$"
else
typeFound = Usertype.find_by_user_id(user.id)
if(typeFound)
type = typeFound.privilege
if(type == "Reviewer")
value = "^"
elsif(type == "Banned")
value = "!"
else
value = "~"
end
else
value = "~"
end
end
return value
end
def movieApproved
movieFound = Movie.find_by_id(params[:movie_id])
if(movieFound)
movieFound.reviewed = true
pouch = Pouch.find_by_user_id(movieFound.user_id)
pointsForMovie = 10
pouch.amount += pointsForMovie
@pouch = pouch
@pouch.save
@movie = movieFound
@movie.save
# MovieMailer.movie_approved(@movie, pointsForMovie).deliver
redirect_to movies_review_path
else
render "public/404"
end
end
def movieDenied
movieFound = Movie.find_by_id(params[:movie_id])
if(movieFound)
#Retrieve the user who owns this pet first
#userEmail = petFound.user.email
#Send mail to user with link to edit the pet they sent
@movie = movieFound
MovieMailer.movie_denied(@movie).deliver
redirect_to movies_review_path
else
render "public/404"
end
end
def createMovie(subplaylistFound)
newMovie = subplaylistFound.movies.new
@subplaylist = subplaylistFound
@movie = newMovie
end
def saveMovie(subplaylistFound, logged_in)
newMovie = subplaylistFound.movies.new(params[:movie])
newMovie.user_id = logged_in.id
currentTime = Time.now
newMovie.created_on = currentTime
@movie = newMovie
if(@movie.save)
@subplaylist = subplaylistFound
# MovieMailer.review_movie(@movie).deliver
flash[:success] = "#{@movie.title} is currently being reviewed please check back later."
redirect_to subplaylist_movie_path(@subplaylist, @movie)
else
render "new"
end
end
def switch(type)
if(type == "index") #Admin only
logged_in = current_user
if(logged_in)
if(logged_in.admin)
allMovies = Movies.order("created_on desc").page(params[:page]).per(10)
@movies = allMovies
else
redirect_to root_path
end
else
redirect_to root_path
end
elsif(type == "show")
movieFound = Movie.find_by_id(params[:id])
if(movieFound)
subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
if(subplaylistFound)
if(movieFound.reviewed)
@subplaylist = subplaylistFound
@movie = movieFound
else
logged_in = current_user
if(logged_in)
userMatch = ((logged_in.id == movieFound.user_id) || logged_in.admin)
if(userMatch)
@subplaylist = subplaylistFound
@movie = movieFound
else
redirect_to root_path
end
else
redirect_to root_path
end
end
else
redirect_to root_path
end
else
render "public/404"
end
elsif(type == "new")
logged_in = current_user
if(logged_in)
subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
if(subplaylistFound)
if(subplaylistFound.collab_mode)
createMovie(subplaylistFound)
else
userMatch = (logged_in.id == subplaylistFound.user_id)
if(userMatch)
createMovie(subplaylistFound)
else
redirect_to root_path
end
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "create")
logged_in = current_user
if(logged_in)
subplaylistFound = Subplaylist.find_by_id(params[:subplaylist_id])
if(subplaylistFound)
if(subplaylistFound.collab_mode)
saveMovie(subplaylistFound, logged_in)
else
userMatch = (logged_in.id == subplaylistFound.user_id)
if(userMatch)
saveMovie(subplaylistFound, logged_in)
else
redirect_to root_path
end
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "edit")
logged_in = current_user
if(logged_in)
movieFound = Movie.find_by_id(params[:id])
if(movieFound)
userMatch = (logged_in.id == movieFound.user_id)
if(userMatch)
subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
if(subplaylistFound)
@subplaylist = subplaylistFound
@movie = movieFound
else
render "public/404"
end
else
redirect_to root_path
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "update")
logged_in = current_user
if(logged_in)
movieFound = Movie.find_by_id(params[:id])
if(movieFound)
userMatch = (logged_in.id == movieFound.user_id)
if(userMatch)
subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
if(subplaylistFound)
@movie = movieFound
if(@movie.update_attributes(params[:movie]))
@subplaylist = subplaylistFound
flash[:success] = 'Movie was successfully updated.'
redirect_to subplaylist_movie_path(@subplaylist, @movie)
else
render "edit"
end
else
render "public/404"
end
else
redirect_to root_path
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "destroy")
logged_in = current_user
if(logged_in)
movieFound = Movie.find_by_id(params[:id]) #Need to move this below the admin section to protect it
if(movieFound)
if(logged_in.admin)
subplaylistFound = Subplaylist.find_by_id(movieFound.subplaylist_id)
if(subplaylistFound)
@movie = movieFound
@subplaylist = subplaylistFound
@movie.destroy
redirect_to mainplaylist_subplaylist_path(@subplaylist.mainplaylist, @subplaylist)
else
render "public/404"
end
else
redirect_to root_path
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "review") #Admin
logged_in = current_user
if(logged_in)
if(logged_in.admin)
allMovies = Movie.all
moviesToReview = allMovies.select{|movie| !movie.reviewed}
@movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
else
typeFound = Usertype.find_by_user_id(logged_in.id)
if(typeFound.privilege == "Reviewer")
allMovies = Movie.all
moviesToReview = allMovies.select{|movie| !movie.reviewed}
@movies = Kaminari.paginate_array(moviesToReview).page(params[:page]).per(10)
else
redirect_to root_path
end
end
else
redirect_to root_path
end
elsif(type == "approve") #Admin
logged_in = current_user
if(logged_in)
if(logged_in.admin)
movieApproved
else
typeFound = Usertype.find_by_user_id(logged_in.id)
if(typeFound.privilege == "Reviewer")
movieApproved
else
redirect_to root_path
end
end
else
redirect_to root_path
end
elsif(type == "deny") #Admin
logged_in = current_user
if(logged_in)
if(logged_in.admin)
movieDenied
else
typeFound = Usertype.find_by_user_id(logged_in.id)
if(typeFound.privilege == "Reviewer")
movieDenied
else
redirect_to root_path
end
end
else
redirect_to root_path
end
end
end
endHere is the subplaylists show code
<% provide(:title, "Subplaylist: The place where users videos gets uploaded to!") %>
<% provide(:keywords, "user, video, uploaded") %>
<% provide(:description, "Allows the categorization of various videos that the user submitted successfully.") %>
<p><%= notice %></p>
<h1 class="pageheader"><%= @subplaylist.title %></h1>
<br />
<p class="pagetext"><%= @subplaylist.description %></p>
<br />
<div class="pagebox"><%= paginate @movies %></div>
<br />
<div class="pagetext">
<% @movies.each_with_index do |movie, index| %>
<div class="container">
<div class="inner">
<div class="inner"><%= link_to movie.title, subplaylist_movie_path(@subplaylist, movie) %></div>
<% if current_user && (current_user.id == movie.user_id || current_user.admin? )%>
<div class="inner"><%= button_to 'Edit', edit_subplaylist_movie_path(@subplaylist, movie), method: :get %></div>
<div class="inner"><%= button_to 'Destroy', [@subplaylist, movie], method: :delete, data: { confirm: 'Are you sure?' } %></div>
<% end %>
<p><%= video_tag movie.video_url(:thumb).to_s, controls: true %></p>
</div>
<br />
<p>Created on: <%= movie.created_on.strftime("%B-%d-%Y") %></p>
<p>Owner: <%= getType(movie.user) %><%= link_to movie.user.vname, user_path(movie.user) %></p>
</div>
<% if ((index + 1) % 3) == 0 %>
<br />
<br />
<% end %>
<% end %>
</div>
<br />
<% if current_user %>
<p class="pagetext"><%= link_to "New Movie", new_subplaylist_movie_path(@subplaylist) %></p>
<br />
<% end %>
<p class="pagetext"><%= link_to 'Back', user_mainplaylist_path(@mainplaylist.user.vname, @subplaylist.mainplaylist.title) %></p>Here is the subplaylists model
class Subplaylist < ActiveRecord::Base
attr_accessible :title, :description, :collab_mode
belongs_to :user
belongs_to :mainplaylist
has_many :movies, :foreign_key => "subplaylist_id", :dependent => :destroy
VALID_NAME = /\A[A-Za-z][A-Za-z1-9][A-Za-z1-9 ]+\z/
validates :title, presence: true, format: {with: VALID_NAME}
validates :description, presence: true
endHere is the subplaylists controller code
class SubplaylistsController < ApplicationController
include SubplaylistsHelper
def index
mode "index"
end
def show
mode "show"
end
def new
mode "new"
end
def edit
mode "edit"
end
def create
mode "create"
end
def update
mode "update"
end
def destroy
mode "destroy"
end
endHere is the subplaylist helper code
module SubplaylistsHelper
def mode(type)
code = auto_logout
if(code == true)
sign_out
redirect_to root_path
else
#Check if Maintenance is turned_on
allmode = Maintenancemode.find_by_id(1)
subplaylistmode = Maintenancemode.find_by_id(18)
mode_turned_on = (allmode.maintenance_on || subplaylistmode.maintenance_on)
#Determine if any maintenance is on
if(mode_turned_on)
#Determine if we are a regular user
regularUser = (!current_user || !current_user.admin?)
if(regularUser)
#Determine which maintenance mode is on
if(allmode.maintenance_on)
redirect_to maintenance_path
else
redirect_to subplaylists_maintenance_path
end
else
switch type
end
else
switch type
end
end
end
private
def getType(user)
if(user.admin)
value = "$"
else
typeFound = Usertype.find_by_user_id(user.id)
if(typeFound)
type = typeFound.privilege
if(type == "Reviewer")
value = "^"
elsif(type == "Banned")
value = "!"
else
value = "~"
end
else
value = "~"
end
end
return value
end
def switch(type)
if(type == "show")
subplaylistFound = Subplaylist.find_by_id(params[:id])
if(subplaylistFound)
mainplaylistFound = Mainplaylist.find_by_title(params[:mainplaylist_id])
if(mainplaylistFound)
playlistMatch = (subplaylistFound.mainplaylist_id == mainplaylistFound.id)
if(playlistMatch)
@mainplaylist = mainplaylistFound
@subplaylist = subplaylistFound
subplaylistMovies = @subplaylist.movies.all
reviewedMovies = subplaylistMovies
if(subplaylistMovies.count > 0)
reviewedMovies = subplaylistMovies.select{|movie| movie.reviewed}
end
@movies = Kaminari.paginate_array(reviewedMovies).page(params[:page]).per(10)
else
redirect_to root_path
end
else
render "public/404"
end
else
redirect_to root_path
end
elsif(type == "destroy")
logged_in = current_user
if(logged_in)
subplaylistFound = Subplaylist.find_by_id(params[:id]) #Need to move this below the admin section to protect it
if(subplaylistFound)
if(logged_in.admin)
mainplaylistFound = Mainplaylist.find_by_id(subplaylistFound.mainplaylist_id)
if(mainplaylistFound)
@subplaylist = subplaylistFound
@mainplaylist = mainplaylistFound
@subplaylist.destroy
redirect_to mainplaylist_subplaylists_path(@mainplaylist)
else
render "public/404"
end
else
redirect_to root_path
end
else
render "public/404"
end
else
redirect_to root_path
end
end
end
endHere is the User model
class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name, :login_id, :vname, :password, :password_confirmation, :avatar
has_secure_password
mount_uploader :avatar, AvatarUploader
before_save { |user| user.email = user.email.downcase }
before_save { |user| user.first_name = user.first_name.humanize }
#key
has_one :sessionkey, :foreign_key => "user_id", :dependent => :destroy
has_one :usertype, :foreign_key => "user_id", :dependent => :destroy
#Video section
has_many :mainplaylists, :foreign_key => "user_id", :dependent => :destroy
has_many :subplaylists, :foreign_key => "user_id", :dependent => :destroy
has_many :movies, :foreign_key => "user_id", :dependent => :destroy
#validates :first_name, presence: true
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_NAME_REGEX = /\A[a-z][a-z][a-z]+\z/i
VALID_VNAME_REGEX = /\A[A-Za-z][A-Za-z][A-Za-z][A-Za-z0-9 ]+([-][A-Za-z0-9 ]+)?\z/
VALID_PASSWORD_REGEX = /\A[A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!][A-Za-z0-9!]+\z/
validates :first_name, presence: true, format: { with: VALID_NAME_REGEX}
validates :last_name, presence: true, format: { with: VALID_NAME_REGEX}
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX}
validates :login_id, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
validates :vname, presence: true, format: { with: VALID_VNAME_REGEX}, uniqueness: { case_sensitive: false}
validates :password, length: {minimum: 6}#, format: { with: VALID_PASSWORD_REGEX}
validates :password_confirmation, presence: true #, format: { with: VALID_PASSWORD_REGEX}
def to_param
vname
end
endHere is the sessionkey model
class Sessionkey < ActiveRecord::Base
belongs_to :user
endHere is the usertype model
class Usertype < ActiveRecord::Base
attr_accessible :privilege, :user_id #Only priviledge will be changeable
belongs_to :user
endError message
No such file or directory - ffmpeg -i /home/eric/Projects/Local/Lduelingpets/Trial/public/uploads/tmp/1466811951-3149-2702/mp4_TrialMovies.mp4
-
Discord 24/7 video stream self-bot crashes after a couple hours
21 juillet 2023, par angeloI've implemented this library to make a self-bot that streams videos from a local folder in a loop 24/7 (don't ask me why). I set up an ubuntu vps to run the bot and it works perfectly fine the first 2-3 hours, after that it gets more and more laggy until the server crashes.
pd : It's basically my first time using javascript and stole most of the code from this repo so don't bully me.


Here's the code :


import { Client, TextChannel, CustomStatus, ActivityOptions } from "discord.js-selfbot-v13";
import { command, streamLivestreamVideo, VoiceUdp, setStreamOpts, streamOpts } from "@dank074/discord-video-stream";
import config from "./config.json";
import fs from 'fs';
import path from 'path';

const client = new Client();

client.patchVoiceEvents(); //this is necessary to register event handlers

setStreamOpts(
 config.streamOpts.width,
 config.streamOpts.height,
 config.streamOpts.fps,
 config.streamOpts.bitrateKbps,
 config.streamOpts.hardware_acc
)

const prefix = '$';

const moviesFolder = config.movieFolder || './movies';

const movieFiles = fs.readdirSync(moviesFolder);
let movies = movieFiles.map(file => {
 const fileName = path.parse(file).name;
 // replace space with _
 return { name: fileName.replace(/ /g, ''), path: path.join(moviesFolder, file) };
});
let originalMovList = [...movies];
let movList = movies;
let shouldStop = false;

// print out all movies
console.log(`Available movies:\n${movies.map(m => m.name).join('\n')}`);

const status_idle = () => {
 return new CustomStatus()
 .setState('摸鱼进行中')
 .setEmoji('🐟')
}

const status_watch = (name) => {
 return new CustomStatus()
 .setState(`Playing ${name}...`)
 .setEmoji('📽')
}

// ready event
client.on("ready", () => {
 if (client.user) {
 console.log(`--- ${client.user.tag} is ready ---`);
 client.user.setActivity(status_idle() as ActivityOptions)
 }
});

let streamStatus = {
 joined: false,
 joinsucc: false,
 playing: false,
 channelInfo: {
 guildId: '',
 channelId: '',
 cmdChannelId: ''
 },
 starttime: "00:00:00",
 timemark: '',
}

client.on('voiceStateUpdate', (oldState, newState) => {
 // when exit channel
 if (oldState.member?.user.id == client.user?.id) {
 if (oldState.channelId && !newState.channelId) {
 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 streamStatus.channelInfo = {
 guildId: '',
 channelId: '',
 cmdChannelId: streamStatus.channelInfo.cmdChannelId
 }
 client.user?.setActivity(status_idle() as ActivityOptions)
 }
 }
 // when join channel success
 if (newState.member?.user.id == client.user?.id) {
 if (newState.channelId && !oldState.channelId) {
 streamStatus.joined = true;
 if (newState.guild.id == streamStatus.channelInfo.guildId && newState.channelId == streamStatus.channelInfo.channelId) {
 streamStatus.joinsucc = true;
 }
 }
 }
})

client.on('messageCreate', async (message) => {
 if (message.author.bot) return; // ignore bots
 if (message.author.id == client.user?.id) return; // ignore self
 if (!config.commandChannels.includes(message.channel.id)) return; // ignore non-command channels
 if (!message.content.startsWith(prefix)) return; // ignore non-commands

 const args = message.content.slice(prefix.length).trim().split(/ +/); // split command and arguments
 if (args.length == 0) return;

 const user_cmd = args.shift()!.toLowerCase();

 if (config.commandChannels.includes(message.channel.id)) {
 switch (user_cmd) {
 case 'play':
 playCommand(args, message);
 break;
 case 'stop':
 stopCommand(message);
 break;
 case 'playtime':
 playtimeCommand(message);
 break;
 case 'pause':
 pauseCommand(message);
 break;
 case 'resume':
 resumeCommand(message);
 break;
 case 'list':
 listCommand(message);
 break;
 case 'status':
 statusCommand(message);
 break;
 case 'refresh':
 refreshCommand(message);
 break;
 case 'help':
 helpCommand(message);
 break;
 case 'playall':
 playAllCommand(args, message);
 break;
 case 'stream':
 streamCommand(args, message);
 break;
 case 'shuffle':
 shuffleCommand();
 break;
 case 'skip':
 //skip cmd
 break;
 default:
 message.reply('Invalid command');
 }
 }
});

client.login("TOKEN_HERE");

let lastPrint = "";

async function playAllCommand(args, message) {
 if (streamStatus.joined) {
 message.reply("Already joined");
 return;
 }

 // args = [guildId]/[channelId]
 if (args.length === 0) {
 message.reply("Missing voice channel");
 return;
 }

 // process args
 const [guildId, channelId] = args.shift()!.split("/");
 if (!guildId || !channelId) {
 message.reply("Invalid voice channel");
 return;
 }

 await client.joinVoice(guildId, channelId);
 streamStatus.joined = true;
 streamStatus.playing = false;
 streamStatus.starttime = "00:00:00";
 streamStatus.channelInfo = {
 guildId: guildId,
 channelId: channelId,
 cmdChannelId: message.channel.id,
 };

 const streamUdpConn = await client.createStream();

 streamUdpConn.voiceConnection.setSpeaking(true);
 streamUdpConn.voiceConnection.setVideoStatus(true);

 playAllVideos(streamUdpConn); // Start playing videos

 // Keep the stream open

 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 lastPrint = "";
 streamStatus.channelInfo = {
 guildId: "",
 channelId: "",
 cmdChannelId: "",
 };
}

async function playAllVideos(udpConn: VoiceUdp) {

 console.log("Started playing video");

 udpConn.voiceConnection.setSpeaking(true);
 udpConn.voiceConnection.setVideoStatus(true);

 try {
 let index = 0;

 while (true) {
 if (shouldStop) {
 break; // For the stop command
 }

 if (index >= movies.length) {
 // Reset the loop
 index = 0;
 }

 const movie = movList[index];

 if (!movie) {
 console.log("Movie not found");
 index++;
 continue;
 }

 let options = {};
 options["-ss"] = "00:00:00";

 console.log(`Playing ${movie.name}...`);

 try {
 let videoStream = streamLivestreamVideo(movie.path, udpConn);
 command?.on('progress', (msg) => {
 // print timemark if it passed 10 second sionce last print, becareful when it pass 0
 if (streamStatus.timemark) {
 if (lastPrint != "") {
 let last = lastPrint.split(':');
 let now = msg.timemark.split(':');
 // turn to seconds
 let s = parseInt(now[2]) + parseInt(now[1]) * 60 + parseInt(now[0]) * 3600;
 let l = parseInt(last[2]) + parseInt(last[1]) * 60 + parseInt(last[0]) * 3600;
 if (s - l >= 10) {
 console.log(`Timemark: ${msg.timemark}`);
 lastPrint = msg.timemark;
 }
 } else {
 console.log(`Timemark: ${msg.timemark}`);
 lastPrint = msg.timemark;
 }
 }
 streamStatus.timemark = msg.timemark;
 });
 const res = await videoStream;
 console.log("Finished playing video " + res);
 } catch (e) {
 console.log(e);
 }

 index++; // Pasar a la siguiente película
 }
 } finally {
 udpConn.voiceConnection.setSpeaking(false);
 udpConn.voiceConnection.setVideoStatus(false);
 }

 command?.kill("SIGINT");
 // send message to channel, not reply
 (client.channels.cache.get(streamStatus.channelInfo.cmdChannelId) as TextChannel).send('Finished playing video, timemark is ' + streamStatus.timemark);
 client.leaveVoice();
 client.user?.setActivity(status_idle() as ActivityOptions)
 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 lastPrint = ""
 streamStatus.channelInfo = {
 guildId: '',
 channelId: '',
 cmdChannelId: ''
 };
}

function shuffleArray(array) {
 for (let i = array.length - 1; i > 0; i--) {
 const j = Math.floor(Math.random() * (i + 1));
 [array[i], array[j]] = [array[j], array[i]];
 }
}

function shuffleCommand() {
 shuffleArray(movList);
}

async function playCommand(args, message) {
 if (streamStatus.joined) {
 message.reply('Already joined');
 return;
 }

 // args = [guildId]/[channelId]
 if (args.length == 0) {
 message.reply('Missing voice channel');
 return;
 }

 // process args
 const [guildId, channelId] = args.shift()!.split('/');
 if (!guildId || !channelId) {
 message.reply('Invalid voice channel');
 return;
 }

 // get movie name and find movie file
 let moviename = args.shift()
 let movie = movies.find(m => m.name == moviename);

 if (!movie) {
 message.reply('Movie not found');
 return;
 }

 // get start time from args "hh:mm:ss"
 let startTime = args.shift();
 let options = {}
 // check if start time is valid
 if (startTime) {
 let time = startTime.split(':');
 if (time.length != 3) {
 message.reply('Invalid start time');
 return;
 }
 let h = parseInt(time[0]);
 let m = parseInt(time[1]);
 let s = parseInt(time[2]);
 if (isNaN(h) || isNaN(m) || isNaN(s)) {
 message.reply('Invalid start time');
 return;
 }
 startTime = `${h}:${m}:${s}`;
 options['-ss'] = startTime;
 console.log("Start time: " + startTime);
 }

 await client.joinVoice(guildId, channelId);
 streamStatus.joined = true;
 streamStatus.playing = false;
 streamStatus.starttime = startTime ? startTime : "00:00:00";
 streamStatus.channelInfo = {
 guildId: guildId,
 channelId: channelId,
 cmdChannelId: message.channel.id
 }
 const streamUdpConn = await client.createStream();
 playVideo(movie.path, streamUdpConn, options);
 message.reply('Playing ' + (startTime ? ` from ${startTime} ` : '') + moviename + '...');
 client.user?.setActivity(status_watch(moviename) as ActivityOptions);
}

function stopCommand(message) {
 client.leaveVoice()
 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 streamStatus.channelInfo = {
 guildId: '',
 channelId: '',
 cmdChannelId: streamStatus.channelInfo.cmdChannelId
 }
 // use sigquit??
 command?.kill("SIGINT");
 // msg
 message.reply('Stopped playing');
 shouldStop = true;
 movList = [...originalMovList];
}

function playtimeCommand(message) {
 // streamStatus.starttime + streamStatus.timemark
 // starttime is hh:mm:ss, timemark is hh:mm:ss.000
 let start = streamStatus.starttime.split(':');
 let mark = streamStatus.timemark.split(':');
 let h = parseInt(start[0]) + parseInt(mark[0]);
 let m = parseInt(start[1]) + parseInt(mark[1]);
 let s = parseInt(start[2]) + parseInt(mark[2]);
 if (s >= 60) {
 m += 1;
 s -= 60;
 }
 if (m >= 60) {
 h += 1;
 m -= 60;
 }
 message.reply(`Play time: ${h}:${m}:${s}`);
}

function pauseCommand(message) {
 if (!streamStatus.playing) {
 command?.kill("SIGSTOP");
 message.reply('Paused');
 streamStatus.playing = false;
 } else {
 message.reply('Not playing');
 }
}

function resumeCommand(message) {
 if (!streamStatus.playing) {
 command?.kill("SIGCONT");
 message.reply('Resumed');
 streamStatus.playing = true;
 } else {
 message.reply('Not playing');
 }
}

function listCommand(message) {
 message.reply(`Available movies:\n${movies.map(m => m.name).join('\n')}`);
}

function statusCommand(message) {
 message.reply(`Joined: ${streamStatus.joined}\nJoin success: ${streamStatus.joinsucc}\nPlaying: ${streamStatus.playing}\nChannel: ${streamStatus.channelInfo.guildId}/${streamStatus.channelInfo.channelId}\nTimemark: ${streamStatus.timemark}\nStart time: ${streamStatus.starttime}`);
}

function refreshCommand(message) {
 // refresh movie list
 const movieFiles = fs.readdirSync(moviesFolder);
 movies = movieFiles.map(file => {
 const fileName = path.parse(file).name;
 // replace space with _
 return { name: fileName.replace(/ /g, ''), path: path.join(moviesFolder, file) };
 });
 message.reply('Movie list refreshed ' + movies.length + ' movies found.\n' + movies.map(m => m.name).join('\n'));
}

function helpCommand(message) {
 // reply all commands here
 message.reply('Available commands:\nplay [guildId]/[channelId] [movie] [start time]\nstop\nlist\nstatus\nrefresh\nplaytime\npause\nresume\nhelp');
}

async function playVideo(video: string, udpConn: VoiceUdp, options: any) {
 console.log("Started playing video");

 udpConn.voiceConnection.setSpeaking(true);
 udpConn.voiceConnection.setVideoStatus(true);
 try {
 let videoStream = streamLivestreamVideo(video, udpConn);
 command?.on('progress', (msg) => {
 // print timemark if it passed 10 second sionce last print, becareful when it pass 0
 if (streamStatus.timemark) {
 if (lastPrint != "") {
 let last = lastPrint.split(':');
 let now = msg.timemark.split(':');
 // turn to seconds
 let s = parseInt(now[2]) + parseInt(now[1]) * 60 + parseInt(now[0]) * 3600;
 let l = parseInt(last[2]) + parseInt(last[1]) * 60 + parseInt(last[0]) * 3600;
 if (s - l >= 10) {
 console.log(`Timemark: ${msg.timemark}`);
 lastPrint = msg.timemark;
 }
 } else {
 console.log(`Timemark: ${msg.timemark}`);
 lastPrint = msg.timemark;
 }
 }
 streamStatus.timemark = msg.timemark;
 });
 const res = await videoStream;
 console.log("Finished playing video " + res);
 } catch (e) {
 console.log(e);
 } finally {
 udpConn.voiceConnection.setSpeaking(false);
 udpConn.voiceConnection.setVideoStatus(false);
 }
 command?.kill("SIGINT");
 // send message to channel, not reply
 (client.channels.cache.get(streamStatus.channelInfo.cmdChannelId) as TextChannel).send('Finished playing video, timemark is ' + streamStatus.timemark);
 client.leaveVoice();
 client.user?.setActivity(status_idle() as ActivityOptions)
 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 lastPrint = ""
 streamStatus.channelInfo = {
 guildId: '',
 channelId: '',
 cmdChannelId: ''
 }
}

async function streamCommand(args, message) {

 if (streamStatus.joined) {
 message.reply('Already joined');
 return;
 }

 // args = [guildId]/[channelId]
 if (args.length == 0) {
 message.reply('Missing voice channel');
 return;
 }

 // process args
 const [guildId, channelId] = args.shift()!.split('/');
 if (!guildId || !channelId) {
 message.reply('Invalid voice channel');
 return;
 }

 let url = args.shift()
 let options = {}

 await client.joinVoice(guildId, channelId);
 streamStatus.joined = true;
 streamStatus.playing = false;
 //streamStatus.starttime = startTime ? startTime : "00:00:00";
 streamStatus.channelInfo = {
 guildId: guildId,
 channelId: channelId,
 cmdChannelId: message.channel.id
 }
 const streamUdpConn = await client.createStream();
 playStream(url, streamUdpConn, options);
 message.reply('Playing url');
 client.user?.setActivity(status_watch('livestream') as ActivityOptions);
}

async function playStream(video: string, udpConn: VoiceUdp, options: any) {
 console.log("Started playing video");

 udpConn.voiceConnection.setSpeaking(true);
 udpConn.voiceConnection.setVideoStatus(true);

 try {
 console.log("Trying to stream url");
 const res = await streamLivestreamVideo(video, udpConn);
 console.log("Finished streaming url");
 } catch (e) {
 console.log(e);
 } finally {
 udpConn.voiceConnection.setSpeaking(false);
 udpConn.voiceConnection.setVideoStatus(false);
 }

 command?.kill("SIGINT");
 client.leaveVoice();
 client.user?.setActivity(status_idle() as ActivityOptions)
 streamStatus.joined = false;
 streamStatus.joinsucc = false;
 streamStatus.playing = false;
 streamStatus.channelInfo = {
 guildId: '',
 channelId: '',
 cmdChannelId: ''
 }

}

// run server if enabled in config
if (config.server.enabled) {
 // run server.js
 require('./server');
}




I've tried running the code with the nocache package, setting up a cron job to clean the cache every 5 minutes, unifying functions in the code, but nothigns works.
I think that the problem has to do with certain process that never really ends after one video finishes playing, probably ffmpeg. I don't know whether is my code, my vps or the library the problem.


I wanted the bot to stay in the voice channel streaming my videos 24/7 (no interruptions), I don't know how to prevent it from getting laggy after a while.


This is the config.json file just in case you wanna test the code and can't find it


{
 "token": "DCTOKEN",
 "videoChannels": ["ID", "OTHERID"],
 "commandChannels": ["ID", "OTHERID"],
 "adminIds": ["ID"],
 "movieFolder": "./movies/",
 "previewCache": "/tmp/preview-cache",
 "streamOpts": {
 "width": 1280,
 "height": 720,
 "fps": 30,
 "bitrateKbps": 3000,
 "hardware_acc": true
 },
 "server": {
 "enabled": false,
 "port": 8080
 }
}




-
Android FFmpeg - Mux encoded h264 frames from MediaCodec
27 janvier 2019, par Bob RossI’m trying to capture h264 frames from Android camera (encoded by MediaCodec) and pass them to an FFmpeg process running on the same device.
I currently do it by writing the encoded byte arrays I receive from the MediaCodec to a file called out.h264.
Like so :
FileOutputStream fosVideo = new ...
...
// encoder callback
@Override
public void onVideoData(ByteBuffer h264Buffer, MediaCodec.BufferInfo info) {
fosVideo.write(h264Buffer);
}While the h264 file is being written to is I start the FFmpeg process and provide the h264 file as input.
ffmpeg -re -i out.h264 -c:v copy -r 30 -loglevel 48 a.mp4
I also tried
ffmpeg -re -framerate 25 -i out.h264 -c:v copy -r 30 -loglevel 48 a.mp4
The FFmpeg process runs anywhere between 10 seconds to a few minutes and then stops abruptly with :
frame= 330 fps= 29 q=31.0 size= 512kB time=00:00:10.98 bitrate= 381.8kbits/s dup=55 drop=0 speed=0.972x
[h264 @ 0xf1863800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863b80] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863f00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
*** 1 dup!
[h264 @ 0xf1864280] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
Clipping frame in rate conversion by 0.199989
[h264 @ 0xf1864600] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1862a00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1862d80] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
[h264 @ 0xf1863100] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1
*** 1 dup!
Clipping frame in rate conversion by 0.199989
*** 1 dup!
frame= 347 fps= 29 q=31.0 size= 768kB time=00:00:11.53 bitrate= 545.5kbits/s dup=58 drop=0 speed=0.974x
Clipping frame in rate conversion by 0.199989
[out_0_0 @ 0xf182e1e0] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
frame= 349 fps= 29 q=24.8 Lsize= 920kB time=00:00:17.68 bitrate= 426.1kbits/s dup=58 drop=0 speed=1.48x
video:631kB audio:282kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.732886%
Input file #0 (/storage/emulated/0/MOVIES/out.h264):
Input stream #0:0 (video): 291 packets read (6065016 bytes); 291 frames decoded;
Total: 291 packets (6065016 bytes) demuxed
Input file #1 (/storage/emulated/0/MOVIES/out.aac):
Input stream #1:0 (audio): 830 packets read (289119 bytes);
Total: 830 packets (289119 bytes) demuxed
Output file #0 (/storage/emulated/0/hls/a.mp4):
Output stream #0:0 (video): 349 frames encoded; 349 packets muxed (645952 bytes);
Output stream #0:1 (audio): 830 packets muxed (289119 bytes);
Total: 1179 packets (935071 bytes) muxed
291 frames successfully decoded, 0 decoding errorsEven though the out.h264 file is still being recorded into.
It is as if the ffmpeg process thinks that the file has ended.Any idea what could it be ?