Linux 下 通过ffmpeg 读取yuv编码264 码流
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/time.h>
#include <libavutil/opt.h>
#include <libavutil/imgutils.h>
}
int encodeH264(AVCodecContext* codecContent, AVPacket* packet, AVFrame* frame)
{
//编码
int ret = avcodec_send_frame(codecContent, frame);
if (ret < 0)
{
fprintf(stderr, "Error sending a frame for encoding\n");
return -1;
}
while (ret == 0)
{
ret = avcodec_receive_packet(codecContent, packet);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
return 0;
}
else if (ret < 0) {
fprintf(stderr, "Error encoding video frame\n");
return -1;
}
if (ret == 0)
{
return ret;
//fwrite(packet->data, 1, packet->size, outFile);
}
}
return -1;
}
//
int main() {
//av_register_all();
const char* inputFileName = "001.mp4";
const char* audioutputFileName = "001_test.pcm";
const char* videoOutputFileName="001_test.yuv";
const char *outFileName="001_test.264";
#if 1
int ret = 0;
AVCodecContext* codecContent_enc264 = nullptr;
AVPacket* packet_enc264 = nullptr;
AVFrame* frame_enc264 = nullptr;
FILE* inFile = nullptr;
FILE* outFile = nullptr;
//查找指定编码器
const AVCodec* codec_enc264 = avcodec_find_encoder(AV_CODEC_ID_H264);
if (codec_enc264 == nullptr)
{
printf("could not find h264 encoder!");
return -1;
}
//申请编码器上下文
codecContent_enc264 = avcodec_alloc_context3(codec_enc264);
if (codecContent_enc264 == nullptr)
{
printf("could not alloc h264 content!");
return -1;
}
//必设
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!