Recherche avancée

Médias (1)

Mot : - Tags -/ticket

Autres articles (65)

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

Sur d’autres sites (12219)

  • ffmpeg avcodec_send_packet fail after several frames

    8 janvier 2024, par Xingdi

    I am trying to use ffmpeg to decode a video stream and convert to Opencv cv::Mat.

    


    I found this piece of code and made it compiled. Howerver, the decoding process will always fail after several frames. The call to avcodec_send_packet return error code -11.

    


    I do now know what the problem is. I am sure the video stream and my FFmpeg is ok. I can transcode the stream video using ffmpeg command line.

    


    The error always happen on

    


    error = avcodec_send_packet(videoCodecContext, &packet);


    


    #include <iostream>&#xA;#include <string>&#xA;#include <vector>&#xA;&#xA;extern "C" {&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;}&#xA;&#xA;&#xA;#include <opencv2></opencv2>opencv.hpp>&#xA;&#xA;// helper function to check for FFmpeg errors&#xA;inline void checkError(int error, const std::string&amp; message) {&#xA;    if (error &lt; 0) {&#xA;        //std::cerr &lt;&lt; message &lt;&lt; ": " &lt;&lt; av_err2str(error) &lt;&lt; std::endl;  //error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conv>&#xA;        std::cerr &lt;&lt; message &lt;&lt; ": " &lt;&lt; std::to_string(error) &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;}&#xA;&#xA;int main() {&#xA;    // initialize FFmpeg&#xA;    av_log_set_level(AV_LOG_ERROR);&#xA;    avformat_network_init();&#xA;&#xA;    // open the input file&#xA;    std::string fileName = "rtsp://xyz@192.168.15.112:554//Streaming/Channels/101";&#xA;    AVFormatContext* formatContext = nullptr;&#xA;    int error = avformat_open_input(&amp;formatContext, fileName.c_str(), nullptr, nullptr);&#xA;    checkError(error, "Error opening input file");&#xA;&#xA;    //Read packets of a media file to get stream information.&#xA;    ////////////////////////////////////////////////////////////////////////////&#xA;    error = avformat_find_stream_info(formatContext, nullptr);&#xA;    checkError(error, "Error avformat find stream info");&#xA;    ////////////////////////////////////////////////////////////////////////////&#xA;&#xA;&#xA;    // find the video stream&#xA;    AVStream* videoStream = nullptr;&#xA;    for (unsigned int i = 0; i &lt; formatContext->nb_streams; i&#x2B;&#x2B;) {&#xA;       if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &amp;&amp; !videoStream) {&#xA;            videoStream = formatContext->streams[i];&#xA;        }&#xA;    }&#xA;    if (!videoStream) {&#xA;        std::cerr &lt;&lt; "Error: input file does not contain a video stream" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;&#xA;    // create the video codec context&#xA;    const AVCodec* videoCodec = avcodec_find_decoder(videoStream->codecpar->codec_id);&#xA;    AVCodecContext* videoCodecContext = avcodec_alloc_context3(videoCodec);&#xA;    if (!videoCodecContext) {&#xA;        std::cerr &lt;&lt; "Error allocating video codec context" &lt;&lt; std::endl;&#xA;        exit(EXIT_FAILURE);&#xA;    }&#xA;    error = avcodec_parameters_to_context(videoCodecContext, videoStream->codecpar);&#xA;    checkError(error, "Error setting video codec context parameters");&#xA;    error = avcodec_open2(videoCodecContext, videoCodec, nullptr);&#xA;    checkError(error, "Error opening video codec");&#xA;&#xA;    // create the frame scaler&#xA;    int width = videoCodecContext->width;&#xA;    int height = videoCodecContext->height;&#xA;&#xA;    std::cout&lt;&lt;"frame width:" &lt;&lt; width &lt;&lt; std::endl;&#xA;    std::cout&lt;&lt;"frame height:" &lt;&lt; height &lt;&lt; std::endl;&#xA;    std::cout&lt;&lt;"frame pix fmt:" &lt;&lt; videoCodecContext->pix_fmt &lt;&lt; std::endl;&#xA;&#xA;    struct SwsContext* frameScaler = sws_getContext(width, height, videoCodecContext->pix_fmt, width, height, AV_PIX_FMT_BGR24, SWS_BICUBIC, nullptr, nullptr, nullptr);&#xA;&#xA;    // read the packets and decode the video frames&#xA;    std::vector videoFrames;&#xA;    AVPacket packet;&#xA;    int i=0;&#xA;    while (av_read_frame(formatContext, &amp;packet) == 0) {&#xA;            std::cout&lt;&lt;"frame number:"&lt;&lt; i&#x2B;&#x2B; &lt;index) {&#xA;            // decode the video frame&#xA;          AVFrame* frame = av_frame_alloc();&#xA;            int gotFrame = 0;&#xA;            error = avcodec_send_packet(videoCodecContext, &amp;packet);&#xA;            checkError(error, "Error sending packet to video codec");&#xA;            if (error&lt;0) {&#xA;                    continue;&#xA;            }&#xA;            error = avcodec_receive_frame(videoCodecContext, frame);&#xA;&#xA;            //There is not enough data for decoding the frame, have to free and get more data&#xA;            ////////////////////////////////////////////////////////////////////////////&#xA;            if (error == AVERROR(EAGAIN))&#xA;            {&#xA;                av_frame_unref(frame);&#xA;                av_freep(frame);&#xA;                continue;&#xA;            }&#xA;&#xA;            if (error == AVERROR_EOF)&#xA;            {&#xA;                std::cerr &lt;&lt; "AVERROR_EOF" &lt;&lt; std::endl;&#xA;                break;&#xA;            }&#xA;            ////////////////////////////////////////////////////////////////////////////&#xA;&#xA;            checkError(error, "Error receiving frame from video codec");&#xA;&#xA;&#xA;            if (error == 0) {&#xA;                gotFrame = 1;&#xA;            }&#xA;            if (gotFrame) {&#xA;                // scale the frame to the desired format&#xA;                AVFrame* scaledFrame = av_frame_alloc();&#xA;                av_image_alloc(scaledFrame->data, scaledFrame->linesize, width, height, AV_PIX_FMT_BGR24, 32);&#xA;                sws_scale(frameScaler, frame->data, frame->linesize, 0, height, scaledFrame->data, scaledFrame->linesize);&#xA;             // copy the frame data to a cv::Mat object&#xA;                cv::Mat mat(height, width, CV_8UC3, scaledFrame->data[0], scaledFrame->linesize[0]);&#xA;&#xA;                //Show mat image for testing&#xA;                ////////////////////////////////////////////////////////////////////////////&#xA;                //cv::imshow("mat", mat);&#xA;                //cv::waitKey(100);   //Wait 100msec (relativly long time - for testing).&#xA;                ////////////////////////////////////////////////////////////////////////////&#xA;&#xA;&#xA;                videoFrames.push_back(mat.clone());&#xA;&#xA;                // clean up&#xA;                av_freep(&amp;scaledFrame->data[0]);&#xA;                av_frame_free(&amp;scaledFrame);&#xA;            }&#xA;            av_frame_free(&amp;frame);&#xA;        }&#xA;        av_packet_unref(&amp;packet);&#xA;    }&#xA;&#xA;    // clean up&#xA;    sws_freeContext(frameScaler);&#xA;    avcodec_free_context(&amp;videoCodecContext);&#xA;    avformat_close_input(&amp;formatContext);&#xA;&#xA;    return 0;&#xA;}&#xA;</vector></string></iostream>

    &#xA;

  • Android Merging two video with different (sizes,codec,frames,aspect raito) using FFMPEG

    6 septembre 2017, par Alok Kumar Verma

    I’m making an app which merges two or more than two video files which I’m getting from another activity. After choosing the files we pass the files to another activity where the merging happens. I’ve followed this link to do the same : AndroidWarZone FFMPEG

    Here I found the way on how to merge the two files only with different qualities. The command is given below :

    String[] complexCommand = {"ffmpeg","-y","-i","/storage/emulated/0/videokit/sample.mp4",
    "-i","/storage/emulated/0/videokit/in.mp4","-strict","experimental",
    "-filter_complex",
    "[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
    "-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k","/storage/emulated/0/vk2_out/out.mp4"}

    Since I have a list of selected videos inside my array which I’m passing to the next page, I’ve done some changes in my command, like this :

    private void mergeVideos() {
       String savingPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4";

       ArrayList<file> fileList = mList;

       List<string> filenames = new ArrayList<string>();

       for (int i = 0; i &lt; fileList.size(); i++) {
           filenames.add("-i");
           filenames.add(fileList.get(i).toString());
       }

       Log.e("Log===",filenames.toString());

       String joined = TextUtils.join(", ",filenames);

       Log.e("Joined====",joined);

       String complexCommand[] = {"-y", joined,
               "-filter_complex",
               "[0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
               "-ab","48000","-ac","2","-ar","22050","-s","640x480","-r","30","-vcodec","mpeg4","-b","2097k", savingPath};
       Log.e("RESULT====",Arrays.toString(complexCommand));

      execFFmpegBinary(complexCommand);  }
    </string></string></file>

    In the log this is the the output I’m getting :

    This one is for received data which I have added in the mList

    E/RECEIVED DATA=====: [/mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4]
    E/RESULT====: [-y, -i, /mnt/m_external_sd/DCIM/Camera/VID_31610130_011933_454.mp4, -i, /mnt/m_external_sd/DCIM/Camera/VID_23120824_054526_878.mp4, -filter_complex, [0:v]scale=640x480,setsar=1:1[v0];[1:v]scale=640x480,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1, -ab, 48000, -ac, 2, -ar, 22050, -s, 640x480, -r, 30, -vcodec, mpeg4, -b, 2097k, /storage/emulated/0/video.mp4]

    Here result is the complexCommand that is going inside the exeFFMPEGBinary() but not working.

    This is my exceFFMPEGBinary()

    private void execFFmpegBinary(final String[] combine) {
       try{
       fFmpeg.execute(combine, new ExecuteBinaryResponseHandler() {
           @Override
           public void onFailure(String s) {
               Log.d("", "FAILED with output : " + s);
           }

           @Override
           public void onSuccess(String s) {
               Log.d("", "SUCCESS with output : " + s);
               Toast.makeText(getApplicationContext(),"Success!",Toast.LENGTH_SHORT)
                       .show();
           }

           @Override
           public void onProgress(String s) {
               Log.d("", "progress : " + s);
           }

           @Override
           public void onStart() {
               progressDialog.setMessage("Processing...");
               progressDialog.show();
           }

           @Override
           public void onFinish() {
               progressDialog.dismiss();
           }
       });
    } catch (FFmpegCommandAlreadyRunningException e) {
       // do nothing for now
    }
    }

    I’ve done this and run my project, now the problem is it is not merging/concatenating anything, just a progressDialog comes up for a fraction of second and all I’m getting is this in my log :

    E/FFMPEG====: ffmpef : coorect loaded

    This means that ffmpeg is loading and nothing is getting implemented. I don’t get any log for onFailur, onSuccess(), onStart().

    Any suggestions would help me achieve my goal. Thanks.

    Note : I have done this merging with the use of Mp4Parser but there is a glitch inside it, it requires the file with same specification. So this is not my requirement.

    EDITS

    I did some more research and got this to concatenate, but this is not working either, here is the link : Concatenating two files

    I’ve found this stuff also from a link : FFMPEG Merging/Concatenating
    and found that his piece of code is working fine. But not mine.

    I’ve used that command also but it is not working nor giving me any log results. Except the FFMPEG Loading.

    Here is the command :

    complexCommand = new String[]{"-y", "-i", file1.toString(), "-i", file2.toString(), "-strict", "experimental", "-filter_complex",
               "[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1","-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", rootPath + "/output.mp4"};
  • Revision 35436 : Petites pétouilles en passant par là (écriture aux dernières normes ...

    22 février 2010, par marcimat@… — Log

    Petites pétouilles en passant par là (écriture aux dernières normes ISO)…