Ubuntu – Using avconv, when remuxing to MKV, is there a way to fix packed AVI input files

avconvavimkvtranscodevideo

Due to compatibility bugs between Plex server and Panasonic TVs, the only way to get it to work well is remux everything to MKV, straight copy all streams (video, audio, subtitle)

Seems simple enough:

avconv -i "input.avi" -c copy "output.mkv"

Except:

avconv version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:00:59 with gcc 4.6.3
[mpeg4 @ 0x8422140] Invalid and inefficient vfw-avi packed B frames detected
Input #0, avi, from 'input.avi':
  Metadata:
    encoder         : VirtualDubMod 1.5.4.1 (build 2117/release)
  Duration: 00:27:38.52, start: 0.000000, bitrate: 1173 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 640x352 [PAR 1:1 DAR 20:11], 25 tbr, 25 tbn, 25 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 132 kb/s
File 'output.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'output.mkv':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: mpeg4, yuv420p, 640x352 [PAR 1:1 DAR 20:11], q=2-31, 1k tbn, 25 tbc
    Stream #0.1: Audio: libmp3lame, 48000 Hz, stereo, 132 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press ctrl-c to stop encoding
[matroska @ 0x8422cc0] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument

With the relevant gotcha lines being:

[mpeg4 @ 0x8422140] Invalid and inefficient vfw-avi packed B frames detected#
<snip>
[matroska @ 0x8422cc0] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument

I can't see an option to unpack the B frames (or build a VBR timemap? do we need those in avconv?)

Is there a way to do this, like in avidemux?

Best Answer

A workaround is to convert to .mp4 first:

avconv -i input.avi -c copy temp.mp4
avconv -i temp.mp4 -c copy output.mkv
rm temp.mp4

Sadly, one cannot simply pipe the mp4 format between avconv instances: "[mp4 @ 0x80846c0] muxer does not support non seekable output"