Tomas, Thank you for your help. I think I am very close to a solution, but I am having difficulty with the timestamps, as you warned at the bottom of your response. It seems that depending on the values of 'pts' and 'dts' that I set, I receive the following error in my call to av_interleaved_write_frame for either the audio packets or the following video packets.
[mpeg4 @ 0x1826a00]error, non monotone timestamps 23552 >= -100 I do not understand the relationships between pts and dts for video and audio in adjacent streams, as they don't seem to track. For example, I log the following values of the packet parameters for the input stream. The "monotone timestamps" error occurs during processing of the first video packet following the audio packets. ... AVPacket: flags 0x1, size 474, data 0x1211e70, pts 21504, dts 21504, pos 10466, duration 1024, stream index 0 AVPacket: flags 0x1, size 471, data 0x12120a0, pts 22528, dts 22528, pos 10940, duration 1024, stream index 0 AVPacket: flags 0x1, size 478, data 0x12122c0, pts 23552, dts 23552, pos 11411, duration 1024, stream index 0 AVPacket: flags 0x1, size 57523, data 0x11dd000, pts 0, dts -100, pos 11889, duration 0, stream index 1 In this version of the software, I am copying the input stream values of pts and dts to the corresponding output values. I do not understand why a video frame would have dts=-100. I tried setting all pts/dts values to AV_NOPTS_VALUE. I also tried the same thing for just the audio and for just the video. These changes did not seem to significantly affect the output. All of your assumptions about what I was already doing, below, were correct. I did not figure out how to use av_codec_get_tag(). Do you have an example? Instead, I copied the value of codec_tag from the input stream codec to the output. Is my alternative valid? Finally, after the while loop, the function for writing the trailer is always crashing with a BUS ERROR. av_write_trailer(oc); - Thank you, David Tomas Härdin wrote: > > On Mon, 2010-01-04 at 23:12 -0800, dmanpearl wrote: >> Hello, >> I am using libffmpeg to open a video file, modify individual image frames >> as >> they are read, and then write them into an output video file along with >> unmodified audio packets. >> Using ImageMagick Magick++ library I am able to modify the image frames. >> With audio disabled, I can recreate a valid output video file. >> I have been unable to decode the audio stream because of a codec problem >> I >> am having with AAC, however, I really want to stay away from a solution >> that >> involves decoding audio. >> >> Please help me copy the raw audio packets from the input stream to the >> output stream. > > Tomas Mardin wrote: > I quite recently fixed > some similar problems I had with (re)muxing I'll present some of my > findings. Hopefully they'll be of some use. > > I'll assume you've created a new AVStream* in the muxer for the audio > using av_new_stream(). We'll call this stream "stream". First default > the values in stream->codec thusly: > > avcodec_get_context_defaults(stream->codec); > > Next, set the following fields: > > * stream->codec->flags (CODEC_FLAG_GLOBAL_HEADER if ofmt->flags & > AVFMT_GLOBALHEADER) > * stream->codec->codec_id > * stream->codec->codec_tag (derive using av_codec_get_tag()) > * stream->codec->codec_type > * stream->codec->extradata_size (copy from corresponding stream in the > demuxer) > * stream->codec->extradata (copy from corresponding stream in the > demuxer) > > For audio, additionally make sure the following are set (using the same > values as the audio stream in the muxer should work): > > * stream->codec->sample_fmt > * stream->codec->sample_rate > * stream->codec->channels > * stream->codec->frame_size > * stream->codec->block_align > > For completeness (in case someone else stumbles upon this post) I'll > list what is needed to mux video: > > * stream->codec->width > * stream->codec->height > * stream->codec->pix_fmt > * stream->codec->time_base > > There are probably more fields that needs to be set for various special > cases, but these seem to do the trick in all cases I test for or have > encountered. > > Once set up, simply pass that packets you get from av_read_frame() to > the muxer using av_interleave_frame() as I assume you already do with > video. If it nags about timestamps try setting packet.pts = packet.dts = > AV_NOPTS_VALUE. That seems cause them to be generated instead. > > Finally, poking around in ffmpeg.c usually sheds light on things. In > this case searching for "copy" should help. > Good luck > /Tomas > -- View this message in context: http://n4.nabble.com/How-To-Copy-Raw-Audio-Packets-from-Input-to-Output-Stream-tp998866p1008633.html Sent from the libav-users mailing list archive at Nabble.com. _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
