[Libav-user] How to get some packet information before decoding

Mohammed Bey Ahmed Khernache mohbeyinfo at gmail.com
Sat Apr 18 23:05:41 EEST 2020


Thank you for your replies.
> The parser should tell you (if FFmpeg provides a parser for
> the video format).
That's what I used to get what I need.
Below is the code.

Best regards.
----------------------------------------
AVFormatContext *pFormatContext = NULL;
    AVPacket *pPacket = NULL;

    pFormatContext = avformat_alloc_context();
    if (pFormatContext == NULL) {
        printf("%s\n", "error when allocating memory for pFormatContext !!
\n");
        exit(1);
    }
    /* open the media file */
    if (avformat_open_input(&pFormatContext, filename, NULL, NULL) != 0) {
        printf("%s\n", "couldn't open the media !!");
        exit(1);
    }
    /* get information about the media file */
    avformat_find_stream_info(pFormatContext, NULL);
    /* print out some information */

    /* get packets from the video stream and decode them into frames */
    pPacket = av_packet_alloc();
    if (pPacket == NULL) {
        printf("%s\n", "unable to allocate memory for pPacket !! \n");
    }
    int cpt = 0;
    while (av_read_frame(pFormatContext, pPacket) >= 0) {
        ++cpt;
        printf("packet_number=%d \n", cpt);
        printf("packet_size=%d \n", pPacket->size);
        // --- check whether the parser is freed or not yet. the parser is
freed just after the last packet of the bit-stream is read.
        if (pFormatContext->streams[0]->parser != NULL) {
            printf("packet_type=%d \n",
pFormatContext->streams[0]->parser->pict_type);
        } else {
            printf("packet_type=3 \n");
        }
        av_packet_unref(pPacket);
    }
    printf("the end of parsing ... \n");
    avformat_close_input(&pFormatContext);
    avformat_free_context(pFormatContext);
    av_packet_free(&pPacket);




_______________________________________________

> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200418/accdadbc/attachment.html>


More information about the Libav-user mailing list