相关疑难解决方法(0)

使用libavcodec将音频编码到aac

我正在使用libavcodec(截至3/3/10的最新git)将原始pcm编码为aac(启用了libfaac支持).我通过每次使用codec_context-> frame_size样本重复调用avcodec_encode_audio来完成此操作.前四个调用成功返回,但第五个调用永远不会返回.当我使用gdb中断时,堆栈已损坏.

如果我使用audacity将pcm数据导出到.wav文件,那么我可以使用命令行ffmpeg转换为aac而没有任何问题,所以我确定这是我做错了.

我写了一个小的测试程序来复制我的问题.它从文件中读取测试数据,可在此处获取:http: //birdie.protoven.com/audio.pcm(签名16位LE pcm约2秒)

如果我直接使用FAAC,我可以完成所有工作,但如果我可以使用libavcodec,那么代码会更清晰一些,因为我也编码视频,并将两者写入mp4.

ffmpeg版本信息:

FFmpeg version git-c280040, Copyright (c) 2000-2010 the FFmpeg developers
  built on Mar  3 2010 15:40:46 with gcc 4.4.1
  configuration: --enable-libfaac --enable-gpl --enable-nonfree --enable-version3 --enable-postproc --enable-pthreads --enable-debug=3 --enable-shared
  libavutil     50.10. 0 / 50.10. 0
  libavcodec    52.55. 0 / 52.55. 0
  libavformat   52.54. 0 / 52.54. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Run Code Online (Sandbox Code Playgroud)

有没有我没有设置的东西,或者在我的编解码器环境中设置不正确,也许?任何帮助是极大的赞赏!

这是我的测试代码: …

c audio ffmpeg aac libavcodec

13
推荐指数
1
解决办法
2万
查看次数

FFmpeg如何将视频写入文件

我想要的是

 1. Get video packet from stream source
 2. Decode it
 3. And write  that decoded data as video file(avi, mpeg etc)
Run Code Online (Sandbox Code Playgroud)

我可以从文件中获取视频数据包(如AVPacket),也可以解码并保存为图像.(原始)(FFmpeg教程显示如何操作). 但我不能(不知道)将视频数据写入可由媒体播放器(如VLC)播放的文件(其他).

最好的祝愿

Ps:如果可能的话,真正的代码样本会很棒......

现在我用av_interleaved_write进行测试, 但我得到了奇怪的错误"非单调时间戳"(我无法控制媒体源的pts值)

一些额外的信息

在FFmpeg,我必须

  1. 从媒体源读取媒体数据包(可能是真实文件(.avi,mov)甚至是rtsp服务器).
  2. 然后将这些媒体数据包写入真实文件(物理.avi,.mov等文件)

我需要读者和作家.我可以读取媒体源文件(甚至根据给定的格式对数据包进行编码).但是我不能写文件......(任何玩家都可以玩)

还有一些伪代码

File myFile("MyTestFile.avi");

while ( source ->hasVideoPackets)
{
     packet = source->GetNextVideoPacket();
     Frame decodedFrame = Decode(packet);
     VideoPacket encodedPacket = Encode( decodedFrame);
     myFile.WriteFile(encodedPacket);
 }
Run Code Online (Sandbox Code Playgroud)

或者只是编写没有编码解码的原始文件

     File myFile("MyTestFile.avi");

     while ( source ->hasVideoPackets)
     {
         packet = source->GetNextVideoPacket();
         myFile.WriteFile(packet);
     }
Run Code Online (Sandbox Code Playgroud)

然后

I can able to …
Run Code Online (Sandbox Code Playgroud)

c ffmpeg

13
推荐指数
1
解决办法
2万
查看次数

从可打开的URI将本机fd int传递给FFMPEG

我试图CATEGORY_OPENABLE从存储访问框架的URI中打开文件描述符.我首先尝试使用sdcard上的文件,我已经可以使用该_data列解析到文件路径并打开(我正在尝试远离这样做,而是使用文件描述符).

我得到了这样的native int fd:

int fd = getContentResolver().openFileDescriptor(data.getData(), "r").detachFd();
Run Code Online (Sandbox Code Playgroud)

然后在C++中,我试图像这样打开它,这个想法取自如何在Android中使用JNI将资产FileDescriptor正确传递给FFmpeg:

pFormatCtx = avformat_alloc_context();
pFormatCtx->iformat = av_find_input_format("mp3");

char path[50];
sprintf(path, "pipe:%d", fd);

int e;
if(e=(avformat_open_input(&pFormatCtx,path,NULL,NULL)!=0)){
    av_strerror(e, path, 50);
    return error;
}
Run Code Online (Sandbox Code Playgroud)

这会产生"未知错误" avformat_open_input.如果我使用jniGetFDFromFileDescriptor上面链接的jni方法FileDescriptor来获取int fd,则会发生同样的事情.如何在不使用文件路径的情况下正确打开带有FFMPEG的可打开URI?

android ffmpeg storage-access-framework

8
推荐指数
1
解决办法
655
查看次数

标签 统计

ffmpeg ×3

c ×2

aac ×1

android ×1

audio ×1

libavcodec ×1

storage-access-framework ×1