R
R
redcircle2021-12-28 17:14:05
linux
redcircle, 2021-12-28 17:14:05

How to determine if a file is a video in a bash script and get its permission?

In a bash script, you need to determine if a certain file is a video and get its permission in 2 bash variables.
In this case, the file codec and file extension can be any.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2021-12-28
@redcircle

as part of the ffmpeg project, there is ffprobe, use it.
ffmpeg.org/ffprobe.html Available
in various formats. And plain text(ini) or csv,xml,json
Examples:

$ ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=nw=1 "My video file.mpg" 
width=704
height=576

$ ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "another vide file.mkv"
1280,720

$ ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of json "one_more video.mkv"
{
    "programs": [

    ],
    "streams": [
        {
            "width": 1152,
            "height": 480
        }
    ]
}

V
Voland69, 2021-12-28
@Voland69

ffprobe from ffmpeg package

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=nw=1:nk=1 input.mp4

Peeped here

A
AVKor, 2021-12-28
@AVKor

#!/usr/bin/env bash

w=$(mediainfo --Inform="Video;%Width%" FileName)
h=$(mediainfo --Inform="Video;%Height%" FileName)

K
ky0, 2021-12-28
@ky0

Well, set some ffmpeg on the file in the metadata display mode, parse the necessary fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question