# Some handy ffmpeg commands



## NapoleonWils0n (Feb 8, 2020)

Hi

Heres how to extract the audio from a single video file


```
ffmpeg -i infile.mp4 -vn -c:a copy outfile.m4a
```

batch extract audio from video files


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -vn -c:a copy "${0%.*}.m4a"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 8, 2020)

Hi 

extract the video track from a video file


```
ffmpeg -i infile.mp4 -an -c:v copy outfile.mp4
```

batch extract video tracks from all the mp4s in the current directory


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -an -c:v copy "${0%.*}-extracted.mp4"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 14, 2020)

You can use ffmpeg to change the audio rate of a file,
for example change the audio from 48000 to 44100

change audio rate to 44100


```
ffmpeg -i infile.mp4 -ar 44100 outfile.mp4
```

change audio rate to 44100 batch process


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -ar 44100 "${0%.*}-audiorate.mp4"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 14, 2020)

You can convert stereo file to mono with ffmpeg


```
ffmpeg -i infile.mp4 -ac 1 outfile.mp4
```

convert stereo to mono batch process


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -ac 1 "${0%.*}-mono.mp4"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 14, 2020)

change a videos frame rate to 30fps


```
ffmpeg -i infile.mp4 -filter:v fps=fps=30 outfile.mp4
```

change frame rate batch process to 30fps


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -filter:v fps=fps=30 "${0%.*}-framerate.mp4"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 14, 2020)

resize a video to 1080p with ffmpeg and the scale and pad filters


```
ffmpeg -i infile.mp4 -vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2" outfile.mp4
```

scale and pad a video to 1080 batch process


```
find -s . -type f -name "*.mp4" -exec sh -c \
'ffmpeg -i "${0}" -vf "scale=-1:1080,pad=1920:ih:(ow-iw)/2" "${0%.*}-1080.mp4"' \
"{}" \;
```


----------



## NapoleonWils0n (Feb 14, 2020)

You can concatenate ( join ) video files together with ffmpeg

If you have media files with exactly the same codec
and codec parameters you can concatenate them

Create a list of all the mp4s in the current directory to concatenate


```
printf "file '%s'\n" *.mp4 > list.txt
```

You can edit the list.txt file and change the order videos you want to concatenate

play the list with ffplay to check the order of the videos before you concatenate them


```
ffplay -f concat -i list.txt
```

Use ffmpeg to concatenate the list of videos in the text file


```
ffmpeg -f concat -i list.txt -c copy outfile.mp4
```


----------

