pythonffmpegvideo-encodingmoviepyvideo-conversion

How can I check the encoders used for a video


I am making a python script that uses ffmpeg and moviepy to convert videos to mp4. I want to make an if statement that checks if the input file needs to be reencoded or just rewrapped.(if the input file is aac and h.264 it does not need to be reencoded.) Is there a simple way I can grab that file info?


Solution

  • Use ffprobe. Example JSON output:

    $ ffprobe -loglevel error -show_entries stream=codec_name -of json input.mkv
    {
        "programs": [
    
        ],
        "streams": [
            {
                "codec_name": "h264"
            },
            {
                "codec_name": "aac"
            }
        ]
    }
    

    Examples showing video and audio separately (-select_streams) and only output the codec_name value:

    $ ffprobe -loglevel error -select_streams V -show_entries stream=codec_name -of csv=p=0 input.mkv
    h264
    $ ffprobe -loglevel error -select_streams a -show_entries stream=codec_name -of csv=p=0 input.mkv
    aac