Recherche avancée

Médias (3)

Mot : - Tags -/collection

Autres articles (50)

  • 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 ;

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

Sur d’autres sites (5876)

  • C# server problem with FFmpeg Visual Studio 2022

    16 mai 2024, par seanofdead

    Hello everyone I've spent countless hours on my server I'm trying to create that will share video from one stream to another client computer. That is the goal anyway. I'm using Visual Studio 2022 most recent update. Currently this is my code

    


    using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using FFmpeg.AutoGen;
using NLog;

public class VideoStreamServer
{
    private const int Port = 5000;
    private TcpListener server;
    private FFmpegVideoEncoder encoder;
    private static readonly Logger logger = LogManager.GetCurrentClassLogger();

    public VideoStreamServer()
    {
        // Initialize FFmpeg network components
        Console.WriteLine("Initializing FFmpeg network components...");
        int result = ffmpeg.avformat_network_init();
        if (result != 0)
        {
            throw new ApplicationException($"Failed to initialize FFmpeg network components: {result}");
        }

        // Initialize encoder
        encoder = new FFmpegVideoEncoder(1920, 1080, AVCodecID.AV_CODEC_ID_H264); // Screen size & codec
    }

    public static void Main()
    {
        // Initialize NLog
        var logger = LogManager.GetCurrentClassLogger();
        logger.Info("Application started");

        var server = new VideoStreamServer();
        server.Start().Wait();
    }

    public async Task Start()
    {
        server = new TcpListener(IPAddress.Any, Port);
        server.Start();
        logger.Info($"Server started on port {Port}...");

        try
        {
            while (true)
            {
                TcpClient client = await server.AcceptTcpClientAsync();
                logger.Info("Client connected...");
                _ = HandleClientAsync(client);
            }
        }
        catch (Exception ex)
        {
            logger.Error(ex, "An error occurred");
        }
    }

    private async Task HandleClientAsync(TcpClient client)
    {
        using (client)
        using (NetworkStream netStream = client.GetStream())
        {
            try
            {
                await encoder.StreamEncodedVideoAsync(netStream);
            }
            catch (IOException ex)
            {
                logger.Error(ex, $"Network error: {ex.Message}");
                // Additional logging and recovery actions
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Unexpected error: {ex.Message}");
                // Log and handle other exceptions
            }
            finally
            {
                // Ensure all resources are cleaned up properly
                client.Close();
                logger.Info("Client connection closed properly.");
            }
        }
    }
}

public class FFmpegVideoEncoder
{
    private readonly int width;
    private readonly int height;
    private readonly AVCodecID codecId;
    private static readonly Logger logger = LogManager.GetCurrentClassLogger();

    public FFmpegVideoEncoder(int width, int height, AVCodecID codecId)
    {
        this.width = width;
        this.height = height;
        this.codecId = codecId;
        InitializeEncoder();
    }

    private void InitializeEncoder()
    {
        // Initialize FFmpeg encoder here
        logger.Debug("FFmpeg encoder initialized");
    }

    public async Task StreamEncodedVideoAsync(NetworkStream netStream)
    {
        // Initialize reusable buffers for efficiency
        byte[] buffer = new byte[4096];

        // Capture and encode video frames
        while (true)
        {
            try
            {
                // Simulate capture and encoding
                byte[] videoData = new byte[1024]; // This would come from the encoder

                // Simulate streaming
                for (int i = 0; i < videoData.Length; i += buffer.Length)
                {
                    int chunkSize = Math.Min(buffer.Length, videoData.Length - i);
                    Buffer.BlockCopy(videoData, i, buffer, 0, chunkSize);
                    await netStream.WriteAsync(buffer, 0, chunkSize);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error streaming video data");
                throw; // Rethrow to handle in the calling function
            }

            await Task.Delay(1000 / 30); // For 30 FPS
        }
    }
}


    


    When I build no issues but when i run it in debug mode I get this error

    


    System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'avformat.59 under C:\Users\phlfo\Downloads\cfolder\server\ConsoleApp\bin\Debug\': The specified module could not be found.
  Source=FFmpeg.AutoGen
  StackTrace:
   at FFmpeg.AutoGen.ffmpeg.LoadLibrary(String libraryName, Boolean throwException)
   at FFmpeg.AutoGen.ffmpeg.<>c.<.cctor>b__7_0(String libraryName)
   at FFmpeg.AutoGen.ffmpeg.<>c.<.cctor>b__7_242()
   at FFmpeg.AutoGen.ffmpeg.avformat_network_init()
   at VideoStreamServer..ctor() in C:\Users\phlfo\Downloads\cfolder\server\ConsoleApp\Program.cs:line 20
   at VideoStreamServer.Main() in C:\Users\phlfo\Downloads\cfolder\server\ConsoleApp\Program.cs:line 36


    


    I have FFmpeg.AutoGen package installed through VS i originally started with 7.0 but then switched to 5.0 to see if an older version might work (it did not). I also have the files in the same directory as the .exe for testing purposes as seen in the screenshot. Can someone please help me figure out this error.
enter image description here

    


  • 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

    


  • How to contribute to open source, for companies

    18 octobre 2010, par Dark Shikari — development, open source, x264

    I have seen many nigh-incomprehensible attempts by companies to contribute to open source projects, including x264. Developers are often simply boggled, wondering why the companies seem incapable of proper communication. The companies assume the developers are being unreceptive, while the developers assume the companies are being incompetent, idiotic, or malicious. Most of this seems to boil down to a basic lack of understanding of how open source works, resulting in a wide variety of misunderstandings. Accordingly, this post will cover the dos and don’ts of corporate contribution to open source.

    Do : contact the project using their preferred medium of communication.

    Most open source projects use public methods of communication, such as mailing lists and IRC. It’s not the end of the world if you mistakenly make contact with the wrong people or via the wrong medium, but be prepared to switch to the correct one once informed ! You may not be experienced using whatever form of communication the project uses, but if you refuse to communicate through proper channels, they will likely not be as inclined to assist you. Larger open source projects are often much like companies in that they have different parts to their organization with different roles. Don’t assume that everyone is a major developer !

    If you don’t know what to do, a good bet is often to just ask someone.

    Don’t : contact only one person.

    Open source projects are a communal effort. Major contributions are looked over by multiple developers and are often discussed by the community as a whole. Yet many companies tend to contact only a single person in lieu of dealing with the project proper. This has many flaws : to begin with, it forces a single developer (who isn’t paid by you) to act as your liaison, adding yet another layer between what you want and the people you want to talk to. Contribution to open source projects should not be a game of telephone.

    Of course, there are exceptions to this : sometimes a single developer is in charge of the entirety of some particular aspect of a project that you intend to contribute to, in which case this might not be so bad.

    Do : make clear exactly what it is you are contributing.

    Are you contributing code ? Development resources ? Money ? API documentation ? Make it as clear as possible, from the start ! How developers react, which developers get involved, and their expectations will depend heavily on what they think you are providing. Make sure their expectations match reality. Great confusion can result when they do not.

    This also applies in the reverse — if there’s something you need from the project, such as support or assistance with development of your patch, make that explicitly clear.

    Don’t : code dump.

    Code does not have intrinsic value : it is only useful as part of a working, living project. Most projects react very negatively to large “dumps” of code without associated human resources. That is, they expect you to work with them to finalize the code until it is ready to be committed. Of course, it’s better to work with the project from the start : this avoids the situation of writing 50,000 lines of code independently and then finding that half of it needs to be rewritten. Or, worse, writing an enormous amount of code only to find it completely unnecessary.

    Of course, the reverse option — keeping such code to yourself — is often even more costly, as it forces you to maintain the code instead of the official developers.

    Do : ignore trolls.

    As mentioned above, many projects use public communication methods — which, of course, allow anyone to communicate, by nature of being public. Not everyone on a project’s IRC or mailing list is necessarily qualified to officially represent the project. It is not too uncommon for a prospective corporate contributor to be turned off by the uninviting words of someone who isn’t even involved in the project due to assuming that they were. Make sure you’re dealing with the right people before making conclusions.

    Don’t : disappear.

    If you are going to try to be involved in a project, you need to stay in contact. We’ve had all too many companies who simply disappear after the initial introduction. Some tell us that we’ll need an NDA, then never provide it or send status updates. You may know why you’re not in contact — political issues at the company, product launch crunches, a nice vacation to the Bahamas — but we don’t ! If you disappear, we will assume that you gave up.

    Above all, don’t assume that being at a large successful company makes you immune to these problems. If anything, these problems seem to be the most common at the largest companies. I didn’t name any names in this post, but practically every single one of these rules has been violated at some point by companies looking to contribute to x264. In the larger scale of open source, these problems happen constantly. Don’t fall into the same traps that many other companies have.

    If you’re an open source developer reading this post, remember it next time you see a company acting seemingly nonsensically in an attempt to contribute : it’s quite possible they just don’t know what to do. And just because they’re doing it wrong doesn’t mean that it isn’t your responsibility to try to help them do it right.