0

我已经编写了一些 C 代码,它采用带有 h264 编码视频和 AAC 编码音频的 mp4 文件并将其写入分段的 .ts 文件。

代码可以在这里看到:http: //pastebin.com/JVdgjM9G

问题是代码在音频数据包上阻塞。因为我是从 h264 转换的,所以我必须使用我最终为视频帧工作的“h264_mp4toannexb”。但是,一旦程序到达第一个音频包(下面的流 1),它就会崩溃。

样本输出:

Output #0, mpegts, to 'testvideo':
    Stream #0.0: Video: libx264, yuv420p, 1280x720, q=2-31, 1416 kb/s, 90k tbn, 23.98 tbc
    Stream #0.1: Audio: libfaac, 48000 Hz, stereo, 127 kb/s
First chunk: testvideo-00001.ts
Read frame, keyframe: 1, index: 0
Did bitfilter fun!
Read frame, keyframe: 0, index: 0
Did bitfilter fun!
(...this repeats several more times, truncated for space...)
Did bitfilter fun!
Read frame, keyframe: 0, index: 0
Did bitfilter fun!
Read frame, keyframe: 1, index: 1
base(54516) malloc: *** error for object 0x7fd2db404520: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

我尝试更改代码以也在音频流上运行过滤器(使用audio_stream->codec而不是video_stream->codec),但这只是从过滤器中给出错误。

当我尝试调用时出现问题av_interleaved_write_frame(output_context, &packet);- 对于过滤后的视频数据包,没有问题,但它完全阻塞了音频数据包。不过,我有点困惑为什么,所以任何帮助表示赞赏。

4

1 回答 1

0

It turns out the av_free_packet call after the bitfilter manipulation was actually releasing the video packets. Removing that call caused the code to run correctly!

于 2013-06-13T08:58:43.560 回答