{"id":4101,"date":"2014-03-30T07:42:41","date_gmt":"2014-03-30T07:42:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/converting-mp4-to-mpeg2-ts-crashes-on-audio-packets-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:42:41","modified_gmt":"2014-03-30T07:42:41","slug":"converting-mp4-to-mpeg2-ts-crashes-on-audio-packets-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/converting-mp4-to-mpeg2-ts-crashes-on-audio-packets-collection-of-common-programming-errors\/","title":{"rendered":"Converting mp4 to mpeg2-ts crashes on audio packets-Collection of common programming errors"},"content":{"rendered":"<p>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.<\/p>\n<p>The code can be seen here: http:\/\/pastebin.com\/JVdgjM9G<\/p>\n<p>The problem is that the code chokes on audio packets. Because I am converting from h264, I have to use the &#8220;h264_mp4toannexb&#8221; which I finally got working for video frames. However, as soon as the program reaches the first audio packet (stream 1 below) it crashes.<\/p>\n<p>Sample output:<\/p>\n<pre><code>Output #0, mpegts, to 'testvideo':\n    Stream #0.0: Video: libx264, yuv420p, 1280x720, q=2-31, 1416 kb\/s, 90k tbn, 23.98 tbc\n    Stream #0.1: Audio: libfaac, 48000 Hz, stereo, 127 kb\/s\nFirst chunk: testvideo-00001.ts\nRead frame, keyframe: 1, index: 0\nDid bitfilter fun!\nRead frame, keyframe: 0, index: 0\nDid bitfilter fun!\n(...this repeats several more times, truncated for space...)\nDid bitfilter fun!\nRead frame, keyframe: 0, index: 0\nDid bitfilter fun!\nRead frame, keyframe: 1, index: 1\nbase(54516) malloc: *** error for object 0x7fd2db404520: pointer being freed was not allocated\n*** set a breakpoint in malloc_error_break to debug\nAbort trap: 6\n<\/code><\/pre>\n<p>I tried changing the code to also run the filter on the audio stream (using <code>audio_stream-&gt;codec<\/code> instead of <code>video_stream-&gt;codec<\/code>), but that simply just gives an error from the filter.<\/p>\n<p>The problem happens when I try to call <code>av_interleaved_write_frame(output_context, &amp;packet);<\/code>&#8211; 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;h264_mp4toannexb&#8221; which I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4101","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4101"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4101\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}