I have mkv videos (matroska container) which are recordings from TV. Each matroska file contains several sections (video stream, audio stream, some attributes like channel name or similar, and optionally second audio stream with different languate, and optionally subtitles).
I need to transcode (scale, resize) the video stream to smaller screen resolution, preserving all other sections untouched.
I wish to do that in Linux, thus I need a script which will call ffmpeg (or any other encoding program which is freely available) with right parameters, which will accept two arguments:
- argument 1: input - the mkv file full path as a source file
- argument 2: output - the new mkv file full path as a destination where resized video will be written
There are, however, several important requirements:
- the newly created mkv file must preserve all the sections from original matroska file, including all audio tracks and subtitle tracks (if exist), and other infos and tags, etc.
- the newly created mkv file must contain the video stream in half resolution. That is, if the original is 640x480, the new transcoded video will be 320x240. The size of each video is different so this can't be hardcoded, your script must be able to detect the original size and transcode video to the half of it.
- output video stream format will be MPEG2 or MP4
- last, but the most important requirement, the newly created mkv file must keep aspect ratio for all video frames like the original source video. This needs to be explained further:
the source video, as recorded from TV, contains some parts in different aspect ratios than other parts. The best is to provide example, so here is an example video (attached below). As you can see while playing the video, first two seconds of the [url removed, login to view] video are 1024 x 576, which is 16:9, but since the 00:03 seconds, the video is 768 x 576 Pixels (4:3). I believe it has something to do with DAR (display aspect ratio). The output video, scalled down by 50% and encoded by the script you provide, must preserve this behavior.
I believe this will be just few-lines script so I don't expect your bids to be much bigger than the minimum $30.