44
55#include < jni.h>
66#include < string>
7- #include < android/log.h>
87#include " ffmpeg_jni_define.h"
98
109#define TAG " FFmpegPusher"
@@ -19,7 +18,6 @@ extern "C" {
1918
2019PUSHER_FUNC (jint, pushStream, jstring filePath, jstring liveUrl) {
2120
22- AVOutputFormat *output_format = NULL ;
2321 AVFormatContext *in_format = NULL , *out_format = NULL ;
2422 AVPacket packet;
2523 const char *file_path, *live_url;
@@ -77,8 +75,8 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
7775// out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
7876 }
7977 }
80- output_format = out_format-> oformat ;
81- if (!(output_format ->flags & AVFMT_NOFILE )) {
78+
79+ if (!(out_format-> oformat ->flags & AVFMT_NOFILE )) {
8280 ret = avio_open (&out_format->pb , live_url, AVIO_FLAG_WRITE );
8381 if (ret < 0 ) {
8482 LOGE (TAG , " could not open output url '%s'" , live_url);
@@ -98,7 +96,7 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
9896 if (ret < 0 ) {
9997 break ;
10098 }
101- // 计算帧间隔,参考时钟/采样率
99+ // calculate pts and dts
102100 if (packet.pts == AV_NOPTS_VALUE ) {
103101 AVRational time_base = in_format->streams [video_index]->time_base ;
104102 int64_t cal_duration = (int64_t ) (AV_TIME_BASE /
@@ -123,9 +121,9 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
123121
124122 // pts to dts
125123 packet.pts = av_rescale_q_rnd (packet.pts , in_stream->time_base , out_stream->time_base ,
126- (AVRounding) ( AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX ) );
124+ AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX );
127125 packet.dts = av_rescale_q_rnd (packet.dts , in_stream->time_base , out_stream->time_base ,
128- (AVRounding) ( AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX ) );
126+ AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX );
129127 packet.duration = av_rescale_q (packet.duration , in_stream->time_base ,
130128 out_stream->time_base );
131129 packet.pos = -1 ;
@@ -146,13 +144,12 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
146144 // Write tail
147145 av_write_trailer (out_format);
148146
149- end:
150- avformat_close_input (&in_format);
147+ end:
151148 if (out_format && !(out_format->flags & AVFMT_NOFILE )) {
152149 avio_close (out_format->pb );
153150 }
154- avformat_free_context (in_format);
155151 avformat_free_context (out_format);
152+ avformat_close_input (&in_format);
156153 env->ReleaseStringUTFChars (filePath, file_path);
157154 env->ReleaseStringUTFChars (liveUrl, live_url);
158155 if (ret < 0 && ret != AVERROR_EOF ) {
0 commit comments