Repacking Without Transcoding
Hi, I'm trying to convert my video collection so it is suitable for use with all of my devices via Plex without realtime transcoding, which limits the format I can use to MP4 containers with H264 video and AAC audio. Unfortunately, the DVDs I've been extracting over time (as the shelf space around the TV has been running out) are mostly in MKV containers with H264 video, which my Chromecasts won't play natively. What I would ideally like to do is extract the H264 video data and repack it into an MP4 container without transcoding (I don't want to lose any video quality and transcoding is CPU expensive while just re-containering should be much cheaper). Is there a way to do that? Also, in many cases, although the video streams I have been encoding are H264, I have mostly been using MP3 audio rather than AAC, so I will need to transcode the audio. What is the best way of doing that while minimizing the risk of upsetting A/V synchronisation? Many thanks in advance. Gordan
On Mon, Nov 3, 2014 at 10:16 PM, Gordan Bobic <gordan@bobich.net> wrote:
Hi,
I'm trying to convert my video collection so it is suitable for use with all of my devices via Plex without realtime transcoding, which limits the format I can use to MP4 containers with H264 video and AAC audio.
Unfortunately, the DVDs I've been extracting over time (as the shelf space around the TV has been running out) are mostly in MKV containers with H264 video, which my Chromecasts won't play natively.
What I would ideally like to do is extract the H264 video data and repack it into an MP4 container without transcoding (I don't want to lose any video quality and transcoding is CPU expensive while just re-containering should be much cheaper).
Is there a way to do that?
Also, in many cases, although the video streams I have been encoding are H264, I have mostly been using MP3 audio rather than AAC, so I will need to transcode the audio. What is the best way of doing that while minimizing the risk of upsetting A/V synchronisation?
Many thanks in advance.
Gordan
Use mkvextract to dump the video and/or audio. Then encode the audio and mux the video with the encoded audio with MP4Box. you can use mkvmerge -i file.mkv to get the track IDs which you'll need to provide them to mkvextract. Most likely ID 0 is you video so a cmd for that will look like mkvextract tracks file.mkv 0:video.h264 it will dump the video to a file called video.h264
_______________________________________________ MEncoder-users mailing list MEncoder-users@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/mencoder-users
-- Yours truly
Hi Gordon, mencoder is no longer actively developed, and ffmpeg is recommended as a replacement for most use cases. Especially yours. :-) On Mon, Nov 03, 2014 at 21:16:16 +0000, Gordan Bobic wrote:
Unfortunately, the DVDs I've been extracting over time (as the shelf space around the TV has been running out) are mostly in MKV containers with H264 video, which my Chromecasts won't play natively.
I would have expected more from Google, the propagators of WebM, but there you go. *shrug*
What I would ideally like to do is extract the H264 video data and repack it into an MP4 container without transcoding (I don't want to lose any video quality and transcoding is CPU expensive while just re-containering should be much cheaper).
Really easy with ffmpeg: $ ffmpeg -i infile.mkv -c copy outfile.mp4 is usually all there is to it. If you have more than just one video and one audio stream - so for example multiple audio tracks, or subtitle streams - you'll have to modify the commandline. $ ffmpeg -i infile.mkv -sn -c copy -map 0 outfile.mp4 will omit the subtitle streams, but take all available audio (and video) streams into the target file.
Also, in many cases, although the video streams I have been encoding are H264, I have mostly been using MP3 audio rather than AAC, so I will need to transcode the audio.
You should check whether MP3 audio isn't accepted first. Otherwise, modify the above to $ ffmpeg -i infile.mkv -sn -c:v copy -c:a libfdk_aac -map 0 outfile.mp4 or if you don't have libfdk_aac: $ ffmpeg -i infile.mkv -sn -c:v copy -c:a aac -strict experimental -map 0 outfile.mp4 More help on using ffmpeg here: https://ffmpeg.org/mailman/listinfo/ffmpeg-user Hope this helps, Moritz
On 11/03/2014 10:00 PM, Moritz Barsnick wrote:
Hi Gordon,
mencoder is no longer actively developed, and ffmpeg is recommended as a replacement for most use cases. Especially yours. :-)
On Mon, Nov 03, 2014 at 21:16:16 +0000, Gordan Bobic wrote:
Unfortunately, the DVDs I've been extracting over time (as the shelf space around the TV has been running out) are mostly in MKV containers with H264 video, which my Chromecasts won't play natively.
I would have expected more from Google, the propagators of WebM, but there you go. *shrug*
What I would ideally like to do is extract the H264 video data and repack it into an MP4 container without transcoding (I don't want to lose any video quality and transcoding is CPU expensive while just re-containering should be much cheaper).
Really easy with ffmpeg:
$ ffmpeg -i infile.mkv -c copy outfile.mp4
is usually all there is to it. If you have more than just one video and one audio stream - so for example multiple audio tracks, or subtitle streams - you'll have to modify the commandline.
$ ffmpeg -i infile.mkv -sn -c copy -map 0 outfile.mp4
will omit the subtitle streams, but take all available audio (and video) streams into the target file.
Also, in many cases, although the video streams I have been encoding are H264, I have mostly been using MP3 audio rather than AAC, so I will need to transcode the audio.
You should check whether MP3 audio isn't accepted first. Otherwise, modify the above to
$ ffmpeg -i infile.mkv -sn -c:v copy -c:a libfdk_aac -map 0 outfile.mp4
or if you don't have libfdk_aac:
$ ffmpeg -i infile.mkv -sn -c:v copy -c:a aac -strict experimental -map 0 outfile.mp4
More help on using ffmpeg here: https://ffmpeg.org/mailman/listinfo/ffmpeg-user
Thanks for the hints. I wrote a short script that uses mplayer -ao null -vo null -really-quiet -identify -frames 1 to get some basic info on the files, and apply transcoding using ffmpeg only when necessary. Thank you again for pointing me in the right direction. Gordan
participants (3)
-
Gordan Bobic -
Grozdan -
Moritz Barsnick