Archive

Posts Tagged ‘audio’

DeMuxing and ReMuxing M2TS/MP4/FLV to MKV under –insert-your-preferred-unixoid-os-here–

March 17, 2010 8 comments

Sometimes I get some video files in mp4, flv or even m2ts containers. Since I am a big, big fan of the mkv container format, I usually remux those files. When I first tried to find a solution for this using Linux, Google spit out everything and the kitchen sink, but not the most obvious choices: use ffmpeg or mplayer.

To demux with ffmpeg:

ffmpeg -i input.{mp4,flv,m2ts} -vcodec copy out.{h264,m2v} -acodec copy out.{aac,mp3}

AFAIK mplayer involves two steps to demux video and audio separately:

mplayer -dumpvideo -dumpfile out.{h264,m2v} input.{mp4,flv,m2ts}
mplayer -dumpaudio -dumpfile out.{aac,mp3} input.{mp4,flv,m2ts}

There are probably a gazillion ways more (mencoder comes to mind) to achieve the demuxed material and if the input files contain more than one video and one audio stream, you might have to – personally I never was in such a scenario – dig up ffmpeg’s manual about stream selection. Which actually is pretty easy to do.

Once you got your streams demuxed, use the most excellent mkvtoolnix suite to remux them into a mkv container (note: mmg is your friend here). As you will be most likely adding elementary streams, mkvmerge won’t be able to automatically determine the correct fps. Just manually enter them, ffmpeg or mplayer should have spit them out in the demuxing process. Here you can also add subtitles and w/e your heart desires into the container.

out.{h264,m2v} input.{mp4,flv,m2ts}
Advertisements
Categories: linux, unix Tags: , , ,
%d bloggers like this: