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.
> 

Hi

It seems you've posted the same question in two threads, so I'll respond
to this one since it's the most recent. Since 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

Reply via email to