Recherche avancée

Médias (1)

Mot : - Tags -/illustrator

Autres articles (69)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

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

  • 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

Sur d’autres sites (9466)

  • Modify video frames but keep their timestamp in python (maybe with ffmpeg ?)

    3 août 2018, par bendaf

    I have .ts videos with variable frame rate and I would like to modify the frames of the videos and keep the timestamps belonging to the frames. I am using python and experiencing with ffmpeg, but I am open to any solution.

    The output of

    $ffmpeg -i myvideo.ts -hide_banner

    Input #0, mpegts, from 'myvideo.ts':
     Duration: 00:02:37.84, start: 1.400000, bitrate: 13799 kb/s
     Program 1
       Metadata:
         service_name    : Service01
         service_provider: FFmpeg
       Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 3840x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc

    What I have tried so far is :

    import skvideo.io

    outpudict = {"-map": "0",
                "-vcodec": "libx264",
                "-pix_fmt": "yuv420p",
                "-f": "mpegts"
                }

    videogen = skvideo.io.vreader(args.input_video)
    writer = skvideo.io.FFmpegWriter(filename + file_extension, outputdict=outpudict)
    for i, frame in enumerate(videogen):
       # modify the frame
       writer.writeFrame(frame)

    writer.close()

    But so far I am not able to keep the pts and dts parameters of the frames only the format and encoding.

    Note : I have tried to use skvideo.io.FFmpegReader or pass the outputdict parameter also to vreader but the script crashed because of this bug.

    Note2 : I am checking the pts of the frames with

    $ffprobe -hide_banner -show_entries packet=pts,dts myvideo.ts

    Thank you for reading through my question, any idea would be appreciated !

  • ffmpeg demux into audio and video resets PTS

    30 juillet 2018, par Mukund Manikarnike

    Demuxing

    I am demuxing TS segments into audio and video as follows.

    ffmpeg -y -i input.ts -vcodec copy -an output_video.ts
    ffmpeg -y -i input.ts -acodec copy -vn output_audio.aac

    Inspecting Input

    The start_pts and start_time on input.ts are as shown below. I was able to inspect these values using ffprobe -show_streams -print_format json input.ts

    "start_pts": 8306558438,
    "start_time": "92295.093756",

    Inspecting output video

    The output .ts has some default start_pts and start_time values as shown below. These were also obtained using the same ffprobe command as indicated above.

    "start_pts": 126000,
    "start_time": "1.400000",

    Inspecting output audio

    The same ffprobe command on output_audio.aac shows that the output aac has invalid codec_tag and codec_tag_string as shown below. The start_pts and start_time are not present in the output_audio.aac.

    "codec_tag_string": "[0][0][0][0]", (should have been [15][0][0][0])
    "codec_tag": "0x0000", (should have been 0xf000)

    Questions

    1. Wondering if this difference in the start_pts, start_time, codec_tag is expected ?
    2. If it is expected, what can I do to ensure that the all of these parameters get retained on the output ?
    3. If it is not expected, is there some more information I can share to track this down ?

    Note

    There were other outputs that I found inconsistent in the ffprobe command for the output_audio.aac like duration etc.. I shared what I thought are most valuable at this point. If required I can share complete outputs from all of the above executions.

    [EDIT 07/30/2018 - 08:00 MST]
    logs for ffmpeg -y -i input.ts -vcodec copy -an output_video.ts -acodec copy -vn output_audio.aacare as shown below.

    ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
     built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
     configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.3.0/include/openjpeg-2.3 --enable-nonfree
     libavutil      56. 14.100 / 56. 14.100
     libavcodec     58. 18.100 / 58. 18.100
     libavformat    58. 12.100 / 58. 12.100
     libavdevice    58.  3.100 / 58.  3.100
     libavfilter     7. 16.100 /  7. 16.100
     libavresample   4.  0.  0 /  4.  0.  0
     libswscale      5.  1.100 /  5.  1.100
     libswresample   3.  1.100 /  3.  1.100
     libpostproc    55.  1.100 / 55.  1.100
    [mpegts @ 0x7f88ed803000] start time for stream 0 is not set in estimate_timings_from_pts
    Input #0, mpegts, from 'i7h9456s_media_46185.ts':
     Duration: 00:00:06.05, start: 86216.852667, bitrate: 2898 kb/s
     Program 1
       Stream #0:0[0x102]: Data: timed_id3 (ID3  / 0x20334449)
       Stream #0:1[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
       Stream #0:2[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
    Output #0, mpegts, to '../output_video.ts':
     Metadata:
       encoder         : Lavf58.12.100
       Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
    Output #1, adts, to '../output_audio.aac':
     Metadata:
       encoder         : Lavf58.12.100
       Stream #1:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
    Stream mapping:
     Stream #0:1 -> #0:0 (copy)
     Stream #0:2 -> #1:0 (copy)
    Press [q] to stop, [?] for help
    frame=  180 fps=0.0 q=-1.0 Lsize=    2088kB time=00:00:06.03 bitrate=2833.8kbits/s speed= 904x    
    video:1918kB audio:142kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.349750%
  • ffmpeg memory leak in the avcodec_open2 method

    21 août 2019, par unresolved_external

    I’ve developed an application which handles live video stream. The problem is that it should run as a service and over time I am noticing some memory increase. When I check the application with valgrind - it did not find any leak related issues.
    So I’ve check it with google profile tools. This is a result(substracting the one of the first dumps from the latest) after approximately 6 hour run :

      30.0  35.7%  35.7%     30.0  35.7% av_malloc
       28.9  34.4%  70.2%     28.9  34.4% av_reallocp
       24.5  29.2%  99.4%     24.5  29.2% x264_malloc

    When I check the memory on the graph I see, that these allocations are related to avcodec_open2. The client code is :

    `           g_EncoderMutex.lock();
               ffmpeg_encoder_start(OutFileName.c_str(), AV_CODEC_ID_H264, m_FPS, width, height);
               for (pts = 0; pts < VideoImages.size(); pts++) {                
                   m_frame->pts = pts;
                   ffmpeg_encoder_encode_frame(VideoImages[pts].RGBimage[0]);
               }
               ffmpeg_encoder_finish();
               g_EncoderMutex.unlock()

    The ffmpeg_encoder_start method is :

    void VideoEncoder::ffmpeg_encoder_start(const char *filename, int codec_id, int fps, int width, int height)
           {
               int ret;
               m_FPS=fps;
               AVOutputFormat * fmt = av_guess_format(filename, NULL, NULL);
               m_oc = NULL;
               avformat_alloc_output_context2(&m_oc, NULL, NULL, filename);

               m_stream = avformat_new_stream(m_oc, 0);
               AVCodec *codec=NULL;

               codec =  avcodec_find_encoder(codec_id);    
               if (!codec)
               {
                   fprintf(stderr, "Codec not found\n");
                   return; //-1
               }

               m_c=m_stream->codec;

               avcodec_get_context_defaults3(m_c, codec);

               m_c->bit_rate = 400000;
               m_c->width = width;
               m_c->height = height;
               m_c->time_base.num = 1;
               m_c->time_base.den = m_FPS;
               m_c->gop_size = 10;
               m_c->max_b_frames = 1;
               m_c->pix_fmt = AV_PIX_FMT_YUV420P;
               if (codec_id == AV_CODEC_ID_H264)
                   av_opt_set(m_c->priv_data, "preset", "ultrafast", 0);

               if (m_oc->oformat->flags & AVFMT_GLOBALHEADER)
                   m_c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
               avcodec_open2( m_c, codec, NULL );

               m_stream->time_base=(AVRational){1, m_FPS};

               if (avio_open(&m_oc->pb, filename, AVIO_FLAG_WRITE) < 0)
               {
                   printf( "Could not open '%s'\n", filename);
                   exit(1);
               }            

               avformat_write_header(m_oc, NULL);
               m_frame = av_frame_alloc();
               if (!m_frame) {
                   printf( "Could not allocate video frame\n");
                   exit(1);
               }
               m_frame->format = m_c->pix_fmt;
               m_frame->width  = m_c->width;
               m_frame->height = m_c->height;
               ret = av_image_alloc(m_frame->data, m_frame->linesize, m_c->width, m_c->height, m_c->pix_fmt, 32);
               if (ret < 0) {
                   printf("Could not allocate raw picture buffer\n");
                   exit(1);
               }
           }

    The ffmpeg_encoder_encode_frame is :

    void VideoEncoder::ffmpeg_encoder_encode_frame(uint8_t *rgb)
    {
       int ret, got_output;
       ffmpeg_encoder_set_frame_yuv_from_rgb(rgb);
       av_init_packet(&m_pkt);
       m_pkt.data = NULL;
       m_pkt.size = 0;

       ret = avcodec_encode_video2(m_c, &m_pkt, m_frame, &got_output);
       if (ret < 0) {
           printf("Error encoding frame\n");
           exit(1);
       }
       if (got_output)
       {

            av_packet_rescale_ts(&m_pkt,
                           (AVRational){1, m_FPS}, m_stream->time_base);
           m_pkt.stream_index = m_stream->index;
           int ret = av_interleaved_write_frame(m_oc, &m_pkt);

           av_packet_unref(&m_pkt);

       }

    }

    ffmpeg_encoder_finish code is :

    void VideoEncoder::ffmpeg_encoder_finish(void)
           {
               int got_output, ret;

               do {

                   ret = avcodec_encode_video2(m_c, &m_pkt, NULL, &got_output);
                   if (ret < 0) {
                       printf( "Error encoding frame\n");
                       exit(1);
                   }
                   if (got_output) {

                       av_packet_rescale_ts(&m_pkt,
                                   (AVRational){1, m_FPS}, m_stream->time_base);
                       m_pkt.stream_index = m_stream->index;
                       int ret = av_interleaved_write_frame(m_oc, &m_pkt);

                       av_packet_unref(&m_pkt);
                   }
               } while (got_output);

               av_write_trailer(m_oc);
               avio_closep(&m_oc->pb);

               avformat_free_context(m_oc);

               av_freep(&m_frame->data[0]);
               av_frame_free(&m_frame);

               av_packet_unref(&m_pkt);
               sws_freeContext(m_sws_context);
           }

    This code runs multiple times in the loop.
    So my question is - what am I doing wrong ? maybe ffmpeg is using some kind of internal buffering ? If so, how to disable it ? Because such an increase in memory usage is unacceptable at all.