Recherche avancée

Médias (91)

Autres articles (79)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (14500)

  • ffmpeg av_read_frame "Invalid data found"

    26 mai 2017, par DweebsUnited

    I am using ffmpeg to cut part of a file, following the remux example provided. However, I am having issues reading from files. I am given a file descriptor as input and an output filename, and can successfully set up the output file, read the stream info, copy all the streams, etc, etc. On the first call to av_read_frame though, I get an "Invalid data found when processing input" error. I have tried this with many different video files, and have not been able to get a single one to process correctly.

    Here is my code. I get no errors anywhere, except av_read_frame, which gives Invalid data found no matter what video file I give it.

    char path[512];
    sprintf(path, "pipe:%d", fileno(fp));


    AVOutputFormat *ofmt = NULL;
    AVFormatContext *ifmt_ctx = avformat_alloc_context(), *ofmt_ctx = NULL;
    AVPacket pkt;
    int ret, i;

    av_register_all();
    avcodec_register_all();

    if ((ret = avformat_open_input(&ifmt_ctx, path, av_find_input_format("mp4"), NULL)) < 0) {
       LOG("Could not open input file '%s'", path);
       goto end;
    }

    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
       LOG("Failed to retrieve input stream information", "");
       goto end;
    }

    avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
    if (!ofmt_ctx) {
       LOG("Could not create output context\n");
       ret = AVERROR_UNKNOWN;
       goto end;
    }

    ofmt = ofmt_ctx->oformat;

    for (i = 0; i < ifmt_ctx->nb_streams; i++) {
       AVStream *in_stream = ifmt_ctx->streams[i];
       AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);

       if (!out_stream) {
           LOG("Failed allocating output stream\n");
           goto end;
       }

       ret = avcodec_parameters_copy(out_stream->codecpar, in_stream->codecpar);
       if (ret < 0) {
           LOG("Failed to copy context from input to output stream codec context\n");
           goto end;
       }
       out_stream->codecpar->codec_tag = 0;
    }

    if (!(ofmt->flags & AVFMT_NOFILE)) {
       ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
       if (ret < 0) {
           LOG("Could not open output file '%s'", out_filename);
           goto end;
       }
    }

    ret = avformat_write_header(ofmt_ctx, NULL);
    if (ret < 0) {
       LOG("Error occurred when opening output file\n");
       goto end;
    }

    //    int indexs[8] = {0};

    //    int64_t start_from = 8*AV_TIME_BASE;
    ret = av_seek_frame(ifmt_ctx, -1, from_seconds*AV_TIME_BASE, AVSEEK_FLAG_ANY);
    if (ret < 0) {
       LOG("Error seek\n");
       goto end;
    }

    int64_t *dts_start_from;
    int64_t *pts_start_from;
    dts_start_from = (int64_t *) malloc(sizeof(int64_t) * ifmt_ctx->nb_streams);
    memset(dts_start_from, 0, sizeof(int64_t) * ifmt_ctx->nb_streams);
    pts_start_from = (int64_t *) malloc(sizeof(int64_t) * ifmt_ctx->nb_streams);
    memset(pts_start_from, 0, sizeof(int64_t) * ifmt_ctx->nb_streams);

    while (1) {
       AVStream *in_stream, *out_stream;

       ret = av_read_frame(ifmt_ctx, &pkt);
       if (ret < 0)
           break;

       in_stream = ifmt_ctx->streams[pkt.stream_index];
       out_stream = ofmt_ctx->streams[pkt.stream_index];

       if (av_q2d(in_stream->time_base) * pkt.pts > end_seconds) {
           av_packet_unref(&pkt);
           break;
       }

       if (dts_start_from[pkt.stream_index] == 0)
           dts_start_from[pkt.stream_index] = pkt.dts;
       if (pts_start_from[pkt.stream_index] == 0)
           pts_start_from[pkt.stream_index] = pkt.pts;

       /* copy packet */
       pkt.pts = ::av_rescale_q_rnd(pkt.pts - pts_start_from[pkt.stream_index], in_stream->time_base, out_stream->time_base, (AVRounding) (AV_ROUND_NEAR_INF |
                                                                                                                                           AV_ROUND_PASS_MINMAX));
       pkt.dts = ::av_rescale_q_rnd(pkt.dts - dts_start_from[pkt.stream_index], in_stream->time_base, out_stream->time_base, (AVRounding) (AV_ROUND_NEAR_INF |
                                                                                                                                           AV_ROUND_PASS_MINMAX));
       if (pkt.pts < 0) {
           pkt.pts = 0;
       }
       if (pkt.dts < 0) {
           pkt.dts = 0;
       }
       pkt.duration = (int) av_rescale_q((int64_t) pkt.duration, in_stream->time_base, out_stream->time_base);
       pkt.pos = -1;

       ret = av_interleaved_write_frame(ofmt_ctx, &pkt);
       if (ret < 0) {
           LOG("Error muxing packet\n");
           break;
       }
       av_packet_unref(&pkt);
    }
    free(dts_start_from);
    free(pts_start_from);

    av_write_trailer(ofmt_ctx);

    end:
    LOG("END");

    avformat_close_input(&ifmt_ctx);

    /* close output */
    if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
       avio_closep(&ofmt_ctx->pb);
    avformat_free_context(ofmt_ctx);

    if (ret < 0 && ret != AVERROR_EOF) {
       LOG("-- Error occurred: %s\n", av_err2str(ret));
       return 1;
    }

    Thank you for any help, I’m still getting used to ffmpeg. Did I miss some setting on the input ? Am I not setting something up that I need to be ? This problem is really stumping me.

  • Using libavcodec to read .mkv video file

    10 mars 2020, par Slav

    Trying to read .mkv file and write it to .bmp, but resulting .bmp is black-and-white and consists of multiple mini-images of what supposed to be written :

    int main()
    {
       av_register_all();
       avformat_network_init();
       avfilter_register_all();

       //crashes on -Ofast without =NULL initialization:
       AVFormatContext * format = NULL;
       if ( avformat_open_input( & format, VIDEO_FILE, NULL, NULL ) != 0 ) {
           cerr << "Could not open file " << VIDEO_FILE << endl;
           return -1;
       }

       // Retrieve stream information
       if ( avformat_find_stream_info( format, NULL ) < 0) {
           cerr << "avformat_find_stream_info() failed." << endl;
           return -1;
       }
       av_dump_format( format, 0, VIDEO_FILE, false );

       AVCodec * video_dec = (AVCodec*)1;
       AVCodec * audio_dec = (AVCodec*)1;
       const auto video_stream_index = av_find_best_stream( format, AVMEDIA_TYPE_VIDEO, -1, -1, & video_dec, 0 );
       const auto audio_stream_index = av_find_best_stream( format, AVMEDIA_TYPE_AUDIO, -1, -1, & audio_dec, 0 );
       if ( video_stream_index < 0 ) {
           cerr << "Failed to find video stream." << endl;
           return -1;
       }
       if ( audio_stream_index < 0 ) {
           cerr << "Failed to find audio stream." << endl;
           return -1;
       }

       AVCodecParameters * videoParams = format->streams[ video_stream_index ]->codecpar;
       cout << "Having " << videoParams->width << " | " << videoParams->height << " video." << endl;

       av_read_play( format );

       // create decoding context
       AVCodecContext * video_ctx = avcodec_alloc_context3( video_dec );
       AVCodecContext * audio_ctx = avcodec_alloc_context3( audio_dec );
       if ( ! video_ctx || ! audio_ctx ) {
           cerr << "Failed to avcodec_alloc_context3()" << endl;
           return -1;
       }
       if ( video_dec->capabilities & AV_CODEC_CAP_TRUNCATED ) video_ctx->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames

       /* For some codecs, such as msmpeg4 and mpeg4, width and height
          MUST be initialized there because this information is not
          available in the bitstream. */

       avcodec_parameters_to_context( video_ctx, format->streams[ video_stream_index ]->codecpar );
       avcodec_parameters_to_context( audio_ctx, format->streams[ audio_stream_index ]->codecpar );
       if ( avcodec_open2( video_ctx, video_dec, NULL ) < 0 ) {
           cout << "Failed to open video decoder." << endl;
           return -1;
       }
       if ( avcodec_open2( audio_ctx, audio_dec, NULL ) < 0 ) {
           cout << "Failed to open audio decoder." << endl;
           return -1;
       }

       uint8_t* picture_buffer = (uint8_t*) (av_malloc( avpicture_get_size( AV_PIX_FMT_RGB24 , videoParams->width, videoParams->height ) ));
       AVFrame* picture = av_frame_alloc();
       avpicture_fill( (AVPicture *) picture, picture_buffer, AV_PIX_FMT_RGB24, video_ctx->width, video_ctx->height );

       AVPacket packet;
       av_init_packet( & packet );

       int cnt = 0;
       while ( av_read_frame( format, & packet ) >= 0 && cnt < 10 ) {
           if ( packet.stream_index == video_stream_index ) {
               int check;
               const auto result = avcodec_decode_video2( video_ctx, picture, & check, & packet );
               cout << "Bytes decoded " << result << " check " << check << endl;

               std::string name = "debug/av/";
               name += std::to_string( cnt ) + ".bmp";
               cout << "Writing frame " << name << " with linesize " << picture->linesize[0] << " ..." << endl;
               write_bmp( (uint8_t*) picture->data, videoParams->width, videoParams->height, name.c_str() );

               av_frame_unref( picture );

               ++ cnt;
           }
           else if ( packet.stream_index == audio_stream_index ) {
               cout << "Sound packet" << endl;
           }
           av_free_packet( & packet );
           av_init_packet( & packet );
       }
    }

    How can I fix it ?

  • Workflow for creating animated hand-drawn videos - encoding difficulties

    8 décembre 2017, par Mircode

    I want to create YouTube videos, kind of in the style of a white-board animation.

    Tldr question : How can I encode into a lossless rgb video format with ffmpeg, including alpha channel ?

    More detailed :
    My current workflow looks like this :

    I draw the slides in Inkscape, I group all paths that are to be drawn in one go (one scene so to say) and store the slide as svg. Then I run a custom python script over that. It animates the slides as described here https://codepen.io/MyXoToD/post/howto-self-drawing-svg-animation. Each frame is exported as svg, converted to png and fed to ffmpeg for making a video from it.

    For every scene (a couple of paths being drawn, there are several scenes per slide) I create an own video file and then I also store a png file that contains the last frame of that video.

    I then use kdenlive to join it all together : A video containing the drawing of the first scene, then a png which holds the last image of the video while I talk about the drawing, then the next animated drawing, then the next still image where I continue talking and so on. I use these intermediate images because freezing the last frame is tedious in kdenlive and I have around 600 scenes. Here I do the editing, adjust the duration of the still images and render the final video.

    The background of the video is a photo of a blackboard which never changes, the strokes are paths with a filter to make it look like chalk.

    So far so good, everything almost works.

    My problem is : Whenever there is a transition between an animation and a still image, it is visible in the final result. I have tried several approaches to make this work but nothing is without flaws.

    My first approach was to encode the animations as mp4 like this :

    p = Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', str(fps), '-i', '-', '-vcodec', 'libx264', '-crf', '21', '-bf', '2', '-flags', '+cgop', '-pix_fmt', 'yuv420p', '-movflags', 'faststart', '-r', str(fps), videofile], stdin=PIPE)

    which is recommended for YouTube. But then there is a little brightness difference between video and still image.

    Then I tried mov with png codec :

    p = Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', str(fps), '-i', '-', '-vcodec', 'png', '-r', str(fps), videofile], stdin=PIPE)

    I think this encodes every frame as png in the video. It creates way bigger files since every frame is encoded separately. But it’s ok since I can use transparency for the background and just store the chalk strokes. However, sometimes I want to swipe parts of the chalk on a slide away, which I do by drawing background over it. Which would work if those overlaid, animated background chunks which are stored in the video looked exactly like the underlying png in the background. But it doesn’t. It’s slightly more blurry and I believe the color changes a tiny bit as well. Which I don’t understand since I thought the video just stores a sequence of pngs... Is there some quality setting that I miss here ?

    Then I read about ProRes4444 and tried that :

    p = Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', str(fps), '-i', '-', '-c:v', 'prores_ks', '-pix_fmt', 'yuva444p10le', '-alpha_bits', '8', '-profile:v', '4444', '-r', str(fps), videofile], stdin=PIPE)

    and this actually seems to work. However, the animation files become larger than the bunch of png files they contain, probably because this format stores 12 bit per channel. This is not thaat horrible since only intermediate videos grow big, the final result is still ok.

    But ideally there would be a lossless codec which stores in rgb colorspace with 8 bit per channel, 8 bit for alpha and considers only the difference to the previous frame (because all that changes from frame to frame is a tiny bit of chalk drawing). Is there such a thing ? Alternatively, I’d also be ok without transparency but then I have to store the background in every scene. But if only changes are stored from frame to frame within one scene, that should be manageable.

    Or should I make some fundamental changes in my workflow altogether ?

    Sorry that this is rather lengthy, I appreciate any help.

    Cheers !