Recherche avancée

Médias (91)

Autres articles (112)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

Sur d’autres sites (14004)

  • FFmpeg : how does avcodec_decode_video2 calculate linesize alignment ?

    9 août 2021, par yaskovdev

    I am new to video encoding. I am using FFmpeg library to decode a H.264 frame. I have the below C++ code (full code is here) :

    


    AVCodecContext *context = create_codec_context();
AVFrame *decoded_frame = av_frame_alloc();
int got_frame;
avcodec_decode_video2(context, decoded_frame, &got_frame, &encoded_frame);

std::cout << decoded_frame->width << std::endl; // prints 1620, as expected
std::cout << decoded_frame->linesize[0] << std::endl; // prints 1664!


    


    What looks strange to me is the linesize of the decoded frame. Although the width of the frame is 1620, the linesize[0] is 1664. According to this answer, the linesize is calculated taking alignment into consideration. In order to get 1664 from 1620, one should apply 64 as an alignment to the initial width.

    


    My question is, where does this 64 alignment come from ? Searching through FFmpeg code did not give any results. Does the encoded frame itself already have this information ?

    


    If afterwards I decide to "flatten" the decoded frame into a one-dimensional array using av_image_copy_to_buffer(), what alignment should I use ? Should it also be 64 ?

    


  • PHP calculate process of Handbrake CLI [closed]

    22 mars 2021, par Olive

    there. Here's a piece of code that converts video files to mp4 type, using ffmpeg or handbrake according to the config constant variable value.

    


    <?php
include( dirname( __FILE__ ) . '/../config/config.php' );
if(isset($_POST['file']))
{
 // Video Converter Using FFMPEG Service
    if(VIDEO_CONVERTER_TYPE == "ffmpeg"){
        $rotate = " -metadata:s:v:0 rotate=0 ";

        // get rotation of the video
        ob_start();
        passthru("mediainfo " . $_POST['file'] . " | grep Rotation 2>&1");
        $duration_output = ob_get_contents();
        ob_end_clean();

        // rotate?
        if (preg_match('/Rotation *: (.*?)\n/', $duration_output, $matches))
        {
            $rotation = $matches[1];
            if (strpos($rotation, "90") !== false)
                $rotate .= '-vf "transpose=1" ';
            else if (strpos($rotation, "180") !== false)
                $rotate .= '-vf "transpose=1,transpose=1" ';
            else if (strpos($rotation, "270") !== false)
                $rotate .= '-vf "transpose=2" ';
        }

        require_once('getid3/getid3.php');
        $getID3 = new getID3;
        $file = $getID3->analyze($_POST['file']);

        $dimension = "";
        $convFlag = false;
        if($file != null && !empty($file['video'])){
            if($file['video']['resolution_x'] > 1280){
                $new_width = 1280;
                $new_height = intval($file['video']['resolution_y'] * (1280 / $file['video']['resolution_x']));
                if($new_height % 2 != 0)
                    $new_height ++;
                $convFlag = true;
            } else if($file['video']['resolution_y'] > 800){
                $new_height = 800;
                $new_width = intval($file['video']['resolution_x'] * (800 / $file['video']['resolution_y']));
                if($new_width % 2 != 0)
                    $new_width ++;
                $convFlag = true;
            }
            if($convFlag)
                $dimension = $new_width . "x" . $new_height;
        }

        $info = pathinfo($_POST['file']);
        if(strtolower($info['extension']) == 'mp4' && $_POST['type'] == 'mp4'){
            $src = $info['dirname'].'/'.$info['filename'].'_original.'.$info['extension'];
            rename($_POST['file'], $src);
        } else
            $src = $_POST['file'];

        $dst = '"'.$info['dirname'].'/'.$info['filename'].'.'.$_POST['type'].'"';

        $command = 'ffmpeg -y -i "'.$src.'"' . $rotate . '-vcodec libx264 -acodec copy -ar 44100 ' . ($dimension != "" ? "-s ".$dimension : "") . ' ' . ($_POST['type'] == 'flv' ? '-crf 28 ' : '') . $dst.' 1> '.dirname(__FILE__) .'/block.txt'.' 2>&1';
        exec($command);
        unlink($src);
        echo json_encode($command);
    } else {
        $rotate = "";

        // get rotation of the video
        ob_start();
        passthru("mediainfo " . $_POST['file'] . " | grep Rotation 2>&1");
        $duration_output = ob_get_contents();
        ob_end_clean();

        // rotate?
        if (preg_match('/Rotation *: (.*?)\n/', $duration_output, $matches))
        {
            $rotation = $matches[1];
            if (strpos($rotation, "90") !== false)
                $rotate .= ' --rotate=4';
            else if (strpos($rotation, "180") !== false)
                $rotate .= ' --rotate=3';
            else if (strpos($rotation, "270") !== false)
                $rotate .= ' --rotate=7';
        }

        require_once('getid3/getid3.php');
        $getID3 = new getID3;
        $file = $getID3->analyze($_POST['file']);

        // $dimension = false;
        $convFlag = false;
        if($file != null && !empty($file['video'])){
            if($file['video']['resolution_x'] > 1280){
                $new_width = 1280;
                $new_height = intval($file['video']['resolution_y'] * (1280 / $file['video']['resolution_x']));
                if($new_height % 2 != 0)
                    $new_height ++;
                $convFlag = true;
            } else if($file['video']['resolution_y'] > 800){
                $new_height = 800;
                $new_width = intval($file['video']['resolution_x'] * (800 / $file['video']['resolution_y']));
                if($new_width % 2 != 0)
                    $new_width ++;
                $convFlag = true;
            }
        }

        $info = pathinfo($_POST['file']);
        if(strtolower($info['extension']) == 'mp4' && $_POST['type'] == 'mp4'){
            $src = $info['dirname'].'/'.$info['filename'].'_original.'.$info['extension'];
            rename($_POST['file'], $src);
        } else
            $src = $_POST['file'];

        $dst = '"'.$info['dirname'].'/'.$info['filename'].'.'.$_POST['type'].'"';

        $command = 'HandBrakeCLI -i "'.$src.'" -e x264 -R44.1 ' . ($convFlag ? "-w ".$new_width . " -h " . $new_height : "") . ' -o ' . $dst.$rotate.' 1> '.dirname(__FILE__) .'/block.txt'.' 2>&1';
        exec($command);
        unlink($src);
        echo json_encode($command);
}
}
else if(isset($_POST['progress'])) // Progress API for Video Converter
{
$content = @file_get_contents('block.txt');

if($content){
    if(VIDEO_CONVERTER_TYPE == "ffmpeg"){
        //get duration of source
        preg_match("/Duration: (.*?), start:/", $content, $matches);
        if(count($matches) <= 1)
        {
            $result['result'] = 'failed';
            $result['progress'] = 0;
            echo json_encode($result);
        }
        else
        {
            $rawDuration = $matches[1];

            //rawDuration is in 00:00:00.00 format. This converts it to seconds.
            $ar = array_reverse(explode(":", $rawDuration));
            $duration = floatval($ar[0]);
            if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
            if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;

            //get the time in the file that is already encoded
            preg_match_all("/time=(.*?) bitrate/", $content, $matches);
            if(count($matches) <= 1)
            {
                $result['result'] = 'failed';
                $result['progress'] = 0;
                echo json_encode($result);
            }
            else
            {
                $rawTime = array_pop($matches);

                //this is needed if there is more than one match
                if (is_array($rawTime)){$rawTime = array_pop($rawTime);}

                //rawTime is in 00:00:00.00 format. This converts it to seconds.
                $ar = array_reverse(explode(":", $rawTime));
                $time = floatval($ar[0]);
                if (!empty($ar[1])) $time += intval($ar[1]) * 60;
                if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;

                //calculate the progress
                $progress = round(($time/$duration) * 100);

                $result = array();
                $result['result'] = 'success';
                $result['progress'] = $progress;

                echo json_encode($result);
            }
        }       
    } else {
        //get duration of source
        preg_match_all("/task 1 of 1, (.*?) %/", $content, $matches);
        if(count($matches) <= 1)
        {
            $result['result'] = 'failed';
            $result['progress'] = 0;
            echo json_encode($result);
        }
        else
        {
            $progress = array_pop($matches);
            $result = array();
            $result['result'] = 'success';
            $result['progress'] = floatval($progress);

            echo json_encode($result);
        }
    }
}
else
{
    $result['result'] = 'fail';
    $result['progress'] = 0;
    echo json_encode($result);
}
}
else
{
    $result['result'] = 'fail';
    $result['progress'] = 0;
    echo json_encode($result);
}
?>


    


    As you can see, the above half part is for making the cli command, and executing it, and another half is for calculating the progress. On the cli part, you can see that it's writing process output contents to the block.txt file. For the ffmpeg process, it works fine. The problem is HandbrakeCLI. It doesn't return process while converting, only it does when the convert process is completely finished.
I know this is because of the locking / unlocking problem of the file. Do you have any thoughts or experience about this problem ? If so, please help me ! Thank you, Yutaka.

    


  • How to make a basic youtube music bot work with searching titles instead of the URL

    21 janvier 2021, par Brandon

    Hello so i've followed this tutorial and added this code to my current bot to make it have a music bot function. Im wondering how to make the following code work with the youtube search function, for example right now I have to do !play URL but I would also like to be able to do !play name of song then the bot will search and play the most matched song.

    



    I am new to javascript but I know I shouldn't be looking for handouts, but some help would be appreciated.

    



    const Discord = require("discord.js");
const { prefix, token } = require("./config.json");
const ytdl = require("ytdl-core");

const client = new Discord.Client();

const queue = new Map();

client.once("ready", () => {
  console.log("Ready!");
});

client.once("reconnecting", () => {
  console.log("Reconnecting!");
});

client.once("disconnect", () => {
  console.log("Disconnect!");
});

client.on("message", async message => {
  if (message.author.bot) return;
  if (!message.content.startsWith(prefix)) return;

  const serverQueue = queue.get(message.guild.id);

  if (message.content.startsWith(`${prefix}play`)) {
    execute(message, serverQueue);
    return;
  } else if (message.content.startsWith(`${prefix}skip`)) {
    skip(message, serverQueue);
    return;
  } else if (message.content.startsWith(`${prefix}stop`)) {
    stop(message, serverQueue);
    return;
  } else {
    message.channel.send("You need to enter a valid command!");
  }
});

async function execute(message, serverQueue) {
  const args = message.content.split(" ");

  const voiceChannel = message.member.voice.channel;
  if (!voiceChannel)
    return message.channel.send(
      "You need to be in a voice channel to play music!"
    );
  const permissions = voiceChannel.permissionsFor(message.client.user);
  if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
    return message.channel.send(
      "I need the permissions to join and speak in your voice channel!"
    );
  }

  const songInfo = await ytdl.getInfo(args[1]);
  const song = {
    title: songInfo.title,
    url: songInfo.video_url
  };

  if (!serverQueue) {
    const queueContruct = {
      textChannel: message.channel,
      voiceChannel: voiceChannel,
      connection: null,
      songs: [],
      volume: 5,
      playing: true
    };

    queue.set(message.guild.id, queueContruct);

    queueContruct.songs.push(song);

    try {
      var connection = await voiceChannel.join();
      queueContruct.connection = connection;
      play(message.guild, queueContruct.songs[0]);
    } catch (err) {
      console.log(err);
      queue.delete(message.guild.id);
      return message.channel.send(err);
    }
  } else {
    serverQueue.songs.push(song);
    return message.channel.send(`${song.title} has been added to the queue!`);
  }
}

function skip(message, serverQueue) {
  if (!message.member.voice.channel)
    return message.channel.send(
      "You have to be in a voice channel to stop the music!"
    );
  if (!serverQueue)
    return message.channel.send("There is no song that I could skip!");
  serverQueue.connection.dispatcher.end();
}

function stop(message, serverQueue) {
  if (!message.member.voice.channel)
    return message.channel.send(
      "You have to be in a voice channel to stop the music!"
    );
  serverQueue.songs = [];
  serverQueue.connection.dispatcher.end();
}

function play(guild, song) {
  const serverQueue = queue.get(guild.id);
  if (!song) {
    serverQueue.voiceChannel.leave();
    queue.delete(guild.id);
    return;
  }

  const dispatcher = serverQueue.connection
    .play(ytdl(song.url))
    .on("finish", () => {
      serverQueue.songs.shift();
      play(guild, serverQueue.songs[0]);
    })
    .on("error", error => console.error(error));
  dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  serverQueue.textChannel.send(`Start playing: **${song.title}**`);
}

client.login(token);