Recherche avancée

Médias (1)

Mot : - Tags -/code

Sur d’autres sites (14)

  • Tele-Arena Lives On

    25 février 2011, par Multimedia Mike — Game Hacking

    Readers know I have a peculiar interest in taking apart video games and that I would rather study a game’s inner workings than actually play it. I take an interest on others’ efforts in this same area. It’s still in my backlog to take a closer look at Clone2727’s body of work. But I wanted to highlight my friend’s work on re-implementing a game called Tele-Arena.



    Back In The Day
    As some of you are likely aware, there was a dark age of online communication that predated the era of widespread internet access. This was known as "The BBS Age". People dialed into these BBSes using modems that operated at abysmal transfer speeds and would communicate with other users, upload and download files, and play an occasional game.

    BBS software evolved and perhaps the ultimate (and final) evolution was Galacticomm’s MajorBBS (MBBS). There were assorted games that plugged into the MBBS, all rendered in glorious color ANSI graphics. One of the most famous of these games was Tele-Arena (TA). TA was a multiplayer fantasy-themed text adventure game. Perhaps you could think of it as World of Warcraft, only rendered as interactive fiction instead of a rich 3D landscape. (Disclaimer : I might not be qualified to make that comparison since I have never experienced WoW firsthand, though I did play TA on and off about 17 years ago).

    TA was often compared to multi-user dungeons — or MUDs — that were played by telneting into internet servers hosting games. Such comparisons were usually unfavorable as people who had experience with both TA and MUDs were sniffy elitists with internet access who thought they were sooooo much better than those filthy, BBS-dialing serfs.

    Sorry, didn’t mean to open old wounds.

    Modern Retelling of A Classic Tale
    Anyway, my friend Ron Kinney is perhaps the world’s biggest fan of TA. So much so that he has re-implemented the engine in Java under the project name Ether. He’s in a similar situation as the ScummVM project in that, while the independent, open source engine is fair game for redistribution, it would be questionable to redistribute the original data files. That’s why he created an AreaBuilder application that generates independent game data files.

    Ironically, you can also telnet into a server on which Ron hosts an instance of Tele-Arena (ironic in the sense that the internet/BBS conflict gets a little blurry).

    I hope that one day Ron will regale us with the strangest tales from the classic TA days. My personal favorite was "Wrath of a Sysop."

  • WinAPI multithreading access violation when writing in local variable

    26 février 2016, par JustPingo

    I’m making a multithreaded program using Visual C++, Win32 API (using _beginthread) that also uses FFmpeg (it is claimed to be thread-safe, and I’m using it only with one single thread anyway).

    Here is the part of my thread’s code that causes problems (everything is inside of the thread function) :

    Arena* arena = NULL;

    switch (task) {
       case TaskOne:
           arena = (Arena*) malloc(sizeof(Arena));
           for (uint i = 0; i < FIGHTSPERROUND; i++) {
               generateArena(arena, ARENAWALLSAMOUNT, ARENAWIDTH, ARENAHEIGHT, ARENAMAXENTITIES, 255);
               spawnPlayer(arena, playerOne, 3, 1, 0, 0, ARENAPLAYERLIFE);
               spawnPlayer(arena, playerTwo, 2, 2, ARENAWIDTH-1, ARENAHEIGHT-1, ARENAPLAYERLIFE);

               do {
                   tickArena(arena);
               } while ((result = getResult(arena)) == 0);

               switch (result) {
                   case 1: teamOneScore++; break;
                   case 2: teamTwoScore++; break;
                   default: break;
               }

               freeArena(arena);
               clearMemory(playerOne);
               clearMemory(playerTwo);
               clearBrain(playerOne);
               clearBrain(playerTwo);
           }
           threadTeamOneScore[threadID] = teamOneScore;
           threadTeamTwoScore[threadID] = teamTwoScore;
           break;

       default: break;
    }

    Here is how I generate my arena :

    void generateArena(Arena* arena, uint wallsAmount, uint xSize, uint ySize, uint maxEntities, uint maxTurns) {
       CasesTypes** map;
       map = (CasesTypes**) malloc(xSize * sizeof(CasesTypes*));
       memset(map, 0, xSize * sizeof(CasesTypes*));
       for (uint i = 0; i < xSize; i++) {
           map[i] = (CasesTypes*)malloc(ySize * sizeof(CasesTypes));
           memset(map[i], 0, ySize * sizeof(CasesTypes));
       }

       arena->map = map;
       arena->entities = (Entity*) malloc(maxEntities * sizeof(Entity));
       memset(arena->entities, 0, maxEntities * sizeof(Entity));
       arena->width = xSize;
       arena->height = ySize;
       arena->maxEntities = maxEntities;
       arena->maxTurns = maxTurns;
       arena->currentTurn = 0;
       arena->entitiesAmount = 0;
       for (uint i = 0; i < wallsAmount; i++)
           arena->map[random2(1, xSize-1)][random2(1, ySize-1)] = Wall;
    }

    This works as expected 4 times in 5.
    But sometimes, for some reason, arena = (Arena*) malloc(sizeof(Arena)); throws an access violation exception.

    For example, Visual Studio 2015’s debugger once said :
    Exception thrown at 0x77DBE389 (ntdll.dll) in MyProgram.exe: 0xC0000005: Access violation writing location 0x007C160F.

    When I used the debugger to find what ((void*) 0x007C160F) was, it always happened to be something similar to :

    avformat-57.dll!0x007c160f (load symbols for additional information)

    avformat is a part of FFmpeg. The address was different every times, but it always had something to do with FFmpeg.

    I can’t figure out what is causing the problem.
    If that can help, sometimes the arena also happens to get corrupted (some of its fields get extremely big while generating them with generateArena although it is never changed and only set once to an integer, this leads to a crash later).

    Thank you in advance !

  • Convert from oga to mp3 using pydub : ffmpeg returned error code : 1

    29 juin 2023, par Juan David

    I want to take an OGA file within a binary stream and convert it into mp3 using also another stream. I'm getting a permissions error even with running VSCode as administrator. This is my code :

    


    from pydub import AudioSegment
AudioSegment.converter = "C:\\ProgramData\\chocolatey\\lib\\ffmpeg\\tools\\ffmpeg\\bin\\ffmpeg.exe"

input_stream = io.BytesIO()
input_stream.seek(0) 
await new_file.download_to_memory(input_stream)
 
# Create an audio segment from the binary stream
audio = AudioSegment.from_file(input_stream, format='ogg')

# Create an output stream for the MP3 data
output_stream = io.BytesIO()

# Export the audio to MP3 using ffmpeg and write the output to the stream
audio.export(output_stream, format='mp3', codec='libmp3lame')

# Get the MP3 data from the output stream
mp3_data = output_stream.getvalue()


    


    Error message :

    


      File "C:\ProgramData\Anaconda3\envs\chatbot\lib\site-packages\telegram\ext\_application.py", line 1124, in process_update
    await coroutine
  File "C:\ProgramData\Anaconda3\envs\chatbot\lib\site-packages\telegram\ext\_handler.py", line 141, in handle_update
    return await self.callback(update, context)
  File "c:\Users\jdbol\OneDrive\Desktop\testbots\echobot.py", line 80, in voice_to_text
    audio = AudioSegment.from_file(input_stream, format='ogg')
  File "C:\ProgramData\Anaconda3\envs\chatbot\lib\site-packages\pydub\audio_segment.py", line 773, in from_file     
    raise CouldntDecodeError(
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1

Output from ffmpeg/avlib:

ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
fd:: End of file


    


    I ran the command in a terminal and the file converted without an issue :

    


    ffmpeg -i .\file_12.oga output.mp3 


    


      

    1. I'm not sure if the .exe file must be included into the path. When I don't do it, What I get is a permissions error.
    2. 


    3. What other codecs can be used here ?
    4. 


    5. Is it possible to use oga files ? I tried to declare this but I got an 'Unknown input format : 'oga' message (audio = AudioSegment.from_file(input_stream, format='oga'))
    6. 


    


    Thanks !

    


    UPDATE : I created a more simple version that is not using a binary stream and worked like a charm, so we know for sure that something is happening with the BytesIO object

    


    async def voice_to_text(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    # Get the absolute path of the script
    filename = 'file_9.oga'
    script_dir = os.path.dirname(os.path.abspath(__file__))

    # Construct the file paths for input and output files
    input_file_path = os.path.join(script_dir, filename)
    output_file_path = os.path.join(script_dir, os.path.splitext(filename)[0] + ".mp3")

    # Load the OGA audio file
    audio = AudioSegment.from_file(input_file_path, format='ogg')

    # Export the audio to MP3 format
    audio.export(output_file_path, format='mp3')

    print("Conversion complete. MP3 file saved as:", output_file_path)


    


    UPDATE 2 : It seems like await new_file.download_to_memory(input_stream) is the problematic line. I tried to save the file and its corrupt. Not sure how to use this method then.

    


    https://docs.python-telegram-bot.org/en/stable/telegram.file.html#telegram.File.download_to_memory