社区
资源
帖子详情
网络版ffmpeg解码的问题
鄢老
2008-10-20 03:47:53
上次用ffmpeg做了一个播放文件的本地播放器,效果不错。这次公司让我做一个网络版的播放器,一想到ffmpeg来解码服务器发过来的mp4视频数据包就没了主意,自己做的实验老是通不过。
诸位,谁有这方面的经验,可否告知一二,如分数不够,还可以加分。
...全文
784
9
打赏
收藏
网络版ffmpeg解码的问题
上次用ffmpeg做了一个播放文件的本地播放器,效果不错。这次公司让我做一个网络版的播放器,一想到ffmpeg来解码服务器发过来的mp4视频数据包就没了主意,自己做的实验老是通不过。 诸位,谁有这方面的经验,可否告知一二,如分数不够,还可以加分。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
glacierful
2012-05-03
打赏
举报
回复
楼主能说说用什么方式来播放ffmpeg解码的数据吗?
直接当成一副图像来显示吗?
a1111111984
2009-04-01
打赏
举报
回复
[Quote=引用 7 楼 lookforyou 的回复:]
直接使用av_open_input_file打开网络流就可,ffmpeg会自己寻找对应的格式
[/Quote]
你确定?
lookforyou
2008-12-18
打赏
举报
回复
直接使用av_open_input_file打开网络流就可,ffmpeg会自己寻找对应的格式
wolfman301
2008-11-04
打赏
举报
回复
比较乱,看不太明白
鄢老
2008-10-31
打赏
举报
回复
发现这里没高手,帖子发那么久了,还得不到一点有效的帮助。
lius1984
2008-10-25
打赏
举报
回复
这网站上有ffmpeg视频解码器源代码下载,希望对你有用 www.shgx.net
鄢老
2008-10-21
打赏
举报
回复
楼上的,压缩的现在不需要考虑,只考虑客户端在接收到服务器的mp4数据流时能正确解码,得到图象就行了。
VsirSoft
2008-10-20
打赏
举报
回复
网络的 不需要压缩么?? 视频这方面不是很熟
鄢老
2008-10-20
打赏
举报
回复
代码如下,是模拟网络发送数据包的,期待您的指导:
void main(void)
{
AVCodec *codec;
AVFrame *pFrameRGB,*pFramePic;
AVCodecContext *pCodecCtx= NULL;
int frame, size, got_picture, len;
FILE *fp;
int nFrames=0;
int nWidth=320,nHeight=280;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
avcodec_init();
av_register_all();
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
printf("Video decoding\n");
int numBytes=0;
uint8_t *buffer;
codec = avcodec_find_decoder(CODEC_ID_H264);//CODEC_ID_MPEG2VIDEO CODEC_ID_H264 CODEC_ID_MPEG4
if (!codec) {
fprintf(stderr, "codec not found\n");
return;
}
pCodecCtx= avcodec_alloc_context();
pFramePic= avcodec_alloc_frame();
pFrameRGB=avcodec_alloc_frame();
avpicture_alloc((AVPicture *)pFramePic,PIX_FMT_RGB24,nWidth,nHeight);
avpicture_alloc((AVPicture *)pFrameRGB,PIX_FMT_RGB24,nWidth,nHeight);
if(codec->capabilities&CODEC_CAP_TRUNCATED)
pCodecCtx->flags|= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
if (avcodec_open(pCodecCtx, codec) < 0) {
fprintf(stderr, "could not open codec\n");
return;
}
/* the codec gives us the frame size, in samples */
char *strFileName="d:\\6.mp4";
fp= fopen(strFileName, "rb");
if (!fp)
{
fprintf(stderr, "could not open %s\n", strFileName);
return;
}
fseek(fp,0,SEEK_SET);
frame = 0;
for(;;) {
size = fread(inbuf,1,INBUF_SIZE,fp);
if (size == 0)
{
break;
}
inbuf_ptr = inbuf;
while (size > 0)
{
got_picture=0;
len = avcodec_decode_video(pCodecCtx, pFramePic, &got_picture,inbuf_ptr, size);
if (len < 0)
{
fprintf(stderr, "Error while decoding frame %d\n", frame);
// return;
goto end_loop;
}
if (got_picture)
{
printf("saving frame %3d\n", nFrames);
// frame++;
// Determine required buffer size and allocate buffer
/*
if(numBytes==0)
{
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height);
buffer=new uint8_t[numBytes];
avpicture_fill((AVPicture *)pFramePic, buffer, PIX_FMT_RGB24,pCodecCtx->width, pCodecCtx->height);
delete [] buffer;
}
*/
//
static struct SwsContext *img_convert_ctx=NULL;
pFramePic->data[0] += pFramePic->linesize[0]*(pCodecCtx->height-1);
pFramePic->linesize[0] *= -1;
pFramePic->data[1] += pFramePic->linesize[1]*(pCodecCtx->height/2 - 1);
pFramePic->linesize[1] *= -1;
pFramePic->data[2] += pFramePic->linesize[2]*(pCodecCtx->height/2 - 1);//m_pFrameDec
pFramePic->linesize[2] *= -1;
img_convert_ctx = sws_getCachedContext(img_convert_ctx,
pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmt ,
pCodecCtx->width,pCodecCtx->height,PIX_FMT_BGR24,SWS_X, NULL, NULL, NULL); //PIX_FMT_RGB24
sws_scale(img_convert_ctx, pFramePic->data,pFramePic->linesize,/*0*/pCodecCtx->width,
pCodecCtx->height,pFrameRGB->data,pFrameRGB->linesize);
nFrames++;
//char strBmpFile[80];
//sprintf(strBmpFile,"d:\\new\\%d.bmp",nFrames);
//CreateBmp(strBmpFile,(uint8_t *)pFrameRGB->data[0],pCodecCtx->width,pCodecCtx->height,24);
// fprintf(g_file,"P5\n%d %d\n%d\n",pCodecCtx->width,pCodecCtx->height,255);
}
size -= len;
inbuf_ptr += len;
}
}
end_loop: fclose(fp);
avcodec_close(pCodecCtx);
av_free(pCodecCtx);
av_free(pFramePic);
av_free(pFrameRGB);
printf("\n");
}
海康视频数据+
ffmpeg
解码
+再编码
海康网络摄像机+
ffmpeg
解码
后再编码+图像质量很高,值得研究。源码实现,二次编码后图像很清晰
FFmpeg
获取网络摄像头数据
解码
这里是利用
FFmpeg
获取网络摄像头的数据,然后
解码
播放。 开发环境:win7+opencv3.0+
ffmpeg
+VS2013
VS2015环境
ffmpeg
解码
SDL显示来自网络的rtsp流媒体视频
用来学习
ffmpeg
解码
和SDL显示的例程。VS2015环境,包含64位
ffmpeg
库和SDL库,视频源来自网络,是一段动画片。
FFMPEG
解码
实时流,支持cpu、gpu
解码
FFMPEG
解码
实时流,支持cpu、gpu
解码
ffmpeg
基于dxva2的
解码
基于最新的
ffmpeg
-3.0实现的dxva2
解码
,测试4k视频(4096*2304)平均8毫秒
解码
一帧(不包括存储拷贝),下载源码后建立vs工程,把
ffmpeg
配置好就可以直接跑起来了。
资源
2,586
社区成员
18,436
社区内容
发帖
与我相关
我的任务
资源
VC/MFC 资源
复制链接
扫一扫
分享
社区描述
VC/MFC 资源
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章