TL; DR
How to convert this .ogm file to an .mp4 file using ffmpeg, such that audio and video are properly synced?
My attempts
The problem seems to be that the audio in the .ogm file is a non-monotonous DTS. My first attempt was naive:
However, video frames are duplicated and the latency accumulates. The input video is 23:11 and the output is 27:35. The output video and audio are out of sync, but the difference is not constant, it accumulates through the video. I tried delaying audio/video by a constant time, but it doesn't solve the problem, since the difference is not constant.Code:ffmpeg -i inp.ogm -max_muxing_queue_size 100000 -c:v h264_qsv -global_quality 18 -look_ahead 1 -pix_fmt nv12 out.mp4
I tried all combinations of "-vsync X -async Y", where X and Y are 0, 1, or 2. None of that works. When "async" is set to 1, video and audio are synced, but the problem is that the audio is interspersed by periods of silence after every ~0.5 seconds (non constant). The second problem is that the output video is again 27:35 long, instead of 23:11.
Also tried changing "atempo", redefining DTS timestamps using PTS, changing output framerate, but none of that works. It results in weird audio/video glitches.
My understanding is that the audio consists of chunks, each chunk contains the starting time and the audio data. However, the length of the audio data is longer than the video frame duration (inverse of the framerate), so ffmpeg fills the gaps with duplicated frames. With "-async 1", it doesn't duplicate frames, but it leaves periods of silence (this seems counter-intuitive to me, I don't actually know why it happens).
The .ogm file plays perfectly fine using ffplay. My goal is to convert the .ogm file to an .mp4 file that plays just like ffplay plays the .ogm file.
+ Reply to Thread
Results 1 to 9 of 9
-
Last edited by Patrick1389; 18th Aug 2023 at 05:09.
-
What do you intend to do aboout the interlacing/combing in the source?
Leave it and encode it as is?
Or perhaps reduce it to 25 (or 23.976) to recover the underlying frame rate? -
Thank you for the reply. I just want to create an .mp4 file from the .ogm file that plays exactly the same as ffplay plays the .ogm file. That is, the output file duration should be 23:11 and the audio and video should be synchronized. Naively re-encoding both streams results in a longer video, many frames are duplicated and audio is out of sync.
I've managed to achieve what I want by first extracting audio and video streams separately, then re-encoding video only, and finally combining the streams into one file:
Code:ffmpeg -i inp.ogm -c:v copy -an v0.mp4 ffmpeg -i v0.mp4 -max_muxing_queue_size 100000 -c:v h264_qsv -global_quality 18 -look_ahead 1 -pix_fmt nv12 v.mp4 ffmpeg -i inp.ogm -vn -c:a copy a.mp4 ffmpeg -i v.mp4 -i a.mp4 -c copy out.mp4 rm v0.mp4 v.mp4 a.mp4
-
Even a simple command using Libx264 results in a good file.
Code:ffmpeg.exe -i "C:\Users\davex\Downloads\inp\inp.mkv" -c:v libx264 -preset faster -c:a copy out.mp4
-
I don't know what the problem with ffmpeg is but this works well in AviSynth:
Code:v = LWLibavVideoSource("inp.ogm") a = LWLibavAudioSource("inp.ogm") AudioDub(v,a) DelayAudio(0.2) # 200 ms AssumeTFF() QTGMC(preset="fast") SRestore(frate=25)
-
see this thread post #10 - https://forum.videohelp.com/threads/361242-Help-ffmpeg-bat-ogm-mp4
-
Doesn't seem to be a HW encoding problem. Running your command exactly, I get a 27:35 video, which is undesired. What does ffprobe output for your out.mp4 if you run that command on your machine? If the duration is 27:35, then your command doesn't produce a "good" file. If the duration is 23:11, then my installation of ffmpeg is broken for some reason.
That thread is unrelated. -
The command there didn't work. There's just something odd about the timecodes in the OP's mp4 file. ffmpeg gives a video that's about 4 minutes too long.
But I was able to get the right result by remuxing to MKV first (with lots of timecode warnings), then converting that MKV using the OP's command line.
Code:ffmpeg -y -fflags +genpts -i inp.ogm -vcodec copy -acodec copy inp.mkv ffmpeg -y -i inp.mkv -max_muxing_queue_size 100000 -c:v h264_qsv -global_quality 18 -look_ahead 1 -pix_fmt nv12 out.mp4
-
Yes I converted to MKV myself (forgot to mention, mux in MKVtoolnix). I think just doing that fixes some issues.
As you can see, mine (the encode using LIbx264) looks good:
Code:Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L3 Format settings : CABAC / 4 Ref Frames Format settings, CABAC : Yes Format settings, Reference frames : 4 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 23 min 11 s Bit rate : 887 kb/s Width : 720 pixels Height : 480 pixels Display aspect ratio : 3:2 Frame rate mode : Constant Frame rate : 29.970 (29970/1000) FPS Standard : NTSC Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.086 Stream size : 147 MiB (86%)
Similar Threads
-
ffmpeg convert wmv to mp4 Failed
By kucing in forum Newbie / General discussionsReplies: 11Last Post: 16th Apr 2022, 12:28 -
ffmpeg better code convert to mp4
By kucing in forum Newbie / General discussionsReplies: 8Last Post: 25th Feb 2022, 12:33 -
using ffmpeg to convert a mkv or mp4 to MPEG-4 suitable for a DVD player
By NeilTelford in forum Video ConversionReplies: 5Last Post: 3rd Jun 2021, 10:55 -
Is it possible to download dash mpd and convert into mp4 using ffmpeg?
By MonikaChen in forum Video Streaming DownloadingReplies: 4Last Post: 16th Feb 2021, 09:09 -
FFMPEG: How to convert multiple DNG to MP4 very fast...
By clkdiv in forum Video ConversionReplies: 0Last Post: 8th Nov 2020, 11:26