获取AMR格式音频的播放总时间

    技术2022-05-20  51

    原理:

     

    amr 一帧对应20ms,那么一秒有50帧的音频数据。由于比特率不同,每帧的数据大小也不同。

    如果比特率是12.2kbs,那么每秒采样的音频数据位数为:

    12200 / 50 = 244bit = 30.5byte,取整为31字节。

    取整要四舍五入。

    再加上一个字节的帧头,这样数据帧的大小为32字节。

     

    获取总时间函数:

     

    int gst_rec_get_play_duration()

    {

       GstQuery *query;       gint64 duration;       gint64 ret_value, fram;       GstFormat format;

       if((APP_STATE_PLAY != app.state) || (NULL == app.play_pipeline))      {        return -1;      }

          format = GST_FORMAT_BYTES;       query = gst_query_new_duration (format);

     if (gst_element_query(app.play_pipeline, query))     {       gst_query_parse_duration (query, NULL, &duration);       printf("duration =  %ld/n", duration);    }     else    {       printf("duration query fail=====/n");       duration = 0;    }

     gst_query_unref (query);

     fram = ((duration - 6) / 32) * 0.02;

     return fram;}


    最新回复(0)