Recherche avancée

Médias (9)

Mot : - Tags -/soundtrack

Autres articles (72)

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

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

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

  • What to input for variable frame rate in pts / dts in ffmpeg

    23 novembre 2014, par William

    I am capturing frames from a webcam stream which sends frames in at a variable rate. My output video plays much faster than it was captured because there are less frames available than the input fps.

    I’m really new to ffmpeg and don’t know what to put into pts and dts. I can get an Int64 representing nanoseconds since 1600 when the frame arrives. How do I use the av_rescale_q function with it ?

    Reading online it seems a solution may be to clone frames so the output fits into a constant frame rate video. However it would be better just to put the timestamp in there.

  • ffmeg mux video and audio into a mp4 file, no sound in quicktime player

    10 novembre 2014, par user2789801

    I’m using ffmpeg to mux a video file and a audio file into a single mp4 file.The mp4 file plays fine on windows, but it has no sound in quicktime player on mac. And I get a error message "2041 invalid sample description".
    Here’s what I’m doing,
    First, I open the video file and the audio file, init a output frame context.
    Then I add a video stream and a audio stream according to the video and audio files.
    Then write the header, then start muxing, then write the trailer.

    Here’s my code

    #include "CoreRender.h"

    CoreRender::CoreRender(const char* _vp, const char * _ap, const char * _op)
    {
       sprintf(videoPath, "%s", _vp);
       sprintf(audioPath, "%s", _ap);
       sprintf(outputPath, "%s", _op);
       formatContext_video = NULL;
       formatContext_audio = NULL;
       formatContext_output = NULL;

       videoStreamIdx = -1;
       outputVideoStreamIdx = -1;
       videoStreamIdx = -1;
       audioStreamIdx = -1;
       outputVideoStreamIdx = -1;
       outputAudioStreamIdx = -1;
       av_init_packet(&pkt);
       init();
    }

    void CoreRender::init()
    {
       av_register_all();
       avcodec_register_all();
       // allocate a memory for the AVFrame object
       frame = (AVFrame *)av_mallocz(sizeof(AVFrame));
       rgbFrame = (AVFrame *)av_mallocz(sizeof(AVFrame));

       if (avformat_open_input(&formatContext_video, videoPath, 0, 0) < 0)
       {
           release();
       }
       if (avformat_find_stream_info(formatContext_video, 0) < 0)
       {
           release();
       }
       if (avformat_open_input(&formatContext_audio, audioPath, 0, 0) < 0)
       {
           release();
       }
       if (avformat_find_stream_info(formatContext_audio, 0) < 0)
       {
           release();
       }

       avformat_alloc_output_context2(&formatContext_output, NULL, NULL, outputPath);
       if (!formatContext_output)
       {
           release();
       }
       ouputFormat = formatContext_output->oformat;
       for (int i = 0; i < formatContext_video->nb_streams; i++)
       {
           // create the output AVStream according to the input AVStream
           if (formatContext_video->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
           {
               videoStreamIdx = i;
               AVStream * in_stream = formatContext_video->streams[i];
               AVStream * out_stream = avformat_new_stream(formatContext_output, in_stream->codec->codec);
               if (! out_stream)
               {
                   release();
               }
               outputVideoStreamIdx = out_stream->index;
               if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0)
               {
                   release();
               }
               out_stream->codec->codec_tag = 0;
               if (formatContext_output->oformat->flags & AVFMT_GLOBALHEADER)
               {
                   out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
               }
               break;
           }
       }

       for (int i = 0; i < formatContext_audio->nb_streams; i++)
       {
           if (formatContext_audio->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
           {
               AVCodec *encoder;
               encoder = avcodec_find_encoder(AV_CODEC_ID_AAC);

               audioStreamIdx = i;
               AVStream *in_stream = formatContext_audio->streams[i];
               AVStream *out_stream = avformat_new_stream(formatContext_output, encoder);
               if (!out_stream)
               {
                   release();
               }
               outputAudioStreamIdx = out_stream->index;

               AVCodecContext *dec_ctx, *enc_ctx;

               dec_ctx = in_stream->codec;
               enc_ctx = out_stream->codec;


               enc_ctx->sample_rate = dec_ctx->sample_rate;
               enc_ctx->channel_layout = dec_ctx->channel_layout;
               enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout);

               enc_ctx->time_base = { 1, enc_ctx->sample_rate };
               enc_ctx->bit_rate = 480000;

               if (avcodec_open2(enc_ctx, encoder, NULL) < 0)
               {
                   release();
               }

               if (formatContext_output->oformat->flags & AVFMT_GLOBALHEADER)
               {
                   out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
               }
               break;
           }
       }

       if (!(ouputFormat->flags & AVFMT_NOFILE))
       {
           if (avio_open(&formatContext_output->pb, outputPath, AVIO_FLAG_WRITE) < 0)
           {
               release();
           }
       }

       if (avformat_write_header(formatContext_output, NULL) < 0)
       {
           release();
       }
    }

    void CoreRender::mux()
    {

       // find the decoder for the audio codec
       codecContext_a = formatContext_audio->streams[audioStreamIdx]->codec;
       codec_a = avcodec_find_decoder(codecContext_a->codec_id);
       if (codec == NULL)
       {
           avformat_close_input(&formatContext_audio);
           release();
       }

       codecContext_a = avcodec_alloc_context3(codec_a);

       if (codec_a->capabilities&CODEC_CAP_TRUNCATED)
           codecContext_a->flags |= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */

       if (avcodec_open2(codecContext_a, codec_a, NULL) < 0)
       {
           avformat_close_input(&formatContext_audio);
           release();
       }

       int frame_index = 0;
       int64_t cur_pts_v = 0, cur_pts_a = 0;

       while (true)
       {
           AVFormatContext *ifmt_ctx;
           int stream_index = 0;
           AVStream *in_stream, *out_stream;

           if (av_compare_ts(cur_pts_v,
               formatContext_video->streams[videoStreamIdx]->time_base,
               cur_pts_a,
               formatContext_audio->streams[audioStreamIdx]->time_base) <= 0)
           {
               ifmt_ctx = formatContext_video;
               stream_index = outputVideoStreamIdx;

               if (av_read_frame(ifmt_ctx, &pkt) >=0)
               {
                   do
                   {
                       if (pkt.stream_index == videoStreamIdx)
                       {
                           cur_pts_v = pkt.pts;
                           break;
                       }
                   } while (av_read_frame(ifmt_ctx, &pkt) >= 0);              
               }
               else
               {
                   break;
               }
           }
           else
           {
               ifmt_ctx = formatContext_audio;
               stream_index = outputAudioStreamIdx;
               if (av_read_frame(ifmt_ctx, &pkt) >=0)
               {
                   do
                   {
                       if (pkt.stream_index == audioStreamIdx)
                       {
                           cur_pts_a = pkt.pts;
                           break;
                       }
                   } while (av_read_frame(ifmt_ctx, &pkt) >=0);
                   processAudio();
               }
               else
               {
                   break;
               }
           }

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

           if (pkt.pts == AV_NOPTS_VALUE)
           {
               AVRational time_base1 = in_stream->time_base;
               int64_t calc_duration = (double)AV_TIME_BASE / av_q2d(in_stream->r_frame_rate);
               pkt.pts = (double)(frame_index * calc_duration) / (double)(av_q2d(time_base1) * AV_TIME_BASE);
               pkt.dts = pkt.pts;
               pkt.duration = (double)calc_duration / (double)(av_q2d(time_base1) * AV_TIME_BASE);
               frame_index++;
           }

           pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (enum AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
           pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (enum AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
           pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
           pkt.pos = -1;
           pkt.stream_index = stream_index;

           LOGE("Write 1 Packet. size:%5d\tpts:%8d", pkt.size, pkt.pts);
           if (av_interleaved_write_frame(formatContext_output, &pkt) < 0)
           {
               break;
           }
           av_free_packet(&pkt);
       }
       av_write_trailer(formatContext_output);

    }

    void CoreRender::processAudio()
    {
       int got_frame_v = 0;
       AVFrame *tempFrame = (AVFrame *)av_mallocz(sizeof(AVFrame));
       avcodec_decode_audio4(formatContext_audio->streams[audioStreamIdx]->codec, tempFrame, &got_frame_v, &pkt);
       if (got_frame_v)
       {
           tempFrame->pts = av_frame_get_best_effort_timestamp(tempFrame);
           int ret;
           int got_frame_local;
           int * got_frame = &got_frame_v;
           AVPacket enc_pkt;
           int(*enc_func)(AVCodecContext *, AVPacket *, const AVFrame *, int *) = avcodec_encode_audio2;

           if (!got_frame)
           {
               got_frame = &got_frame_local;
           }
           // encode filtered frame
           enc_pkt.data = NULL;
           enc_pkt.size = 0;
           av_init_packet(&enc_pkt);
           ret = enc_func(codecContext_a, &enc_pkt, tempFrame, got_frame);
           av_frame_free(&tempFrame);
           av_frame_free(&tempFrame);
           if (ret < 0)
           {
               return ;
           }
           if (!(*got_frame))
           {
               return ;
           }
           enc_pkt.stream_index = outputAudioStreamIdx;
           av_packet_rescale_ts(&enc_pkt,
           formatContext_output->streams[outputAudioStreamIdx]->codec->time_base,
           formatContext_output->streams[outputAudioStreamIdx]->time_base);

       }
    }

    void CoreRender::release()
    {
       avformat_close_input(&formatContext_video);
       avformat_close_input(&formatContext_audio);

       if (formatContext_output&& !(ouputFormat->flags & AVFMT_NOFILE))
           avio_close(formatContext_output->pb);
       avformat_free_context(formatContext_output);
    }


    CoreRender::~CoreRender()
    {
    }

    As you can see, I transcode the audio format into aac, and keep the video as it is.
    Here’s how I use it

    CoreRender render("d:\\bg.mp4", "d:\\music.mp3", "d:\\output.mp4");
    render.mux();
    return 0;

    The video file is always in h.264 format.
    So what I’m doing wrong ?

  • FFMPEG Cutting Commercials puts audio out of sync

    11 septembre 2014, par JaBbA

    Ubuntu 14.04.1 with the real ffmpeg loaded (same problem with the avconv version).

    I’m trying to take files created in MythTV with a HDPVR, cut the commercials and put the video into an MP4 container for use with MythRoku.

    the command

    ffmpeg -i $file -acodec copy -vcodec copy -f mp4 file.mp4

    Works fine. Once I update the database, I can watch the file in MythRoku or Plex.

    However, when I try to cut out the commercials, the audio gets out of sync by just over 1 second (audio delayed) whenever I cut past the 0 mark. Totem Video player and VLC both play the resulting video fine, but I can see a "hitch" at the beginning while they are syncing the audio, so I know the information on the audio sync is in the file somewhere. Mythroku and Plex both are out of sync when playing the file. The MythTV Frontend player actually does play it correctly, and I can hear the "hitch" as it syncs the audio.

    After hours of reading posts and playing with settings, I’ve got it down to this :

    If I say :

    ffmpeg -i $file -acodec copy -vcodec copy -f mp4 -ss 0 -t <anything> out.mp4</anything>

    The file is fine, plays both locally and in MythRoku/Plex

    But if I advance the start any amount - even 1 second - audio is out of sync

    ffmpeg -i $file -acodec copy -vcodec copy -f mp4 -ss 1 -t <anything> out.mp4</anything>

    I’ve tried splitting the video (as mp4) and audio (as ac3) first, splitting them separately, and then putting them back together as the last step, but I get the same results.

    The information is in the file - Totem, VLC and the Frontend all can figure it out. How can I get ffmpeg to figure out the sync and write the file so it’s correct ?

    Original file :

    mythtv@marvin:~$ mediainfo /var/lib/mythtv/recordings/2225_20140824001500.mpg
    General
    ID                                       : 0 (0x0)
    Complete name                            :     /var/lib/mythtv/recordings/2225_20140824001500.mpg
    Format                                   : MPEG-TS
    File size                                : 4.03 GiB
    Duration                                 : 1h 45mn
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 5 491 Kbps

    Video
    ID                                       : 4113 (0x1011)
    Menu ID                                  : 1 (0x1)
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Main@L4.0
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 4 frames
    Format settings, GOP                     : M=4, N=32
    Codec ID                                 : 27
    Duration                                 : 1h 45mn
    Bit rate mode                            : Variable
    Bit rate                                 : 4 831 Kbps
    Maximum bit rate                         : 20.0 Mbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate                               : 59.940 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.087
    Stream size                              : 3.55 GiB (88%)
    Color primaries                          : BT.709
    Transfer characteristics                 : BT.709
    Matrix coefficients                      : BT.709

    Audio
    ID                                       : 4352 (0x1100)
    Menu ID                                  : 1 (0x1)
    Format                                   : AC-3
    Format/Info                              : Audio Coding 3
    Mode extension                           : CM (complete main)
    Format settings, Endianness              : Big
    Codec ID                                 : 129
    Duration                                 : 1h 45mn
    Bit rate mode                            : Constant
    Bit rate                                 : 384 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 48.0 KHz
    Bit depth                                : 16 bits
    Compression mode                         : Lossy
    Delay relative to video                  : -6ms
    Stream size                              : 289 MiB (7%)

    File cut from 0 :

    mythtv@marvin:~$ mediainfo 2225_20140824001500_1.mp4
    General
    Complete name                            : 2225_20140824001500_1.mp4
    Format                                   : MPEG-4
    Format profile                           : Base Media
    Codec ID                                 : isom
    File size                                : 58.5 MiB
    Duration                                 : 1mn 45s
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 4 676 Kbps
    Writing application                      : Lavf54.63.104

    Video
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Main@L4.0
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 4 frames
    Format settings, GOP                     : M=4, N=32
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Duration                                 : 1mn 45s
    Bit rate mode                            : Variable
    Bit rate                                 : 4 281 Kbps
    Maximum bit rate                         : 20.0 Mbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Variable
    Frame rate                               : 59.940 fps
    Minimum frame rate                       : 59.920 fps
    Maximum frame rate                       : 59.960 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.077
    Stream size                              : 53.6 MiB (92%)
    Color primaries                          : BT.709
    Transfer characteristics                 : BT.709
    Matrix coefficients                      : BT.709

    Audio
    ID                                       : 2
    Format                                   : AC-3
    Format/Info                              : Audio Coding 3
    Mode extension                           : CM (complete main)
    Format settings, Endianness              : Big
    Codec ID                                 : ac-3
    Duration                                 : 1mn 45s
    Bit rate mode                            : Constant
    Bit rate                                 : 384 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 48.0 KHz
    Bit depth                                : 16 bits
    Compression mode                         : Lossy
    Stream size                              : 4.81 MiB (8%)

    File cut from 1 second with audio sync problem :

    mythtv@marvin:~$ mediainfo 2225_20140824001500_2.mp4
    General
    Complete name                            : 2225_20140824001500_2.mp4
    Format                                   : MPEG-4
    Format profile                           : Base Media
    Codec ID                                 : isom
    File size                                : 68.0 MiB
    Duration                                 : 2mn 0s
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 4 750 Kbps
    Writing application                      : Lavf54.63.104

    Video
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Main@L4.0
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 4 frames
    Format settings, GOP                     : M=4, N=32
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Duration                                 : 1mn 58s
    Bit rate mode                            : Variable
    Bit rate                                 : 4 394 Kbps
    Maximum bit rate                         : 20.0 Mbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Variable
    Frame rate                               : 59.940 fps
    Minimum frame rate                       : 59.920 fps
    Maximum frame rate                       : 59.960 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.080
    Stream size                              : 62.3 MiB (92%)
    Color primaries                          : BT.709
    Transfer characteristics                 : BT.709
    Matrix coefficients                      : BT.709

    Audio
    ID                                       : 2
    Format                                   : AC-3
    Format/Info                              : Audio Coding 3
    Mode extension                           : CM (complete main)
    Format settings, Endianness              : Big
    Codec ID                                 : ac-3
    Duration                                 : 2mn 0s
    Bit rate mode                            : Constant
    Bit rate                                 : 384 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 48.0 KHz
    Bit depth                                : 16 bits
    Compression mode                         : Lossy
    Stream size                              : 5.49 MiB (8%)