2

您好我正在尝试使用 ffmpeg 更改视频文件的音频流的采样率。但我无法更改原始文件的音频。到目前为止,我能够分别读取音频和视频流并显示其采样率。不知道如何永久应用此效果。以下是我的 Java 代码。

 public class MainActivity extends Activity {
public static native float logFileInfo(String inputfilename);
static
{
    System.loadLibrary("mylib");
}


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv= new TextView(this);
    String path= Environment.getExternalStorageDirectory().getPath();
    path+="/test2_modified.mp4";
    float x=logFileInfo(path);
    String y=Float.toString(x);
    tv.setText(y);
    setContentView(tv);   
}

和我的原生文件

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

AVFormatContext *pFormatCtx;
int             i, videoStream, audioStream;
AVCodecContext  *pCodecCtx; 
AVCodec         *pCodec;
AVFrame         *pFrame; 
AVPacket        packet;
int             frameFinished;
float           aspect_ratio;
AVCodecContext  *aCodecCtx;
AVCodec         *aCodec;


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_VIDEO &&
        videoStream < 0) {
                    videoStream=i;
        }
    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
        audioStream < 0) {
                    audioStream=i;
        }
}
if(videoStream==-1)
     LOGI("Video stream is -1");    
;
if(audioStream==-1)
     LOGI("Audio stream is -1");
        ;   

//pFormatCtx->streams[audioStream]->codec->sample_rate=16000;
aCodecCtx=pFormatCtx->streams[audioStream]->codec;
//aCodecCtx->sample_rate=16000;
jfloat sr=aCodecCtx->sample_rate;
return sr;}
4

0 回答 0