ffmpeg提取YUV和PCM

这篇博客介绍了作者在学习数字音视频课程时,如何使用ffmpeg从视频文件中提取视频流并保存为YUV格式,同时将音频提取并保存为PCM格式。通过参考雷大神的代码,作者编写了自己的实现,并分享了运行代码后生成的YUV和PCM文件如何用ffplay播放。
摘要由CSDN通过智能技术生成

最近在学数字音视频的课,就研究了下如何从一个视频文件中提取视频流存为YUV以及提取视频文件中的音频文件存为PCM。
由于我是初学者,对于ffmpeg并不是很熟悉,在这里大的框架主要还是参考了雷大神的代码。
话不多说,直接上代码,如下:

#include <stdio.h>

#define __STDC_CONSTANT_MACROS

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
};

int main(int argc, char* argv[])
{
    AVFormatContext *pFormatCtx;
    int             i, videoindex,audioindex;
    AVCodecContext  *pCodecCtx,*iaCodecCtx;
    AVCodec         *pCodec,*iaCodec;
    AVFrame *pFrame,*pFrameYUV,*aFrame;
    uint8_t *out_buffer,*buffer;
    AVPacket *packet;
    int y_size;
    int ret, got_picture;
    struct SwsContext *img_convert_ctx;
    //输入文件路径
    char filepath[]="Titanic.ts";

    int frame_cnt = 0;

    av_register_all();
    //avformat_network_init();
    pFormatCtx = avformat_alloc_context();

    if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){
        printf("Couldn't open input stream.\n");
        return -1;
    }
    if(avformat_find_stream_info(pFormatCtx,NULL)<0){
        printf("Couldn't find stream information.\n");
        return -1;
    }
    videoindex=-1;
    a
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值