Normally, it is quiet easy to convert video files to a different format. However, now and then you need some extra parameters.
Although streaming video is nowadays the default environment to view video materials, sometimes you want to store your video locally. Suppose, you want to download a video from youtube, the following command will do the job:
$ youtube-dl --verbose 'https://www.youtube.com/watch?v=abcXyZ'
If your video player does not support the video format of the the downloaded file, you can easily convert the codec to another format, using the ffmpeg
command. The following example converts an MKV
file into an MP4
:
$ ffmpeg -i myVideo.mkv -codec copy myVideo.mp4
As simple as it looks, apparently it does not always work. In my case, the above command requires some extra parameters:
$ ffmpeg -i "video.mkv" -map 0 -c copy -c:a aac "video.mp4"
A final note on the conversion of video names containing white space. The following script first replaces all white spaces by hyphens, then the codec conversion is carried out:
MY_MKV=a\ special\ video.mkv
MY_MKV2=$( echo "$MY_MKV" | tr ' ' '-' )
MY_MP4=${MY_MKV2%.mkv}.mp4
ffmpeg -i "$MY_MKV2" -map 0 -c copy -c:a aac "$MY_MP4"
This is a lot of preparation for one file, but it can be useful if you want to process a whole list of files.
Tags: linux, video, youtube-dl, ffmpeg