ffmpeg command for transcoding MKVs into Vegas friendly h.264 MP4s?

Miles-Thatch wrote on 1/27/2022, 11:31 AM

Good day, everyone. After years of struggling with editing MKV rewrapped to mp4s in Vegas, my last editing session has pushed me over the edge. I don't think re-wrapping is the way to go, vegas is far too unstable to re-wraps. I want to try out transcoding. Right now, after re-wrapping mkv to mp4, I still end up with double the hard drive space consumed, and the resulting mp4 files still cause crashes. Now I've posted about this a whole number of times and the solutions varied from using the Otterscripts importer to recording MP4 files right away. Otterscripts hangs unresponsive due to the source files and I don't really want to go into figuring it out as that's another tangent I don't want to go into right now. I'd rather get use ffmpeg cli anyways for practice. Can't record MP4s right away because of the risk of corruption - mkvs are infinitely more corruption proof so I still record in mkv.

All I am looking to do right now - is to figure out the ffmpeg command for most optimal result in transcoding mkvs to mp4s.

Some things for the fmmpeg command to consider:

I'd like to preserve as much quality as possible from the original mkv

The MKVs have multi-track audio which needs to be preserved.

I have attached the media info in pastebin: https://pastebin.com/zEhiq3AB

Comments

john_dennis wrote on 1/27/2022, 11:45 AM

@Miles-Thatch

  1. Even if you use other screen recording software, have you tried re-muxing your MKV files with Open Broadcaster Software? Little Discussed Secret: It uses FFMPEG in the background

  1. Post Mediainfo report for the MKV file.

 

Miles-Thatch wrote on 1/27/2022, 11:47 AM

@Miles-Thatch

  1. Even if you use other screen recording software, have you tried re-muxing your MKV files with Open Broadcaster Software? Little Discussed Secret: It uses FFMPEG in the background

  1. Post Mediainfo report for the MKV file.

 

I am indeed aware that OBS offers an onboard remuxer, but isn't remuxing same thing as re-wrapping? Or are they completely different things?
I've updated the initial post with a pastebin text link for media-info

john_dennis wrote on 1/27/2022, 11:51 AM

"Well remuxing is basically re-wrapping, right?"

Yes.

"I have attached the media info file as .mp3, just rename it to .txt"

This site doesn't act as a file sharing site. Media files are encoded.

Miles-Thatch wrote on 1/27/2022, 11:54 AM

The video uses a copy mode, that's re-wrapping / remuxing as far as I know. Remuxing doesn't produce as stable of a result as conversion. It's the same thing I am doing now with VLC's builtin batch converter tool.

john_dennis wrote on 1/27/2022, 11:58 AM

@Miles-Thatch

You don't have to send us all over the Internet to post Text data:

General
Complete name                            : C:\Users\John\Desktop\Render\2022-01-26 Leaking Water Meter.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
Format profile                           : OpenDML
File size                                : 8.96 GiB
Duration                                 : 20 min 0 s
Overall bit rate                         : 64.1 Mb/s
Encoded by                               : John Dennis
Copyright                                : 2021
TCOD                                     : 0
TCDO                                     : 12000000000

Video
ID                                       : 0
Format                                   : M8RG
Codec ID                                 : M8RG
Duration                                 : 20 min 0 s
Bit rate                                 : 64.1 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 1.000 FPS
Bits/(Pixel*Frame)                       : 7.731
Stream size                              : 8.96 GiB (100%)

 

Miles-Thatch wrote on 1/27/2022, 12:04 PM

@Miles-Thatch

You don't have to send us all over the Internet to post Text data:

The media info report tends to be huge and I don't know what is and what isn't relevant so I'm inclined to include everything. Couple that with that fact that forum people have historically never liked seeing post with giant walls of text. - Pastebin to the rescue - one link, not much of an "all over the internet"

john_dennis wrote on 1/27/2022, 12:09 PM

I don't like redirection or ads when I'm focused on your problem.

It's a nice day, I could always walk another 5 miles before lunch.

Miles-Thatch wrote on 1/27/2022, 12:22 PM

Looks like my media-info report included more than yours did. Not sure if any of that is relevant.

3d87c4 wrote on 1/27/2022, 1:16 PM

I tinker with ffmpeg...my apologies if you are already way ahead of me on this subject...

I generally use google searches, a couple of ffmpeg books, and the ffmpeg documentation to find solutions.

My basic mkv to mp4 transcode file is

ffmpeg -i "input.mkv" -c copy -strict -2 "output.mp4"

I forget where I got this or why the -strict -2 is needed, but remember having trouble converting mkv's without it.j

Based on this discussion (I found today) you will likely need to add -map 0 to get all of the audio streams

https://askubuntu.com/questions/50433/how-to-convert-mkv-file-into-mp4-file-losslessly
 

fmpeg -i "input.mkv" -map 0 -c copy -strict -2 "output.mp4"


See also this thread:

https://gist.github.com/jamesmacwhite/58aebfe4a82bb8d645a797a1ba975132





 

Last changed by 3d87c4 on 1/27/2022, 1:30 PM, changed a total of 1 times.

Del XPS 17 laptop

Processor    13th Gen Intel(R) Core(TM) i9-13900H   2.60 GHz
Installed RAM    32.0 GB (31.7 GB usable)
System type    64-bit operating system, x64-based processor
Pen and touch    Touch support with 10 touch points

Edition    Windows 11 Pro
Version    22H2
Installed on    ‎6/‎8/‎2023
OS build    22621.1848
Experience    Windows Feature Experience Pack 1000.22642.1000.0

NVIDIA GeForce RTX 4070 Laptop GPU
Driver Version: 31.0.15.2857
8GB memory
 

Musicvid wrote on 1/27/2022, 3:08 PM

Miles, from the red flags raised by your description, I strongly suspect that your AVC-encoded files have stream errors that do not get corrected by remuxing ("rewrapping"). Otherwise, I have no plausible explanation why remuxing is failing or causing you fits with consumer source; and of course, remuxing will preserve every bit of data in the MKV, for better or for worse, regardless of the container, even program streams. Of course, such files can cause fits for transcoders as well.

Were these originally streaming or downloaded recordings, or did you record them?

If you can upload a short MKV sample that is causing problems to Drive or Dropbox, I can easily check for errors and probably correct in VRD.

Miles-Thatch wrote on 1/27/2022, 8:59 PM

Miles, from the red flags raised by your description, I strongly suspect that your AVC-encoded files have stream errors that do not get corrected by remuxing ("rewrapping"). Otherwise, I have no plausible explanation why remuxing is failing or causing you fits with consumer source; and of course, remuxing will preserve every bit of data in the MKV, for better or for worse, regardless of the container, even program streams. Of course, such files can cause fits for transcoders as well.

Were these originally streaming or downloaded recordings, or did you record them?

If you can upload a short MKV sample that is causing problems to Drive or Dropbox, I can easily check for errors and probably correct in VRD.

I record with OBS into MKVs The instability shows itself in different ways. Sometimes it's abysmal editing playback speeds when multiple video layers are usually overlaying one another (view within view sort of thing, something that doesn't happen or nearly not as bad my source files are recorded mp4s from the get go), as well as crashes during rendering. The rendering crashes could happen at random too, it's not a specific dropped frame. It could be at a 2 minute mark, could be at 2:14:24 hour mark - it's random. Sometimes it doesn't crash at all. The only time I have a smooth editing experience is when my source footage is recorded into MP4 right away. But because of how esily corruptible it is due to interrupted recording (power outage, storage ran out, OBS crashes, OS crashes, Windows decides to update, etc)

It's clear to me that remuxing isn't going to make Vegas behave as I've been struggling with this for years. Either I risk capturing with MP4 or I do transcoding with minimal data loss.

I'm just here for the ffmpeg command line that allows me to transcode

Musicvid wrote on 1/27/2022, 9:14 PM

Miles, once again your OBS source captures may have stream errors that are not revealed during normal stream playback, but which are problematic for unpacked decoding to raw bits, as in Vegas.

I appreciate your speculation, and it is all quite plausible; however, I have worked extensively with OBS capture settings, using both software and hardware encoders such as yours, and the problems you are encountering are not atypical, especially at high frame rates, as are yours.

It is worth repeating that there are no fundamental differences between MKV and MP4 as wrappers for AVC/AAC media.

Samples that exhibit the decoding problems you mentioned in Vegas, please; we may be able to suggest other capture settings that will avoid the situation during capture, also screenshots of your OBS recording settings, thanks.

If my suspicions are correct, transcoding by ffmpeg may not result in an improvement, but the internet is full of suggested command lines, and Happy Otter Scripts come with their own set of tested presets for doing just what you may want. If you don't wish to share source samples, I understand, and you may want to continue your experiments there. Do let us know how it turns out for you, OK?

Miles-Thatch wrote on 1/27/2022, 9:21 PM

Miles, once again your OBS source captures may have stream errors that are not revealed during normal stream playback, but which are problematic for unpacked decoding to raw bits, as in Vegas.

I appreciate your speculation, and it is all quite plausible; however, I have worked extensively with OBS capture settings, using both software and hardware encoders such as yours, and the problems you are encountering are not atypical, especially at high frame rates, as yours are.

Samples that exhibit the decoding problems you mentioned in Vegas, please; we may be able to suggest other capture settings that will avoid the situation during capture, also screenshots of your OBS recording settings, thanks.

Will do. I'll have to take a moment.

Musicvid wrote on 1/27/2022, 9:59 PM

My basic mkv to mp4 transcode file is

ffmpeg -i "input.mkv" -c copy -strict -2 "output.mp4"

fmpeg -i "input.mkv" -map 0 -c copy -strict -2 "output.mp4"

Those are copy (rewrap) commands, not transcodes.

@3d87c4

3d87c4 wrote on 1/28/2022, 12:43 PM

Yes, but I wanted to get some discussion of FFMPEG going, if really wanted.

It would be nice if smaller sample clip were available to tinker with.

Last changed by 3d87c4 on 1/28/2022, 12:45 PM, changed a total of 1 times.

Del XPS 17 laptop

Processor    13th Gen Intel(R) Core(TM) i9-13900H   2.60 GHz
Installed RAM    32.0 GB (31.7 GB usable)
System type    64-bit operating system, x64-based processor
Pen and touch    Touch support with 10 touch points

Edition    Windows 11 Pro
Version    22H2
Installed on    ‎6/‎8/‎2023
OS build    22621.1848
Experience    Windows Feature Experience Pack 1000.22642.1000.0

NVIDIA GeForce RTX 4070 Laptop GPU
Driver Version: 31.0.15.2857
8GB memory
 

Howard-Vigorita wrote on 1/28/2022, 12:53 PM

I'm just here for the ffmpeg command line that allows me to transcode

@Miles-Thatch If you want to transcode instead of copying a stream from one container to another, specify a codec other than "copy". For instance, instead of "-c copy", indicate that it's a video codec you're talking about and specify something like this, "-c:v libx264". That'll use the software-only h.264 video codec to transcode but may require other specifics like pixel format, frame size, bitrate, quality, etc. But stick to the "copy" codec if you can because its the simplest, fastest, and cleanest. Before giving up on rewrapping the video stream, are you sure the video stream is the problem? Try a rewrap without the any audio and see if the video alone edits ok. The ffmpeg option to omit all audio streams is "-an". If the audio channels are your sticking point, rewraping or transcoding to an mxf container might help... Vegas has some mxf-specific audio stream options that might work for you.

If the captured video stream is the problem... another alternative to fixing it with a transcode is to use a different tool to capture it in the 1st place. Looks like whatever you're using to capture is using ffmeg libs but must not be exposing enough options if you can only capture mkv. To capture gameplay, doing it in hardware within your gpu is another way to go which is usually best... Nvidia, Amd, and Intel all have ways to do that. Vegas can also do screen capture and works well for some but gives me mixed results on my systems.

Former user wrote on 1/28/2022, 9:10 PM

To capture gameplay, doing it in hardware within your gpu is another way to go which is usually best... Nvidia, Amd, and Intel all have ways to do that. Vegas can also do screen capture and works well for some but gives me mixed results on my systems.

@Howard-Vigorita I only skimmed through this, but from everything I"ve seen it seems like he would be using NVENC encoding, and Vegas doesn't like Nvenc encoding which is his problem. It causes the poor timeline playback/scrubbing and the crashes. Lots of experience with that. He claims encoding in MP4 directly doesn't produce the same problems as recording in MKV and rewraping using OBS. I don't believe there should be any difference.

Vegas does like x264 encodes though. signature says he has 8 core cpu, that may be enough to encode using one of the x264 profiles, and not even bother with Nvenc. As I don't believe there actually is any difference between a OBS recorded mp4 and a OBS recorded mkv rewrapped to mp4 (using OBS) that may be the solution. Depends if he has enough CPU, a 3900 or 5900 would be the preference for x264 screen capture when gaming over his 3800X

frankp wrote on 1/28/2022, 10:40 PM

Stream errors… VideoRedo’s QuickStream Fix is good for this.
I’m pretty sure there’s a ffmpeg commandline similar to it. I have it somewhere written and saved as a text file. Try searching “quickstream fix ffmpeg”

Magix Vegas Pro 17 Edit

OS: Windows 10 Pro 64

CPU: Intel Core i7-9700K Coffee Lake 8-Core 3.6 GHz LGA 1151 

Cooler: Noctua NH-L9x65

Motherboard: Gigabyte Z390 Designare

RAM: Ballistix Sport LT 32GB DDR4 2400 MT/s

GPU: Sapphire Radeon RX Vega 64 8GB

Capture Card: Blackmagic Intensity Pro 4K

PSU: Corsair RMx Series 850W

Boot Drive: Samsung 970 EVO NVMe 2TB

Data Drives: Toshiba X300 5TB 7200 RPM (x4)

RAID: G-Technology G-RAID with Thunderbolt 3 and Blackjet VX-2SSD USB 3.1 10Gbps USB Type-C

Case: iStarUSA D400 Black

Monitors: Viewsonic VP2785-4K, VP2468 IPS Panels

Camera: Sony a6600 APS-C, Sony ZV-1