Recherche avancée

Médias (0)

Mot : - Tags -/formulaire

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (45)

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (9463)

  • AudioSegment.from_mp3 is giving Couldnot Decode error

    13 septembre 2020, par Pranaswi Reddy

    Actually, i am making 1sec chunks of 4sec mp3 audio files. But while reading mp3 files i used AudioSegment.from_mp3(path of audio file,"mp3")
i am getting following error.Please help me fix this .I have wasted 2 days forthis error.I installed ffmpeg 4.3 .Path of ffmpeg is set in environment variables.
Traceback (most recent call last) :
File "F :\cnn-lstm\chunking_code.py", line 23, in 
myaudio = pydub.AudioSegment.from_mp3(audio_path,"mp3")
File "C :\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\pydub\audio_segment.py", line 738, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C :\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\pydub\audio_segment.py", line 723, in from_file
raise CouldntDecodeError(
pydub.exceptions.CouldntDecodeError : Decoding failed. ffmpeg returned error code : 1

    


    Output from ffmpeg/avlib :

    


    ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers

    


    built with gcc 9.3.1 (GCC) 20200621

    


    configuration : —enable-gpl —enable-version3 —enable-sdl2 —enable-fontconfig —enable-gnutls —enable-iconv —enable-libass —enable-libdav1d —enable-libbluray —enable-libfreetype —enable-libmp3lame —enable-libopencore-amrnb —enable-libopencore-amrwb —enable-libopenjpeg —enable-libopus —enable-libshine —enable-libsnappy —enable-libsoxr —enable-libsrt —enable-libtheora —enable-libtwolame —enable-libvpx —enable-libwavpack —enable-libwebp —enable-libx264 —enable-libx265 —enable-libxml2 —enable-libzimg —enable-lzma —enable-zlib —enable-gmp —enable-libvidstab —enable-libvmaf —enable-libvorbis —enable-libvo-amrwbenc —enable-libmysofa —enable-libspeex —enable-libxvid —enable-libaom —enable-libgsm —disable-w32threads —enable-libmfx —enable-ffnvcodec —enable-cuda-llvm —enable-cuvid —enable-d3d11va —enable-nvenc —enable-nvdec —enable-dxva2 —enable-avisynth —enable-libopenmpt —enable-amf

    


    libavutil 56. 51.100 / 56. 51.100

    


    libavcodec 58. 91.100 / 58. 91.100

    


    libavformat 58. 45.100 / 58. 45.100

    


    libavdevice 58. 10.100 / 58. 10.100

    


    libavfilter 7. 85.100 / 7. 85.100

    


    libswscale 5. 7.100 / 5. 7.100

    


    libswresample 3. 7.100 / 3. 7.100

    


    libpostproc 55. 7.100 / 55. 7.100

    


    [mp3float @ 000002163cdc7940] Header missing

    


    [mp3 @ 000002163cdbd600] decoding for stream 0 failed

    


    [mp3 @ 000002163cdbd600] Could not find codec parameters for stream 0 (Audio : mp3 (mp3float), 0 channels, fltp) : unspecified frame size

    


    Consider increasing the value for the 'analyzeduration' and 'probesize' options

    


    Input #0, mp3, from 'F :\cnn-lstm\signals_speech\sample-000008.mp3' :

    


    Duration : N/A, start : 0.000000, bitrate : N/A

    


    Stream #0:0: Audio: mp3, 0 channels, fltp


    


    [NULL @ 000002163ce39a00] Unable to find a suitable output format for 'm'

    


    m : Invalid argument

    


    This is my code

    


    # Import necessary libraries

#from pydub import AudioSegment
from pydub.utils import which
from pydub.utils import make_chunks


import os
import glob
import pydub

pydub.AudioSegment.converter = r"C:\\ffmpeg-4.3-win64-static\\bin\\ffmpeg.exe"



data_dir = "F:\\cnn-lstm\\signals_speech\\*.mp3"
dest0 = "F:\\cnn-lstm\\chunks_1s_sr_vadnet"
for audio_path in glob.glob(data_dir):
    #print("audio_path",audio_path)
    dest1 = audio_path[-17:-4]
    #print("dest1",dest1)
    myaudio = pydub.AudioSegment.from_mp3(audio_path,"mp3")
    chunk_length_ms = 1000 # pydub calculates in millisec
    chunks = make_chunks(myaudio, chunk_length_ms) #Make chunks of two sec

    #Export all of the individual chunks as wav files

    for i, chunk in enumerate(chunks):
        chunk_name = dest0+'\\'+dest1+"_{0}.mp3".format(i)
        print ("exporting", chunk_name)
        chunk.export(chunk_name, format="mp3")


    


  • How to get currecnt AVFrame sequential number after av_seek_frame ?

    15 janvier 2023, par Sirop4ik

    I am new in decoder and FFmpeg. What I need is to implement the logic that can read frames with some step (ex:20), in other words, I have a file and I need to read frames 0, 20, 40, 60...

    


    what I do is

    


    
AVFrame * m_pAVFrame = nullptr;
int firstFrameIdx = 0;

while(true)
{

if(firstFrameIdx > 0)
{
int64_t seekTarget = FrameToPts(m_pAVStream, firstFrameIdx);
nRet = av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME);
}

nRet = av_read_frame(m_pAVFormatCtx, m_pAVPkt);
ret = avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt);
ret = avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame);

firstFrameIdx+=20;
}



    


    But problem is that av_seek_frame moves the pointer to the Iframe, lets say the video file has keyframes each 15(of course it could be a different number) like 0, 15, 30... So it means that if I try to seek to frame 20 actually I get to frame 15.

    


    I see that AVFrame has a property coded_picture_number that could be useful in my case, I tried to put these returned values to the vector and I see that these values irrelevant

    


    enter image description here

    


    what I expected to see there is 0, 15, 30, 45...

    


    It'll be useful if I for example can make a seek then get a frame to ask the order number (ex:15) then I can understand that Iframe is 15 and in order to reach frame 20 I need to read and skip 5 frames so as a result, I get to frame 20, but as you see above after the seek I ask the order number and get weird values like 0, 2, 1, 3... there is nothing to do with it...

    


    I feel like there is some basic knowledge that I miss, could someone explain how to make a seek logic and get to the right frame ?

    


    UPDATE

    


    Init logic

    


    bool FFmpegDecoder::Init(unsigned char const * pData, int dataSize, int reqId, bool bUseHWAccel, FFmpegDecoderCallback * pCB)&#xA;{&#xA;    Deinit();&#xA;&#xA;    // From memory:&#xA;    if (pData == nullptr || dataSize == 0)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: neither filename nor memory data were given !\n");&#xA;        return false;&#xA;    }&#xA;    m_pIoCtx = std::make_shared<aviocontextmem>(pData, dataSize);&#xA;&#xA;    if (m_pIoCtx->IsValid() == false)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: m_pIoCtx is nullptr !\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_reqId = reqId;&#xA;    m_bUseHWAccel = bUseHWAccel;&#xA;    m_pCB = pCB;&#xA;    m_pData = pData;&#xA;    m_dataSize = dataSize;&#xA;&#xA;    m_bRequestedAbort = false;&#xA;&#xA;    m_pAVPkt = av_packet_alloc();&#xA;    av_init_packet(m_pAVPkt);&#xA;&#xA;    m_pAVFrame = av_frame_alloc();&#xA;    m_pAVFrameRGB = av_frame_alloc();&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwAVFrameForHw = av_frame_alloc();&#xA;    }&#xA;&#xA;    m_pAVFormatCtx = avformat_alloc_context();&#xA;    m_pIoCtx->initAVFormatContext(m_pAVFormatCtx);&#xA;&#xA;    if (avformat_open_input(&amp;m_pAVFormatCtx, "", nullptr, nullptr) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_open_input\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(m_pAVFormatCtx, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_find_stream_info\n");&#xA;        return false;&#xA;    }&#xA;&#xA;&#xA;    //av_dump_format(ctx_format, 0, "", false);&#xA;    for (int i = 0; i &lt; (int)m_pAVFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;    {&#xA;        if (m_pAVFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            m_streamIdx = i;&#xA;            m_pAVStream = m_pAVFormatCtx->streams[i];&#xA;            break;&#xA;        }&#xA;    }&#xA;    if (m_pAVStream == nullptr)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: failed to find video stream\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodec = avcodec_find_decoder(m_pAVStream->codecpar->codec_id);&#xA;    if (!m_pAVCodec)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_find_decoder\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec);&#xA;    if (!m_pAVCodecCtx)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_alloc_context3\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(m_pAVCodecCtx, m_pAVStream->codecpar) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_parameters_to_context\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        AVHWDeviceType hwDevType = AV_HWDEVICE_TYPE_DXVA2;&#xA;        g_hwPixFormat = find_fmt_by_hw_type(hwDevType);&#xA;        m_pAVCodecCtx->get_format = get_hw_format;&#xA;        av_opt_set_int(m_pAVCodecCtx, "refcounted_frames", 1, 0);&#xA;        if (av_hwdevice_ctx_create(&amp;m_pBufferRefForHw, hwDevType, NULL, NULL, 0) &lt; 0)&#xA;        {&#xA;            printf("FFmpegDecoder::InitFFmpeg: error in av_hwdevice_ctx_create\n");&#xA;            return false;&#xA;        }&#xA;        m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(m_pBufferRefForHw);&#xA;    }&#xA;&#xA;    if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_open2\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVFrameRGB->format = AV_PIX_FMT_BGR24;&#xA;    m_pAVFrameRGB->width = m_pAVCodecCtx->width;&#xA;    m_pAVFrameRGB->height = m_pAVCodecCtx->height;&#xA;    if (av_frame_get_buffer(m_pAVFrameRGB, 32) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in av_frame_get_buffer\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_streamRotationDegrees = GetAVStreamRotation(m_pAVStream);&#xA;    m_estimatedFramesCount = 0;&#xA;    assert(m_pAVFormatCtx->nb_streams > 0);&#xA;    if (m_pAVFormatCtx->nb_streams > 0)&#xA;    {&#xA;        m_estimatedFramesCount = m_pAVFormatCtx->streams[0]->nb_frames;&#xA;    }&#xA;&#xA;    //InitConvertColorSpace&#xA;    // Init converter from YUV420p to BGR:&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_NV12, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    else&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, m_pAVCodecCtx->pix_fmt, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    if (!m_pSwsCtxConvertImg)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in sws_getContext\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_bInitOK = true;&#xA;    return true;&#xA;}&#xA;</aviocontextmem>

    &#xA;

    Decoding logic with last changes

    &#xA;

    void FFmpegDecoder::DecodeWithStep(int step)&#xA;{&#xA;    step = 20;&#xA;    int currentFramePos = 0;&#xA;    int number_of_errors = 0;&#xA;    const int MAX_ERROR_NUM = 10;&#xA;&#xA;    while (true)&#xA;    {&#xA;        if (step > 0)&#xA;        {&#xA;            int seekPos = currentFramePos &#x2B; step;&#xA;            int64_t seekTarget = FrameToPts(m_pAVStream, seekPos);&#xA;&#xA;            if (av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME) &lt; 0)&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;            else&#xA;            {&#xA;                currentFramePos = seekPos;&#xA;                m_is_seeked = true;&#xA;            }&#xA;        }&#xA;&#xA;        if (av_read_frame(m_pAVFormatCtx, m_pAVPkt) == 0)&#xA;        {&#xA;            if (m_pAVPkt->stream_index == m_streamIdx) //to make sure that I dont get packets from other streams&#xA;            {&#xA;                if (m_is_seeked)&#xA;                {&#xA;                    avcodec_flush_buffers(m_pAVCodecCtx);&#xA;                    m_is_seeked = false;&#xA;                }&#xA;&#xA;                if (avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt) == 0)&#xA;                {&#xA;                    printf("----- BATCH\n");&#xA;&#xA;                    while (avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame) == 0)&#xA;                    {&#xA;                        ProcessFrame(m_pAVFrame);&#xA;                        av_frame_unref(m_pAVFrame);&#xA;                        currentFramePos&#x2B;&#x2B;;&#xA;                        printf("----- cur position (%d) \n", currentFramePos);&#xA;                    }&#xA;                }&#xA;&#xA;                av_packet_unref(m_pAVPkt);&#xA;            }&#xA;        }&#xA;        else&#xA;        {&#xA;            number_of_errors&#x2B;&#x2B;;&#xA;        }&#xA;&#xA;        if (number_of_errors == MAX_ERROR_NUM)&#xA;        {&#xA;            printf("EXIT\n");&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    UPDATE

    &#xA;

    Init logic

    &#xA;

    bool FFmpegDecoder::Init(unsigned char const * pData, int dataSize, int reqId, bool bUseHWAccel, FFmpegDecoderCallback * pCB)&#xA;{&#xA;    Deinit();&#xA;&#xA;    // From memory:&#xA;    if (pData == nullptr || dataSize == 0)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: neither filename nor memory data were given !\n");&#xA;        return false;&#xA;    }&#xA;    m_pIoCtx = std::make_shared<aviocontextmem>(pData, dataSize);&#xA;&#xA;    if (m_pIoCtx->IsValid() == false)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: m_pIoCtx is nullptr !\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_reqId = reqId;&#xA;    m_bUseHWAccel = bUseHWAccel;&#xA;    m_pCB = pCB;&#xA;    m_pData = pData;&#xA;    m_dataSize = dataSize;&#xA;&#xA;    m_bRequestedAbort = false;&#xA;&#xA;    m_pAVPkt = av_packet_alloc();&#xA;    av_init_packet(m_pAVPkt);&#xA;&#xA;    m_pAVFrame = av_frame_alloc();&#xA;    m_pAVFrameRGB = av_frame_alloc();&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwAVFrameForHw = av_frame_alloc();&#xA;    }&#xA;&#xA;    m_pAVFormatCtx = avformat_alloc_context();&#xA;    m_pIoCtx->initAVFormatContext(m_pAVFormatCtx);&#xA;&#xA;    if (avformat_open_input(&amp;m_pAVFormatCtx, "", nullptr, nullptr) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_open_input\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(m_pAVFormatCtx, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_find_stream_info\n");&#xA;        return false;&#xA;    }&#xA;&#xA;&#xA;    //av_dump_format(ctx_format, 0, "", false);&#xA;    for (int i = 0; i &lt; (int)m_pAVFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;    {&#xA;        if (m_pAVFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            m_streamIdx = i;&#xA;            m_pAVStream = m_pAVFormatCtx->streams[i];&#xA;            break;&#xA;        }&#xA;    }&#xA;    if (m_pAVStream == nullptr)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: failed to find video stream\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodec = avcodec_find_decoder(m_pAVStream->codecpar->codec_id);&#xA;    if (!m_pAVCodec)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_find_decoder\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec);&#xA;    if (!m_pAVCodecCtx)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_alloc_context3\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(m_pAVCodecCtx, m_pAVStream->codecpar) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_parameters_to_context\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        AVHWDeviceType hwDevType = AV_HWDEVICE_TYPE_DXVA2;&#xA;        g_hwPixFormat = find_fmt_by_hw_type(hwDevType);&#xA;        m_pAVCodecCtx->get_format = get_hw_format;&#xA;        av_opt_set_int(m_pAVCodecCtx, "refcounted_frames", 1, 0);&#xA;        if (av_hwdevice_ctx_create(&amp;m_pBufferRefForHw, hwDevType, NULL, NULL, 0) &lt; 0)&#xA;        {&#xA;            printf("FFmpegDecoder::InitFFmpeg: error in av_hwdevice_ctx_create\n");&#xA;            return false;&#xA;        }&#xA;        m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(m_pBufferRefForHw);&#xA;    }&#xA;&#xA;    if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_open2\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVFrameRGB->format = AV_PIX_FMT_BGR24;&#xA;    m_pAVFrameRGB->width = m_pAVCodecCtx->width;&#xA;    m_pAVFrameRGB->height = m_pAVCodecCtx->height;&#xA;    if (av_frame_get_buffer(m_pAVFrameRGB, 32) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in av_frame_get_buffer\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_streamRotationDegrees = GetAVStreamRotation(m_pAVStream);&#xA;    m_estimatedFramesCount = 0;&#xA;    assert(m_pAVFormatCtx->nb_streams > 0);&#xA;    if (m_pAVFormatCtx->nb_streams > 0)&#xA;    {&#xA;        m_estimatedFramesCount = m_pAVFormatCtx->streams[0]->nb_frames;&#xA;    }&#xA;&#xA;    //InitConvertColorSpace&#xA;    // Init converter from YUV420p to BGR:&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_NV12, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    else&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, m_pAVCodecCtx->pix_fmt, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    if (!m_pSwsCtxConvertImg)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in sws_getContext\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_bInitOK = true;&#xA;    return true;&#xA;}&#xA;</aviocontextmem>

    &#xA;

    void FFmpegDecoder::DecodeWithStep(int step)&#xA;{&#xA;    step = 20;&#xA;    int currentFramePos = 0;&#xA;    int number_of_errors = 0;&#xA;    const int MAX_ERROR_NUM = 10;&#xA;    int seekPos = 0;&#xA;&#xA;    while (true)&#xA;    {&#xA;        if (step > 1)&#xA;        {&#xA;            seekPos = currentFramePos &#x2B; step;&#xA;            int64_t seekTarget = FrameToPts(m_pAVStream, seekPos);&#xA;&#xA;            if (av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME) &lt; 0)&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;            else&#xA;            {&#xA;                m_is_seeked = true;&#xA;            }&#xA;        }&#xA;&#xA;        while (true)&#xA;        {&#xA;            if (av_read_frame(m_pAVFormatCtx, m_pAVPkt) == 0)&#xA;            {&#xA;                if (m_pAVPkt->stream_index == m_streamIdx) //to make sure that I dont get packets from other streams&#xA;                {&#xA;                    if (m_is_seeked)&#xA;                    {&#xA;                        avcodec_flush_buffers(m_pAVCodecCtx);&#xA;                        m_is_seeked = false;&#xA;                    }&#xA;&#xA;                    if (avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt) == 0)&#xA;                    {&#xA;                        int ret = 0;&#xA;                        while (ret >= 0)&#xA;                        {&#xA;                            ret = avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame);&#xA;&#xA;                            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                            {&#xA;                                av_frame_unref(m_pAVFrame);&#xA;                                break;&#xA;                            }&#xA;&#xA;                            currentFramePos = m_pAVFrame->display_picture_number; //In order to get position of currect frame (seek move poiter to the key frame)&#xA;&#xA;                            if (currentFramePos &lt; seekPos) //Some frames need to be skiped in order to reach needed frame&#xA;                            {&#xA;                                printf("----- SKIP : cur position (%d) \n", currentFramePos);&#xA;                                av_frame_unref(m_pAVFrame);&#xA;                                continue;&#xA;                            }&#xA;&#xA;                            ProcessFrame(m_pAVFrame); //needed frame was processed&#xA;                            av_frame_unref(m_pAVFrame);&#xA;                            printf("----- cur position (%d) \n", currentFramePos);&#xA;                            break;&#xA;                        }&#xA;                    }&#xA;&#xA;                    av_packet_unref(m_pAVPkt);&#xA;                }&#xA;                else&#xA;                {&#xA;                    av_packet_unref(m_pAVPkt); //we got a frame from the wrong stream&#xA;                }&#xA;            }&#xA;            else&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;&#xA;            if (number_of_errors == MAX_ERROR_NUM)&#xA;            {&#xA;                printf("EXIT1\n");&#xA;                break;&#xA;            }&#xA;        }&#xA;&#xA;        if (number_of_errors == MAX_ERROR_NUM)&#xA;        {&#xA;            printf("EXIT2\n");&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    int64_t FrameToPts(AVStream* pavStream, int frame)&#xA;{&#xA;    return (int64_t(frame) * pavStream->r_frame_rate.den *  pavStream->time_base.den) /&#xA;        (int64_t(pavStream->r_frame_rate.num) * pavStream->time_base.num);&#xA;}&#xA;

    &#xA;

  • How to get currecnt AVFrame siquential number after av_seek_frame ?

    14 mai 2021, par Aleksey Timoshchenko

    I am new in decoder and FFmpeg. What I need is to implement the logic that can read frames with some step (ex:20), in other words, I have a file and I need to read frames 0, 20, 40, 60...

    &#xA;

    what I do is

    &#xA;

    &#xA;AVFrame * m_pAVFrame = nullptr;&#xA;int firstFrameIdx = 0;&#xA;&#xA;while(true)&#xA;{&#xA;&#xA;if(firstFrameIdx > 0)&#xA;{&#xA;int64_t seekTarget = FrameToPts(m_pAVStream, firstFrameIdx);&#xA;nRet = av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME);&#xA;}&#xA;&#xA;nRet = av_read_frame(m_pAVFormatCtx, m_pAVPkt);&#xA;ret = avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt);&#xA;ret = avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame);&#xA;&#xA;firstFrameIdx&#x2B;=20;&#xA;}&#xA;&#xA;

    &#xA;

    But problem is that av_seek_frame moves the pointer to the Iframe, lets say the video file has keyframes each 15(of course it could be a different number) like 0, 15, 30... So it means that if I try to seek to frame 20 actually I get to frame 15.

    &#xA;

    I see that AVFrame has a property coded_picture_number that could be useful in my case, I tried to put these returned values to the vector and I see that these values irrelevant

    &#xA;

    enter image description here

    &#xA;

    what I expected to see there is 0, 15, 30, 45...

    &#xA;

    It'll be useful if I for example can make a seek then get a frame to ask the order number (ex:15) then I can understand that Iframe is 15 and in order to reach frame 20 I need to read and skip 5 frames so as a result, I get to frame 20, but as you see above after the seek I ask the order number and get weird values like 0, 2, 1, 3... there is nothing to do with it...

    &#xA;

    I feel like there is some basic knowledge that I miss, could someone explain how to make a seek logic and get to the right frame ?

    &#xA;

    UPDATE

    &#xA;

    Init logic

    &#xA;

    bool FFmpegDecoder::Init(unsigned char const * pData, int dataSize, int reqId, bool bUseHWAccel, FFmpegDecoderCallback * pCB)&#xA;{&#xA;    Deinit();&#xA;&#xA;    // From memory:&#xA;    if (pData == nullptr || dataSize == 0)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: neither filename nor memory data were given !\n");&#xA;        return false;&#xA;    }&#xA;    m_pIoCtx = std::make_shared<aviocontextmem>(pData, dataSize);&#xA;&#xA;    if (m_pIoCtx->IsValid() == false)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: m_pIoCtx is nullptr !\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_reqId = reqId;&#xA;    m_bUseHWAccel = bUseHWAccel;&#xA;    m_pCB = pCB;&#xA;    m_pData = pData;&#xA;    m_dataSize = dataSize;&#xA;&#xA;    m_bRequestedAbort = false;&#xA;&#xA;    m_pAVPkt = av_packet_alloc();&#xA;    av_init_packet(m_pAVPkt);&#xA;&#xA;    m_pAVFrame = av_frame_alloc();&#xA;    m_pAVFrameRGB = av_frame_alloc();&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwAVFrameForHw = av_frame_alloc();&#xA;    }&#xA;&#xA;    m_pAVFormatCtx = avformat_alloc_context();&#xA;    m_pIoCtx->initAVFormatContext(m_pAVFormatCtx);&#xA;&#xA;    if (avformat_open_input(&amp;m_pAVFormatCtx, "", nullptr, nullptr) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_open_input\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(m_pAVFormatCtx, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_find_stream_info\n");&#xA;        return false;&#xA;    }&#xA;&#xA;&#xA;    //av_dump_format(ctx_format, 0, "", false);&#xA;    for (int i = 0; i &lt; (int)m_pAVFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;    {&#xA;        if (m_pAVFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            m_streamIdx = i;&#xA;            m_pAVStream = m_pAVFormatCtx->streams[i];&#xA;            break;&#xA;        }&#xA;    }&#xA;    if (m_pAVStream == nullptr)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: failed to find video stream\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodec = avcodec_find_decoder(m_pAVStream->codecpar->codec_id);&#xA;    if (!m_pAVCodec)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_find_decoder\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec);&#xA;    if (!m_pAVCodecCtx)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_alloc_context3\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(m_pAVCodecCtx, m_pAVStream->codecpar) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_parameters_to_context\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        AVHWDeviceType hwDevType = AV_HWDEVICE_TYPE_DXVA2;&#xA;        g_hwPixFormat = find_fmt_by_hw_type(hwDevType);&#xA;        m_pAVCodecCtx->get_format = get_hw_format;&#xA;        av_opt_set_int(m_pAVCodecCtx, "refcounted_frames", 1, 0);&#xA;        if (av_hwdevice_ctx_create(&amp;m_pBufferRefForHw, hwDevType, NULL, NULL, 0) &lt; 0)&#xA;        {&#xA;            printf("FFmpegDecoder::InitFFmpeg: error in av_hwdevice_ctx_create\n");&#xA;            return false;&#xA;        }&#xA;        m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(m_pBufferRefForHw);&#xA;    }&#xA;&#xA;    if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_open2\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVFrameRGB->format = AV_PIX_FMT_BGR24;&#xA;    m_pAVFrameRGB->width = m_pAVCodecCtx->width;&#xA;    m_pAVFrameRGB->height = m_pAVCodecCtx->height;&#xA;    if (av_frame_get_buffer(m_pAVFrameRGB, 32) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in av_frame_get_buffer\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_streamRotationDegrees = GetAVStreamRotation(m_pAVStream);&#xA;    m_estimatedFramesCount = 0;&#xA;    assert(m_pAVFormatCtx->nb_streams > 0);&#xA;    if (m_pAVFormatCtx->nb_streams > 0)&#xA;    {&#xA;        m_estimatedFramesCount = m_pAVFormatCtx->streams[0]->nb_frames;&#xA;    }&#xA;&#xA;    //InitConvertColorSpace&#xA;    // Init converter from YUV420p to BGR:&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_NV12, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    else&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, m_pAVCodecCtx->pix_fmt, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    if (!m_pSwsCtxConvertImg)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in sws_getContext\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_bInitOK = true;&#xA;    return true;&#xA;}&#xA;</aviocontextmem>

    &#xA;

    Decoding logic with last changes

    &#xA;

    void FFmpegDecoder::DecodeWithStep(int step)&#xA;{&#xA;    step = 20;&#xA;    int currentFramePos = 0;&#xA;    int number_of_errors = 0;&#xA;    const int MAX_ERROR_NUM = 10;&#xA;&#xA;    while (true)&#xA;    {&#xA;        if (step > 0)&#xA;        {&#xA;            int seekPos = currentFramePos &#x2B; step;&#xA;            int64_t seekTarget = FrameToPts(m_pAVStream, seekPos);&#xA;&#xA;            if (av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME) &lt; 0)&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;            else&#xA;            {&#xA;                currentFramePos = seekPos;&#xA;                m_is_seeked = true;&#xA;            }&#xA;        }&#xA;&#xA;        if (av_read_frame(m_pAVFormatCtx, m_pAVPkt) == 0)&#xA;        {&#xA;            if (m_pAVPkt->stream_index == m_streamIdx) //to make sure that I dont get packets from other streams&#xA;            {&#xA;                if (m_is_seeked)&#xA;                {&#xA;                    avcodec_flush_buffers(m_pAVCodecCtx);&#xA;                    m_is_seeked = false;&#xA;                }&#xA;&#xA;                if (avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt) == 0)&#xA;                {&#xA;                    printf("----- BATCH\n");&#xA;&#xA;                    while (avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame) == 0)&#xA;                    {&#xA;                        ProcessFrame(m_pAVFrame);&#xA;                        av_frame_unref(m_pAVFrame);&#xA;                        currentFramePos&#x2B;&#x2B;;&#xA;                        printf("----- cur position (%d) \n", currentFramePos);&#xA;                    }&#xA;                }&#xA;&#xA;                av_packet_unref(m_pAVPkt);&#xA;            }&#xA;        }&#xA;        else&#xA;        {&#xA;            number_of_errors&#x2B;&#x2B;;&#xA;        }&#xA;&#xA;        if (number_of_errors == MAX_ERROR_NUM)&#xA;        {&#xA;            printf("EXIT\n");&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    UPDATE

    &#xA;

    Init logic

    &#xA;

    bool FFmpegDecoder::Init(unsigned char const * pData, int dataSize, int reqId, bool bUseHWAccel, FFmpegDecoderCallback * pCB)&#xA;{&#xA;    Deinit();&#xA;&#xA;    // From memory:&#xA;    if (pData == nullptr || dataSize == 0)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: neither filename nor memory data were given !\n");&#xA;        return false;&#xA;    }&#xA;    m_pIoCtx = std::make_shared<aviocontextmem>(pData, dataSize);&#xA;&#xA;    if (m_pIoCtx->IsValid() == false)&#xA;    {&#xA;        printf("FFmpegDecoder::Init FAILED: m_pIoCtx is nullptr !\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_reqId = reqId;&#xA;    m_bUseHWAccel = bUseHWAccel;&#xA;    m_pCB = pCB;&#xA;    m_pData = pData;&#xA;    m_dataSize = dataSize;&#xA;&#xA;    m_bRequestedAbort = false;&#xA;&#xA;    m_pAVPkt = av_packet_alloc();&#xA;    av_init_packet(m_pAVPkt);&#xA;&#xA;    m_pAVFrame = av_frame_alloc();&#xA;    m_pAVFrameRGB = av_frame_alloc();&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwAVFrameForHw = av_frame_alloc();&#xA;    }&#xA;&#xA;    m_pAVFormatCtx = avformat_alloc_context();&#xA;    m_pIoCtx->initAVFormatContext(m_pAVFormatCtx);&#xA;&#xA;    if (avformat_open_input(&amp;m_pAVFormatCtx, "", nullptr, nullptr) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_open_input\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(m_pAVFormatCtx, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avformat_find_stream_info\n");&#xA;        return false;&#xA;    }&#xA;&#xA;&#xA;    //av_dump_format(ctx_format, 0, "", false);&#xA;    for (int i = 0; i &lt; (int)m_pAVFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;    {&#xA;        if (m_pAVFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            m_streamIdx = i;&#xA;            m_pAVStream = m_pAVFormatCtx->streams[i];&#xA;            break;&#xA;        }&#xA;    }&#xA;    if (m_pAVStream == nullptr)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: failed to find video stream\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodec = avcodec_find_decoder(m_pAVStream->codecpar->codec_id);&#xA;    if (!m_pAVCodec)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_find_decoder\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec);&#xA;    if (!m_pAVCodecCtx)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_alloc_context3\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(m_pAVCodecCtx, m_pAVStream->codecpar) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_parameters_to_context\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        AVHWDeviceType hwDevType = AV_HWDEVICE_TYPE_DXVA2;&#xA;        g_hwPixFormat = find_fmt_by_hw_type(hwDevType);&#xA;        m_pAVCodecCtx->get_format = get_hw_format;&#xA;        av_opt_set_int(m_pAVCodecCtx, "refcounted_frames", 1, 0);&#xA;        if (av_hwdevice_ctx_create(&amp;m_pBufferRefForHw, hwDevType, NULL, NULL, 0) &lt; 0)&#xA;        {&#xA;            printf("FFmpegDecoder::InitFFmpeg: error in av_hwdevice_ctx_create\n");&#xA;            return false;&#xA;        }&#xA;        m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(m_pBufferRefForHw);&#xA;    }&#xA;&#xA;    if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, nullptr) &lt; 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_open2\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_pAVFrameRGB->format = AV_PIX_FMT_BGR24;&#xA;    m_pAVFrameRGB->width = m_pAVCodecCtx->width;&#xA;    m_pAVFrameRGB->height = m_pAVCodecCtx->height;&#xA;    if (av_frame_get_buffer(m_pAVFrameRGB, 32) != 0)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in av_frame_get_buffer\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_streamRotationDegrees = GetAVStreamRotation(m_pAVStream);&#xA;    m_estimatedFramesCount = 0;&#xA;    assert(m_pAVFormatCtx->nb_streams > 0);&#xA;    if (m_pAVFormatCtx->nb_streams > 0)&#xA;    {&#xA;        m_estimatedFramesCount = m_pAVFormatCtx->streams[0]->nb_frames;&#xA;    }&#xA;&#xA;    //InitConvertColorSpace&#xA;    // Init converter from YUV420p to BGR:&#xA;    if (m_bUseHWAccel)&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_NV12, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    else&#xA;    {&#xA;        m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, m_pAVCodecCtx->pix_fmt, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);&#xA;    }&#xA;    if (!m_pSwsCtxConvertImg)&#xA;    {&#xA;        printf("FFmpegDecoder::InitFFmpeg: error in sws_getContext\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    m_bInitOK = true;&#xA;    return true;&#xA;}&#xA;</aviocontextmem>

    &#xA;

    void FFmpegDecoder::DecodeWithStep(int step)&#xA;{&#xA;    step = 20;&#xA;    int currentFramePos = 0;&#xA;    int number_of_errors = 0;&#xA;    const int MAX_ERROR_NUM = 10;&#xA;    int seekPos = 0;&#xA;&#xA;    while (true)&#xA;    {&#xA;        if (step > 1)&#xA;        {&#xA;            seekPos = currentFramePos &#x2B; step;&#xA;            int64_t seekTarget = FrameToPts(m_pAVStream, seekPos);&#xA;&#xA;            if (av_seek_frame(m_pAVFormatCtx, m_streamIdx, seekTarget, AVSEEK_FLAG_FRAME) &lt; 0)&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;            else&#xA;            {&#xA;                m_is_seeked = true;&#xA;            }&#xA;        }&#xA;&#xA;        while (true)&#xA;        {&#xA;            if (av_read_frame(m_pAVFormatCtx, m_pAVPkt) == 0)&#xA;            {&#xA;                if (m_pAVPkt->stream_index == m_streamIdx) //to make sure that I dont get packets from other streams&#xA;                {&#xA;                    if (m_is_seeked)&#xA;                    {&#xA;                        avcodec_flush_buffers(m_pAVCodecCtx);&#xA;                        m_is_seeked = false;&#xA;                    }&#xA;&#xA;                    if (avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt) == 0)&#xA;                    {&#xA;                        int ret = 0;&#xA;                        while (ret >= 0)&#xA;                        {&#xA;                            ret = avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame);&#xA;&#xA;                            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                            {&#xA;                                av_frame_unref(m_pAVFrame);&#xA;                                break;&#xA;                            }&#xA;&#xA;                            currentFramePos = m_pAVFrame->display_picture_number; //In order to get position of currect frame (seek move poiter to the key frame)&#xA;&#xA;                            if (currentFramePos &lt; seekPos) //Some frames need to be skiped in order to reach needed frame&#xA;                            {&#xA;                                printf("----- SKIP : cur position (%d) \n", currentFramePos);&#xA;                                av_frame_unref(m_pAVFrame);&#xA;                                continue;&#xA;                            }&#xA;&#xA;                            ProcessFrame(m_pAVFrame); //needed frame was processed&#xA;                            av_frame_unref(m_pAVFrame);&#xA;                            printf("----- cur position (%d) \n", currentFramePos);&#xA;                            break;&#xA;                        }&#xA;                    }&#xA;&#xA;                    av_packet_unref(m_pAVPkt);&#xA;                }&#xA;                else&#xA;                {&#xA;                    av_packet_unref(m_pAVPkt); //we got a frame from the wrong stream&#xA;                }&#xA;            }&#xA;            else&#xA;            {&#xA;                number_of_errors&#x2B;&#x2B;;&#xA;            }&#xA;&#xA;            if (number_of_errors == MAX_ERROR_NUM)&#xA;            {&#xA;                printf("EXIT1\n");&#xA;                break;&#xA;            }&#xA;        }&#xA;&#xA;        if (number_of_errors == MAX_ERROR_NUM)&#xA;        {&#xA;            printf("EXIT2\n");&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    int64_t FrameToPts(AVStream* pavStream, int frame)&#xA;{&#xA;    return (int64_t(frame) * pavStream->r_frame_rate.den *  pavStream->time_base.den) /&#xA;        (int64_t(pavStream->r_frame_rate.num) * pavStream->time_base.num);&#xA;}&#xA;

    &#xA;