【问题标题】:Not able to read audio streams with ffmpeg无法使用 ffmpeg 读取音频流
【发布时间】:2023-03-27 02:13:01
【问题描述】:

我正在尝试解决一个大问题,但遇到了非常小的问题。我试图在 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;}

【问题讨论】:

    标签: android ffmpeg android-audiomanager libavcodec libavformat


    【解决方案1】:

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

    here

    here

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 2010-11-11
      • 2013-01-07
      相关资源
      最近更新 更多