资源简介
利用FFmpeg将mkv视频转换为H.264,转换后的视频请用VLC播放。

代码片段和文件信息
// FFMepg_to_mp4.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
extern “C“
{
#include “libavcodec/avcodec.h“
#include “libavformat/avformat.h“
#include “libswscale/swscale.h“
#include
#include
#include “libavutil/pixdesc.h“
}
const char* SRC_FILE = “Titanic.mkv“;
const char* OUT_FILE = “Titanic.h264“;
const char* OUT_FMT_FILE = “Titanic.mp4“;
int _tmain(int argc _TCHAR* argv[])
{
av_register_all();
AVFormatContext* pFormat = NULL;
if (avformat_open_input(&pFormat SRC_FILE NULL NULL) < 0)
{
return 0;
}
AVCodecContext* video_dec_ctx = NULL;
AVCodec* video_dec = NULL;
if (avformat_find_stream_info(pFormat NULL) < 0)
{
return 0;
}
av_dump_format(pFormat 0 SRC_FILE 0);
video_dec_ctx = pFormat->streams[0]->codec;
video_dec = avcodec_find_decoder(video_dec_ctx->codec_id);
if (avcodec_open2(video_dec_ctx video_dec NULL) < 0)
{
return 0;
}
AVFormatContext* pOFormat = NULL;
AVOutputFormat* ofmt = NULL;
if (avformat_alloc_output_context2(&pOFormat NULL NULL OUT_FILE) < 0)
{
return 0;
}
ofmt = pOFormat->oformat;
if (avio_open(&(pOFormat->pb) OUT_FILE AVIO_FLAG_READ_WRITE) < 0)
{
return 0;
}
AVCodecContext *video_enc_ctx = NULL;
AVCodec *video_enc = NULL;
video_enc = avcodec_find_encoder(AV_CODEC_ID_H264);
AVStream *video_st = avformat_new_stream(pOFormat video_enc);
if (!video_st)
return 0;
video_enc_ctx = video_st->codec;
video_enc_ctx->width = video_dec_ctx->width;
video_enc_ctx->height = video_dec_ctx->height;
video_enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
video_enc_ctx->time_base.num = 1;
video_enc_ctx->time_base.den = 25;
video_enc_ctx->bit_rate = video_dec_ctx->bit_rate;
video_enc_ctx->gop_size = 250;
video_enc_ctx->max_b_frames = 10;
video_enc_ctx->qmin = 10;
video_enc_ctx->qmax = 51;
if (avcodec_open2(video_enc_ctx video_enc NULL) < 0)
{
printf(“编码器打开失败!\n“);
return 0;
}
printf(“Output264video Information====================\n“);
av_dump_format(pOFormat 0 OUT_FILE 1);
printf(“Output264video Information====================\n“);
//mp4 file
AVFormatContext* pMp4Format = NULL;
AVOutputFormat* pMp4OFormat = NULL;
if (avformat_alloc_output_context2(&pMp4Format NULL NULL OUT_FMT_FILE) < 0)
{
return 0;
}
pMp4OFormat = pMp4Format->oformat;
if (avio_open(&(pMp4Format->pb) OUT_FMT_FILE AVIO_FLAG_READ_WRITE) < 0)
{
return 0;
}
for (int i = 0; i < pFormat->nb_streams; i++) {
AVStream *in_stream = pFormat->streams[i];
AVStream *out_stream = avformat_new_stream(pMp4Format in_stream->codec->codec);
if (!out_stream) {
return 0;
}
int ret = 0;
ret = avcodec_copy_context(out_stream->codec in_stream->codec);
if (ret < 0) {
fprintf(stderr “Failed to copy context from input to output stream codec context\n“);
return 0;
}
out_stream->codec->codec_tag = 0;
if (pMp4Format->oformat->flags & AVFMT_GLOBALHEADER)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5831 2016-06-25 15:25 FFMepg_to_mp4.cpp
文件 5238 2016-06-25 15:31 FFMepg_to_mp4.vcxproj
文件 1320 2016-06-25 08:25 FFMepg_to_mp4.vcxproj.filters
文件 1552 2016-06-25 08:25 ReadMe.txt
文件 219 2016-06-25 08:25 stdafx.cpp
文件 234 2016-06-25 08:25 stdafx.h
文件 236 2016-06-25 08:25 targetver.h
文件 2834432 2015-07-15 16:19 Titanic.mkv
- 上一篇:KillMBR,硬盘逻辑锁
- 下一篇:资讯网站模板
相关资源
- nginx-rtmp-win32-master.rar
- FFMEPG实现h264解码
- ffmpegh265rtmp.zip
- ffserver(windows下编译32位)
- qt_ffmpeg_mp4_export_and_import.zip
- 最简单的基于FFmpeg的推流器 1.2
- 简单的ffmpeg推流demo
- FFmpeg和SDL,读内存中的视频流,进行
- ffmpeg之pcm转AAC
- ffmpeg-2.8.14.tar.gz
- 利用ffmpeg的filter混音
- vs2010 ffmpeg实时解码h264码流
- ffmpeg 音视频转码代码
- windows上自己编译的最新的ffmpeg库
- Qt基于FFmpeg播放本地 H.264H264文件
- 从ffmpeg中抽取的h264解码器,可用于
- ffplay源代码
- 最简单的基于FFmpeg的推流器以推送R
- DVD文件VOB的生成代码
- FFmpeg 采集摄像头输出rtmp直播流媒体,
- 基于ffmpeg将avi视频转换为mp4视频
- (补充)修改output-example,将H.264AAC帧
- ffmpeg-win64位库
- X264实时编码,FFmpeg实时解码
- FFmpeg API读取视音频文件信息的一个工
- 使用FFmpeg采集摄像头图像和麦克风音
- opencv_ffmpeg249.dll
- FFmpeg-3.1 windows vs2013编译动态库静态库
- 基于FFmpeg4.0.2的AAC编码器
- FFmpeg获取网络摄像头数据解码
评论
共有 条评论