#include <windows.h>
#include "include\sdl2\SDL.h"
extern "C"
{
#include "include\libavformat\avformat.h"
};
static AVFormatContext *i_fmt_ctx;
static AVStream *i_video_stream;
static AVFormatContext *o_fmt_ctx;
static AVStream *o_video_stream;
static bool bStop = false;
static unsigned __stdcall rtsp2mp4(void * pThis)
{
avcodec_register_all();
av_register_all();
avformat_network_init();
i_fmt_ctx = NULL;//需要将指针指向空,那样avformat_open_input()才会申请一个新的而不会出错
const char *filename = "1111.ts";
if(avformat_open_input(&i_fmt_ctx,"test.ts",NULL,NULL)!=0)
{
fprintf(stderr,"could not open input file\n");
return -1;
}
if(avformat_find_stream_info(i_fmt_ctx, NULL) < 0)
{
fprintf(stderr,"could not find stream info\n");
return -2;
}
av_dump_format(i_fmt_ctx,0,"test.ts",0);
for (unsigned i=0;i<i_fmt_ctx->nb_streams;i++)
{
if(i_fmt_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
i_video_stream = i_fmt_ctx->streams[i];
break;
}
}
if(i_video_stream == NULL)
{
fprintf(stderr,"didn't find any video stream\n");
return -3;
}
avformat_alloc_output_context2(&o_fmt_ctx,NULL,NULL,filename);
//如果所有的输入文件信息都完整了,就可以从第一个输入文件信息开始设置输出的编码器信息了
o_video_stream = avformat_new_stream(o_fmt_ctx,NULL);
if(o_video_stream != NULL)
{
AVCodecContext *c;
c = o_video_stream->codec;
c->bit_rate = 400000;
c->codec_id = i_video_stream->codec->codec_id;
c->codec_type = i_video_stream->codec->codec_type;
c->time_base.num = i_video_stream->time_base.num;
c->time_base.den = i_video_stream->time_base.den;
//fprintf(stderr, "time_base.num = %d time_base.den = %d\n",c->time_base.num,c->time_base.den);
c->width = i_video_stream->codec->width;
c->height = i_video_stream->codec->height;
c->pix_fmt = i_video_stream->codec->pix_fmt;
//printf("%d %d %d",c->width,c->height,c->pix_fmt);
c->flags = i_video_stream->codec->flags;
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
c->me_range = i_video_stream->codec->me_range;
c->max_qdiff = i_video_stream->codec->max_qdiff;
c->qmin = i_video_stream->codec->qmin;
c->qmax = i_video_stream->codec->qmax;
c->qcompress = i_video_stream->codec->qcompress;
}
avio_open(&o_fmt_ctx->pb,filename,AVIO_FLAG_WRITE);
avformat_write_header(o_fmt_ctx,NULL);
int last_pts = 0;
int last_dts = 0;
int64_t pts, dts;
while(!bStop)
{
AVPacket i_pkt;
av_init_packet(&i_pkt);
i_pkt.size = 0;
i_pkt.data = NULL;
if(av_read_frame(i_fmt_ctx,&i_pkt) <0 )
break;
//pts and dts should increase monotonically pts should be >= dts
i_pkt.flags |= AV_PKT_FLAG_KEY;
pts = i_pkt.pts;
i_pkt.pts += last_pts;
dts = i_pkt.dts;
i_pkt.dts += last_dts;
i_pkt.stream_index = 0;
//printf("%lld %lld\n", i_pkt.pts, i_pkt.dts);
static int num = 1;
//printf("frame %d\n", num++);
av_interleaved_write_frame(o_fmt_ctx,&i_pkt);
av_free_packet(&i_pkt);
av_init_packet(&i_pkt);
Sleep(10);
}
last_dts += dts;
last_pts += pts;
avformat_close_input(&i_fmt_ctx);
av_write_trailer(o_fmt_ctx);
avcodec_close(o_fmt_ctx->streams[0]->codec);
av_freep(&o_fmt_ctx->streams[0]->codec);
av_freep(&o_fmt_ctx->streams[0]);
avio_close(o_fmt_ctx->pb);
av_free(o_fmt_ctx);
}
int main(int argc,char **argv)
{
bStop = false;
HANDLE hth;
unsigned uiThreadID;
hth = (HANDLE)_beginthreadex(NULL,0,rtsp2mp4,NULL,0,&uiThreadID);
if(hth == 0)
{
printf("Failed to create thread\n");
return -4;
}
system("PAUSE");
bStop = true;
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
FFmpeg -- VC2010 -- 视频流打开文件输入,内存输出到新文件
共225个文件
h:162个
tlog:26个
lib:11个
4星 · 超过85%的资源 需积分: 12 71 下载量 165 浏览量
2015-06-13
16:47:53
上传
评论
收藏 39.5MB ZIP 举报
温馨提示
FFmpeg -- VC2010 -- 视频流打开文件输入,内存输出到新文件,代码从网上得来,因为不是自己需要的,所以只是建立了工程,进行了测试,证实是可行的代码,不过新生成的视频流,比原装要小一些,具体没测试,只是这里说明下
资源推荐
资源详情
资源评论
收起资源包目录
FFmpeg -- VC2010 -- 视频流打开文件输入,内存输出到新文件 (225个子文件)
FFmpeg_9.cpp 4KB
avcodec-56.dll 21.33MB
avformat-56.dll 5.73MB
avfilter-5.dll 2.28MB
avdevice-56.dll 1.32MB
SDL2.dll 984KB
avutil-54.dll 482KB
swscale-3.dll 442KB
swresample-1.dll 275KB
postproc-53.dll 129KB
FFmpeg_9.vcxproj.filters 957B
SDL_opengl.h 622KB
avcodec.h 178KB
SDL_opengles2.h 129KB
avformat.h 103KB
avfilter.h 56KB
SDL_haptic.h 38KB
opt.h 37KB
pixfmt.h 34KB
SDL_video.h 33KB
SDL_render.h 32KB
SDL_events.h 26KB
frame.h 24KB
avio.h 22KB
swresample.h 20KB
SDL_audio.h 20KB
SDL_hints.h 19KB
SDL_surface.h 18KB
intreadwrite.h 18KB
avdevice.h 18KB
SDL_pixels.h 15KB
SDL_scancode.h 15KB
pixdesc.h 15KB
SDL_keycode.h 14KB
mem.h 14KB
common.h 14KB
old_pix_fmts.h 14KB
SDL_stdinc.h 14KB
avstring.h 13KB
SDL_test_fuzzer.h 13KB
swscale.h 12KB
SDL_assert.h 10KB
log.h 10KB
old_codec_ids.h 10KB
SDL_gamecontroller.h 10KB
samplefmt.h 10KB
SDL_thread.h 10KB
buffer.h 10KB
channel_layout.h 9KB
SDL_atomic.h 9KB
avutil.h 8KB
imgutils.h 8KB
SDL_joystick.h 8KB
_mingw.h 8KB
vdpau.h 8KB
dict.h 8KB
bprint.h 8KB
parseutils.h 7KB
buffersink.h 7KB
SDL_mouse.h 7KB
SDL_rwops.h 7KB
SDL_syswm.h 7KB
SDL_system.h 7KB
SDL_mutex.h 7KB
version.h 6KB
SDL_keyboard.h 6KB
SDL_log.h 6KB
xvmc.h 6KB
SDL_endian.h 6KB
vda.h 6KB
stdint.h 6KB
inttypes.h 6KB
SDL_shape.h 6KB
SDL_config.h 5KB
error.h 5KB
SDL.h 5KB
timecode.h 5KB
eval.h 5KB
SDL_filesystem.h 5KB
mathematics.h 5KB
SDL_version.h 5KB
fifo.h 5KB
cpu.h 5KB
SDL_test_common.h 5KB
buffersrc.h 5KB
SDL_test_md5.h 5KB
SDL_messagebox.h 5KB
audio_fifo.h 4KB
SDL_main.h 4KB
SDL_platform.h 4KB
rational.h 4KB
SDL_test_harness.h 4KB
attributes.h 4KB
begin_code.h 4KB
SDL_rect.h 4KB
version.h 4KB
SDL_cpuinfo.h 4KB
vaapi.h 4KB
dv_profile.h 4KB
stereo3d.h 4KB
共 225 条
- 1
- 2
- 3
资源评论
- zhulei198803312017-01-20学习学习,谢谢分享
- 特雷西_KID2016-04-07就是一堆的库。。。
- 你丫至于么2016-01-19可以使用。。。
- fanhongjun20042017-07-04很好的资源,非常感谢
黄忻
- 粉丝: 27
- 资源: 108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 原生微信小程序源码 - -仿豆瓣图书
- 原生微信小程序源码 - -滴滴公交-查公交
- 人工智能实验四 感知器算法的设计实现
- java小项目多线程多线程 复制文件 冒泡排序 群聊
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功