Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法使用ffmpeg读取音频流_Android_Ffmpeg_Android Audiomanager_Libavcodec_Libavformat - Fatal编程技术网

Android 无法使用ffmpeg读取音频流

Android 无法使用ffmpeg读取音频流,android,ffmpeg,android-audiomanager,libavcodec,libavformat,Android,Ffmpeg,Android Audiomanager,Libavcodec,Libavformat,我正试图解决一个大问题,但遇到了一个非常小的问题。我试图在ffmpeg的帮助下读取视频文件中的音频流,但是应该遍历整个流文件的循环只运行了几次。我想不出是什么问题,因为其他人也用过类似的方法。 以下是我的代码,请检查: JNIEXPORT jint JNICALL Java_ru_dzakhov_ffmpeg_test_MainActivity_logFileInfo (JNIEnv * env, jobject this, jstring filename

我正试图解决一个大问题,但遇到了一个非常小的问题。我试图在ffmpeg的帮助下读取视频文件中的音频流,但是应该遍历整个流文件的循环只运行了几次。我想不出是什么问题,因为其他人也用过类似的方法。 以下是我的代码,请检查:

JNIEXPORT jint JNICALL Java_ru_dzakhov_ffmpeg_test_MainActivity_logFileInfo
    (JNIEnv * env,
     jobject this,
     jstring filename
    )
{

AVFormatContext *pFormatCtx;
int             i,j,k, videoStream, audioStream;
AVCodecContext  *pCodecCtx; 
AVCodec         *pCodec;
AVFrame         *pFrame; 
AVPacket        packet;
int             frameFinished;
float           aspect_ratio;
AVCodecContext  *aCodecCtx;
AVCodec         *aCodec;
//uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
j=0;

av_register_all();
char *str = (*env)->GetStringUTFChars(env, filename, 0);
 LOGI(str);
// Open video file
if(av_open_input_file(&pFormatCtx, str, NULL, 0, NULL)!=0)
    ;

// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
    ;

 LOGI("Separating");
// Find the first video stream  
videoStream=-1;
audioStream=-1;

for(i=0; i<&pFormatCtx->nb_streams; i++) {

    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
    {
        LOGI("Audio Stream");
        audioStream=i;
        }
}
av_write_header(pFormatCtx);
if(videoStream==-1)
     LOGI("Video stream is -1");    


if(audioStream==-1)
     LOGI("Audio stream is -1");

return i;}
JNIEXPORT jint JNICALL Java_ru_dzakhov_ffmpeg_test_main activity_logFileInfo
(JNIEnv*env,
这个,,
jstring文件名
)
{
AVFormatContext*pFormatCtx;
inti,j,k,视频流,音频流;
AVCodecContext*pCodecCtx;
AVCodec*pCodec;
AVFrame*pFrame;
数据包;
int框架完成;
浮动纵横比;
AVCodecContext*aCodecCtx;
AVCodec*aCodec;
//uint8\u t inbuf[音频inbuf\u大小+FF\u输入缓冲区\u填充大小];
j=0;
av_寄存器_all();
char*str=(*env)->GetStringUTFChars(env,文件名,0);
后勤(str);
//打开视频文件
if(av\u open\u input\u文件(&pFormatCtx,str,NULL,0,NULL)!=0)
;
//检索流信息
如果(av\u查找\u流\u信息(pFormatCtx)流[i]->编解码器->编解码器\u类型==AVMEDIA\u类型\u音频)
{
LOGI(“音频流”);
音频流=i;
}
}
av_写入_头(pFormatCtx);
如果(视频流==-1)
LOGI(“视频流为-1”);
如果(音频流==-1)
LOGI(“音频流为-1”);
返回i;}

您可能遇到与库加载和卸载相关的问题,以及这与通过jni重复调用的关系。不确定您的症状是什么,但如果您没有解决方案,请尝试阅读: