Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd March 2015, 15:55   #1  |  Link
jriker1
Registered User
 
Join Date: Dec 2003
Posts: 485
Converting MKV Lossless

For the longest time I've been using Handbrake to convert MKV files to MP4 lossless as an interim file format so I could open them in Premiere to do some editing. Little did I know that I wasn't editing a lossless file. Thought by setting CQ to 0 it was lossless because it said it was. One day I looked at the logs and long story short found out I had to set H.264 profile to Auto so it could pick a profile I couldn't pick manually to actually use the lossless settings. Well after that I couldn't view the MP4 file it created and the best Premiere could do was open it in black and white. Not very helpful.

OK, sorry for the history story. So I started looking at other ways to lossless convert my videos to something other than MKV that I could use in Premiere. Looking for advice on if this makes sense and if it does hopefully help others.

Steps to lossless convert MKV to MP4:

1. Install AVISynth (if not installed).
2. Create AVS file containing one line:

Code:
ffmpegsource2("<mkv filename to be converted>", vtrack = -1, atrack = -1)
May have to adjust vtrack and atrack if you have multiple titles or audio tracks.

3. Open AVS file in VirtualDub
4. Select Video > Fast Recompress
5. Select Video > Compression > Lagarith > Configure > Mode > YUY2 (use Lagarith or whatever other lossless codec works for you)
6. File > Save as AVI

The AVS file may have to be tweaked with like NicAC3 or something if you have more complicated audio streams but mine was basic two channel ac3 at the time so didn't have to worry about surround channels or anything.

Thoughts?

Thanks.

JR
jriker1 is offline   Reply With Quote
Old 2nd March 2015, 19:00   #2  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Why all this work?

Use MkvToMp4 by oreons. It will not convert the streams if they are already MP4 compatible, it will use chapters and subs from the MKV, everything is quick and easy and the resulting files are totally Apple compatible.


Cheers
manolito
manolito is offline   Reply With Quote
Old 2nd March 2015, 19:34   #3  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 643
Because non-intra-only codecs are bad for editing - they are slow and could miss frames (well, it's just NLE's decoders being terrible, but still).
vivan is offline   Reply With Quote
Old 3rd March 2015, 04:37   #4  |  Link
jriker1
Registered User
 
Join Date: Dec 2003
Posts: 485
Also because MKVtoMP4 can't convert lossless.

JR
jriker1 is offline   Reply With Quote
Old 3rd March 2015, 06:20   #5  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote:
Originally Posted by jriker1 View Post
Also because MKVtoMP4 can't convert lossless.
What???

From the MkvToMp4 description:
Quote:
Features:
- Change the container to Mp4 without transcoding video (If the original video in h264 format)
If the video in the MKV is already AVC and the audio is AAC, it won't convert the streams at all. It will only repack the streams to a different container. How much more "lossless" can you ask for?


Cheers
manolito
manolito is offline   Reply With Quote
Old 3rd March 2015, 12:56   #6  |  Link
Ghitulescu
Registered User
 
Ghitulescu's Avatar
 
Join Date: Mar 2009
Location: Germany
Posts: 5,769
His process is as follows (based on other threads of him)

take a DVD and prepare it for editing (whatever it may mean)
re-encode the result (edited video) to MP4 to be watched on something else than a DVDplayer

Therefore indeed it will not be a lossless process, anyhow one may twist the concepts.
__________________
Born in the USB (not USA)
Ghitulescu is offline   Reply With Quote
Old 3rd March 2015, 13:56   #7  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,419
Quote:
Originally Posted by manolito View Post
If the video in the MKV is already AVC and the audio is AAC, it won't convert the streams at all. It will only repack the streams to a different container. How much more "lossless" can you ask for?
Because the OP isn't asking about lossless re-containering, they're talking about Lossless H.264 (the reference to --cq 0 gives that away), and how to convert [mistakenly created] Lossless H.264 files into a different lossless format that their NLE will handle.

And it's quite a bit simpler than that convoluted process from the first post:
Code:
ffmpeg -i lossless-h264.mp4 -vcodec ffv1 output.avi
(or -vcodec utvideo or -vcodec huffyuv or -vcodec ffvhuff, etc.)
qyot27 is offline   Reply With Quote
Old 3rd March 2015, 17:06   #8  |  Link
jriker1
Registered User
 
Join Date: Dec 2003
Posts: 485
Thank you all for your input and yes I am not trying to swap containers. Trying to re-encode the source losslessly. Couple reasons for this:

1. Sometimes the source content has issues that re-encoding before going in my NLE fixes, like hiccups or audio sync problems.

2. There are so many variants of content I work with, DVD, BD, Camcorder, source materials that are everything and the kitchen sink. Want to consistently end up with an MP4 to edit in my NLE.

That said, in this case I am talking about a source that was provided as an MKV file. And say that container has content that even if you multiplexed it into an MP4 container couldn't be read by my NLE. Say MPEG2 content for instance.

I know my final output will not be lossless, as was mentioned here, but believe minimizing the loss while working on the footage is a good idea. Just for reference, in my NLE I do a lot of cropping, inserting, NeatVideo cleanup, titling, hard subtitling, etc on footage.

That said, is my process that convoluted? If you already have VDub and AVISynth?

Would your ffmpeg suggestion qyot27 work the same for am MKV file? Just replace "lossless-h264.mp4" with a reference to the MKV? What scares me sometimes about using ffmpeg and the suggestion, is knowing what settings the codec is using. For example Lagarith has RGB or YUY2 settings. Not sure command line what it's using. Others like MagicYUV have a lot more settings in the GUI even if you want to interlace or maybe it's asking if the source is interlaced. Without defining those things not sure what the codec is doing.

JR

Last edited by jriker1; 3rd March 2015 at 17:08.
jriker1 is offline   Reply With Quote
Old 3rd March 2015, 20:42   #9  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,419
FFmpeg won't change the pixel format unless you tell it to, or the destination codec doesn't support it (which won't happen if you output to ffv1 or ffvhuff, since those both support pretty much every pixel format available in SWScale; huffyuv and utvideo are more stingy; the drawback is merely that decoding ffv1 or ffvhuff requires ffdshow's VFW interface to be installed, unless your NLE opens files through DirectShow so you can use LAV Filters). And yes, changing 'lossless-h264.mp4' to whatever the MKV's filename is will/should work. FFmpeg's support of lossless H.264 isn't restricted by container.

The reason I said it was convoluted is because you're still using FFMS2 to open the file and then have to go in through the GUI to convert it to something else in multiple steps. But FFMS2 uses FFmpeg's decoders, so you really only need the one step: give the file to FFmpeg and output to the desired output format. AviSynth would be useful if you were doing other filtering at the same time, of course, but for simple 1:1 format conversion it's not really that necessary (and for that matter, FFmpeg supports AviSynth too, so you could just as easily give the script to it and output in one step).
qyot27 is offline   Reply With Quote
Old 4th March 2015, 16:26   #10  |  Link
jriker1
Registered User
 
Join Date: Dec 2003
Posts: 485
Quote:
Originally Posted by qyot27 View Post
FFmpeg won't change the pixel format unless you tell it to, or the destination codec doesn't support it (which won't happen if you output to ffv1 or ffvhuff, since those both support pretty much every pixel format available in SWScale; huffyuv and utvideo are more stingy; the drawback is merely that decoding ffv1 or ffvhuff requires ffdshow's VFW interface to be installed, unless your NLE opens files through DirectShow so you can use LAV Filters). And yes, changing 'lossless-h264.mp4' to whatever the MKV's filename is will/should work. FFmpeg's support of lossless H.264 isn't restricted by container.

The reason I said it was convoluted is because you're still using FFMS2 to open the file and then have to go in through the GUI to convert it to something else in multiple steps. But FFMS2 uses FFmpeg's decoders, so you really only need the one step: give the file to FFmpeg and output to the desired output format. AviSynth would be useful if you were doing other filtering at the same time, of course, but for simple 1:1 format conversion it's not really that necessary (and for that matter, FFmpeg supports AviSynth too, so you could just as easily give the script to it and output in one step).
Thanks qyot27. Excellent information. Let me ask you one follow-up question. Say the only editing I'm going to do on this footage is with NeatVideo to clean it up. Today I do this in Premiere. If I got the VirtualDub plugin, and could incorporate this into AVISynth would that workflow make sense? Was thinking of ways to limit my application footprint and I know using premiere for just video cleanup may be overkill if it could be done as part of the prior conversion process. Only issue I see with it is I do not believe Premiere or the standard AVISynth will use more than one core so will be a lot slower then encoding in Premiere Pro. Tried the multi-threaded version of AVISynth but had it's challenges.

JR
jriker1 is offline   Reply With Quote
Old 4th March 2015, 21:43   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by jriker1 View Post
Say the only editing I'm going to do on this footage is with NeatVideo to clean it up. Today I do this in Premiere. If I got the VirtualDub plugin, and could incorporate this into AVISynth would that workflow make sense? Was thinking of ways to limit my application footprint and I know using premiere for just video cleanup may be overkill if it could be done as part of the prior conversion process. Only issue I see with it is I do not believe Premiere or the standard AVISynth will use more than one core so will be a lot slower then encoding in Premiere Pro. Tried the multi-threaded version of AVISynth but had it's challenges.


It's doesn't matter much in that scenario - your bottleneck will be neat video in either host application, regardless of multithreading
poisondeathray is offline   Reply With Quote
Old 5th March 2015, 08:06   #12  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
The only good reason to do it in VirtualDub would be to skip the overhead of an initial lossless compression, followed by a second lossless compression that ultimately gets compressed for real. You can load an avisynth directly into VirtualDub and it'll be lossless, but you could also just as easily use the Premiere Avisynth plugin.

Right now your workflow is decode->lossless->filter->?? when decode->filter->?? would be much easier and faster, and use a lot less hard drive space.

If you were doing actual non-linear editing in Premiere, then you'd have little choice but to make the lossless file first.
foxyshadis is offline   Reply With Quote
Old 6th March 2015, 13:56   #13  |  Link
bxyhxyh
Registered User
 
Join Date: Dec 2011
Posts: 354
CQ 0 should be lossless unless you change colorspace right?
Does profile really matters?
bxyhxyh is offline   Reply With Quote
Old 6th March 2015, 16:24   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by bxyhxyh View Post
CQ 0 should be lossless unless you change colorspace right?
Yes

Quote:
Does profile really matters?
Yes. You need --profile high444 (even if it's 4:2:0, 4:2:2, or 4:4:4) to enable lossless encoding
poisondeathray is offline   Reply With Quote
Old 7th March 2015, 00:30   #15  |  Link
jriker1
Registered User
 
Join Date: Dec 2003
Posts: 485
Good luck though with profile high444. When I use that in Handbrake I can't play it and can't edit it. At least Premiere opens it in black and white.

As a side question to my original question, is there any value in doing neatvideo in premiere over just using VDub? Any quality differences? Also should I set my final output to RGB? Thinking so as my YUV content is converted in the app to RGB since that's where neatvideo works in. Never looked at what colorspace WMV content, which some of my final results ends up in, uses.

JR

EDIT: Using VDub may be pointless for NeatVideo. Can't get it to complete an encoding without crashing. Will take about 9 hours to run, gets a few hours in and VDub just crashes.

Last edited by jriker1; 7th March 2015 at 05:14.
jriker1 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:21.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.