Recherche avancée

Médias (91)

Autres articles (111)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    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 (...)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

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

Sur d’autres sites (9594)

  • ffmpeg API muxing h264 endoced frames to mkv

    24 mars 2017, par Pawel K

    Hi I’m having some problems with muxing h264 encoded frames into mkv container using code of ffmpeg-3.2.4.
    I have ended up with the following code that is a mashup of code found on SO and muxing.c example of ffmpeg :
    (and yes I am aware that it is ugly, no errors checked etc. it is meant to be like that for clarity :) )

    char *filename = "out.mkv";
    const uint8_t SPS[] = { 0x67, 0x42, 0x40, 0x1F, 0x96, 0x54, 0x02, 0x80, 0x2D, 0xD0, 0x0F, 0x39, 0xEA };
    const uint8_t PPS[] = { 0x68, 0xCE, 0x38, 0x80 };
    int fps = 5;

    typedef struct OutputStream
    {
      AVStream *st;
      AVCodecContext *enc;

      /* pts of the next frame that will be generated */
      int64_t next_pts;
      int samples_count;
      AVFrame *frame;
      AVFrame *tmp_frame;
      float t, tincr, tincr2;
      struct SwsContext *sws_ctx;
      struct SwrContext *swr_ctx;
    } OutputStream;

    static void avlog_cb(void *s, int level, const char *szFmt, va_list varg)
    {
      vprintf(szFmt, varg);
    }

    void main()
    {
      AVOutputFormat *fmt;
      AVFormatContext *formatCtx;
      AVCodec *audio_codec;
      AVCodec *video_codec;
      OutputStream video_st = { 0 };
      OutputStream audio_st = { 0 };
      av_register_all();

      av_log_set_level(AV_LOG_TRACE);
      //av_log_set_callback(avlog_cb);

      //allocate output and format ctxs
      avformat_alloc_output_context2(&formatCtx, NULL, NULL, filename);
      fmt = formatCtx->oformat;

      //allocate streams
      video_codec = avcodec_find_encoder(fmt->video_codec);
      video_st.st = avformat_new_stream(formatCtx, NULL);
      video_st.st->id = 0;

      AVCodecContext *codecCtx =  avcodec_alloc_context3(video_codec);
      fmt->video_codec = AV_CODEC_ID_H264;
      video_st.enc = codecCtx;

      codecCtx->codec_id = fmt->video_codec;
      codecCtx->bit_rate = 400000;
      codecCtx->width  = 1080;
      codecCtx->height = 720;
      codecCtx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
      codecCtx->level = 31;

      video_st.st->time_base = (AVRational){ 1, fps };
      codecCtx->time_base = video_st.st->time_base;
      codecCtx->gop_size = 4;
      codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;

      //open video codec
      codecCtx->extradata_size = 24;
      codecCtx->extradata = (uint8_t *)av_malloc(codecCtx->extradata_size);
      uint8_t extra_data_array[] = { 0x01, SPS[1], SPS[2], SPS[3], 0xFF, 0xE1, 0xc0, 0, 0x42, 0x40, 0x1F, 0x96, 0x54, 0x02, 0x80, 0x2D, 0xD0, 0x0F, 0x39, 0xEA, 0x03, 0xCE, 0x38, 0x80 };
      memcpy(codecCtx->extradata, extra_data_array, codecCtx->extradata_size);

      AVCodecContext *c = video_st.enc;
      AVDictionary *opt = NULL;
      avcodec_open2(c, video_codec, &opt);
      avcodec_parameters_from_context(video_st.st->codecpar, c);

      //open output file
      avio_open(&formatCtx->pb, filename, AVIO_FLAG_WRITE);

      //write header
      int res = avformat_write_header(formatCtx, NULL);

      //write frames

      // get the frames from file
      uint32_t u32frameCnt = 0;

      do
      {
         int8_t i8frame_name[64] = "";

         uint8_t  *pu8framePtr = NULL;
         AVPacket pkt = { 0 };

         av_init_packet(&pkt);
         sprintf(i8frame_name, "frames/frame%d.bin", u32frameCnt++);
         //reading frames from files
         FILE *ph264Frame = fopen(i8frame_name, "r");
         if(NULL == ph264Frame)
         {
            goto leave;
         }

         //get file size
         fseek(ph264Frame, 0L, SEEK_END);
         uint32_t u32file_size = 0;
         u32file_size = ftell(ph264Frame);
         fseek(ph264Frame, 0L, SEEK_SET);

         pu8framePtr = malloc(u32file_size);
         uint32_t u32readout = fread(pu8framePtr, 1, u32file_size, ph264Frame);

         //if the read frame is a key frame i.e. nalu hdr type = 5 set it as a key frame
         if(0x65 == pu8framePtr[4])
         {
            pkt.flags = AV_PKT_FLAG_KEY;
         }
         pkt.data = (uint8_t *)pu8framePtr;
         pkt.size = u32readout;
         pkt.pts  = u32frameCnt;
         pkt.dts  = pkt.pts;

         av_packet_rescale_ts(&pkt, c->time_base, video_st.st->time_base);
         pkt.stream_index = video_st.st->index;
         av_interleaved_write_frame(formatCtx, &pkt);
         free(pu8framePtr);
         fclose(ph264Frame);
      }
      while(1);
    leave:

      av_write_trailer(formatCtx);
      av_dump_format(formatCtx, 0, filename, 1);
      avcodec_free_context(&video_st.enc);
      avio_closep(&formatCtx->pb);
      avformat_free_context(formatCtx);
    }

    It can be compiled with the following command line (after adding headers) :

    gcc file.c -o test_app -I/usr/local/include -L/usr/local/lib -lxcb-shm -lxcb -lX11 -lx264 -lm -lz -pthread -lswresample -lswscale -lavcodec -lavformat -lavdevice -lavutil

    The files that are read are valid annexB stream (valid as in it’s playable in vlc after concatenating into file) it is a Constrained Baseline 3.1 profile H264 and it comes from an IPcam’s interleaved RTCP/RTP stream (demuxed)

    The result is ... well I don’t see the picture. I get only black screen with the progress bar and timer running. I don’t know if I do something wrong with setting up the codecs and streams, or it’s just wrong timestamps.
    I know I got them wrong in some manner but I don’t understand that fully yet (how to calculate the correct presentation times), i.e. the stream and the codec both contain time_base field, and then I know that the sample rate of the video is 90kHz and the frame rate is 5 fps

    On top of it all the examples I’ve found have to some extend deprecated parts that change the flow/meaning of the application and that doesn’t help at all so thus If anyone could help I would appreciate it (I think not only me I would guess)

    Regards, Pawel

  • Encoding RGB frames using x264 and AVCodec in C

    6 novembre 2016, par deepwork

    I have RGB24 frames streamed from camera and i want to encode them into h264 ,i found that AVCodec and x264 can do so, the problem is x264 as default accepts YUV420 as input so what i wrote was a program which convert RGB frames to YUV420 .that was by sws_scale function .this works well except that it does not satisfy the required FPS because the converting (RGB->YUV420) takes time.

    This is how i setup my encoder context :

    videoStream->id = 0;
    vCodecCtx = videoStream->codec;

    vCodecCtx->coder_type       = AVMEDIA_TYPE_VIDEO;
    vCodecCtx->codec_id         = AV_CODEC_ID_H264;
    vCodecCtx->bit_rate         = 400000;
    vCodecCtx->width            = Width;
    vCodecCtx->height           = Height;
    vCodecCtx->time_base.den    = FPS;
    vCodecCtx->time_base.num    = 1;
    //vCodecCtx->time_base      = (AVRational){1,};
    vCodecCtx->gop_size         = 12;
    vCodecCtx->max_b_frames     = 1;
    vCodecCtx->pix_fmt          = AV_PIX_FMT_YUV420P;

    if(formatCtx->oformat->flags & AVFMT_GLOBALHEADER)
       vCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;

    av_opt_set(vCodecCtx->priv_data, "preset", "ultrafast", 0);
    av_opt_set(vCodecCtx->priv_data, "profile", "baseline", AV_OPT_SEARCH_CHILDREN);

    if (avcodec_open2(vCodecCtx, h264Codec, NULL) < 0){
       return 0;
    }

    when i changes AV_PIX_FMT_YUV420P to AV_PIX_FMT_RGB24 ,avcodec_open2 will fail.
    i read that there is a version of libx264 for RGB called libx264rgb but i even dont know whether i have to rebuild x264 with enabling this option or to download another source or i have to do it programmatically with the first x264 lib.

    the question is how to enable RGB as input to libx264 to use with libavcodec in C .or how to make the encoding or sws_scale more fast .

    Edit :

    How i built ffmpeg :

    NDK=D:/AndroidDev/android-ndk-r9
    PLATFORM=$NDK/platforms/android-18/arch-arm/
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64

    GENERAL="\
    --enable-small \
    --enable-cross-compile \
    --extra-libs="-lgcc" \
    --arch=arm \
    --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
    --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
    --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
    --extra-cflags="-I../x264/android/arm/include" \
    --extra-ldflags="-L../x264/android/arm/lib" "


    MODULES="\
    --enable-gpl \
    --enable-libx264"

    function build_ARMv6
    {
     ./configure \
     --target-os=linux \
     --prefix=./android/armeabi \
     ${GENERAL} \
     --sysroot=$PLATFORM \
     --enable-shared \
     --disable-static \
     --extra-cflags=" -O3 -fpic -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 -mfloat-abi=softfp -mfpu=vfp -marm -march=armv6" \
     --extra-ldflags="-lx264 -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
     --enable-zlib \
     ${MODULES} \
     --disable-doc \
     --enable-neon

     make clean
     make
     make install
    }

    build_ARMv6

    echo Android ARMEABI builds finished

    How i built x264 :

    NDK=D:/AndroidDev/android-ndk-r9
    PLATFORM=$NDK/platforms/android-18/arch-arm/
    TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64
    PREFIX=./android/arm

    function build_one
    {
     ./configure \
     --prefix=$PREFIX \
     --enable-static \
     --enable-pic \
     --host=arm-linux \
     --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
     --sysroot=$PLATFORM

     make clean
     make
     make install
    }

    build_one

    echo Android ARM builds finished
  • duration change after transcode ts

    25 décembre 2017, par Feilong Luo

    i have a problem about transcode with ffmpeg

    i want to cover m3u8 to mp4, so i transcode every ts file first, and then concat them to a mp4, but i found that the duration will be bigger than source file.

    source file is :
    http://oc7iy3eta.bkt.clouddn.com/src_20.ts

    after transcode, test file is :
    http://oc7iy3eta.bkt.clouddn.com/test_20.ts

    i use the command as bellow to change to 5fps, and 400k bitrate :

    sudo ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -nostdin -y -v warning -i ./src_20.ts -threads 3 -movflags faststart -metadata:s:v rotate=0 -chunk_duration 520000 -video_track_timescale 25000 -pix_fmt yuv420p -copytb 1 -vcodec libx264 -b:v 400000 -minrate 400000 -maxrate 400000 -bufsize 500k -force_key_frames "expr:gte(t,n_forced*2)" -vsync 1 -r 5 -s 544*960 -acodec libfaac -async 1 ./test_20.ts

    i use ffprobe command to see video info :

    source file info :

    Duration : 00:00:01.26, start : 28.346989, bitrate : 921 kb/s
    Program 1
    Metadata :
    service_name : Service01
    service_provider : FFmpeg
    Stream #0:0[0x100] : Audio : aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 23 kb/s
    Stream #0:1[0x101] : Video : h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 544x960, 10.67 tbr, 90k tbn, 180k tbc

    test file :

    Input #0, mpegts, from ’test_20.ts’ :
    Duration : 00:00:01.62, start : 1.576778, bitrate : 447 kb/s
    Program 1
    Metadata :
    service_name : Service01
    service_provider : FFmpeg
    Stream #0:0[0x100] : Video : h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 544x960, 5 fps, 5 tbr, 90k tbn, 10 tbc
    Stream #0:1[0x101] : Audio : aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 5 kb/s

    =======================================================================

    question

    so , we can see that the duration of src file is 1.26s , but after transcode, the test file is 1.62s.

    why ? can anybody help