采用 gdb研究函数调用关系,要特别注意断点下的位置,do_video_out是一个关键函数,
在avcodec_encode_video2函数处下断点,可以了解x264编码细节;另外,例如:libavformat/mux.c如下代码:
***1 去理解flv输出细节,
***2 去理解rtmp封包。
-
if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
-
AVFrame *frame = (AVFrame *)pkt->data;
-
av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE);
-
ret = s->oformat->write_uncoded_frame(s, pkt->stream_index, &frame, 0);
-
av_frame_free(&frame);
-
} else {
-
***1 ret = s->oformat->write_packet(s, pkt);
-
}
-
-
if (s->flush_packets && s->pb && ret >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
-
***2 avio_flush(s->pb);
函数调用堆栈:
-
(gdb) bt
-
#0 tcp_write (h=0x663e80, buf=0xca56e0 "g/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro"..., size=128) at libavformat/tcp.c:182
-
#1 0x00007ffff763ce7d in retry_transfer_wrapper (h=0x663e80, buf=0xca56e0 "g/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro"..., size=128, size_min=128, transfer_func=0x7ffff776b00c <tcp_write>) at libavformat/avio.c:303
-
#2 0x00007ffff763d079 in ffurl_write (h=0x663e80, buf=0xca56e0 "g/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro"..., size=128) at libavformat/avio.c:352
-
#3 0x00007ffff7722a7c in ff_rtmp_packet_write (h=0x663e80, pkt=0x6616f8, chunk_size=128, prev_pkt_ptr=0x661698, nb_prev_pkt=0x6616a4) at libavformat/rtmppkt.c:382
-
#4 0x00007ffff772405b in rtmp_send_packet (rt=0x661680, pkt=0x6616f8, track=0) at libavformat/rtmpproto.c:247
-
#5 0x00007ffff772cfbb in rtmp_write (s=0x664040, buf=0x6658c0 "\t", size=20444) at libavformat/rtmpproto.c:3048
-
#6 0x00007ffff763ce7d in retry_transfer_wrapper (h=0x664040, buf=0x6658c0 "\t", size=20444, size_min=20444, transfer_func=0x7ffff772c86f <rtmp_write>) at libavformat/avio.c:303
-
#7 0x00007ffff763d079 in ffurl_write (h=0x664040, buf=0x6658c0 "\t", size=20444) at libavformat/avio.c:352
-
#8 0x00007ffff763d74c in writeout (s=0x663f20, data=0x6658c0 "\t", len=20444) at libavformat/aviobuf.c:131
-
#9 0x00007ffff763d7fb in flush_buffer (s=0x663f20) at libavformat/aviobuf.c:143
-
#10 0x00007ffff763da7b in avio_flush (s=0x663f20) at libavformat/aviobuf.c:199
-
#11 0x00007ffff76e6be9 in write_packet (s=0x65fbe0, pkt=0x7fffffffd880) at libavformat/mux.c:603
-
#12 0x00007ffff76e7c77 in av_interleaved_write_frame (s=0x65fbe0, pkt=0x0) at libavformat/mux.c:907
-
#13 0x000000000041fae8 in write_frame (s=0x65fbe0, pkt=0x7fffffffdb70, ost=0x660a40) at ffmpeg.c:718
-
#14 0x00000000004217f1 in do_video_out (s=0x65fbe0, ost=0x660a40, next_picture=0xb8b680) at ffmpeg.c:1127
-
#15 0x000000000042209d in reap_filters () at ffmpeg.c:1273
-
#16 0x000000000042ce4c in transcode_step () at ffmpeg.c:3744
-
#17 0x000000000042cf05 in transcode () at ffmpeg.c:3787
-
#18 0x000000000042d443 in main (argc=18, argv=0x7fffffffe058) at ffmpeg.c:3964
调用循环,另外的堆栈:
-
(gdb) bt
-
#0 tcp_write (h=0x663e80, buf=0x7fffffffd337 "\306L\323\377\377\377\177", size=1) at libavformat/tcp.c:182
-
#1 0x00007ffff763ce7d in retry_transfer_wrapper (h=0x663e80, buf=0x7fffffffd337 "\306L\323\377\377\377\177", size=1, size_min=1, transfer_func=0x7ffff776b00c <tcp_write>) at libavformat/avio.c:303
-
#2 0x00007ffff763d079 in ffurl_write (h=0x663e80, buf=0x7fffffffd337 "\306L\323\377\377\377\177", size=1) at libavformat/avio.c:352
-
#3 0x00007ffff7722ae4 in ff_rtmp_packet_write (h=0x663e80, pkt=0x6616f8, chunk_size=128, prev_pkt_ptr=0x661698, nb_prev_pkt=0x6616a4) at libavformat/rtmppkt.c:387
-
#4 0x00007ffff772405b in rtmp_send_packet (rt=0x661680, pkt=0x6616f8, track=0) at libavformat/rtmpproto.c:247
-
#5 0x00007ffff772cfbb in rtmp_write (s=0x664040, buf=0x6658c0 "\t", size=20444) at libavformat/rtmpproto.c:3048
-
#6 0x00007ffff763ce7d in retry_transfer_wrapper (h=0x664040, buf=0x6658c0 "\t", size=20444, size_min=20444, transfer_func=0x7ffff772c86f <rtmp_write>) at libavformat/avio.c:303
-
#7 0x00007ffff763d079 in ffurl_write (h=0x664040, buf=0x6658c0 "\t", size=20444) at libavformat/avio.c:352
-
#8 0x00007ffff763d74c in writeout (s=0x663f20, data=0x6658c0 "\t", len=20444) at libavformat/aviobuf.c:131
-
#9 0x00007ffff763d7fb in flush_buffer (s=0x663f20) at libavformat/aviobuf.c:143
-
#10 0x00007ffff763da7b in avio_flush (s=0x663f20) at libavformat/aviobuf.c:199
-
#11 0x00007ffff76e6be9 in write_packet (s=0x65fbe0, pkt=0x7fffffffd880) at libavformat/mux.c:603
-
#12 0x00007ffff76e7c77 in av_interleaved_write_frame (s=0x65fbe0, pkt=0x0) at libavformat/mux.c:907
-
#13 0x000000000041fae8 in write_frame (s=0x65fbe0, pkt=0x7fffffffdb70, ost=0x660a40) at ffmpeg.c:718
-
#14 0x00000000004217f1 in do_video_out (s=0x65fbe0, ost=0x660a40, next_picture=0xb8b680) at ffmpeg.c:1127
-
#15 0x000000000042209d in reap_filters () at ffmpeg.c:1273
-
#16 0x000000000042ce4c in transcode_step () at ffmpeg.c:3744
-
#17 0x000000000042cf05 in transcode () at ffmpeg.c:3787
-
#18 0x000000000042d443 in main (argc=18, argv=0x7fffffffe058) at ffmpeg.c:3964
阅读(6831) | 评论(0) | 转发(0) |