在尝试在 Windows 上使用 x264 编码器构建 ffmpeg 静态库时花费了相当长的时间后,我花了更多时间用它编写一些示例。 当然,有大量关于如何构建、如何使用等等的“说明”……但是,没有一个适用于 Windows。我想 Linux 的家伙在这里处于更好的位置。现在,亿万美元的问题是“这一切的目的是什么?”。不仅这在 Windows 上毫无用处,而且我本可以购买一些实际可用的第三方库。
如果有人要说“但是,它有效!”。我必须说,给我一个工作证明。我不关心 10fps 的 200x100。我不需要 H264。演示如何压缩一秒钟的 1080i 素材。它是 H264,它是跨平台的(如果你问我,这听起来很有趣),谷歌正在使用它(它必须是完美的,对吧?),这里更时髦......
最佳答案
首先不要尝试在 Windows 上构建 - 特别是如果你使用 VS - 从 here 获取它
那么顺序是这样的:
// in ctor
ffmpeg::avcodec_register_all();
ffmpeg::avcodec_init();
ffmpeg::av_register_all();
bool createFile(const String &fileName,unsigned int width,unsigned int height,unsigned int fps)
{
close();
pFormatCtx=ffmpeg::avformat_alloc_context();
if(!pFormatCtx)
{
printf("Error allocating format context\n");
return false;
}
pOutputFormat = ffmpeg::av_guess_format( "mp4", filename,NULL);
pFormatCtx->oformat = pOutputFormat;
_snprintf(pFormatCtx->filename, sizeof(pFormatCtx->filename), "%s",filename);
// Add the video stream
pVideoStream = av_new_stream(pFormatCtx,0);
if(!pVideoStream )
{
printf("Could not allocate stream\n");
return false;
}
pCodecCtx=pVideoStream->codec;
pCodecCtx->codec_id = pOutputFormat->video_codec;
pCodecCtx->codec_type = ffmpeg::AVMEDIA_TYPE_VIDEO;
pCodecCtx->width = Width = width;
pCodecCtx->height = Height = height;
pCodecCtx->time_base.num = 1;
pCodecCtx->time_base.den = Fps = fps;
pCodecCtx->pix_fmt = ffmpeg::PIX_FMT_YUV420P;
// needed for x264 to work
pCodecCtx->me_range = 16;
pCodecCtx->max_qdiff = 4;
pCodecCtx->qmin = 10;
pCodecCtx->qmax = 51;
pCodecCtx->qcompress = 0.6;
pCodecCtx->gop_size = 12;
avcodec_thread_init(pCodecCtx, 10);
// some formats want stream headers to be separate
if(pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
pCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;
if (av_set_parameters(pFormatCtx, NULL) < 0)
{
printf("Invalid output format parameters\n");
return false;
}
ffmpeg::dump_format(pFormatCtx, 0, pFormatCtx->filename, 1);
// open_video
// find the video encoder
pCodec = avcodec_find_encoder(pCodecCtx->codec_id);
if (!pCodec)
{
printf("codec not found\n");
return false;
}
// open the codec
if (avcodec_open(pCodecCtx, pCodec) < 0)
{
printf("could not open codec\n");
return false;
}
// Allocate memory for output
if(!initOutputBuf())
{
printf("Can't allocate memory for output bitstream\n");
return false;
}
// Allocate the YUV frame
if(!initFrame())
{
printf("Can't init frame\n");
return false;
}
if (url_fopen(&pFormatCtx->pb,pFormatCtx->filename, URL_WRONLY) < 0)
{
printf( "Could not open '%s'\n", pFormatCtx->filename);
return false;
}
av_write_header(pFormatCtx);
return true;
}
然后对于每一帧
int encodeImage(const QImage &img)
{
if (!convertImage_sws(img)) { // SWS conversion
return false;
}
ppicture->pts=pCodecCtx->frame_number;
//memset(outbuf,0,outbuf_size);
int out_size = ffmpeg::avcodec_encode_video(pCodecCtx,outbuf,outbuf_size,ppicture);
if (out_size > 0) {
ffmpeg::AVPacket pkt;
av_init_packet(&pkt);
if (pCodecCtx->coded_frame->pts != (0x8000000000000000LL))
pkt.pts= av_rescale_q(pCodecCtx->coded_frame->pts, pCodecCtx->time_base, pVideoStream->time_base);
if(pCodecCtx->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index= pVideoStream->index;
pkt.data= outbuf;
pkt.size= out_size;
if (av_write_frame(pFormatCtx, &pkt) < 0 ) {
return 0;
}
}
return out_size;
}
void close()
{
av_write_trailer(pFormatCtx);
// close_video
avcodec_close(pVideoStream->codec);
freeFrame();
freeOutputBuf();
/* free the streams */
for(int i = 0; i < pFormatCtx->nb_streams; i++)
{
av_freep(&pFormatCtx->streams[i]->codec);
av_freep(&pFormatCtx->streams[i]);
}
// Close file
url_fclose(pFormatCtx->pb);
// Free the stream
av_free(pFormatCtx);
}
bool initFrame()
{
ppicture = ffmpeg::avcodec_alloc_frame();
if(ppicture==0)
return false;
int size = avpicture_get_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
picture_buf = new uint8_t[size];
if(picture_buf==0)
{
av_free(ppicture);
ppicture=0;
return false;
}
// Setup the planes
avpicture_fill((ffmpeg::AVPicture *)ppicture, picture_buf,pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
ppicture->pts = 0;
return true;
}
关于windows - x264 和 libavcodec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8452985/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m
深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal
我在目录“C:\DocumentsandSettings\test.exe”中有一个文件,但是当我用单引号编写命令时`C:\DocumentsandSettings\test.exe(我无法在此框中显示),用于在Ruby中执行命令,我无法这样做,我收到的错误是找不到文件或目录。我尝试用“//”和“\”替换“\”,但似乎没有任何效果。我也使用过系统、IO.popen和exec命令,但所有的努力都是徒劳的。exec命令还使程序退出,这是我不想发生的。提前致谢。 最佳答案 反引号环境就像双引号,所以反斜杠用于转义。此外,Ruby会将空格解
我在安装“redcarpet”gem时遇到以下错误。它在我friend的机器上安装没有问题。(我想安装它来运行yard)ruby版本:1.9.3命令输出:D:\Learning\Common_POM_FW\SampleProjects>yard[error]:Missing'redcarpet'gemforMarkdownformatting.Installitwith`geminstallredcarpet`D:\Learning\Common_POM_FW\SampleProjects>geminstallredcarpetTemporarilyenhancingPATHtoinc
我们正在开发一个需要推送通知的WP8应用程序。为了测试它,我们使用CURL命令行运行推送通知POST请求,确保它实际连接,使用客户端SSL证书进行身份验证并发送正确的数据。我们确实知道,当我们收到对设备的推送时,这项工作是有效的。这是我们一直用于测试目的的CURL命令:curl--certclient_cert.pem-v-H"Content-Type:text/xml"-H"X-WindowsPhone-Target:Toast"-H"X-NotificationClass:2"-XPOST-d"MytitleMysubtitle"https://db3.notify.live.ne
我在Windows7上运行Jekyll时遇到问题。当我运行时jekyll出现以下错误C:\temp\jekyll\kouphax.github.com>jekyllConfigurationfromC:/temp/jekyll/kouphax.github.com/_config.ymlBuildingsite:C:/temp/jekyll/kouphax.github.com->C:/temp/jekyll/kouphax.github.com/_siteunit-testingYouaremissingalibraryrequiredforTextile.Pleaserun:$[s
我正在尝试使用本手册让Jekyll在Windows8x64上运行:RunningJekyllonWindows我正在使用来自rubyinstaller.org的以下两个下载:ruby2.0.0-p0(x64)DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe所以我根据手册设置了Ruby和DevKit(希望它是更新的版本)。我尝试运行一点HelloWorld.rb脚本,它工作正常,路径变量已设置。然后我尝试运行geminstalljekyll并得到以下输出:geminstalljekyll-outputonpastebin.com问题似乎出在名为f
在Windows上通过ruby2.0.0安装iconv时出错通过ruby2.0.0在Windows上安装iconv时出错我正在尝试安装iconv,但是当我运行以下命令时:geminstalliconv我的结果:TemporarilyenhancingPathtoincludeDevKit...Buildingnativeextensions.Thiscouldtakeawhile...Error:Errorinstallingiconv:ERROR:Failedtobuildgemnativeextension.C:/Ruby/Ruby200/bin/ruby.exe-r./s