+ Reply to Thread
Results 31 to 38 of 38
-
Open the source in Avidemux. Set the output format (lower left) to mp4 muxer.
Use the A and B buttons at the bottom to mark off a short section, one or two minutes.
Save, and verify that the file plays back properly. This will be the reference file for untrunc.
Open untrunc and give it the reference file and the bad file, it will create a third, the "fixed" file. -
First, in post #23 I post the error message when I first open the MP4. Nobody has addressed it, so, I don't know if Avidemux can deal with the file or if I should click on "proceed". Also, nobody has addressed by Avidemux is recommended or required to create the reference file. So, I used this command to create a 2 minute reference file:
Then, I ran untrunc-gui. The first time, I ran it without any changes in the settings tab and it generated this error:Code:ffmpeg out.mp4 -t 00:02:00.000 -c copy to reference.mp4"
I clicked "ignore" and it finished without any other error messages. untrunc does not seem to have the ability to generate a log file and trying to highlight and copy the displayed log does not work. Windows and VLC show the length of the fixed MP4 to be 2:52:05, which is 11 seconds longer than the original MP4. The untrunc-gui log screen shows "Duration of mp4a: 2h 51 min 54s 536ms" and "Duration of avc1: 2h 52min 5s 736ms". When I play it in VLC, it shows a length of 2:52:05 and everything is good until 1:42:22 when both the video and the audio stops. This is the MediaInfo for that MP4:Code:Assertion failed! Program: untrunc-gui.exe File: src/atom.cpp, Line 481 Expression: end - start = = new_length <Abort> <Retry> <Ignore>
Next, I ran untrunc-gui again, but, this time in the "Settings" tab, I click "on":Code:General Complete name : C:out_fixed.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom (isom/iso2/avc1/mp41) File size : 4.66 GiB Duration : 2 h 52 min Overall bit rate : 3 877 kb/s Writing application : Lavf58.78.100 IsTruncated : Yes Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4 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 : 2 h 52 min Bit rate : 6 402 kb/s Maximum bit rate : 20.1 Mb/s Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Variable Frame rate : 29.937 FPS Minimum frame rate : 5.994 FPS Maximum frame rate : 120.000 FPS Original frame rate : 29.970 (30000/1001) FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.103 Stream size : 7.70 GiB Codec configuration box : avcC Audio ID : 2 Format : AAC LC Format/Info : Advanced Audio Codec Low Complexity Codec ID : mp4a-40-2 Duration : 2 h 51 min Bit rate mode : Constant Bit rate : 93.6 kb/s Channel(s) : 2 channels Channel layout : L R Sampling rate : 44.1 kHz Frame rate : 43.066 FPS (1024 SPF) Compression mode : Lossy Stream size : 118 MiB (2%) Default : Yes Alternate group : 1 Text #1 ID : 1-CC1 Format : EIA-608 Muxing mode : SCTE 128 / DTVCC Transport Muxing mode, more info : Muxed in Video #1 Duration : 2 h 52 min Bit rate mode : Constant Stream size : 0.00 Byte (0%) CaptionServiceName : CC1 Text #2 ID : 1-CC3 Format : EIA-608 Muxing mode : SCTE 128 / DTVCC Transport Muxing mode, more info : Muxed in Video #1 Duration : 2 h 52 min Bit rate mode : Constant Stream size : 0.00 Byte (0%) CaptionServiceName : CC3
- "skip unknown (-s)"
- "stretch video to match audio (-sv)"
- "keep unknown sequences (-k)"
So, it looks like untrunc is able to fix the mismatched sync, but, it is not exact. I am not sure what to try next.Code:General Complete name : C:out.mp4_fixed-s1-k-sv.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom (isom/iso2/avc1/mp41) File size : 7.82 GiB Duration : 2 h 52 min Overall bit rate : 6 507 kb/s Writing application : Lavf58.78.100 Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4 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 : 2 h 52 min Bit rate : 6 402 kb/s Maximum bit rate : 20.1 Mb/s Width : 1 920 pixels Height : 1 080 pixels Display aspect ratio : 16:9 Frame rate mode : Variable Frame rate : 29.937 FPS Minimum frame rate : 5.994 FPS Maximum frame rate : 120.000 FPS Original frame rate : 29.970 (30000/1001) FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.103 Stream size : 7.70 GiB (98%) Codec configuration box : avcC Audio ID : 2 Format : AAC LC Format/Info : Advanced Audio Codec Low Complexity Codec ID : mp4a-40-2 Duration : 2 h 51 min Bit rate mode : Constant Bit rate : 93.6 kb/s Channel(s) : 2 channels Channel layout : L R Sampling rate : 44.1 kHz Frame rate : 43.066 FPS (1024 SPF) Compression mode : Lossy Stream size : 118 MiB (1%) Default : Yes Alternate group : 1 Text #1 ID : 1-CC1 Format : EIA-608 Muxing mode : SCTE 128 / DTVCC Transport Muxing mode, more info : Muxed in Video #1 Duration : 2 h 52 min Bit rate mode : Constant Stream size : 0.00 Byte (0%) CaptionServiceName : CC1 Text #2 ID : 1-CC3 Format : EIA-608 Muxing mode : SCTE 128 / DTVCC Transport Muxing mode, more info : Muxed in Video #1 Duration : 2 h 52 min Bit rate mode : Constant Stream size : 0.00 Byte (0%) CaptionServiceName : CC3
-
-
OK, it looks like I have a solution. After running untrunc, I end up with an MP4 where the video (via info from MediaInfo) is 2:51:54 long (the original length) and the audio is 2:52:05 long. A quick look in VLC seems to indicate that the 11 second difference on syncing the audio and video is evenly spread out. Doing a bit a math, the video is 0.998915331556 times as long as the audio. So, I decided to try the following command:
This is supposed to change the speed/rate of the audio. (The "-crf 16" is just trying to retain the original quality and the "16" can be adjusted to whatever your original quality is.) The resulting MP4 seems to have the audio and video in sync!Code:ffmpeg" -i out_of_sync.mp4 -filter_complex "[0:v]setpts=1.0*PTS[v];[0:a]atempo=0.998915331556[a]" -map "[v]" -map "[a]" -crf 16 out_fix.mp4
I will post a final post for the thread that recaps the thread and solution for any future readers. -
**************************************
This is a recap of the thread issue and the solution
**************************************
I have an H264 MP4 that I downloaded from a streaming site via the Firefox add-on "Video DownloadHelper". Windows and VLC tells me that it is 2:51:54 long. At the 1:57:07 mark, the video track speeds up and then stops before the end, but, the audio track continues at normal speed to the end. VLC shows the frame rate to be 94.126760 (yeah, that's weird!). I downloaded that file at least 5 times and the problem starts at the same timestamp each time. When I stream the video in Firefox, everything works fine all of the way through to the end.
It was suggested that I use untrunc to correct the problem - an app that I have never used before. It needs a "reference file" that has all of the attributes/setting that you want for the resulting corrected file. It was suggested that I use Avidemux (another app I have never used) to create this reference file, but, instead I used this ffmpeg command to create a 2 minute long file from the beginning of the MP4:Then, I ran untrunc-gui without clicking "on" any of the checkboxes in the "Settings" tab", but, it did not run properly (see post #34 for that information). Next, I ran untrunc-gui again, but, this time in the "Settings" tab, I click "on":Code:ffmpeg out.mp4 -t 00:02:00.000 -c copy to reference.mp4"
- "skip unknown (-s)"
- "stretch video to match audio (-sv)"
- "keep unknown sequences (-k)"
This command does not change the speed of the video track, changes the audio track speed, and, tries to retain the original overall quality (via "-crf 16") since the file is being re-encoded. This resulted in an MP4 where it is the original length, and, the audio and video tracks are in sync. SUCCESS!Code:ffmpeg" -i out_of_sync.mp4 -filter_complex "[0:v]setpts=1.0*PTS[v];[0:a]atempo=0.998915331556[a]" -map "[v]" -map "[a]" -crf 16 out_new.mp4
The end result is that I was able to fix the MP4. But, I did not learn what might have caused this problem, what app to use to discover where/how/why the problem occurred, or, how it was fixed (meaning, I know that untrunc fixed it but I don't know what it changed/fixed). Simply, I just wanted to know exactly what was broken, but, I guess sometimes it is not worth knowing (for instance: "just reboot the computer to fix that") when you have a tool that can fix it. -
Most of the times I have encountered this is when I have inadvertantly joined 2 segments with different formats, particularly the AUDIO. Joining these videos gives different lengths for audio and video. Other mismatches cause similar problems but almost all that I have encounteredd have been from joining 2 segments of un-similar formats.
Joining 44.1k sample rate with 48k sample rate with ffmpeg delivers the following mediainfo.
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings : CABAC / 3 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 3 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 15 min 54 s
Source duration : 15 min 54 s
Bit rate : 792 kb/s
Width : 854 pixels
Height : 480 pixels
Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 17 min 18 s
Bit rate mode : Constant
Bit rate : 101 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Similar Threads
-
How do I synchronize audio with video in an MP4 file?
By ilyaz in forum Video ConversionReplies: 3Last Post: 31st Mar 2022, 07:13 -
how do i replace part of mp4 file
By cns00 in forum EditingReplies: 7Last Post: 2nd Jan 2021, 10:05 -
How to Remove Some Middle Part From Video .mp4 File
By Daringbaaz in forum Newbie / General discussionsReplies: 2Last Post: 12th Feb 2019, 07:02 -
ToolNix / Avidemux merging mp4, 2nd part grey video correct audio
By jfjfjf in forum EditingReplies: 5Last Post: 18th Nov 2017, 16:56 -
MP4Box: How to extract a given part of a mp4 video
By semantics in forum Newbie / General discussionsReplies: 1Last Post: 9th Jan 2017, 18:38




Quote