Recherche avancée

Médias (1)

Mot : - Tags -/karaoke

Autres articles (95)

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

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

Sur d’autres sites (8049)

  • How to decode mp4 file and encode it to mp4 container using h264 codec in cpp ?

    17 juillet 2017, par Herdesh Verma

    I am developing a cpp program which will take mp4 video file as input, decode it and encode it again using H264 codec.
    Below is the program i have developed so far.

    extern "C"
    {
    #include <libavutil></libavutil>imgutils.h>
    #include <libavutil></libavutil>opt.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>mathematics.h>
    #include <libavutil></libavutil>samplefmt.h>
    #include <libavutil></libavutil>timestamp.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libavfilter></libavfilter>avfiltergraph.h>
    #include <libswscale></libswscale>swscale.h>
    }
    #include
    static AVFormatContext *fmt_ctx = NULL;

    static int frame_index = 0;

    static AVDictionary *pMetaData = NULL;

    static int j = 0, nbytes=0;
    uint8_t *video_outbuf = NULL;
    static AVPacket *pAVPacket=NULL;
    static int value=0;
    static AVFrame *pAVFrame=NULL;
    static AVFrame *outFrame=NULL;
    static AVStream *video_st=NULL;
    static AVFormatContext *outAVFormatContext=NULL;
    static AVCodec *outAVCodec=NULL;
    static AVOutputFormat *output_format=NULL;
    static AVCodecContext *video_dec_ctx = NULL, *audio_dec_ctx;
    static AVCodecContext *outAVCodecContext=NULL;
    static int width, height;
    static enum AVPixelFormat pix_fmt;
    static AVStream *video_stream = NULL, *audio_stream = NULL;
    static const char *src_filename = NULL;
    static const char *video_dst_filename = NULL;
    static const char *audio_dst_filename = NULL;
    static FILE *video_dst_file = NULL;
    static FILE *audio_dst_file = NULL;
    static uint8_t *video_dst_data[4] = {NULL};
    static int      video_dst_linesize[4];
    static int video_dst_bufsize;
    static int video_stream_idx = -1, audio_stream_idx = -1;
    static AVPacket *pkt=NULL;
    static AVPacket *pkt1=NULL;
    static AVFrame *frame = NULL;
    //static AVPacket pkt;
    static int video_frame_count = 0;
    static int audio_frame_count = 0;
    static int refcount = 0;
    AVCodec *codec;
    static struct SwsContext *sws_ctx;
    AVCodecContext *c= NULL;
    int i, out_size, size, x, y, outbuf_size;
    AVFrame *picture;
    uint8_t *outbuf, *picture_buf;
    int video_outbuf_size;
    int w, h;
    AVPixelFormat pixFmt;
    uint8_t *data[4];
    int linesize[4];

    static int open_codec_context(int *stream_idx,
                             AVCodecContext **dec_ctx, AVFormatContext
    *fmt_ctx, enum AVMediaType type)
    {
    int ret, stream_index;
    AVStream *st;
    AVCodec *dec = NULL;
    AVDictionary *opts = NULL;
    ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);
    if (ret &lt; 0) {
       printf("Could not find %s stream in input file '%s'\n",
               av_get_media_type_string(type), src_filename);
       return ret;
    } else {
       stream_index = ret;
       st = fmt_ctx->streams[stream_index];
       /* find decoder for the stream */
       dec = avcodec_find_decoder(st->codecpar->codec_id);
       if (!dec) {
           printf("Failed to find %s codec\n",
                   av_get_media_type_string(type));
           return AVERROR(EINVAL);
       }
       /* Allocate a codec context for the decoder */
       *dec_ctx = avcodec_alloc_context3(dec);
       if (!*dec_ctx) {
           printf("Failed to allocate the %s codec context\n",
                   av_get_media_type_string(type));
           return AVERROR(ENOMEM);
       }
       /* Copy codec parameters from input stream to output codec context */
       if ((ret = avcodec_parameters_to_context(*dec_ctx, st->codecpar)) &lt; 0) {
           printf("Failed to copy %s codec parameters to decoder context\n",
                   av_get_media_type_string(type));
           return ret;
       }
       /* Init the decoders, with or without reference counting */
       av_dict_set(&amp;opts, "refcounted_frames", refcount ? "1" : "0", 0);
       if ((ret = avcodec_open2(*dec_ctx, dec, &amp;opts)) &lt; 0) {
           printf("Failed to open %s codec\n",
                   av_get_media_type_string(type));
           return ret;
       }
       *stream_idx = stream_index;
    }
    return 0;
    }



    int main (int argc, char **argv)
    {
    int ret = 0, got_frame;
    src_filename = argv[1];
    video_dst_filename = argv[2];
    audio_dst_filename = argv[3];
    av_register_all();
    avcodec_register_all();
    printf("Registered all\n");

    /* open input file, and allocate format context */
    if (avformat_open_input(&amp;fmt_ctx, src_filename, NULL, NULL) &lt; 0) {
       printf("Could not open source file %s\n", src_filename);
       exit(1);
    }

    /* retrieve stream information */
    if (avformat_find_stream_info(fmt_ctx, NULL) &lt; 0) {
       printf("Could not find stream information\n");
       exit(1);
    }

    if (open_codec_context(&amp;video_stream_idx, &amp;video_dec_ctx, fmt_ctx,
    AVMEDIA_TYPE_VIDEO) >= 0) {
       video_stream = fmt_ctx->streams[video_stream_idx];
       avformat_alloc_output_context2(&amp;outAVFormatContext, NULL, NULL,
    video_dst_filename);
       if (!outAVFormatContext)
       {
               printf("\n\nError : avformat_alloc_output_context2()");
               return -1;
       }
    }

    if (open_codec_context(&amp;audio_stream_idx, &amp;audio_dec_ctx, fmt_ctx,
    AVMEDIA_TYPE_AUDIO) >= 0) {
       audio_stream = fmt_ctx->streams[audio_stream_idx];
       audio_dst_file = fopen(audio_dst_filename, "wb");
       if (!audio_dst_file) {
           printf("Could not open destination file %s\n", audio_dst_filename);
           ret = 1;
           goto end;
       }
    }
    /* dump input information to stderr */
       printf("Source file dump starts-----------------------\n");
    av_dump_format(fmt_ctx, 0, src_filename, 0);
       printf("Source file dump ends-----------------------\n");

    if (!audio_stream &amp;&amp; !video_stream) {
       printf("Could not find audio or video stream in the input, aborting\n");
       ret = 1;
       goto end;
    }

       output_format = av_guess_format(NULL, video_dst_filename, NULL);
       if( !output_format )
       {
        printf("\n\nError : av_guess_format()");
        return -1;
       }

       video_st = avformat_new_stream(outAVFormatContext ,NULL);
       if( !video_st )
       {
               printf("\n\nError : avformat_new_stream()");
         return -1;
       }



       outAVCodec = avcodec_find_encoder(AV_CODEC_ID_H264);
       if( !outAVCodec )
       {
        printf("\n\nError : avcodec_find_encoder()");
        return -1;
       }
       outAVCodecContext = avcodec_alloc_context3(outAVCodec);
       if( !outAVCodecContext )
       {
         printf("\n\nError : avcodec_alloc_context3()");
         return -1;
       }

       printf("Width=%d Height=%d\n",video_dec_ctx->width, video_dec_ctx-
    >height);

       outAVCodecContext = video_st->codec;
       outAVCodecContext->codec_id = AV_CODEC_ID_H264;// AV_CODEC_ID_MPEG4; //
    AV_CODEC_ID_H264 // AV_CODEC_ID_MPEG1VIDEO
       outAVCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
       outAVCodecContext->pix_fmt  = AV_PIX_FMT_YUV420P;
       outAVCodecContext->bit_rate = 350000; // 2500000
       outAVCodecContext->width = video_dec_ctx->width;
       outAVCodecContext->height = video_dec_ctx->height;
       //outAVCodecContext->width = 720;
       //outAVCodecContext->height = 480;
       outAVCodecContext->gop_size = 100;
       outAVCodecContext->max_b_frames = 0;
       outAVCodecContext->time_base.num = 1;
       outAVCodecContext->time_base.den = 25; // 15fps

       if (outAVCodecContext->codec_id == AV_CODEC_ID_H264)
       {
               printf("HERE");
       //outAVCodecContext->me_range = 16;
       //outAVCodecContext->max_qdiff = 4;
       outAVCodecContext->qmin = 10;
       outAVCodecContext->qmax = 51;
       outAVCodecContext->qcompress = 0.1;
        av_opt_set(outAVCodecContext->priv_data, "preset", "slow", 0);
       av_opt_set(outAVCodecContext->priv_data, "profile", "baseline",
    AV_OPT_SEARCH_CHILDREN);
       }
       if ( outAVFormatContext->oformat->flags &amp; AVFMT_GLOBALHEADER)
       {
               outAVCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
       }

       value = avcodec_open2(outAVCodecContext, outAVCodec, NULL);
       if( value &lt; 0)
       {
               printf("\n\nError : avcodec_open2()=%d", value);
               return -1;
       }

       outAVFormatContext->metadata = fmt_ctx->metadata;
       //outAVFormatContext->streams[video_stream_idx]->metadata=fmt_ctx-
    >streams[video_stream_idx]->metadata;
       av_dict_set(&amp;(outAVFormatContext->streams[video_stream_idx]->metadata),
    "rotate", "90", 0);
    /* create empty video file */
       if ( !(outAVFormatContext->flags &amp; AVFMT_NOFILE) )
       {
        if( avio_open2(&amp;outAVFormatContext->pb , video_dst_filename,
    AVIO_FLAG_WRITE ,NULL, NULL) &lt; 0 )
        {
         printf("\n\nError : avio_open2()");
        }
       }

       if(!outAVFormatContext->nb_streams)
       {
               printf("\n\nError : Output file dose not contain any stream");
         return -1;
       }

       value = avformat_write_header(outAVFormatContext , NULL);
       if(value &lt; 0)
       {
               printf("\n\nError : avformat_write_header()");
               return -1;
       }

       printf("\n\nOutput file information :\n\n");
       av_dump_format(outAVFormatContext , 0 ,video_dst_filename ,1);


       int flag;
       int frameFinished;
       value = 0;

       pAVPacket = (AVPacket *)av_malloc(sizeof(AVPacket));
       av_init_packet(pAVPacket);

       pAVFrame = av_frame_alloc();
       if( !pAVFrame )
       {
        printf("\n\nError : av_frame_alloc()");
        return -1;
       }


       outFrame = av_frame_alloc();//Allocate an AVFrame and set its fields to
    default values.
       if( !outFrame )
       {
        printf("\n\nError : av_frame_alloc()");
        return -1;
       }
       outFrame->format = outAVCodecContext->pix_fmt;
       outFrame->width  = outAVCodecContext->width;
       outFrame->height = outAVCodecContext->height;

       nbytes = av_image_get_buffer_size(outAVCodecContext-
    >pix_fmt,outAVCodecContext->width,outAVCodecContext->height,32);
       video_outbuf = (uint8_t*)av_malloc(nbytes);
       if( video_outbuf == NULL )
       {
       printf("\n\nError : av_malloc()");
       }

       // Setup the data pointers and linesizes based on the specified image
    parameters and the provided array.
       value = av_image_fill_arrays( outFrame->data, outFrame->linesize,
    video_outbuf , AV_PIX_FMT_YUV420P, outAVCodecContext-
    >width,outAVCodecContext->height,1 ); // returns : the size in bytes
    required for src
       if(value &lt; 0)
       {
       printf("\n\nError : av_image_fill_arrays()");
       }

       SwsContext* swsCtx_ ;

       // Allocate and return swsContext.
       // a pointer to an allocated context, or NULL in case of error
       // Deprecated : Use sws_getCachedContext() instead.
       swsCtx_ = sws_getContext(video_dec_ctx->width,
                               video_dec_ctx->height,
                               video_dec_ctx->pix_fmt,
                               video_dec_ctx->width,
                               video_dec_ctx->height,
                               video_dec_ctx->pix_fmt,
                               SWS_BICUBIC, NULL, NULL, NULL);


       AVPacket outPacket;

       int got_picture;

       while( av_read_frame( fmt_ctx , pAVPacket ) >= 0 )
       {
               printf("Starting of while\n");
               if(pAVPacket->stream_index == video_stream_idx)
               {
                       value = avcodec_decode_video2(video_dec_ctx , pAVFrame ,
    &amp;frameFinished , pAVPacket );
                       if( value &lt; 0)
                       {
                               printf("Error : avcodec_decode_video2()");
                       }

                       if(frameFinished)// Frame successfully decoded :)
                       {
                               sws_scale(swsCtx_, pAVFrame->data, pAVFrame-
    >linesize,0, video_dec_ctx->height, outFrame->data,outFrame->linesize);
    //                              sws_scale(swsCtx_, pAVFrame->data, pAVFrame-
    >linesize,0, video_dec_ctx->height, outFrame->data,outFrame->linesize);
                               av_init_packet(&amp;outPacket);
                               outPacket.data = NULL;    // packet data will be
    allocated by the encoder
                               outPacket.size = 0;

                               avcodec_encode_video2(outAVCodecContext ,
    &amp;outPacket ,outFrame , &amp;got_picture);

                               if(got_picture)
                               {
                                       if(outPacket.pts != AV_NOPTS_VALUE)
                                               outPacket.pts =
    av_rescale_q(outPacket.pts, video_st->codec->time_base, video_st-
    >time_base);
                                       if(outPacket.dts != AV_NOPTS_VALUE)
                                               outPacket.dts =
    av_rescale_q(outPacket.dts, video_st->codec->time_base, video_st-
    >time_base);

                                       printf("Write frame %3d (size= %2d)\n",
    j++, outPacket.size/1000);
                                       if(av_write_frame(outAVFormatContext ,
    &amp;outPacket) != 0)
                                       {
                                               printf("\n\nError :
    av_write_frame()");
                                       }

                               av_packet_unref(&amp;outPacket);
                               } // got_picture

                       av_packet_unref(&amp;outPacket);
                       } // got_picture
               }
               printf("Ending of while\n");
       }// End of while-loop
       /* get the delayed frames */
    for (got_picture = 1; got_picture; i++) {
       //fflush(stdout);
       ret = avcodec_encode_video2(outAVCodecContext, &amp;outPacket, NULL,
    &amp;got_picture);
       if (ret &lt; 0) {
           printf("Error encoding frame\n");
           exit(1);
       }
       if (got_picture) {
           printf("Write frame %3d (size=%5d)\n", i, outPacket.size);
           av_write_frame(outAVFormatContext , &amp;outPacket);
           av_free_packet(&amp;outPacket);
       }
    }

       value = av_write_trailer(outAVFormatContext);
       if( value &lt; 0)
       {
               printf("\n\nError : av_write_trailer()");
       }

       //THIS WAS ADDED LATER
       av_free(video_outbuf);

    end:
       avcodec_free_context(&amp;video_dec_ctx);
       avcodec_free_context(&amp;audio_dec_ctx);
       avformat_close_input(&amp;fmt_ctx);
       if (video_dst_file)
           fclose(video_dst_file);
       if (audio_dst_file)
           fclose(audio_dst_file);
    //  av_frame_free(&amp;frame);
       av_free(video_dst_data[0]);
       return ret &lt; 0;
    }

    Above code is generating a mp4 file but it is not playing.
    Can someone please tell me what i am doing wrong ?

  • Encoding real, source duration of a timelapse into MP4 container using FFMPEG (GoPro) [closed]

    13 août 2024, par Marek Towarek

    Footage recorded with GoPro TimeLapse / TimeWarp, indicates the total, real-time duration of recorded data, while the video stream is of reduced length by the timelapse interval.

    &#xA;

    General&#xA;Complete name               : E:\Video\GoPro\GoPro\GH010656.MP4&#xA;Format                      : MPEG-4&#xA;Format profile              : Base Media / Version 1&#xA;Codec ID                    : mp41 (mp41)&#xA;File size                   : 1.94 GiB&#xA;Duration                    : 22 min 55 s&#xA;Overall bit rate mode       : Variable&#xA;Overall bit rate            : 12.1 Mb/s&#xA;&#xA;Video&#xA;ID                          : 1&#xA;Format                      : AVC&#xA;Format/Info                 : Advanced Video Codec&#xA;Format profile              : High@L5&#xA;Format settings             : CABAC / 2 Ref Frames&#xA;Format settings, CABAC      : Yes&#xA;Format settings, Reference  : 2 frames&#xA;Format settings, GOP        : M=1, N=15&#xA;Codec ID                    : avc1&#xA;Codec ID/Info               : Advanced Video Coding&#xA;Duration                    : 4 min 35 s&#xA;Bit rate mode               : Variable&#xA;Bit rate                    : 60.0 Mb/s&#xA;Width                       : 1 920 pixels&#xA;Height                      : 1 440 pixels&#xA;Display aspect ratio        : 4:3&#xA;Rotation                    : 180&#xB0;&#xA;Frame rate mode             : Constant&#xA;Frame rate                  : 29.970 (30000/1001) FPS&#xA;Color space                 : YUV&#xA;Chroma subsampling          : 4:2:0&#xA;Bit depth                   : 8 bits&#xA;Scan type                   : Progressive&#xA;Bits/(Pixel*Frame)          : 0.724&#xA;Stream size                 : 1.92 GiB (99%)&#xA;Title                       : GoPro AVC  &#xA;Language                    : English&#xA;Color range                 : Limited&#xA;colour_range_Original       : Full&#xA;Color primaries             : BT.709&#xA;Transfer characteristics    : BT.709&#xA;Matrix coefficients         : BT.709&#xA;Codec configuration box     : avcC&#xA;&#xA;Other #1&#xA;ID                          : 2&#xA;Type                        : Time code&#xA;Format                      : QuickTime TC&#xA;Duration                    : 4 min 35 s&#xA;Bit rate mode               : Constant&#xA;Frame rate                  : 29.970 (30000/1001) FPS&#xA;Title                       : GoPro TCD  &#xA;Language                    : English&#xA;&#xA;Other #2&#xA;Type                        : meta&#xA;Duration                    : 22 min 55 s&#xA;Source duration             : 4 min 35 s&#xA;Bit rate mode               : Variable&#xA;Stream size                 : 15.0 MiB&#xA;Source stream size          : 15.0 MiB&#xA;

    &#xA;

    This information could be omitted.
    &#xA;But it becomes quite important for correctness of GPS Data stored in Stream #2.

    &#xA;

    Unfortunately, all the settings I have tried for FFMPEG, do not preserve the duration of Stream #2.&#xA;& the output ends up looking like this :

    &#xA;

    General&#xA;Complete name               : C:\Video_Encode\GoPro\GH010656.mp4&#xA;Format                      : MPEG-4&#xA;Format profile              : Base Media&#xA;Codec ID                    : isom (isom/iso2/mp41)&#xA;File size                   : 717 MiB&#xA;Duration                    : 4 min 35 s&#xA;Overall bit rate            : 21.9 Mb/s&#xA;Encoded date                : UTC 2026-03-29 11:28:23&#xA;Tagged date                 : UTC 2026-03-29 11:28:23&#xA;Writing application         : Lavf61.5.101&#xA;&#xA;Video&#xA;ID                          : 1&#xA;Format                      : HEVC&#xA;Format/Info                 : High Efficiency Video Coding&#xA;Format profile              : Main@L5@Main&#xA;Codec ID                    : hvc1&#xA;Codec ID/Info               : High Efficiency Video Coding&#xA;Duration                    : 4 min 35 s&#xA;Bit rate                    : 21.4 Mb/s&#xA;Width                       : 1 920 pixels&#xA;Height                      : 1 440 pixels&#xA;Display aspect ratio        : 4:3&#xA;Frame rate mode             : Constant&#xA;Frame rate                  : 29.970 (30000/1001) FPS&#xA;Color space                 : YUV&#xA;Chroma subsampling          : 4:2:0 (Type 0)&#xA;Bit depth                   : 8 bits&#xA;Scan type                   : Progressive&#xA;Bits/(Pixel*Frame)          : 0.258&#xA;Stream size                 : 702 MiB (98%)&#xA;Title                       : GoPro AVC  &#xA;Writing library             : x265 3.6&#x2B;35-dd594f59d:[Windows][GCC 14.1.0][64 bit] 8bit&#x2B;10bit&#x2B;12bit&#xA;Language                    : English&#xA;Encoded date                : UTC 2026-03-29 11:28:23&#xA;Tagged date                 : UTC 2026-03-29 11:28:23&#xA;Color range                 : Full&#xA;Color primaries             : BT.709&#xA;Transfer characteristics    : BT.709&#xA;Matrix coefficients         : BT.709&#xA;Codec configuration box     : hvcC&#xA;&#xA;Other #1&#xA;ID                          : 2&#xA;Type                        : Time code&#xA;Format                      : QuickTime TC&#xA;Duration                    : 4 min 35 s&#xA;Frame rate                  : 29.970 (30000/1001) FPS&#xA;Time code of first frame    : 17:55:35:02&#xA;Time code of last frame     : 18:00:09:28&#xA;Time code, stripped         : Yes&#xA;Title                       : GoPro TCD  &#xA;Language                    : English&#xA;Default                     : Yes&#xA;Alternate group             : 2&#xA;Encoded date                : UTC 2026-03-29 11:28:23&#xA;Tagged date                 : UTC 2026-03-29 11:28:23&#xA;mdhd_Duration               : 275175&#xA;&#xA;Other #2&#xA;Type                        : meta&#xA;Duration                    : 4 min 35 s&#xA;Bit rate mode               : Variable&#xA;

    &#xA;

    Any ideas how to preserve that real time duration indicator ?
    &#xA;Here is the FFMPEG binary I use to get the TMCD & GMPD data to copy : GitHub Link

    &#xA;

  • avcodec/mediacodec : fix missing crop info when use NDK MediaCodec

    23 novembre 2022, par Zhao Zhili
    avcodec/mediacodec : fix missing crop info when use NDK MediaCodec
    

    Signed-off-by : Zhao Zhili <zhilizhao@tencent.com>

    • [DH] libavcodec/mediacodec_wrapper.c
    • [DH] libavcodec/mediacodec_wrapper.h
    • [DH] libavcodec/mediacodecdec_common.c