Recherche avancée

Médias (1)

Mot : - Tags -/musée

Autres articles (79)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

  • Sélection de projets utilisant MediaSPIP

    29 avril 2011, par

    Les exemples cités ci-dessous sont des éléments représentatifs d’usages spécifiques de MediaSPIP pour certains projets.
    Vous pensez avoir un site "remarquable" réalisé avec MediaSPIP ? Faites le nous savoir ici.
    Ferme MediaSPIP @ Infini
    L’Association Infini développe des activités d’accueil, de point d’accès internet, de formation, de conduite de projets innovants dans le domaine des Technologies de l’Information et de la Communication, et l’hébergement de sites. Elle joue en la matière un rôle unique (...)

Sur d’autres sites (9471)

  • How to accurately/precisely seek to a timestamp in media with ffmpeg API ?

    11 novembre 2024, par wangt13

    I am writing a simple audio player with ffmpeg ver.4.4.4, and I want to seek to specific timestamp of the audio media (a MP3 file).

    


    Here is my code.
I am using avformat_seek_file() with flags of AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD, and when I set seek_pos to 10 second when it is playing frames of 3rd second, it seemed NOT jump to the 10th second, it only played the audios after 3rd second !

    


    Then I added the code skipping/discarding the packets whose pts is before the seek position. This time, it loops in the if (curr_s < seek_ts), not going to 10th seconds.

    


    It seemed NO keyframe at 10th second.

    


    void decode_func(...)
{
    while (1) {
        if (av_read_frame(pfmtctx, packet) < 0) {
            avcodec_flush_buffers(pcodectx);
            printf("Got end of media, breaking\n");
            break;
        }
        /**
         * Discard the packet of pts before seek position
         */
        curr_s = packet->pts * av_q2d(pfmtctx->streams[stream]->time_base);
        if (seek_ts) {
            if (curr_s < seek_ts) {
                avcodec_flush_buffers(pcodectx);
                av_frame_unref(pFrame);
                continue;
            } else {
                seek_ts = 0;
            }
        }
        if (seek_req) {
            int64_t seek_abs;
            seek_req = 0;
            seek_abs = (seek_pos)*AV_TIME_BASE;
            printf("Seek to %lld, pts: %lld\n", seek_abs, packet->pts;
            if (seek_abs < 0) {
                seek_abs = 0;
            }
            if (avformat_seek_file(pfmtctx, -1, INT64_MIN, seek_abs, INT64_MAX, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD) >= 0) {
                avcodec_flush_buffers(pcodectx);
                seek_ts = seek_abs;
                continue;
            } else {
                printf("Failed to seek to %lld\n", seek_abs);
                seek_ts = 0;
            }
        }

        res = avcodec_send_packet(pcodectx, packet);
        while (res >= 0) {
            res = avcodec_receive_frame(pcodectx, pFrame);
            if (res == AVERROR(EAGAIN)) {
                break;
            } else if (res == AVERROR_EOF) {
                break;
            } else if (res >= 0) {
             /// Processing decoded frame
            }
        av_frame_unref(frame);
    }
}


    


    So, how can I precisely (almost) seek to a timestamp with FFMPEG ?

    


  • avformat/mm : fix packets pts generation and add seek support

    26 juin 2024, par Paul B Mahol
    avformat/mm : fix packets pts generation and add seek support
    

    Signed-off-by : Peter Ross <pross@xvid.org>

    • [DH] libavformat/mm.c
    • [DH] tests/ref/fate/alg-mm
  • How to seek one frame forward in ffmpeg [closed]

    10 mars, par Summit

    i want to seek one frame forward when i call this function but it gets stuck on the first frame seeked and does not move forward.

    &#xA;

    void seekFrameUp() {&#xA;    if (!fmt_ctx || video_stream_index == -1) return;&#xA;&#xA;    AVRational frame_rate = fmt_ctx->streams[video_stream_index]->r_frame_rate;&#xA;    if (frame_rate.num == 0) return;  // Avoid division by zero&#xA;&#xA;    // Compute frame duration in AV_TIME_BASE_Q&#xA;    int64_t frame_duration = av_rescale_q(1,&#xA;        av_make_q(frame_rate.den, frame_rate.num),&#xA;        AV_TIME_BASE_Q);&#xA;&#xA;    int64_t next_pts = requestedTimestamp &#x2B; frame_duration;&#xA;&#xA;    qDebug() &lt;&lt; "Seeking forward: " &lt;&lt; next_pts&#xA;        &lt;&lt; " (Current PTS: " &lt;&lt; requestedTimestamp&#xA;        &lt;&lt; ", Frame Duration: " &lt;&lt; frame_duration &lt;&lt; ")";&#xA;&#xA;    requestFrameAt(next_pts);&#xA;&#xA;    // Update the requested timestamp after seeking&#xA;    requestedTimestamp = next_pts;&#xA;}&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;void requestFrameAt(int64_t timestamp) {&#xA;     {&#xA;         std::lock_guard lock(mtx);&#xA;         decoding = true;  // Ensure the thread keeps decoding when needed&#xA;     }&#xA;     cv.notify_one();&#xA; }&#xA;&#xA;&#xA;void decodeLoop() {&#xA;    while (!stopThread) {&#xA;        std::unique_lock lock(mtx);&#xA;        cv.wait(lock, [this] { return decoding || stopThread; });&#xA;&#xA;        if (stopThread) break;&#xA;&#xA;        // Avoid redundant seeking&#xA;        if (requestedTimestamp == lastRequestedTimestamp) {&#xA;            decoding = false;&#xA;            continue;&#xA;        }&#xA;&#xA;       &#xA;&#xA;        lastRequestedTimestamp.store(requestedTimestamp.load());&#xA;        int64_t target_pts = av_rescale_q(requestedTimestamp, AV_TIME_BASE_Q, fmt_ctx->streams[video_stream_index]->time_base);&#xA;&#xA;        target_pts = FFMAX(target_pts, 0); // Ensure it&#x27;s not negative&#xA;&#xA;        if (av_seek_frame(fmt_ctx, video_stream_index, target_pts, AVSEEK_FLAG_ANY) >= 0) {&#xA;            avcodec_flush_buffers(codec_ctx);  // Clear old frames from the decoder&#xA;            qDebug() &lt;&lt; "Seek successful to PTS:" &lt;&lt; target_pts;&#xA;        }&#xA;        else {&#xA;            qDebug() &lt;&lt; "Seeking failed!";&#xA;            decoding = false;&#xA;            continue;&#xA;        }&#xA;&#xA;        lock.unlock();&#xA;&#xA;        // Keep decoding until we receive a valid frame&#xA;        bool frameDecoded = false;&#xA;        while (av_read_frame(fmt_ctx, pkt) >= 0) {&#xA;            if (pkt->stream_index == video_stream_index) {&#xA;                if (avcodec_send_packet(codec_ctx, pkt) == 0) {&#xA;                    while (avcodec_receive_frame(codec_ctx, frame) == 0) {&#xA;                        qDebug() &lt;&lt; "FRAME DECODED &#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B;&#x2B; PTS:" &lt;&lt; frame->pts;&#xA;                        if (frame->pts != AV_NOPTS_VALUE) {&#xA;                            // Rescale PTS to AV_TIME_BASE_Q&#xA;                            int64_t pts_in_correct_base = av_rescale_q(frame->pts,&#xA;                                fmt_ctx->streams[video_stream_index]->time_base,&#xA;                                AV_TIME_BASE_Q);&#xA;&#xA;                            // Ensure we don’t reset to 0 incorrectly&#xA;                            if (pts_in_correct_base > 0) {&#xA;                                current_pts.store(pts_in_correct_base);&#xA;                                qDebug() &lt;&lt; "Updated current_pts to:" &lt;&lt; current_pts.load();&#xA;                            }&#xA;                            else {&#xA;                                qDebug() &lt;&lt; "Warning: Decoded frame has PTS &lt;= 0, keeping last valid PTS.";&#xA;                            }&#xA;                        }&#xA;                        else {&#xA;                            qDebug() &lt;&lt; "Invalid frame->pts (AV_NOPTS_VALUE)";&#xA;                        }&#xA;&#xA;                        QImage img = convertFrameToImage(frame);&#xA;                        emit frameDecodedSignal(img);&#xA;                &#xA;                        frameDecoded = true;&#xA;                        break;  // Exit after the first valid frame&#xA;                    }&#xA;&#xA;                    if (frameDecoded) {&#xA;                        decoding = (requestedTimestamp != lastRequestedTimestamp);&#xA;                        break;&#xA;                    }&#xA;                }&#xA;            }&#xA;            av_packet_unref(pkt);&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;