Please avoid top posting on this list. On Wed, 2010-01-06 at 23:05 -0800, dmanpearl wrote: > 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. >
Very strange indeed. Might just be the way the source file is though. I'm not qutie sure how to solve this. Try generating your own time stamps, either just using one int for each stream and incrementing each by one once such a packet is output (so you get monotone, but not very correct timestamps). Another way would be to generate more correct time stamps. This involves, for both streams, in the codec's time base, an increase by one (for video) or frame_size (for audio) for the respective counter. You have to convert those values (since they're in their codecs' time bases) to their output stream time bases (outputFormatContext->streams[stream_index]->time_base) since the muxer might impose certain limits (like FLV having a fixed 1 kHz stream time base). Use av_rescale_q() for this. ffmpeg.c has some examples of such scaling. Also, try changing video encoder and output format and see what that does. An intra-only codec like MJPEG might work better (although much larger files). > 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? > Your alternative is only valid if you're using the same output format as the input. An example from my code: stream->codec->codec_tag = av_codec_get_tag(outputFormatContext->oformat->codec_tag, codec->id); Just replace codec->id with whichever CODEC_ID_* you're using. > Finally, after the while loop, the function for writing the trailer is > always crashing with a BUS ERROR. > > av_write_trailer(oc); Try debugging your program (and thus the libraries) using gdb. I think BUS ERROR is usually due to alignment errors. Make sure all of your memory allocations are done using av_malloc() instead of malloc() - the former guarantees proper alignment. Finally, try using the latest subversion revision /Tomas > > - 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 > > > _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
