Recherche avancée

Médias (0)

Mot : - Tags -/utilisateurs

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (70)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

Sur d’autres sites (10248)

  • FFMPEG RTSP stream to MPEG4/H264 file using libx264

    16 octobre 2020, par Phi

    Heyo folks,

    



    I'm attempting to transcode/remux an RTSP stream in H264 format into a MPEG4 container, containing just the H264 video stream. Basically, webcam output into a MP4 container.

    



    I can get a poorly coded MP4 produced, using this code :

    



    // Variables here for demo
AVFormatContext * video_file_output_format = nullptr;
AVFormatContext * rtsp_format_context = nullptr;
AVCodecContext * video_file_codec_context = nullptr;
AVCodecContext * rtsp_vidstream_codec_context = nullptr;
AVPacket packet = {0};
AVStream * video_file_stream = nullptr;
AVCodec * rtsp_decoder_codec = nullptr;
int errorNum = 0, video_stream_index = 0;
std::string outputMP4file = "D:\\somemp4file.mp4";

// begin
AVDictionary * opts = nullptr;
av_dict_set(&opts, "rtsp_transport", "tcp", 0);

if ((errorNum = avformat_open_input(&rtsp_format_context, uriANSI.c_str(), NULL, &opts)) < 0) {
    errOut << "Connection failed: avformat_open_input failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
    TacticalAbort();
    return;
}

rtsp_format_context->max_analyze_duration = 50000;
if ((errorNum = avformat_find_stream_info(rtsp_format_context, NULL)) < 0) {
    errOut << "Connection failed: avformat_find_stream_info failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
    TacticalAbort();
    return;
}

video_stream_index = errorNum = av_find_best_stream(rtsp_format_context, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);

if (video_stream_index < 0) {
    errOut << "Connection in unexpected state; made a connection, but there was no video stream.\r\n"
        "Attempts to find a video stream resulted in error " << errorNum << ": " << ErrorRead(errorNum);
    TacticalAbort();
    return;
}

rtsp_vidstream_codec_context = rtsp_format_context->streams[video_stream_index]->codec;

av_init_packet(&packet);

if (!(video_file_output_format = av_guess_format(NULL, outputMP4file.c_str(),  NULL))) {
    TacticalAbort();
    throw std::exception("av_guess_format");
}

if (!(rtsp_decoder_codec = avcodec_find_decoder(rtsp_vidstream_codec_context->codec_id))) {
    errOut << "Connection failed: connected, but avcodec_find_decoder returned null.\r\n"
        "Couldn't find codec with an AV_CODEC_ID value of " << rtsp_vidstream_codec_context->codec_id << ".";
    TacticalAbort();
    return;
}

video_file_format_context = avformat_alloc_context();
video_file_format_context->oformat = video_file_output_format;

if (strcpy_s(video_file_format_context->filename, sizeof(video_file_format_context->filename), outputMP4file.c_str())) {
    errOut << "Couldn't open video file: strcpy_s failed with error " << errno << ".";
    std::string log = errOut.str();
    TacticalAbort();
    throw std::exception("strcpy_s");
}

if (!(video_file_encoder_codec = avcodec_find_encoder(video_file_output_format->video_codec))) {
    TacticalAbort();
    throw std::exception("avcodec_find_encoder");
}

// MARKER ONE

if (!outputMP4file.empty() &&
    !(video_file_output_format->flags & AVFMT_NOFILE) &&
    (errorNum = avio_open2(&video_file_format_context->pb, outputMP4file.c_str(), AVIO_FLAG_WRITE, nullptr, &opts)) < 0) {
    errOut << "Couldn't open video file \"" << outputMP4file << "\" for writing : avio_open2 failed with error " << errorNum << ": " << ErrorRead(errorNum);
    TacticalAbort();
    return;
}

// Create stream in MP4 file
if (!(video_file_stream = avformat_new_stream(video_file_format_context, video_file_encoder_codec))) {
    TacticalAbort();
    return;
}

AVCodecContext * video_file_codec_context = video_file_stream->codec;

// MARKER TWO

// error -22/-21 in avio_open2 if this is skipped
if ((errorNum = avcodec_copy_context(video_file_codec_context, rtsp_vidstream_codec_context)) != 0) {
    TacticalAbort();
    throw std::exception("avcodec_copy_context");
}

//video_file_codec_context->codec_tag = 0;

/*
// MARKER 3 - is this not needed? Examples suggest not.
if ((errorNum = avcodec_open2(video_file_codec_context, video_file_encoder_codec, &opts)) < 0)
{
    errOut << "Couldn't open video file codec context: avcodec_open2 failed with error " << errorNum << ": " << ErrorRead(errorNum);
    std::string log = errOut.str();
    TacticalAbort();
    throw std::exception("avcodec_open2, video file");
}*/

//video_file_format_context->flags |= AVFMT_FLAG_GENPTS;
if (video_file_format_context->oformat->flags & AVFMT_GLOBALHEADER)
{
    video_file_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

if ((errorNum = avformat_write_header(video_file_format_context, &opts)) < 0) {
    errOut << "Couldn't open video file: avformat_write_header failed with error " << errorNum << ":\r\n" << ErrorRead(errorNum);
    std::string log = errOut.str();
    TacticalAbort();
    return;
}


    



    However, there are several issues :

    



      

    1. I can't pass any x264 options to the output file. The output H264 matches the input H264's profile/level - switching cameras to a different model switches H264 level.
    2. 


    3. The timing of the output file is off, noticeably.
    4. 


    5. The duration of the output file is off, massively. A few seconds of footage becomes hours, although playtime doesn't match. (FWIW, I'm using VLC to play them.)
    6. 


    



    Passing x264 options

    



    If I manually increment PTS per packet, and set DTS equal to PTS, it plays too fast, 2-3 seconds' worth of footage in one second playtime, and duration is hours long. The footage also blurs past several seconds, about 10 seconds' footage in a second.

    



    If I let FFMPEG decide (with or without GENPTS flag), the file has a variable frame rate (probably as expected), but it plays the whole file in an instant and has a long duration too (over forty hours for a few seconds). The duration isn't "real", as the file plays in an instant.

    



    At Marker One, I try to set the profile by passing options to avio_open2. The options are simply ignored by libx264. I've tried :

    



    av_dict_set(&opts, "vprofile", "main", 0);
av_dict_set(&opts, "profile", "main", 0); // error, missing '('
// FF_PROFILE_H264_MAIN equals 77, so I also tried
av_dict_set(&opts, "vprofile", "77", 0); 
av_dict_set(&opts, "profile", "77", 0);


    



    It does seem to read the profile setting, but it doesn't use them. At Marker Two, I tried to set it after the avio_open2, before avformat_write_header .

    



    // I tried all 4 av_dict_set from earlier, passing it to avformat_write_header.
// None had any effect, they weren't consumed.
av_opt_set(video_file_codec_context, "profile", "77", 0);
av_opt_set(video_file_codec_context, "profile", "main", 0);
video_file_codec_context->profile = FF_PROFILE_H264_MAIN;
av_opt_set(video_file_codec_context->priv_data, "profile", "77", 0);
av_opt_set(video_file_codec_context->priv_data, "profile", "main", 0);


    



    Messing with privdata made the program unstable, but I was trying anything at that point.
I'd like to solve issue 1 with passing settings, since I imagine it'd bottleneck any attempt to solve issues 2 or 3.

    



    I've been fiddling with this for the better part of a month now. I've been through dozens of documentation, Q&As, examples. It doesn't help that quite a few are outdated.

    



    Any help would be appreciated.

    



    Cheers

    


  • Segfault after 15 seconds while reading a RTSP stream with ffmpeg in Android

    27 juillet 2013, par ABentSpoon

    I'm trying to read a RTSP stream using ffmpeg by way of javacv. I'm able to view the fist 15 seconds or so before I get a segfault on the call to sws_scale. Does this mean I've ran out of memory ? If so, any idea what I'm doing wrong ?

       av_register_all();
       avcodec.avcodec_register_all();
       avformat_network_init();
       AVFormatContext avFormatContext = avformat.avformat_alloc_context();

       if(0 != avformat_open_input(avFormatContext, "rtsp://192.168.0.107:7654/lov2.ffm", null, null)){
           throw new RuntimeException("avformat_open_input failed");
       }

       if(avformat_find_stream_info(avFormatContext, null) < 0){
           throw new RuntimeException("avformat_find_stream_info failed");
       }

       int video_stream_index = 0;

       //search video stream
       for(int i = 0; i < avFormatContext.nb_streams(); i++){
           if(avFormatContext.streams(i).codec().codec_type() == AVMEDIA_TYPE_VIDEO){
               video_stream_index = i;
           }
       }
       Log.d(TAG, "checkpoint 3");
       AVPacket packet = new AVPacket();
       av_init_packet(packet);

       AVStream stream = new AVStream();
       int cnt = 0;

       //start reading packets from stream and write them to file
       av_read_play(avFormatContext);//play RTSP
       AVCodecContext avCodecContext = avFormatContext.streams(video_stream_index).codec();
       AVCodec codec = avcodec_find_decoder(avCodecContext.codec_id());

       if (codec == null){
           throw new RuntimeException("codec not found");
       }

       if (avcodec_open2(avCodecContext, codec, null) < 0){
           throw new RuntimeException("could not open codec");
       }

       SwsContext img_convert_ctx = new SwsContext();
       img_convert_ctx = swscale.sws_getCachedContext(
               img_convert_ctx,
               avCodecContext.width(), avCodecContext.height(),
               avCodecContext.pix_fmt(), avCodecContext.width(), avCodecContext.height(),
               PIX_FMT_RGB24, SWS_BICUBIC, null, null, null
       );

       int size = avpicture_get_size(PIX_FMT_YUV420P, avCodecContext.width(), avCodecContext.height());
       BytePointer picture_buf = new BytePointer(av_malloc(size));
       AVFrame frame = avcodec_alloc_frame();
       AVFrame picrgb = avcodec_alloc_frame();

       int size2 = avpicture_get_size(avutil.PIX_FMT_RGB24, avCodecContext.width(), avCodecContext.height());
       BytePointer picture_buf2 = new BytePointer(av_malloc(size2));

       avpicture_fill(frame, picture_buf, PIX_FMT_YUV420P, avCodecContext.width(), avCodecContext.height());
       avpicture_fill(picrgb, picture_buf2, avutil.PIX_FMT_RGB24, avCodecContext.width(), avCodecContext.height());
       Log.d(TAG, String.format("h: %d,  w: %d; h: %d w: %d", avCodecContext.width(), avCodecContext.height(), avCodecContext.height(), frame.width()));
       Log.d(TAG, "checkpoint 6");
       Bitmap bmp = Bitmap.createBitmap(avCodecContext.width(), avCodecContext.height(), Bitmap.Config.RGB_565);
       while(av_read_frame(avFormatContext, packet) >= 0){

           if(packet.size() > 0 && packet.stream_index() == video_stream_index){//packet is video
               int[] gotFrame = new int[]{0};
               int len = avcodec_decode_video2(avCodecContext, frame, gotFrame, packet);
               if(gotFrame[0] > 0){
                   swscale.sws_scale(
                           img_convert_ctx,
                           frame.data(0), frame.linesize(),
                           0, avCodecContext.height(),
                           picrgb.data(0), picrgb.linesize());
                   bmp.copyPixelsFromBuffer(picture_buf2.asByteBuffer());
                   videoView.drawFrame(bmp);
               }
           }
           av_free_packet(packet);
           av_init_packet(packet);
       }
       av_free(frame);
       av_free(picrgb);
       av_free(picture_buf);
       av_free(picture_buf2);

       av_read_pause(avFormatContext);

    Stack trace :

    F/libc    ( 7460): Fatal signal 11 (SIGSEGV) at 0x76100005 (code=1), thread 7474 (Thread-13601)
    E/Sensors (  720): accelHandler 0.201182 0.180824 10.950029
    I/DEBUG   ( 6409): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    I/DEBUG   ( 6409): Build fingerprint: 'Verizon/d2vzw/d2vzw:4.1.2/JZO54K/I535VRBMB1:user/release-keys'
    I/DEBUG   ( 6409): pid: 7460, tid: 7474, name: Thread-13601  >>> com.example.javacv.stream.test2 <<<
    I/DEBUG   ( 6409): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 76100005
    I/DEBUG   ( 6409):     r0 57995360  r1 594f3c30  r2 59349200  r3 59349020
    I/DEBUG   ( 6409):     r4 59349020  r5 76100005  r6 00000060  r7 594f3cf0
    I/DEBUG   ( 6409):     r8 59349200  r9 59349020  sl 000001e0  fp 76100005
    I/DEBUG   ( 6409):     ip 594f3cf0  sp 5e08bb08  lr 59308bec  pc 593103b8  cpsr 00000010

    FAQ :

    • Why not use MediaPlayer ?

    MediaPlayer forces 2 seconds of latency on the stream, I really need <100ms.

  • changing frame-rate for .mov

    5 juin 2013, par Ryan Saxe

    So I have a script in python that uses urllib to download a bunch of images and I then use ImageMagick to add labels to the images and then throw them into a MOV file.

    My issue is that the MOV file is going at 30 frames per second, and that is way too fast for me to be able to watch what is happening. I need something that is more like 5-10 frames per second.

    Is there a way to do this in ImageMagick, FFmpeg or any other easily accessible and cross platform package ?

    EDIT 1 : showing my ImageMagick

    convert -quality 100 *.png my_movie.mov

    I wasn't able to find it, but is there some line I add like -frameRate or something like that to allow me to choose the frame rate ? I can also use FFmpeg along with it so if anybody knows, that would be greay