Recherche avancée

Médias (1)

Mot : - Tags -/intégration

Autres articles (102)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (9494)

  • Anomalie #4589 (Fermé) : PHP8 : Warning Trying to access array offset on value of type bool in inc...

    4 novembre 2020
  • Discord.py : Access files on the computer of the person who sent a message. Play a song from the local drive of any user on the server

    7 avril 2021, par daDib

    I have a bot that can play music from my computer. Is there a way to play a song from the computer of the person who sent the message ? My thought would be using message.author to somehow access the person's session and get into their drive. Here is my bot. It can join a voice channel, create playlists from local file paths, start a playlist or individual file with stop/pause/play/next/previous controls :

    


    import discord
import os.path
import logging
import asyncio
from os import path

global ready 
global vc
global source
global songQueue
global songIndex
global commandList
global stopPlaylist

ready = False
stopPlaylist = False
songQueue = []
songIndex = 0

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='D:\DnD\DiscordBot\discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)

client = discord.Client()
commands = [
    '!connect\nConnect to a voice channel by channel id. Use !channels to find the desired id.\nExample Command: !connect 827202170973323305\n\n',
    '!channels\nLists all voice channels and their connection id.\n\n',
    '!add\nAdd a file path to the playlist.\nExample Command: !add D:\\DnD\\DiscordBot\\mySong.mp3\n\n',
    '!delete\nDeletes the last song added to the playlist.\n\n',
    '!view\nDisplays the current playlist, in order.\n\n',
    '!playlist\nStarts the playlist from the beginning, or optionally add a number as the start position.\nExample Command: !playlist 3\n\n',
    '!playSong\nPlays a specified file.\nExample Command: !playSong D:\\DnD\\DiscordBot\\mySong.mp3\n\n',
    '!next\nPlays next song in playlist.\n\n',
    '!prev\nPlays previous song in playlist.\n\n',
    '!stop\nStops all music song. Playlist will restart from the beginning.\n\n',
    '!pause\nPauses the current song. Restart with !resumeSong.\n\n',
    '!resume\nResumes the current song.\n\n'
    '!status\nLets you know if the bot thinks it is playing music.'
    ]
commandList=''
for command in commands:
    commandList+=command

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    global ready 
    global vc
    global source
    global songQueue
    global songIndex
    global commandList
    global stopPlaylist

    if message.author == client.user:
        return
#!help
    if message.content.startswith('!help'):
        await message.channel.send('{0}'.format(commandList))
        return
#!connect
    if message.content.startswith('!connect'):  
        if ready:
            await message.channel.send('Bot [{0}] is already connected to a voice channel.'.format(client.user))
            return
        channel = int(message.content[9:])
        vc = await client.get_channel(channel).connect()
        ready = True
        await message.channel.send('Bot [{0}] is connecting to voice.'.format(client.user))
        return
#!channels
    if message.content.startswith('!channels'):
        channelList = ''
        for channel in client.get_all_channels():
            if channel.type == discord.ChannelType.voice:
                channelList += 'name: ' + channel.name + '\n'
                channelList += 'id: ' + str(channel.id) + '\n\n'
        await message.channel.send('{0}'.format(channelList))
        return
#!add
    if message.content.startswith('!add'):
        song = message.content[5:]
        if not path.exists(song):
            await message.channel.send('Song not found or invalid path specified.\nSpecified Path: {0}\nExample command: !addSong C:\\Users\\Public\\Music\\mySong.mp3'.format(song))
            return
        songQueue.append(song)
        await message.channel.send('Song added: {0}\nCurrent playist length: {1} song(s)'.format(song,len(songQueue)))
        return
#!delete
    if message.content.startswith('!delete'):
        if len(songQueue) == 0:
            await message.channel.send('Playlist is empty. Use !addSong, !viewList, and !playList to manage playlists.')
            return
        await message.channel.send('Removed song: {0}'.format(songQueue.pop()))
        return
#!view
    if message.content.startswith('!view'):
        if len(songQueue) == 0:
            await message.channel.send('Playlist is empty. Use !addSong, !deleteSong, and !playList to manage playlists.')
            return
        await message.channel.send('Current Playlist:\n{0}'.format('\n'.join(songQueue)))
        return
#play commands
    if message.content.startswith('!play'):
        if not ready:
            await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
            return
#!playlist  
        if message.content.startswith('!playlist'):
            try:
                songIndex = int(message.content[10:]) - 1
                if songIndex >= len(songQueue):
                    songIndex = len(songQueue) - 1
            except:
                pass    
            playSong()
            return
#!playSong
        if message.content.startswith('!playSong'):
            song = message.content[10:]
            if not path.exists(song):
                await message.channel.send('Song not found or invalid path specified.\nSpecified Path: {0}\nExample command: !play C:\\Users\\Public\\Music\\mySong.mp3'.format(song))
                return
            source = discord.FFmpegPCMAudio(song)
            vc.play(source, after=None)
            await message.channel.send('Playing song: {0}'.format(song))
            return
#!next
    if message.content.startswith('!next'):
        vc.stop()
#!prev
    if message.content.startswith('!prev'):
        songIndex -= 2
        if songIndex < -1:
            songIndex = -1
        vc.stop()
#!stop
    if message.content.startswith('!stop'):
        if not ready:
            await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
            return
        vc.stop()
        songIndex = 0
        stopPlaylist = True
        await message.channel.send('Stopping music.')
        return
#!pause
    if message.content.startswith('!pause'):
        if not ready:
            await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
            return
        vc.pause()
        await message.channel.send('Pausing music.')
        return
#!resume
    if message.content.startswith('!resume'):
        if not ready:
            await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
            return
        vc.resume()
        await message.channel.send('Resuming music.')
        return
#!status
    if message.content.startswith('!status'):
        if not ready:
            await message.channel.send('Bot [{0}] is not connected to a voice channel.'.format(client.user))
            return
        if vc.is_playing():
            await message.channel.send('Something is playing.')
            return
        await message.channel.send('Nothing is playing.')
        return

def playSong():
    global songQueue
    global songIndex
    global vc
    try:
        song = songQueue[songIndex]
        source = discord.FFmpegPCMAudio(song)
        vc.play(source, after=nextSong)
    except Exception as e:
        print('playSong error {0}'.format(e))

def nextSong(error):
    global songQueue
    global songIndex
    global stopPlaylist
    try:
        songIndex += 1
        if songIndex >= len(songQueue):
            stopPlaylist = True
        if stopPlaylist:
            songIndex = 0
            stopPlaylist = False
            return
        futureFunction = asyncio.run_coroutine_threadsafe(playSong(), client.loop)
        futureFunction.result()
    except Exception as e:
        print('nextSong error {0}'.format(e))

#@client.event
#async def on_logout(user)
#   global ready
#   if user == client.user:
#       ready = False

client.run('TOKEN')


    


  • libavcodec/ffmpeg reports two channels when decoding, but segfaults when trying to access the second

    1er décembre 2017, par Astrognome

    I am attempting to decode an audio file into raw pcm data using FFMpeg’s libavcodec. I have the following code so far, but it segfaults when trying to access the second audio channel for some reason.

    #include
    #include
    #include <ao></ao>ao.h>
    #include

    #include <libavutil></libavutil>opt.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>

    #define BUF_SIZE 4096


    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096

    int decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, uint8_t* out_data, int* index) {

       int i, ch;
       int ret, data_size;

       ret = avcodec_send_packet(dec_ctx, pkt);
       if (ret &lt; 0) {
           fprintf(stderr, "Error submitting packet to decoder\n");
           exit(1);
       }

       while (ret >= 0) {
           ret = avcodec_receive_frame(dec_ctx, frame);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
               return 0;
           }
           else if (ret &lt; 0) {
               fprintf(stderr, "Error during decoding\n");
               exit(1);
           }

           data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
           if (data_size &lt; 0) {
               fprintf(stderr, "Failed to calculate data size\n");
               exit(1);
           }
           for (i = 0; i &lt; frame->nb_samples; ++i)
               for (ch = 0; ch &lt; dec_ctx->channels; ++ch) {

                   //Things go wrong here...
                   memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);
                   *index += data_size;
               }
       }

       return 0;
    }

    int decode_audio_file(const char* path, uint8_t* out_data, int size) {
       const AVCodec *codec;
       AVCodecContext *c = NULL;
       AVCodecParserContext *parser = NULL;
       int len, ret;
       FILE *f;
       uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       uint8_t *data;
       size_t data_size;
       AVPacket *pkt;
       AVFrame *decoded_frame = NULL;


       avcodec_register_all();
       pkt = av_packet_alloc();
       codec = avcodec_find_decoder(AV_CODEC_ID_FLAC);
       if (!codec) {
           fprintf(stderr, "Codec not found!\n");
           return -1;
       }

       parser = av_parser_init(codec->id);
       if (!parser) {
           fprintf(stderr, "Parser not found!\n");
           return -1;
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate audio context!\n");
           return -1;
       }

       if(avcodec_open2(c, codec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       f = fopen(path, "rb");
       if(!f) {
           fprintf(stderr, "Could not open %s\n", path);
           exit(1);
       }

       data = inbuf;
       data_size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);

       int index = 0;  
       while (data_size > 0) {
           if (!decoded_frame) {
               if (!(decoded_frame = av_frame_alloc())) {
                   fprintf(stderr, "Could not allocate audio frame\n");
                   exit(1);
               }
           }

           ret = av_parser_parse2(parser, c, &amp;pkt->data, &amp;pkt->size, data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
           if (ret &lt; 0) {
               fprintf(stderr, "Error while parsing\n");
               exit(1);
           }
           data += ret;
           data_size -= ret;

           if (pkt->size)
               decode(c, pkt, decoded_frame, out_data, &amp;index);
           if (data_size &lt; AUDIO_REFILL_THRESH) {
               memmove(inbuf, data, data_size);
               data = inbuf;
               len = fread(data + data_size, 1, AUDIO_INBUF_SIZE - data_size, f);
               if (len > 0)
                   data_size += len;
           }
       }
       avcodec_free_context(&amp;c);
       av_parser_close(parser);
       av_frame_free(&amp;decoded_frame);
       av_packet_free(&amp;pkt);

       return 0;
    }


    int main(int argc, char **argv)
    {
       int bsize = 1024*1024*60;
       uint8_t* audio_buffer = calloc(bsize, sizeof(uint8_t));
       decode_audio_file("testsong.flac", audio_buffer, bsize);
    }

    Here is the offending line :

    memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);

    If you access frame->data[0] it’s fine, but if you attempt to access frame->data[1] it segfaults. The context reports two channels and the file contains two channels (tried with several different tracks).
    But it gets even weirder. If I switch the offending line to

    memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch), data_size);

    it will have the left channel with correct data and the right channel is white noise. This tells me (and I could be wrong) that the first channel actually contains 2 channels of audio interleaved, the actual left channel, plus a junk channel of white noise.
    I was wrong, I forgot to multiple ch by data_size. If the line is memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch*data_size), data_size); things seem to work as expected. This all still seems very sketchy though so if anyone can thoroughly explain what’s happening here, that would be nice.

    I have been working off the decode_audio example available in the ffmpeg documentation here although modified slightly.

    This ALSO happens if I use the vanilla example with the only change being setting the codec to FLAC, so I assume it’s a bug in the library. In that case, how can I work around it.