diff --git a/muxer.cpp b/muxer.cpp index 655c8e6..892b407 100644 --- a/muxer.cpp +++ b/muxer.cpp @@ -6,6 +6,9 @@ extern "C" { } #include +#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22) +#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER + namespace jt { @@ -23,8 +26,7 @@ std::string FFmpegErrorString(int code) { Muxer::Muxer(const std::string &format, const std::string &output_file) noexcept - :output_file_(output_file), output_format_(format) { - av_register_all(); + :output_format_(format), output_file_(output_file) { avformat_network_init(); interrupt_cb_.reset(new AVIOInterruptCB); interrupt_cb_->callback = InterruptCallBack; @@ -108,7 +110,7 @@ bool Muxer::AddVideoStream(int width, } AVCodecContext *vCodecContext = video_stream_->codec; - vCodecContext->pix_fmt = PIX_FMT_YUV420P; + vCodecContext->pix_fmt = AV_PIX_FMT_YUV420P; vCodecContext->width = width; vCodecContext->height = height; vCodecContext->codec_type = AVMEDIA_TYPE_VIDEO; diff --git a/test.cpp b/test.cpp index 91f3613..939acb0 100644 --- a/test.cpp +++ b/test.cpp @@ -10,13 +10,12 @@ extern "C" { #include #include -#include "muxer/muxer.h" +#include "muxer.h" int main(int argc, char* argv[]) { AVFormatContext *ifmt_ctx = NULL; - const char *in_filename = "/Users/jerett/Desktop/shenda1.mp4";//Input file URL + const char *in_filename = "./test.mp4";//Input file URL - av_register_all(); int ret = 0; //Input if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) { @@ -28,7 +27,7 @@ int main(int argc, char* argv[]) { return -1; } - jt::Muxer muxer("mp4", "/Users/jerett/Desktop/out.mp4"); + jt::Muxer muxer("mp4", "out.mp4"); std::map options; muxer.Open(options); @@ -79,7 +78,7 @@ int main(int argc, char* argv[]) { double timestamp = pkt.pts * av_q2d(read_stream->time_base) * 1000; muxer.WriteAAC(pkt.data, pkt.size, timestamp); } - av_free_packet(&pkt); + av_packet_unref(&pkt); } if (ret < 0 && ret != AVERROR_EOF) {