<p>Why convert to OGV when your final upload is going to be to youtube, I may be wrong but you can convert to x264 video codec with AAC Audio even on linux and upload that to youtube considering that is what they prefer to be uploaded anyway.  Have you tried making an h264 and uploading to youtube instead of the OGV file and seeing if that was the issue.  Because I would bet that if that solves it, you then know it was an issue with the OGV being uploaded to youtube, and if it does not solve it, it could be a frame-rate issue with youtube's interpretation or something similar.</p>

<p>There have been a lot of issues with OGV files uploaded to youtube in the past.  I cant imagine that it is 100% fixed even at this point.</p>

<p><a href="http://support.google.com/youtube/bin/answer.py?hl=en&amp;answer=1722171" rel="nofollow">http://support.google.com/youtube/bin/answer.py?hl=en&amp;answer=1722171</a></p>

<p>EDIT: also just noticed that your original footage is at 15fps...this could very well be the source of the issue</p>

<p>EDIT 2: I seemed to slightly have misread the question a little bit...being that you are starting with a video file that is OGV, and I saw that you are going to MP4...this changes things a little bit...but I am going to guess it has something to do with the 15fps and 22050 Hz audio...I know the sample rate has nothing to do with syncing the audio, but from experience when using non standard frame-rates and audio samplerates, I have tended to see drifting...getting these to sync may be rather difficult while not being able to edit these after the initial recording with a cheap video editor...</p>

<p>While software has gotten better about drifting audio it is still a common problem when using uncommon framerates and samplerates as the keyframed sync points are not standard and could be rounding key frames etc...</p>

<p>You see where it says "Broken file, keyframe not correctly marked." that is what it is referring to...</p>

<p>my advice for you would be to get it as close as possible, take it into a video editor and slip and cut up the audio to get it to match the way you want it.  Unfortunately sometimes this is how it is fixed...</p>

<p>Software based transcoders do not always work as they should...hense why a protools setup and/or an avid setup would come with hardware to further ensure sync capabilities and constant frame-rates etc...</p>

<p>Another thing you could try is to convert the footage to a standard framerate, and try to re-mary the audio...as I am pretty sure it is the video drifting...probably ever so slightly slowing down and then speeding up towards the end or vice versa.</p>

<p><strong>EDIT: I was able to get the video to sync to the original using this ffmpeg command...it may have need the rate clause which is what I suspected</strong></p>

<p><code>ffmpeg -i sync_test1.ogv -strict experimental -pix_fmt yuv420p -r 15 -vcodec h264 -acodec aac sync_test1.mp4</code></p>

CC BY-SA 3.0
2013-02-20T01:20:13.933Z
The original file is Theora video and Vorbis audio in ogv container. Amir T is not re-encoding to this format, as far as I know, but when he attempts to re-encode the original with either ffmpeg or YouTube the sync problem manifests.
llogan
CC BY-SA 3.0
2013-02-20T02:36:32.413Z
The input format is ogv which is what gtk-recordmydesktop outputs.  I'm trying to get to anything other than ogv (flv, etc).
Amir T
CC BY-SA 3.0
2013-02-20T02:38:15.993Z
Read my updated answer...I think it is an issue of FPS
Chris James Champeau
CC BY-SA 3.0
2013-02-20T03:08:33.250Z
I added an example source file.  The sync issue is *very* noticeable.  It seems to me like a bunch of frames are elided for various formats.
Amir T
CC BY-SA 3.0
2013-02-23T00:56:15.183Z
Try this...see new answer
Chris James Champeau
CC BY-SA 3.0
2013-02-24T21:50:30.533Z
Adding `-r 15` is the same as omitting it because ffmpeg will inherit the input frame rate by default, and the resulting output files, with or without `-r 15` are exactly the same with ffmpeg from git head (version N-50285-gad89952). If it is working for you using an older ffmpeg version this could be a regression and should be reported to the [FFmpeg bug tracker](https://ffmpeg.org/trac/ffmpeg/).
llogan
CC BY-SA 3.0
2013-02-25T21:37:07.557Z
@ChrisJamesChampeau thanks for the suggestion - I tried the command you listed using the static build of ffmpeg I get slide 2 at 12s and 3 at 17s: https://dl.dropbox.com/u/64693533/sync_test/sync_test1.cjc.mp4
Amir T
CC BY-SA 3.0
2013-02-26T01:21:10.303Z
Well the FFmpeg I am using is a MAC version versus your Linus version not sure but my guess is that there must be a bug with your FFMPEG?? have you tried removing it and reinstalling the latest version?
Chris James Champeau
CC BY-SA 3.0
2013-02-26T02:49:47.240Z
Yeah, I've tried two versions, the ubuntu default from apt-get and the static build.
Amir T
CC BY-SA 3.0
2013-02-27T00:06:24.923Z
I am with @LordNeckbeard you should report this as a bug to FFMPEG
Chris James Champeau
CC BY-SA 3.0
2013-02-20T00:21:23.257Z
2013-02-23T00:57:12.703Z
2013-02-23T00:57:12.703Z
Chris James Champeau
<p>I struggled with a similar issue on Ubuntu 12.04.3 LTS. I fixed the problem using the static ffmpeg build which is available from <a href="http://johnvansickle.com/ffmpeg/" rel="nofollow">http://johnvansickle.com/ffmpeg/</a></p>

CC BY-SA 3.0
2014-07-28T23:44:57.467Z
I also tried a static build and it worked somewhat better.  Perhaps the bug has been fixed, in which case it might be useful to add the version number from the static build to your answer?
Amir T
CC BY-SA 3.0
2014-07-28T16:38:58.250Z
2015-08-04T18:26:31.183Z
2015-08-04T18:26:31.183Z
user2768
<p>It seems this bug is still in <code>recordmydesktop</code>, or at least I got the exact same symptoms here with the version from Debian testing (<code>0.3.8.1+svn602-1.1</code>).</p>

<p>I just managed to transcode this video almost correctly, in the following way:</p>

<ol>
<li>Use VLC.</li>
<li>Ask it to transcode to the WebM "profile".</li>
<li>Ask it to display the video as it is transcoded.</li>
</ol>

<p>The result still has the correct synchronization (yay!), but it still suffers from a problem: the resulting video announces itself as lasting more than 4h whereas my video only lasts 25min.  Peertube hence lists it as a 4h video, tho once you start playing it the correct 25min duration is displayed, so the problem is not too serious.</p>

<p>Point 3 is important, but point 2 is also: maybe other profiles will also work, but at least the H264 profile gave me an unusable video (either with bad sync like <code>ffmpeg</code> or worse).</p>

CC BY-SA 4.0
2020-05-28T18:05:28.637Z
2020-05-28T18:05:28.637Z
Stefan
<p>Try just changing the container to avi rather than transcoding, which seems to work better for youtube:</p>

<pre><code>ffmpeg -i JSP.ogv -vcodec copy -acodec copy JSP.avi
</code></pre>

CC BY-SA 4.0
2019-10-30T20:00:39.210Z
I tried this, and the upload just never finishes processing, same as if I upload OGV. Since this answer predates youtube accepting OGV, it must be that change.  Annoying that ffmpeg still has this conversion problem four years later.
mcr
CC BY-SA 4.0
2019-10-30T20:22:38.813Z
My ffpmeg is:  3.2.14-1~deb9u1  (apt-get installed)
mcr
CC BY-SA 4.0
2019-10-30T20:42:21.283Z
I have tried all the variations above, with static builds (git-20191029), and while it gets a bit better, the audio and video unsync.  If trying one needs a large --max_muxing_queue_size value. I used 40960.
mcr
CC BY-SA 3.0
2015-08-04T03:33:12.123Z
2015-08-04T03:33:12.123Z
CpnCrunch
<p>I've made a set of screencasts using recordmydesktop on ubuntu 12.10.
The output is an ogv file.  When I watch the ogv file using the default movie player (totem) it looks fine - the audio and video are in sync.  When it is transcoded (by me or youtube) the audio and video are out of sync.  It looks like I skip through a slide or two while narrating.</p>

<h2>Update</h2>

<p>I suspect the problem is more properly characterized as dropping duplicate frames during transcoding.  Converting video where the mouse is moving seems to normally work fine.  But when I'm just talking during a slide those duplicate frames are dropped.</p>

<p>I saw this but it isn't quite my situation (trying to go from ogv -> anything) <a href="https://superuser.com/questions/436187/ffmpeg-convert-video-w-dropped-frames-out-of-sync">https://superuser.com/questions/436187/ffmpeg-convert-video-w-dropped-frames-out-of-sync</a></p>

<p>AVI files seem to translate correctly!  I assume this will be a big hint to someone.  I'd still like to track down the underlying issue.  I'm testing the conversion of my previous videos to AVI but this takes a while since I have to check each transition.</p>

<h2>Examples</h2>

<p>This is the original OGV file from gtk-recordmydesktop:
<a href="http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ogv" rel="nofollow noreferrer">http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ogv</a></p>

<p>The video starts with a slide for 10s, then advances to 3 more slides 5s each.  Each time I advance slides I tap the microphone too (10s, 15s, 20s, 25s).</p>

<p>Here are some conversions that were done (each displays it's own video timing issues):</p>

<p><a href="http://dl.dropbox.com/u/64693533/sync_test/sync_test1.mp4" rel="nofollow noreferrer">http://dl.dropbox.com/u/64693533/sync_test/sync_test1.mp4</a></p>

<ul>
<li>this one shows the first slide in the first frame but quickly advances past it</li>
<li>this was done using the stock ffmpeg</li>
</ul>

<p><a href="http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ffmpeg-static.mp4" rel="nofollow noreferrer">http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ffmpeg-static.mp4</a></p>

<ul>
<li>this one is pretty close - for some reason at 13s it decides to advance though</li>
<li>this was done using the static build of ffmpeg from a few days ago</li>
</ul>

<p>Here it is on youtube - you can see that at around 13s it advances early (from slide 1 -> slide 2):
<div class="youtube-embed"><div>
                <iframe width="640px" height="395px" src="https://www.youtube.com/embed/MrCqsoy_WoI?start=11"></iframe>
            </div></div></p>

<p>Here is proof the OGV file works correctly:
<div class="youtube-embed"><div>
                <iframe width="640px" height="395px" src="https://www.youtube.com/embed/yCdpQJZP9ik?start=0"></iframe>
            </div></div></p>

<h2>ffmpeg translation</h2>

<p>Using ffmpeg or avconv I seem to get similar results as youtube (transitions appear to happen early but not necessarily at the same time).</p>

<p>Here is the command I use (with a recent static build of ffmpeg) and output:</p>

<pre>
$ ~/ffmpeg/ffmpeg -i JSP.ogv JSP.mp4
ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 05:23:03 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[ogg @ 0x34d4640] Multiple fisbone for the same stream is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[ogg @ 0x34d4640] Header parsing failed for stream 0
[ogg @ 0x34d4640] Broken file, keyframe not correctly marked.
Input #0, ogg, from 'JSP.ogv':
  Duration: 00:12:49.67, start: 0.000000, bitrate: 224 kb/s
    Stream #0:0: Data: none
    Stream #0:1: Video: theora, yuv420p, 1600x880 [SAR 1:1 DAR 20:11], 15 fps, 15 tbr, 15 tbn, 15 tbc
    Metadata:
      RECORDMYDESKTOP : 0.3.8.1
    Stream #0:2: Audio: vorbis, 22050 Hz, mono, fltp, 89 kb/s
[libx264 @ 0x369c5e0] using SAR=1/1
[libx264 @ 0x369c5e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x369c5e0] profile High, level 4.0
[libx264 @ 0x369c5e0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'JSP.mp4':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1600x880 [SAR 1:1 DAR 20:11], q=-1--1, 15360 tbn, 15 tbc
    Metadata:
      RECORDMYDESKTOP : 0.3.8.1
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 22050 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (theora -> libx264)
  Stream #0:2 -> #0:1 (vorbis -> libvo_aacenc)
Press [q] to stop, [?] for help
[ogg @ 0x34d4640] Broken file, non-keyframe not correctly marked.
    Last message repeated 2 times
Broken file, non-keyframe not correctly marked.=00:00:08.37 bitrate=  28.7kbits/s dup=66 drop=0    
Broken file, keyframe not correctly marked.time=00:00:51.01 bitrate= 125.3kbits/s dup=675 drop=0    
Broken file, keyframe not correctly marked.time=00:00:55.05 bitrate= 140.2kbits/s dup=782 drop=0    
Broken file, keyframe not correctly marked.time=00:00:59.60 bitrate= 140.5kbits/s dup=836 drop=0    
[ogg @ 0x34d4640] Broken file, keyframe not correctly marked.
Broken file, keyframe not correctly marked.time=00:01:08.00 bitrate= 143.0kbits/s dup=900 drop=0    
Broken file, keyframe not correctly marked.time=00:01:11.86 bitrate= 141.6kbits/s dup=910 drop=0    
</pre>

<p>...repeated many times...</p>

<pre>
Broken file, keyframe not correctly marked.time=00:12:47.62 bitrate= 153.0kbits/s dup=9087 drop=0    
frame=11521 fps= 87 q=-1.0 Lsize=   14849kB time=00:12:49.48 bitrate= 158.1kbits/s dup=9087 drop=0    
video:2401kB audio:12024kB subtitle:0 global headers:0kB muxing overhead 2.938094%
[libx264 @ 0x369c5e0] frame I:49    Avg QP:16.05  size: 29658
[libx264 @ 0x369c5e0] frame P:2912  Avg QP: 9.88  size:   114
[libx264 @ 0x369c5e0] frame B:8560  Avg QP:12.76  size:    78
[libx264 @ 0x369c5e0] consecutive B-frames:  0.9%  0.1%  0.2% 98.9%
[libx264 @ 0x369c5e0] mb I  I16..4: 90.8%  0.4%  8.8%
[libx264 @ 0x369c5e0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:99.9%
[libx264 @ 0x369c5e0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.3%  0.0%  0.0%  direct: 0.0%  skip:99.7%  L0:65.3% L1:34.6% BI: 0.1%
[libx264 @ 0x369c5e0] 8x8 transform intra:0.5% inter:15.8%
[libx264 @ 0x369c5e0] coded y,uvDC,uvAC intra: 6.4% 0.1% 0.1% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x369c5e0] i16 v,h,dc,p: 94%  4%  2%  0%
[libx264 @ 0x369c5e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 22% 44%  1%  2%  2%  3%  1%  6%
[libx264 @ 0x369c5e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 17% 19%  4%  5%  5%  5%  5%  5%
[libx264 @ 0x369c5e0] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x369c5e0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x369c5e0] ref P L0: 82.5%  1.4% 11.9%  4.3%
[libx264 @ 0x369c5e0] ref B L0: 47.2% 52.4%  0.4%
[libx264 @ 0x369c5e0] ref B L1: 99.2%  0.8%
[libx264 @ 0x369c5e0] kb/s:25.60
</pre>

<p>The video still advances early but at different times.  It sounds like gtk-recordmydesktop is generating a "broken file".  What's annoying is that the OGV does work so it seems like I should be able to make this work with some set of options.</p>

<p><s>I have found that I can render the video in kdenlive and it seems to be working there.  I'd still like to know what is going on.</s>  kdenlive does a much better job, but it still advances early sometimes.</p>

CC BY-SA 3.0
2013-01-15T17:38:52.703Z
Please show your ffmpeg command and the resulting complete console output.
llogan
CC BY-SA 3.0
2013-02-17T20:26:23.923Z
Good idea @LordNeckbeard I added the command and output.  I notice an error/warning: max_analyze_duration reached.
Amir T
CC BY-SA 3.0
2013-02-17T20:56:32.947Z
Does the issue still occur if you use a recent [static build of ffmpeg](http://ffmpeg.org/download.html#LinuxBuilds)? This will rule out any potential bugs that you may be encountering that have already been fixed with a newer version of ffmpeg. No need to install or anything. Just download, extract the archive, and then execute the included `ffmpeg` binary.
llogan
CC BY-SA 3.0
2013-02-19T19:22:55.237Z
Can you provide a sample input file that the problem can be reproduced with?
llogan
CC BY-SA 3.0
2013-02-19T19:46:27.360Z
Good idea, I'll whip up a small one and post it later tonight.
Amir T
CC BY-SA 3.0
2013-02-20T12:58:23.073Z
Would an answer along the lines of 'use a different screen recording program' be acceptable? It looks like GTK-recordmydesktop is creating broken files.
evilsoup
CC BY-SA 3.0
2013-02-20T16:24:16.073Z
@evilsoup - Unfortunately no, I've created a number of recordings already before noticing the problem.  Moreover I can watch the OGV just fine in linux so it seems it's not totally corrupt.  That being said, I will be trying to track down why it's creating "broken files".
Amir T
CC BY-SA 3.0
2013-02-24T22:22:44.367Z
Unless I'm missing something this is probably a bug or lack of ogg feature support in ffmpeg and/or a bug in recordmydesktop (that ffmpeg hasn't made a special case for). A [bug report](https://ffmpeg.org/trac/ffmpeg/) may be the best option here. Make sure to use the latest ffmpeg version you can, show your ffmpeg command and complete console output, provide `sync_test1.ogv`, and try to show the problem using only native encoders (no `lib*` such as `libx264`) if possible.
llogan
CC BY-SA 3.0
2013-02-25T21:38:40.397Z
Thanks for the suggestion @LordNeckbeard I'll submit a bug report and see where that goes.  Any idea why AVI seems to be working?
Amir T
<ffmpeg><transcoding><youtube>
OGV Format plays properly on my computer but transcoding drops (duplicate?) frames
Amir T
# OGV Format plays properly on my computer but transcoding drops (duplicate?) frames

(Asked by: username_0 on 2013-01-13)

I've made a set of screencasts using recordmydesktop on ubuntu 12.10.
The output is an ogv file.  When I watch the ogv file using the default movie player (totem) it looks fine - the audio and video are in sync.  When it is transcoded (by me or youtube) the audio and video are out of sync.  It looks like I skip through a slide or two while narrating.
Update
I suspect the problem is more properly characterized as dropping duplicate frames during transcoding.  Converting video where the mouse is moving seems to normally work fine.  But when I'm just talking during a slide those duplicate frames are dropped.
I saw this but it isn't quite my situation (trying to go from ogv -> anything) https://superuser.com/questions/436187/ffmpeg-convert-video-w-dropped-frames-out-of-sync
AVI files seem to translate correctly!  I assume this will be a big hint to someone.  I'd still like to track down the underlying issue.  I'm testing the conversion of my previous videos to AVI but this takes a while since I have to check each transition.
Examples
This is the original OGV file from gtk-recordmydesktop:
http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ogv
The video starts with a slide for 10s, then advances to 3 more slides 5s each.  Each time I advance slides I tap the microphone too (10s, 15s, 20s, 25s).
Here are some conversions that were done (each displays it's own video timing issues):
http://dl.dropbox.com/u/64693533/sync_test/sync_test1.mp4

this one shows the first slide in the first frame but quickly advances past it
this was done using the stock ffmpeg

http://dl.dropbox.com/u/64693533/sync_test/sync_test1.ffmpeg-static.mp4

this one is pretty close - for some reason at 13s it decides to advance though
this was done using the static build of ffmpeg from a few days ago

Here it is on youtube - you can see that at around 13s it advances early (from slide 1 -> slide 2):



Here is proof the OGV file works correctly:



ffmpeg translation
Using ffmpeg or avconv I seem to get similar results as youtube (transitions appear to happen early but not necessarily at the same time).
Here is the command I use (with a recent static build of ffmpeg) and output:

$ ~/ffmpeg/ffmpeg -i JSP.ogv JSP.mp4
ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 05:23:03 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[ogg @ 0x34d4640] Multiple fisbone for the same stream is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[ogg @ 0x34d4640] Header parsing failed for stream 0
[ogg @ 0x34d4640] Broken file, keyframe not correctly marked.
Input #0, ogg, from 'JSP.ogv':
  Duration: 00:12:49.67, start: 0.000000, bitrate: 224 kb/s
    Stream #0:0: Data: none
    Stream #0:1: Video: theora, yuv420p, 1600x880 [SAR 1:1 DAR 20:11], 15 fps, 15 tbr, 15 tbn, 15 tbc
    Metadata:
      RECORDMYDESKTOP : 0.3.8.1
    Stream #0:2: Audio: vorbis, 22050 Hz, mono, fltp, 89 kb/s
[libx264 @ 0x369c5e0] using SAR=1/1
[libx264 @ 0x369c5e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x369c5e0] profile High, level 4.0
[libx264 @ 0x369c5e0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'JSP.mp4':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1600x880 [SAR 1:1 DAR 20:11], q=-1--1, 15360 tbn, 15 tbc
    Metadata:
      RECORDMYDESKTOP : 0.3.8.1
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 22050 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (theora -> libx264)
  Stream #0:2 -> #0:1 (vorbis -> libvo_aacenc)
Press [q] to stop, [?] for help
[ogg @ 0x34d4640] Broken file, non-keyframe not correctly marked.
    Last message repeated 2 times
Broken file, non-keyframe not correctly marked.=00:00:08.37 bitrate=  28.7kbits/s dup=66 drop=0    
Broken file, keyframe not correctly marked.time=00:00:51.01 bitrate= 125.3kbits/s dup=675 drop=0    
Broken file, keyframe not correctly marked.time=00:00:55.05 bitrate= 140.2kbits/s dup=782 drop=0    
Broken file, keyframe not correctly marked.time=00:00:59.60 bitrate= 140.5kbits/s dup=836 drop=0    
[ogg @ 0x34d4640] Broken file, keyframe not correctly marked.
Broken file, keyframe not correctly marked.time=00:01:08.00 bitrate= 143.0kbits/s dup=900 drop=0    
Broken file, keyframe not correctly marked.time=00:01:11.86 bitrate= 141.6kbits/s dup=910 drop=0    

...repeated many times...

Broken file, keyframe not correctly marked.time=00:12:47.62 bitrate= 153.0kbits/s dup=9087 drop=0    
frame=11521 fps= 87 q=-1.0 Lsize=   14849kB time=00:12:49.48 bitrate= 158.1kbits/s dup=9087 drop=0    
video:2401kB audio:12024kB subtitle:0 global headers:0kB muxing overhead 2.938094%
[libx264 @ 0x369c5e0] frame I:49    Avg QP:16.05  size: 29658
[libx264 @ 0x369c5e0] frame P:2912  Avg QP: 9.88  size:   114
[libx264 @ 0x369c5e0] frame B:8560  Avg QP:12.76  size:    78
[libx264 @ 0x369c5e0] consecutive B-frames:  0.9%  0.1%  0.2% 98.9%
[libx264 @ 0x369c5e0] mb I  I16..4: 90.8%  0.4%  8.8%
[libx264 @ 0x369c5e0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:99.9%
[libx264 @ 0x369c5e0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.3%  0.0%  0.0%  direct: 0.0%  skip:99.7%  L0:65.3% L1:34.6% BI: 0.1%
[libx264 @ 0x369c5e0] 8x8 transform intra:0.5% inter:15.8%
[libx264 @ 0x369c5e0] coded y,uvDC,uvAC intra: 6.4% 0.1% 0.1% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x369c5e0] i16 v,h,dc,p: 94%  4%  2%  0%
[libx264 @ 0x369c5e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 22% 44%  1%  2%  2%  3%  1%  6%
[libx264 @ 0x369c5e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 17% 19%  4%  5%  5%  5%  5%  5%
[libx264 @ 0x369c5e0] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x369c5e0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x369c5e0] ref P L0: 82.5%  1.4% 11.9%  4.3%
[libx264 @ 0x369c5e0] ref B L0: 47.2% 52.4%  0.4%
[libx264 @ 0x369c5e0] ref B L1: 99.2%  0.8%
[libx264 @ 0x369c5e0] kb/s:25.60

The video still advances early but at different times.  It sounds like gtk-recordmydesktop is generating a "broken file".  What's annoying is that the OGV does work so it seems like I should be able to make this work with some set of options.
I have found that I can render the video in kdenlive and it seems to be working there.  I'd still like to know what is going on.  kdenlive does a much better job, but it still advances early sometimes.

**Tags:** ffmpeg, transcoding, youtube

> **Comments:**
> **username_1**: Please show your ffmpeg command and the resulting complete console output.  
> **username_0**: Good idea @LordNeckbeard I added the command and output.  I notice an error/warning: max_analyze_duration reached.  
> **username_1**: Does the issue still occur if you use a recent [static build of ffmpeg](http://ffmpeg.org/download.html#LinuxBuilds)? This will rule out any potential bugs that you may be encountering that have already been fixed with a newer version of ffmpeg. No need to install or anything. Just download, extract the archive, and then execute the included `ffmpeg` binary.  
> **username_1**: Can you provide a sample input file that the problem can be reproduced with?  
> **username_0**: Good idea, I'll whip up a small one and post it later tonight.  
> **username_2**: Would an answer along the lines of 'use a different screen recording program' be acceptable? It looks like GTK-recordmydesktop is creating broken files.  
> **username_0**: @username_2 - Unfortunately no, I've created a number of recordings already before noticing the problem.  Moreover I can watch the OGV just fine in linux so it seems it's not totally corrupt.  That being said, I will be trying to track down why it's creating "broken files".  
> **username_1**: Unless I'm missing something this is probably a bug or lack of ogg feature support in ffmpeg and/or a bug in recordmydesktop (that ffmpeg hasn't made a special case for). A [bug report](https://ffmpeg.org/trac/ffmpeg/) may be the best option here. Make sure to use the latest ffmpeg version you can, show your ffmpeg command and complete console output, provide `sync_test1.ogv`, and try to show the problem using only native encoders (no `lib*` such as `libx264`) if possible.  
> **username_0**: Thanks for the suggestion @LordNeckbeard I'll submit a bug report and see where that goes.  Any idea why AVI seems to be working?  

---

## 4 answers

### Answer by username_3 on 2013-02-20. Score: 4

Why convert to OGV when your final upload is going to be to youtube, I may be wrong but you can convert to x264 video codec with AAC Audio even on linux and upload that to youtube considering that is what they prefer to be uploaded anyway. Have you tried making an h264 and uploading to youtube instead of the OGV file and seeing if that was the issue. Because I would bet that if that solves it, you then know it was an issue with the OGV being uploaded to youtube, and if it does not solve it, it could be a frame-rate issue with youtube's interpretation or something similar.

There have been a lot of issues with OGV files uploaded to youtube in the past. I cant imagine that it is 100% fixed even at this point.

<http://support.google.com/youtube/bin/answer.py?hl=en&answer=1722171>

EDIT: also just noticed that your original footage is at 15fps...this could very well be the source of the issue

EDIT 2: I seemed to slightly have misread the question a little bit...being that you are starting with a video file that is OGV, and I saw that you are going to MP4...this changes things a little bit...but I am going to guess it has something to do with the 15fps and 22050 Hz audio...I know the sample rate has nothing to do with syncing the audio, but from experience when using non standard frame-rates and audio samplerates, I have tended to see drifting...getting these to sync may be rather difficult while not being able to edit these after the initial recording with a cheap video editor...

While software has gotten better about drifting audio it is still a common problem when using uncommon framerates and samplerates as the keyframed sync points are not standard and could be rounding key frames etc...

You see where it says "Broken file, keyframe not correctly marked." that is what it is referring to...

my advice for you would be to get it as close as possible, take it into a video editor and slip and cut up the audio to get it to match the way you want it. Unfortunately sometimes this is how it is fixed...

Software based transcoders do not always work as they should...hense why a protools setup and/or an avid setup would come with hardware to further ensure sync capabilities and constant frame-rates etc...

Another thing you could try is to convert the footage to a standard framerate, and try to re-mary the audio...as I am pretty sure it is the video drifting...probably ever so slightly slowing down and then speeding up towards the end or vice versa.

**EDIT: I was able to get the video to sync to the original using this ffmpeg command...it may have need the rate clause which is what I suspected**

`ffmpeg -i sync_test1.ogv -strict experimental -pix_fmt yuv420p -r 15 -vcodec h264 -acodec aac sync_test1.mp4`

> **Comments:**
> **username_1**: The original file is Theora video and Vorbis audio in ogv container. username_0 is not re-encoding to this format, as far as I know, but when he attempts to re-encode the original with either ffmpeg or YouTube the sync problem manifests.  
> **username_0**: The input format is ogv which is what gtk-recordmydesktop outputs.  I'm trying to get to anything other than ogv (flv, etc).  
> **username_3**: Read my updated answer...I think it is an issue of FPS  
> **username_0**: I added an example source file.  The sync issue is *very* noticeable.  It seems to me like a bunch of frames are elided for various formats.  
> **username_3**: Try this...see new answer  
> **username_1**: Adding `-r 15` is the same as omitting it because ffmpeg will inherit the input frame rate by default, and the resulting output files, with or without `-r 15` are exactly the same with ffmpeg from git head (version N-50285-gad89952). If it is working for you using an older ffmpeg version this could be a regression and should be reported to the [FFmpeg bug tracker](https://ffmpeg.org/trac/ffmpeg/).  
> **username_0**: @ChrisJamesChampeau thanks for the suggestion - I tried the command you listed using the static build of ffmpeg I get slide 2 at 12s and 3 at 17s: https://dl.dropbox.com/u/64693533/sync_test/sync_test1.cjc.mp4  
> **username_3**: Well the FFmpeg I am using is a MAC version versus your Linus version not sure but my guess is that there must be a bug with your FFMPEG?? have you tried removing it and reinstalling the latest version?  
> **username_0**: Yeah, I've tried two versions, the ubuntu default from apt-get and the static build.  
> **username_3**: I am with @LordNeckbeard you should report this as a bug to FFMPEG  

---

### Answer by username_4 on 2014-07-28. Score: 3

I struggled with a similar issue on Ubuntu 12.04.3 LTS. I fixed the problem using the static ffmpeg build which is available from <http://johnvansickle.com/ffmpeg/>

> **Comments:**
> **username_0**: I also tried a static build and it worked somewhat better.  Perhaps the bug has been fixed, in which case it might be useful to add the version number from the static build to your answer?  

---

### Answer by username_5 on 2020-05-28. Score: 1

It seems this bug is still in `recordmydesktop`, or at least I got the exact same symptoms here with the version from Debian testing (`0.3.8.1+svn602-1.1`).

I just managed to transcode this video almost correctly, in the following way:

1. Use VLC.
2. Ask it to transcode to the WebM "profile".
3. Ask it to display the video as it is transcoded.

The result still has the correct synchronization (yay!), but it still suffers from a problem: the resulting video announces itself as lasting more than 4h whereas my video only lasts 25min. Peertube hence lists it as a 4h video, tho once you start playing it the correct 25min duration is displayed, so the problem is not too serious.

Point 3 is important, but point 2 is also: maybe other profiles will also work, but at least the H264 profile gave me an unusable video (either with bad sync like `ffmpeg` or worse).


---

### Answer by username_6 on 2015-08-04. Score: 0

Try just changing the container to avi rather than transcoding, which seems to work better for youtube:
ffmpeg -i JSP.ogv -vcodec copy -acodec copy JSP.avi

> **Comments:**
> **username_7**: I tried this, and the upload just never finishes processing, same as if I upload OGV. Since this answer predates youtube accepting OGV, it must be that change.  Annoying that ffmpeg still has this conversion problem four years later.  
> **username_7**: My ffpmeg is:  3.2.14-1~deb9u1  (apt-get installed)  
> **username_7**: I have tried all the variations above, with static builds (git-20191029), and while it gets a bit better, the audio and video unsync.  If trying one needs a large --max_muxing_queue_size value. I used 40960.  

---

