Suppose I have two video files A and B.

Now I want to convert A to the same format (i.e. same container, same audio and video codec), same bitrate, size etc. as B.

Is there a way to do this automatically (i.e. without extracting the information manually and giving it manually as input parameters) using a command line tool (or even a GUI tool)?

3 Answers 3


I think if you parse ffmpeg output you could achieve this in part, but beware the labyrinthe documentation on how to encode for best results. It's a little tricky.

Perhaps an alternate approach is to find a common standard whose parameters can be set one, and leave your transcoder job running on all A, B, etc.


No It is not possible to have all the parameters same as B. We need to compromise or adjust some attribute of the Video A, so that the other attribute of the video A matches with the video B.


You are making your own analyzer then.

You can use ffmpeg (path to ffmpeg is $exe) with grep/sed/awk piping to extract information into variables, use if-elif constructs ($A is path to file A)

Here is example to get video codec, video resolution, frame rate and reset to be not greater than 24 fps, and get audio encoding frequency.

videoa=`$exe -i $A 2>&1 | grep Stream.*Video | sed -e 's/.*Video: //' -e 's/[, ].*//'`
if [ $videoa = "h264" ];then videob="-c:v libx264"
elif [ $videoa = "hevc" ];then videob="-c:v libx265"

resolution=$($exe -i "$f"  2>&1 | grep -oP 'Stream .*, \K[0-9]+x[0-9]+')
if [ $(echo $($exe -i "$f" 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p") | awk  '{printf "%.0f\n", $1}';) -gt 24 ];then r="-r 24";else r=""; fi
if [ $(echo $($exe -i "$f" 2>&1 | sed -n "s/.*, \(.*\) Hz.*/\1/p") | awk  '{printf "%.0f\n", $1}';) -gt 44100 ];then af="-ar 44100";else af=""; fi

video="-map_chapters -1 -map_metadata -1 -vf ${crop}scale=${resolution},setsar=1/1,setdar=16/9 $videob -an $r"
$exe -y -ss $ss -i "$f" -t $t -map 0:v:0 $video $v

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .