当前位置:   article > 正文

FFmpeg:播放文件seek功能(附完整源代码)_使用ffmpeg实现seek操作

使用ffmpeg实现seek操作

FFmpeg:播放文件seek功能

#include "libavutil/adler32.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"

int64_t *pts_array;
uint32_t *crc_array;
int size_of_array;
int number_of_elements;

static int add_crc_to_array(uint32_t crc, int64_t pts)
{
   
    if (size_of_array <= number_of_elements) {
   
        if (size_of_array == 0)
            size_of_array = 10;
        size_of_array *= 2;
        crc_array = av_realloc_f(crc_array, size_of_array, sizeof(uint32_t));
        pts_array = av_realloc_f(pts_array, size_of_array, sizeof(int64_t));
        if ((crc_array == NULL) || (pts_array == NULL)) {
   
            av_log(NULL, AV_LOG_ERROR, "Can't allocate array to store crcs\n");
            return AVERROR(ENOMEM);
        }
    }
    crc_array[number_of_elements] = crc;
    pts_array[number_of_elements] = pts;
    number_of_elements++;
    return 0;
}

static int compare_crc_in_array(uint32_t crc, int64_t pts)
{
   
    int i;
    for (i = 0; i < number_of_elements; i++) {
   
        if (pts_array[i] == pts) {
   
            if (crc_array[i] == crc) {
   
                printf("Comparing 0x%08"PRIx32" %"PRId64" %d is OK\n", crc, pts, i);
                return 0;
            }
            else {
   
                av_log(NULL, AV_LOG_ERROR, "Incorrect crc of a frame after seeking\n");
                return -1;
            }
        }
    }
    av_log(NULL, AV_LOG_ERROR, "Incorrect pts of a frame after seeking\n");
    return -1;
}

static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
                                AVCodecContext *ctx, AVPacket *pkt, AVFrame *fr,
                                uint64_t ts_start, uint64_t ts_end, int no_seeking)
{
   
    int number_of_written_bytes;
    int result;
    int byte_buffer_size;
    uint8_t *byte_buffer;
    uint32_t crc;

    byte_buffer_size = 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/647030
推荐阅读
相关标签
  

闽ICP备14008679号