I have written some C code that takes an mp4 file with h264-encoded video and AAC-encoded audio and writes it to segmented .ts files.
The code can be seen here: http://pastebin.com/JVdgjM9G
The problem is that the code chokes on audio packets. Because I am converting from h264, I have to use the "h264_mp4toannexb" which I finally got working for video frames. However, as soon as the program reaches the first audio packet (stream 1 below) it crashes.
Sample output:
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
I tried changing the code to also run the filter on the audio stream (using audio_stream->codec
instead of video_stream->codec
), but that simply just gives an error from the filter.
The problem happens when I try to call av_interleaved_write_frame(output_context, &packet);
- for the filtered video packets, there is no problem but the audio packet it completely chokes on. I am kind of stumped on why though, so any help is appreciated.
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!