Ubuntu – How to convert a video file from mkv to a format supported by the TV set

conversiontvUbuntuvideox264

I have a mkv video file which contains the following content:

> mkvmerge --identify original.mkv 
File 'original.mkv': container: Matroska
Track ID 0: video (V_MPEGH/ISO/HEVC)
Track ID 1: audio (AAC)
Tags for track ID 0: 7 entries
Tags for track ID 1: 7 entries

But a 'standard' conversion using avconv does not work (ubuntu 14.04), neither a suggestion I found elsewhere (see below, and below that…). The original file can neither be played by mplayer nor when played from a hard drive connected to a TV.

How to solve these problem in order to convert the file into a more 'normal/standard' format, so it can be played by mplayer and on TV?

> avconv  -i original.mkv  -vcodec copy -acodec aac -strict -2 -b:a 384k  output.mp4
avconv version 9.18-6:9.18-0ubuntu0.14.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Mar 16 2015 13:19:10 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
[matroska,webm @ 0x11d3200] Unknown/unsupported AVCodecID V_MPEGH/ISO/HEVC.
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 3 with DTS 209, packet 4 with DTS 167
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 4 with DTS 167, packet 5 with DTS 125
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 6 with DTS 292, packet 7 with DTS 250
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 8 with DTS 500, packet 9 with DTS 417
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 9 with DTS 417, packet 10 with DTS 334
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 13 with DTS 709, packet 14 with DTS 626
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 14 with DTS 626, packet 15 with DTS 542
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 18 with DTS 918, packet 19 with DTS 834
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 19 with DTS 834, packet 20 with DTS 751
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 23 with DTS 1126, packet 24 with DTS 1043
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 24 with DTS 1043, packet 25 with DTS 959
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 28 with DTS 1293, packet 29 with DTS 1210
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 29 with DTS 1210, packet 30 with DTS 1168
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 32 with DTS 1460, packet 33 with DTS 1376
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 33 with DTS 1376, packet 34 with DTS 1335
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 36 with DTS 1627, packet 37 with DTS 1543
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 37 with DTS 1543, packet 38 with DTS 1501
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 40 with DTS 1835, packet 41 with DTS 1752
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 41 with DTS 1752, packet 42 with DTS 1668
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 45 with DTS 2002, packet 46 with DTS 1919
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 46 with DTS 1919, packet 47 with DTS 1877
[matroska,webm @ 0x11d3200] Non-increasing DTS in stream 0: packet 49 with DTS 2211, packet 50 with DTS 2127
Input #0, matroska,webm, from 'original.mkv':
  Duration: 00:58:38.02, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: [0][0][0][0] / 0x0000, 1920x1080, PAR 255:254 DAR 680:381, 23.98 fps, 23.98 tbr, 1k tbn (default)
    Metadata:
      BPS             : 1242590
      BPS-eng         : 1242590
      DURATION        : 00:58:38.015000000
      DURATION-eng    : 00:58:38.015000000
      NUMBER_OF_FRAMES: 84348
      NUMBER_OF_FRAMES-eng: 84348
      NUMBER_OF_BYTES : 546431695
      NUMBER_OF_BYTES-eng: 546431695
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-05-16 06:10:27
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-05-16 06:10:27
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0.1: Audio: aac, 48000 Hz, 5.1, fltp (default)
    Metadata:
      BPS             : 187584
      BPS-eng         : 187584
      DURATION        : 00:58:37.995000000
      DURATION-eng    : 00:58:37.995000000
      NUMBER_OF_FRAMES: 82453
      NUMBER_OF_FRAMES-eng: 82453
      NUMBER_OF_BYTES : 82490002
      NUMBER_OF_BYTES-eng: 82490002
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-05-16 06:10:27
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-05-16 06:10:27
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[mp4 @ 0x11daf60] track 0: could not find tag, codec not currently supported in container
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf54.20.4
    Stream #0.0: Video: [0][0][0][0] / 0x0000, 1920x1080 [PAR 255:254 DAR 680:381], q=2-31, 90k tbn, 1k tbc (default)
    Metadata:
      BPS             : 1242590
      BPS-eng         : 1242590
      DURATION        : 00:58:38.015000000
      DURATION-eng    : 00:58:38.015000000
      NUMBER_OF_FRAMES: 84348
      NUMBER_OF_FRAMES-eng: 84348
      NUMBER_OF_BYTES : 546431695
      NUMBER_OF_BYTES-eng: 546431695
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-05-16 06:10:27
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-05-16 06:10:27
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0.1: Audio: aac, 48000 Hz, 5.1, fltp, 384 kb/s (default)
    Metadata:
      BPS             : 187584
      BPS-eng         : 187584
      DURATION        : 00:58:37.995000000
      DURATION-eng    : 00:58:37.995000000
      NUMBER_OF_FRAMES: 82453
      NUMBER_OF_FRAMES-eng: 82453
      NUMBER_OF_BYTES : 82490002
      NUMBER_OF_BYTES-eng: 82490002
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-05-16 06:10:27
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-05-16 06:10:27
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac -> aac)
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

I also tried the following command:

avconv  -i original.mkv  -vcodec x264 -acodec aac -strict -2 -b:a 384k  output.mp4

which gives the following error:

Unknown encoder 'x264'

I also tried the following command:

avconv  -i original.mkv  -vcodec libx264 -acodec aac -strict -2 -b:a 384k  output.mp4

which resulted in this error:

[buffer @ 0x24adb00] Invalid pixel format string '-1'
Error opening filters!

Best Answer

Just use the latest version of ffmpeg. It seems like the development of avconv is way behind. Since there were some changes regarding mp4 container and HEVC your "multiplexer" has to support them, this is probably the reason why you have this output in your first try:

[mp4 @ 0x11daf60] track 0: could not find tag, codec not currently supported in container

Since you are on Ubuntu 14.04 you can not just install ffmpeg using sudo apt-get install ffmpeg (works for Ubuntu > 14.04) but you can either update to 16.04, compile ffmpeg from sources or just install precompiled static builds.

After installation you can either "remultiplex" mkv to mp4:

ffmpeg -i original.mkv -c:v copy output.mp4

Or transcode mkv H.265 to mp4 H.264:

ffmpeg -i original.mkv -c:v libx264 output.mp4

In order to play it you need the corresponding decoder (either software or hardware). You also have to pay attention which profile and level your decoder supports (in case your TV has a HW decoder). But transcoding to H.264 should do it on every TV nowadays.

You can use VLC, ffplay, GPAC MP4Client for playing HEVC content.

Related Question