我正在尝试使用C++中的FFMPEG API将原始H264编码为mp4容器.一切正常,但AVCC框为空,它返回错误:[iso file]框"avcC"大小8无效
如果我然后在输出文件上使用命令行工具:ffmpeg -i output.mp4 -vcodec copy fixed.mp4
输出文件有效,AVCC填充了所需的信息.我不知道为什么这个命令行参数有效,但是我无法使用API产生相同的结果.
我在C++代码中做了什么(也在函数调用之间做了一些事情):
outputFormat_ = av_guess_format( "mp4", NULL, NULL ); //AV_CODEC_H264
formatContext_ = avformat_alloc_context();
formatContext_->oformat = outputFormat_;
...
AVDictionary *opts = NULL;
char tmpstr[50]; sprintf(tmpstr, "%i", muxRate * KILOBYTESTOBYTES);
av_dict_set(&opts, "muxrate", tmpstr, 0);
avformat_write_header( formatContext_, &opts);
av_write_trailer(formatContext_);
Run Code Online (Sandbox Code Playgroud)
输出是正确的,除了它缺少AVCC信息.手动添加它(并相应地固定盒子长度)让我可以正常播放视频.知道为什么API调用没有生成AVCC信息?
作为参考,这里是修复前mp4的字符:.avc1 ...........................8.H ... H. ......................................... YY .... AVCC ... .stts
之后:avc1 .........................€.8.H ...... H ............ .............................. YY ...!avcC.B€(ÿá..gB€(Ú.à. - ...•你好<€.... STTS
我正在用Android/OpenGL编写一个游戏,并试图将我的OpenGL(渲染)逻辑与我的游戏更新逻辑分开,方法是在自己的线程上运行每个逻辑以提高性能.
我设法让每个都在自己的线程上运行,但是根据DDMS中的Tracer,线程仍在顺序运行(世界是我的游戏更新线程):
请参阅url,因为我没有图像权限:http: //img849.imageshack.us/img849/9688/capturegff.png
线程似乎不会同时执行代码.我初始化世界线程如下:
public class World implements Runnable {
Thread thread;
public World(...) {
...
// Initialise the player/ball objects
initialiseObjects();
thread = new Thread(this, "World");
thread.start();
}
}
Run Code Online (Sandbox Code Playgroud)
我在两个线程之间实现了自己的同步.使用类似于Replica Island的方法,我有两个渲染缓冲区:当渲染线程正在读取另一个缓冲区时,更新线程(理想情况下应该)写入其中一个缓冲区.缓冲区包含渲染器绘制每个精灵所需的信息.一旦更新线程完成更新其缓冲区并且渲染器已完成绘制,它们将交换缓冲区并重复该过程.
在游戏更新线程的代码中(渲染线程中的类似代码):
currBuffer.write();
player.draw(currBuffer.getNext());
ball.draw(currBuffer.getNext());
if (particleEffect != null) {
particleEffect.draw(currBuffer);
}
currBuffer.finished();
while(otherBuffer.isFinished() == false) {
//otherBuffer is finished once the render thread has finished drawing
}
DrawBuffer tempBuffer = currBuffer;
currBuffer = otherBuffer;
otherBuffer = tempBuffer;
currBuffer.changed();
while(otherBuffer.isChanged() == false) {
//otherBuffer is changed …Run Code Online (Sandbox Code Playgroud)