#include "ffmpeg.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;
char rtspUrl[] = "rtsp://192.168.0.14:554/user=admin&password=admin123&channel=1&stream=0.sdp?real_stream";
const char *filename = "demo.h264";
if (avformat_open_input(&i_fmt_ctx,rtspUrl,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 -1;
}
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 -1;
}
avformat_alloc_output_context2(&o_fmt_ctx,NULL,NULL,filename);
o_video_stream = avformat_new_stream(o_fmt_ctx,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;
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;
static int num = 1;
printf("frame %d\n",num++);
av_interleaved_write_frame(o_fmt_ctx,&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);
return 0;
}
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 -1;
}
printf("按任意键停止录像\n");
getchar();
bStop = true;
printf("按任意键退出\n");
getchar();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg将RTSP传输的h264原始码流保存到文件中 (255个子文件)
ffmpeg.vcxprojResolveAssemblyReference.cache 713B
ffmpeg.cpp 3KB
avcodec-57.dll 28.09MB
avcodec-57.dll 26.63MB
avcodec-55.dll 18.06MB
avformat-57.dll 6.58MB
avformat-57.dll 5.11MB
avformat-55.dll 5.1MB
avfilter-6.dll 4.02MB
avfilter-6.dll 4.01MB
avfilter-4.dll 1.94MB
avdevice-57.dll 1.36MB
avdevice-57.dll 1.32MB
avdevice-55.dll 1.28MB
SDL2.dll 984KB
swscale-4.dll 893KB
avutil-55.dll 573KB
avutil-55.dll 532KB
swscale-4.dll 516KB
swscale-2.dll 424KB
avutil-52.dll 409KB
swresample-2.dll 350KB
swresample-2.dll 333KB
swresample-0.dll 270KB
postproc-54.dll 120KB
postproc-52.dll 119KB
postproc-54.dll 117KB
ffplay.exe 541KB
ffprobe.exe 159KB
ffmpeg.exe 31KB
ffmpeg.vcxproj.filters 1KB
SDL_opengl.h 622KB
avcodec.h 171KB
SDL_opengles2.h 129KB
avformat.h 97KB
avfilter.h 56KB
SDL_haptic.h 38KB
opt.h 34KB
SDL_video.h 33KB
SDL_render.h 32KB
pixfmt.h 28KB
SDL_events.h 26KB
frame.h 22KB
SDL_audio.h 20KB
SDL_hints.h 19KB
SDL_surface.h 18KB
avio.h 18KB
intreadwrite.h 18KB
avdevice.h 16KB
SDL_pixels.h 15KB
SDL_scancode.h 15KB
SDL_keycode.h 14KB
old_pix_fmts.h 14KB
mem.h 14KB
SDL_stdinc.h 14KB
common.h 14KB
pixdesc.h 13KB
SDL_test_fuzzer.h 13KB
avstring.h 12KB
swscale.h 12KB
swresample.h 12KB
SDL_assert.h 10KB
old_codec_ids.h 10KB
SDL_gamecontroller.h 10KB
SDL_thread.h 10KB
samplefmt.h 10KB
log.h 10KB
buffer.h 10KB
channel_layout.h 9KB
SDL_atomic.h 9KB
avutil.h 8KB
SDL_joystick.h 8KB
_mingw.h 8KB
imgutils.h 8KB
bprint.h 8KB
buffersink.h 7KB
SDL_mouse.h 7KB
parseutils.h 7KB
SDL_rwops.h 7KB
SDL_syswm.h 7KB
SDL_system.h 7KB
SDL_mutex.h 7KB
dict.h 6KB
SDL_keyboard.h 6KB
vdpau.h 6KB
SDL_log.h 6KB
xvmc.h 6KB
SDL_endian.h 6KB
stdint.h 6KB
inttypes.h 6KB
SDL_shape.h 6KB
version.h 5KB
SDL_config.h 5KB
SDL.h 5KB
timecode.h 5KB
eval.h 5KB
SDL_filesystem.h 5KB
mathematics.h 5KB
SDL_version.h 5KB
SDL_test_common.h 5KB
共 255 条
- 1
- 2
- 3
资源评论
- qiji_20132017-10-07可以正常使用!
- 早起的鸟2018-06-14感谢分享!
- 爱吃炸酱面2018-08-11我来下载第二次~
qq_34572638
- 粉丝: 2
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功