ffmpeg decode raw h264
来源:互联网 发布:sql 转日前字符串 编辑:程序博客网 时间:2024/06/08 01:32
1. configure
configure --prefix=/usr/local/ffmpeg \
--enable-version3 \
--enable-gpl --enable-pthreads\
--disable-postproc --enable-avfilter \
--enable-shared \
--disable-ffserver --disable-ffplay \
--enable-encoder=rawvideo \
--enable-decoder=rawvideo \
--disable-encoder=asv1 --disable-encoder=asv2 \
--disable-encoder=bmp --disable-encoder=dvvideo \
--disable-encoder=ffv1 --disable-encoder=ffvhuff \
--disable-encoder=ppm --disable-encoder=rv10 \
--disable-encoder=targa --disable-encoder=xvid \
--disable-encoder=zlib
2. compile
FFMPEG_ROOT=/usr/local/ffmpeg
FFMPEG_INC=${FFMPEG_ROOT}/include
FFMPEG_LIB=${FFMPEG_ROOT}/lib
gcc -o test.x test.c -I${FFMPEG_INC} -L${FFMPEG_LIB} -lavcodec -lavformat
3. ffmpeg decode raw h264 file to yuv (yuv420p)
#include <math.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libavutil/opt.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/common.h>
#include <libavutil/imgutils.h>
#include <libavutil/mathematics.h>
#include <libavutil/samplefmt.h>
void usage(char *prog)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "%s <ifile> <ofile>\n\n");
}
int main(int argc, char **argv)
{
AVFormatContext *ic;
AVCodec *dcodec, *ecodec;
AVCodecContext *dec, *enc;
enum AVCodecID codec_id;
AVFrame *avframe;
AVPacket avpkt, pkt;
int err, got_frame = 0, got_packet = 0, fd;
char buffer[1<<16];
if(argc < 3) {
usage(argv[0]);
exit(-1);
}
av_register_all();
av_init_packet(&avpkt);
av_init_packet(&pkt);
pkt.data = NULL, pkt.size = 0;
ic = avformat_alloc_context();
if (!ic) {
fprintf(stderr, "ic not created.\n");
exit(-1);
}
err = avformat_open_input(&ic, argv[1], 0, 0);
if(err < 0) {
fprintf(stderr, "file [%s] not open.\n", argv[1]);
exit(-1);
}
// dec = avcodec_alloc_context3(dcodec);
dec = ic->streams[0]->codec;
if (!dec) {
fprintf(stderr, "Could not allocate video decoder context\n");
exit(-1);
}
/* find the H264 video decoder */
dcodec = avcodec_find_decoder(dec->codec_id);
if (!dcodec) {
fprintf(stderr, "dcodec not found\n");
exit(-1);
}
/* open dcodec */
if (avcodec_open2(dec, dcodec, NULL) < 0) {
fprintf(stderr, "Could not open dcodec\n");
exit(-1);
}
ic->probesize = (1<<20);
avformat_find_stream_info(ic, NULL);
/* reopen dcodec */
if (avcodec_open2(dec, dcodec, NULL) < 0) {
fprintf(stderr, "Could not open dcodec\n");
exit(-1);
}
ecodec = avcodec_find_encoder(AV_CODEC_ID_RAWVIDEO);
if (!ecodec) {
fprintf(stderr, "ecodec not found\n");
exit(-1);
}
enc = avcodec_alloc_context3(ecodec);
if (!enc) {
fprintf(stderr, "Could not allocate video encoder context\n");
exit(-1);
}
enc->width = dec->width, enc->height = dec->height;
enc->pix_fmt = dec->pix_fmt;
// enc->codec_id = ecodec->id;
// enc->codec = ecodec;
if (avcodec_open2(enc, ecodec, NULL) < 0) {
fprintf(stderr, "Could not open ecodec\n");
exit(-1);
}
avframe = avcodec_alloc_frame();
if(!avframe) {
fprintf(stderr, "Could not allocate video frame\n");
exit(-1);
}
fd = open(argv[2], O_CREAT|O_RDWR|O_TRUNC, 0666);
while(av_read_frame(ic, &avpkt) >= 0) {
got_frame = got_packet = 0;
err = avcodec_decode_video2(dec, avframe, &got_frame, &avpkt);
if(got_frame) {
avcodec_encode_video2(enc, &pkt, avframe, &got_packet);
write(fd, pkt.data, pkt.size);
av_destruct_packet(&pkt);
}
av_init_packet(&avpkt);
}
fprintf(stderr, "finished.\n");
// av_free(avframe);
close(fd);
}
dec->width = 720, dec->height = 480;
dec->pix_fmt = AV_PIX_FMT_YUVJ420P;
dec->pix_fmt = AV_PIX_FMT_YUV420P;
enc->width = dec->width, enc->height = dec->height;
enc->width = txtwidth, enc->height = txtheight;
enc->pix_fmt = dec->pix_fmt;
// enc->pix_fmt = AV_PIX_FMT_YUV420P;
txtwidth = enc->width, txtheight = enc->height;
- ffmpeg decode raw h264
- FFMPEG Intro - decode h264 raw video by ffmpeg
- ios ffmpeg h264 decode
- Exploit FFmpeg Libraries to Decode Raw H264 File in Windows, Which Supports Multithread-Decoding
- ffmpeg H264 decode for Android Native Surface
- 来源于 原创 分类 ios 5.0 ffmpeg decode h264 stream
- 【FFMPEG】从内存中获取H264数据并进行decode
- 使用ffmpeg将mp4文件中的h264码流转为raw h264文件格式或ts文件格式
- ffmpeg h264
- H264 encode and decode
- H264---5 decode
- H264 encode and decode overview
- H264 encode and decode overview
- H264 encode and decode overview
- h264 encode and decode success
- ffmpeg encode/decode example
- ios ffmpeg audio decode
- 自学 FFmpeg转码 decode
- STL
- 虚拟机安装64位Orace_Linux
- 白话经典算法系列之七 堆与堆排序
- Android发送邮件附带文件
- C/C++中 关于对 引用变量 赋值的一些规则
- ffmpeg decode raw h264
- static 全局变量和普通全局变量
- C++中数组作函数参数的问题
- Java Web项目中连接Access数据库
- UML——RUP
- Oracle bulk Insert的用法
- 白话经典算法系列之八 MoreWindows白话经典算法之七大排序总结篇
- [sicily online]1007. To and Fro
- Visual Studio 2010 所有版本 中文 英文 下载,激活,序列号,注册码,下载地址