Recherche avancée

Médias (91)

Autres articles (34)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 is the first MediaSPIP stable release.
    Its official release date is June 21, 2013 and is announced here.
    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 (...)

  • 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 (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

Sur d’autres sites (4320)

  • FFmpeg avcodec_open2 throws -22 ("Invalid Argument")

    14 avril 2023, par stupidbutseeking

    I got stuck trying to write a simple video conversion using C++ and ffmpeg.

    


    When trying to convert a video using FFmpeg, calling avcodec_open2 fails with the code "-22" which seems to be an "Invalid Argument"-error.

    


    I can't figure out why it fails, nor what the invalid argument is. In the following snippet I create the output codec and pass its context the information from the source (code further down below).

    


    The check for the "outputCodec" works and does not throw an error. As far as I know an "AVDictionary"-argument is optional. So I guess the reason for the error is the context.

    


        const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

    if (!outputCodec)
    {
        std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
        return -1;
    }

    AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
    outputCodecContext->bit_rate = bitRate;
    outputCodecContext->width = inputCodecContext->width;
    outputCodecContext->height = inputCodecContext->height;
    outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
    outputCodecContext->time_base = inputCodecContext->time_base;

    **int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL); //THIS RETURNS -22**
    if (errorCode != 0)
    {
        std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
        return -1;
    }


    


    Here is the code for getting the input file & context :

    


        std::string inputFilename = "input_video.mp4";
    std::string outputFilename = "output.avi";
    std::string codecName = "mpeg4";
    int bitRate = 400000;

    AVFormatContext* inputFormatContext = NULL;
    if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
    {
        std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
        return -1;
    }

    [Do Video Stream Search)

    AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
    const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
    AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
    if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
    {
        std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
        return -1;
    }
    if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
    {
        std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
        return -1;
    }


    


    The purpose was simply to get started with ffmpeg in an own C++ project.

    


    If it is of any need, I downloaded the ffmpeg libs from here. I used the gpl shared ones. The architecture is win x64. I referenced them through the project properties (additional libraries and so on).

    


    I tried to convert a .mp4 video to an .avi video with an "mpeg4" compression.
I also tried other compressions like "libx264" but none worked.

    


    I searched for the problem on stackoverflow but could not find the exact same problem. While its purpose is different this post is about the same error code when calling avcodec_open2. But its solution is not working for me. I inspected the watch for the "outputContext" while running the code and the codec_id, codec_type and format is set. I use the time_base from the input file. According to my understanding, this should be equal to the source. So I can not find out what I am missing.

    


    Thanks in advance and sorry for my english.

    


    And for completion, here is the whole method :

    


    int TestConvert()
{
    std::string inputFilename = "input_video.mp4";
    std::string outputFilename = "output.avi";
    std::string codecName = "mpeg4";
    int bitRate = 400000;

    AVFormatContext* inputFormatContext = NULL;
    if (avformat_open_input(&inputFormatContext, inputFilename.c_str(), NULL, NULL) != 0)
    {
        std::cout << "Fehler beim Öffnen der Eingabedatei" << std::endl;
        return -1;
    }

    int videoStreamIndex = -1;
    for (unsigned int i = 0; i < inputFormatContext->nb_streams; i++)
    {
        if (inputFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
        {
            videoStreamIndex = i;
            break;
        }
    }

    AVCodecParameters* inputCodecParameters = inputFormatContext->streams[videoStreamIndex]->codecpar;
    const AVCodec* inputCodec = avcodec_find_decoder(inputCodecParameters->codec_id);
    AVCodecContext* inputCodecContext = avcodec_alloc_context3(inputCodec);
    if (avcodec_parameters_to_context(inputCodecContext, inputCodecParameters) != 0)
    {
        std::cout << "Fehler beim Setzen des Eingabecodecs" << std::endl;
        return -1;
    }
    if (avcodec_open2(inputCodecContext, inputCodec, NULL) != 0)
    {
        std::cout << "Fehler beim Öffnen des Eingabecodecs" << std::endl;
        return -1;
    }

    const AVCodec* outputCodec = avcodec_find_encoder_by_name(codecName.c_str());

    if (!outputCodec)
    {
        std::cout << "Zielformat-Codec nicht gefunden" << std::endl;
        return -1;
    }

    AVCodecContext* outputCodecContext = avcodec_alloc_context3(outputCodec);
    outputCodecContext->bit_rate = bitRate;
    outputCodecContext->width = inputCodecContext->width;
    outputCodecContext->height = inputCodecContext->height;
    outputCodecContext->pix_fmt = outputCodec->pix_fmts[0];
    outputCodecContext->time_base = inputCodecContext->time_base;

    int errorCode = avcodec_open2(outputCodecContext, outputCodec, NULL);
    if (errorCode != 0)
    {
        std::cout << "Fehler beim Öffnen des Zielformat-Codecs" << std::endl;
        return -1;
    }

    AVFormatContext* outputFormatContext = NULL;
    if (avformat_alloc_output_context2(&outputFormatContext, NULL, NULL, outputFilename.c_str()) != 0)
    {
        std::cout << "Fehler beim Erstellen des Ausgabe-Formats" << std::endl;
        return -1;
    }

    AVStream* outputVideoStream = avformat_new_stream(outputFormatContext, outputCodec);
    if (outputVideoStream == NULL)
    {
        std::cout << "Fehler beim Hinzufügen des Video-Streams zum Ausgabe-Format" << std::endl;
        return -1;
    }
    outputVideoStream->id = outputFormatContext->nb_streams - 1;
    AVCodecParameters* outputCodecParameters = outputVideoStream->codecpar;
    if (avcodec_parameters_from_context(outputCodecParameters, outputCodecContext) != 0)
    {
        std::cout << "Fehler beim Setzen des Ausgabe-Codecs" << std::endl;
        return -1;
    }

    if (!(outputFormatContext->oformat->flags & AVFMT_NOFILE))
    {
        if (avio_open(&outputFormatContext->pb, outputFilename.c_str(), AVIO_FLAG_WRITE) != 0)
        {
            std::cout << "Fehler beim Öffnen der Ausgabedatei" << std::endl;
            return -1;
        }
    }

    if (avformat_write_header(outputFormatContext, NULL) != 0)
    {
        std::cout << "Fehler beim Schreiben des Ausgabe-Formats in die Ausgabedatei" << std::endl;
        return -1;
    }

    AVPacket packet;
    int response;
    AVFrame* frame = av_frame_alloc();
    AVFrame* outputFrame = av_frame_alloc();
    while (av_read_frame(inputFormatContext, &packet) == 0)
    {
        if (packet.stream_index == videoStreamIndex)
        {
            response = avcodec_send_packet(inputCodecContext, &packet);
            while (response >= 0)
            {
                response = avcodec_receive_frame(inputCodecContext, frame);
                if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
                {
                    break;
                }
                else if (response < 0)
                {
                    std::cout << "Fehler beim Dekodieren des Video-Pakets" << std::endl;
                    return -1;
                }

                struct SwsContext* swsContext = sws_getContext(inputCodecContext->width, inputCodecContext->height, inputCodecContext->pix_fmt, outputCodecContext->width, outputCodecContext->height, outputCodecContext->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL); if (!swsContext)
                {
                    std::cout << "Fehler beim Erstellen des SwsContext" << std::endl;
                    return -1;
                }
                sws_scale(swsContext, frame->data, frame->linesize, 0, inputCodecContext->height, outputFrame->data, outputFrame->linesize);
                sws_freeContext(swsContext);

                outputFrame->pts = frame->pts;
                outputFrame->pkt_dts = frame->pkt_dts;
                //outputFrame->pkt_duration = frame->pkt_duration;
                response = avcodec_send_frame(outputCodecContext, outputFrame);
                while (response >= 0)
                {
                    response = avcodec_receive_packet(outputCodecContext, &packet);
                    if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
                    {
                        break;
                    }
                    else if (response < 0)
                    {
                        std::cout << "Fehler beim Kodieren des Ausgabe-Frames" << std::endl;
                        return -1;
                    }

                    packet.stream_index = outputVideoStream->id;
                    av_packet_rescale_ts(&packet, outputCodecContext->time_base, outputVideoStream->time_base);
                    if (av_interleaved_write_frame(outputFormatContext, &packet) != 0)
                    {
                        std::cout << "Fehler beim Schreiben des Ausgabe-Pakets" << std::endl;
                        return -1;
                    }
                    av_packet_unref(&packet);
                }
            }
        }
        av_packet_unref(&packet);
    }

    av_write_trailer(outputFormatContext);
    avcodec_free_context(&inputCodecContext);
    avcodec_free_context(&outputCodecContext);
    avformat_close_input(&inputFormatContext);
    avformat_free_context(inputFormatContext);
    avformat_free_context(outputFormatContext);
    av_frame_free(&frame);
    av_frame_free(&outputFrame);

    return 0;

}


    


  • Vinyl record animation with ffmpeg

    14 avril 2023, par pabsdenn

    Is it possible to archive this with ffmpeg ?

    


    Basically I want to have a black or vinyl background, one circle for the cover and one circle for the hole. I then need to replace the cover with an image of 500x500px and let it rotate as loop with a certain speed.

    


    Or is it better to automate it with e.g. After Effects ?

    


  • Concat multiple (self-generated) videos using ffmpeg on raspbian linux

    25 février 2016, par Thomas Kekeisen

    I am a very talented sleep talker, so I decided to write a solution that records the things I talk at night to make funny videos with subtitles of it. The project is nearly done, but I got a big problem with concating videos I generated before.

    The video parts are generated from single png frames using this command :

    ffmpeg -y -framerate 15 -i "${images_file_path}" -c:v libx264 -r 30 -pix_fmt yuv420p "${video_file_path}"

    Then the sound is added using this command (got this from #9049970 and #11779490) :

    ffmpeg -y -i "${video_file_path}" -i "${mp3_file_path}" -map 0:v -map 1:a -vcodec copy -acodec copy -shortest "${final_video_file_path}"

    All this is causing no problems so far, but I think it may be relevant to know how the videos are generated. I can watch all this and get valid video and sound - the full source code of this first part can be found here.

    Now I added a feature that is able to generate "full videos" containing a title and a various number of previously generated "video parts" using this command :

    ffmpeg -f concat -i "${video_list_path}" -filter_complex "${filter_string} concat=n=${input_file_counter}:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" "${full_video_path}"

    But something is wrong with it and I get this error :

    Invalid file index 1 in filtergraph description [0:v:0] [1:v:0] [2:v:0] [2:a:0] [3:v:0] [4:v:0] [4:a:0] [5:v:0] [6:v:0] [6:a:0] [7:v:0] concat=n=8:v=1:a=1 [v] [a].

    The full output is :

    ffmpeg version N-77213-g7c1c453 Copyright (c) 2000-2015 the FFmpeg developers
     built with gcc 4.9.2 (Raspbian 4.9.2-10)
     configuration: --enable-shared --enable-gpl --prefix=/usr --enable-nonfree --enable-libmp3lame --enable-libfaac --enable-libx264 --enable-version3 --disable-mmx
     libavutil      55. 10.100 / 55. 10.100
     libavcodec     57. 17.100 / 57. 17.100
     libavformat    57. 20.100 / 57. 20.100
     libavdevice    57.  0.100 / 57.  0.100
     libavfilter     6. 20.100 /  6. 20.100
     libswscale      4.  0.100 /  4.  0.100
     libswresample   2.  0.101 /  2.  0.101
     libpostproc    54.  0.100 / 54.  0.100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0xc2e900] Auto-inserting h264_mp4toannexb bitstream filter
    Input #0, concat, from '/usr/sleeptalk/records-rendered/3enguzpuu2gw0ogk8wkko/videos.txt':
     Duration: N/A, start: 0.000000, bitrate: 61 kb/s
       Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 58 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s
       Metadata:
         handler_name    : SoundHandler
    Invalid file index 1 in filtergraph description [0:v:0] [1:v:0] [2:v:0] [2:a:0] [3:v:0] [4:v:0] [4:a:0] [5:v:0] [6:v:0] [6:a:0] [7:v:0] concat=n=8:v=1:a=1 [v] [a].

    I also wrote a test case so you can reproduce this on your local machine. Download the files from my dropbox. Also, the full script that renders the "final move" can be found here.

    Would be great to get an Idea, got struggle to fix this the last two days.