Hi David,
David REGADE wrote:
Hi,
x264 is installed on my system. If I use output_example like that it works fine
but without the good container:
Try the attached patch: it should fix the problem.
I do not know if the problem is in output_example (well, it contains at least a
bug or two...) or in the mov muxer... I am going to check on ffmpeg-devel.
Luca
diff --git a/output_example.c b/output_example.c
index 515a172..65e09d0 100644
--- a/output_example.c
+++ b/output_example.c
@@ -156,7 +156,8 @@ static void write_audio_frame(AVFormatContext *oc, AVStream
*st)
pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size,
samples);
- pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
+ if (c->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base,
st->time_base);
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= st->index;
pkt.data= audio_outbuf;
@@ -269,18 +270,6 @@ static void open_video(AVFormatContext *oc, AVStream *st)
exit(1);
}
- video_outbuf = NULL;
- if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
- /* allocate output buffer */
- /* XXX: API change will be done */
- /* buffers passed into lav* can be allocated any way you prefer,
- as long as they're aligned enough for the architecture, and
- they're freed appropriately (such as using av_free for buffers
- allocated with av_malloc) */
- video_outbuf_size = 200000;
- video_outbuf = av_malloc(video_outbuf_size);
- }
-
/* allocate the encoded raw picture */
picture = alloc_picture(c->pix_fmt, c->width, c->height);
if (!picture) {
@@ -373,6 +362,16 @@ static void write_video_frame(AVFormatContext *oc,
AVStream *st)
ret = av_write_frame(oc, &pkt);
} else {
+ video_outbuf = NULL;
+ /* allocate output buffer */
+ /* XXX: API change will be done */
+ /* buffers passed into lav* can be allocated any way you prefer,
+ as long as they're aligned enough for the architecture, and
+ they're freed appropriately (such as using av_free for buffers
+ allocated with av_malloc) */
+ video_outbuf_size = 200000;
+ video_outbuf = av_malloc(video_outbuf_size);
+
/* encode the image */
out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size,
picture);
/* if zero size, it means the image was buffered */
@@ -380,7 +379,8 @@ static void write_video_frame(AVFormatContext *oc, AVStream
*st)
AVPacket pkt;
av_init_packet(&pkt);
- pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base,
st->time_base);
+ if (c->coded_frame->pts != AV_NOPTS_VALUE)
+ pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base,
st->time_base);
if(c->coded_frame->key_frame)
pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= st->index;
@@ -389,6 +389,7 @@ static void write_video_frame(AVFormatContext *oc, AVStream
*st)
/* write the compressed frame in the media file */
ret = av_write_frame(oc, &pkt);
+ av_free(pkt.data);
} else {
ret = 0;
}
@@ -409,7 +410,7 @@ static void close_video(AVFormatContext *oc, AVStream *st)
av_free(tmp_picture->data[0]);
av_free(tmp_picture);
}
- av_free(video_outbuf);
+// av_free(video_outbuf);
}
/**************************************************************/
@@ -463,9 +464,11 @@ int main(int argc, char **argv)
and initialize the codecs */
video_st = NULL;
audio_st = NULL;
+fmt->video_codec = CODEC_ID_H264;
if (fmt->video_codec != CODEC_ID_NONE) {
video_st = add_video_stream(oc, fmt->video_codec);
}
+fmt->audio_codec = CODEC_ID_NONE;
if (fmt->audio_codec != CODEC_ID_NONE) {
audio_st = add_audio_stream(oc, fmt->audio_codec);
}
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user