Using ffprobe to check audio-only files

后端 未结 4 1651
醉梦人生
醉梦人生 2020-11-27 23:53

Is there an ffprobe command I can run to see if an mov file that I have is audio-only or contains video as well? I have various mov files, some of which are audio dubs and s

4条回答
  •  无人及你
    2020-11-28 00:23

    To find out programmatically if a video file has audio, use avformat_open_input() as shown here below - if audio_index is bigger or equal to zero, then the video file has audio.

    if (avformat_open_input(&pFormatCtx, filename, nullptr, nullptr) != 0) {
        fprintf(stderr, "Couldn't open video file!\n");
        return -1;
    }
    
    if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
        fprintf(stderr, "Couldn't find stream information!\n");
        return -1;
    }
    
    av_dump_format(pFormatCtx, 0, videoState->filename, 0);
    
    for (i = 0; i < pFormatCtx->nb_streams; i++) {
    
        if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_index < 0)
            video_index = i;
    
        if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_index < 0)
            audio_index = i;
    }
    

提交回复
热议问题