Search code examples
bashffmpegvlc

How can I play a video from the CLI with no output of video or audio


I have 1000s of video files and I know some of them are corrupted. I want to be able to detect corrupted files with a bash script, I tried using FFmpeg with error logging:

ffmpeg -v error -i "vid.avi" -f null - 2>"vid.log"

The output doesn't seem to be very useful though, some files which report errors play without any problems. The only way to know for sure seems to be to watch the video to see if there is any corruption or if it crashes the media player.

I would like to be able to automate the "watching" by playing the video from the command line and detecting the corruption or crashing there but I can't find a way to run it without outputting the video and audio.

I have tried FFplay but I can only disable one of the outputs not both:

ffplay -nodisp "vid.avi"
ffplay -vn "vid.avi"

These disable the video:

ffplay -an "vid.avi"

This disables the audio but I can't combine them, when I do I get an error:

Failed to open file 'vid.avi' or configure filtergraph

I have tried using the vlc/cvlv suggestions I have found but none have worked, it still opens a graphical interface just with no controls.

Is there any way to do this?


Solution

  • I have found how to run with no GUI using cvlc

    cvlc --verbose 1 --no-audio --no-video
    

    Verbose is not needed to run with no GUI but shows some errors that I wanted to parse.

    I have 2 videos that produce lots of these error, which in most cases aren't meant to be an issue but one wouldn't play in vlc.

    [null @ 0x555bfbc68880] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 179136 >= 179136
    

    EDIT: This error doesn't appear to be related to the broken index error that cvlc finds.

    Running the cvlc command gave me these errors with the video that wouldn't play

    [00007f1830002e30] avi stream warning: chunk ���u does not fit into parent 735130128
    [00007f1830002e30] avi stream warning: unknown chunk: ���u (not loaded)
    [00007f1830004060] avi demux warning: cannot find idx1 chunk, no index defined
    [00007f1830004060] avi demux error: no key frame set for track 0
    [00007f1830004060] avi demux error: no key frame set for track 1
    [00007f1830004060] avi demux warning: broken or missing index, 'seek' will be approximative or will exhibit strange behavior
    [00007f1830004060] avi demux warning: no track selected, exiting...
    [00007f1830002e30] avi stream warning: unknown chunk: ���u (not unloaded)
    

    Code to check for broken index with cvlc

    local err="broken or missing index"
    cvlc --verbose 1 --no-audio --no-video --run-time "2.0" --play-and-exit "vid.avi" 2>&1 \
    | while read -r line; do
        if [[ "${line}" =~ "$err" ]]; then
            exit 1
        fi
    done
    [ "$?" = 1 ] && echo "Broken Index"