Answers.Body: <p>As you said you have similar files, you may try the following:</p>
  
  <pre><code>1) any good mp4 file with the same resolution and bitrate to generate the header files:
  recover_mp4.exe good.mp4 --analyze
  
  2) recover streams from the corrupted file, for example:
  recover_mp4.exe bad.mp4 recovered.h264 recovered.aac
  
  3) join audio and video with ffmpeg:
  ffmpeg.exe -r 30 -i recovered.h264 -i recovered.aac -bsf:a aac_adtstoasc -c:v copy -c:a copy recovered.mp4
  </code></pre>
  
  <p>recover_mp4 : <a href="https://codecpack.co/download/recover-mp4.html" rel="noreferrer">https://codecpack.co/download/recover-mp4.html</a>
  ffmpeg: <a href="https://www.ffmpeg.org/" rel="noreferrer">https://www.ffmpeg.org/</a></p>
  
  <p>I've just covered a mp4 with the above method - although sound is still corrupted, video is all good. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-02T20:48:18.097Z
Answers.Text: Sorry for just answering today… I _did_, in fact, come across that tool; I just had two problems with it — there is _only_ a Windows version for it (I have a Mac, an iPad, an iPhone, and easy access to all sorts of Linux variants, but I do _not_ have Windows...); and allegedly the programmer behind that tool, while still offering the old version for free, has moved on to create a [video recovery service](https://restore.media). The preview mode did _not_ fix my issue, and I wasn't keen in paying for the commercial solution, which _may_ not have worked either...
Answers.UserDisplayName: Gwyneth Llewelyn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-23T21:59:59.267Z
Answers.Text: Dear user000001
  Your comment saved me - I repaired my broken mp4 file. Thanks!
Answers.UserDisplayName: MateuszC
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-23T06:58:22.440Z
Answers.LastActivityDate: 2020-02-25T07:26:43.573Z
Answers.LastEditDate: 2020-02-25T07:26:43.573Z
Answers.UserDisplayName: user000001
Answers.Body: <p>The <code>mdat</code> box in a MP4 contains the media payload but it is freeform. It is as good as gibberish on its own. The <code>moov</code> box identifies how many tracks there are, which codecs and their parameters those tracks contain, which portions of the data in the <code>mdat</code> correspond to which tracks, what their timestamps are..etc.</p>
  <p>What MP4 repair utilities do, is use the track and codec descriptions from the <code>moov</code> box of the reference file and transpose them to the repair candidate. Then they use heuristics to identify each track's data in the candidate. This relies on the codec of each track sporting some consistent &amp; known signature to locate the start of each packet. The timestamps are however unrecoverable. So, if there's no reference <code>moov</code> or a way to create a similar one, the file is essentially unrecoverable.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-12T04:49:44.637Z
Answers.LastActivityDate: 2021-04-12T04:49:44.637Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>duplicate of <a href="https://unix.stackexchange.com/questions/493897/how-to-recover-a-broken-mp4-file-moov-atom-not-found">How to recover a broken mp4 file: moov atom not found</a> at unix.stackexchange.com - especially since you're looking for a linux/macos solution</p>
  <p>limitation: the <a href="https://github.com/ponchio/untrunc" rel="nofollow noreferrer">untrunc</a> tool needs a working similar video file</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-22T19:32:26.067Z
Answers.LastActivityDate: 2021-01-22T19:38:08.283Z
Answers.LastEditDate: 2021-01-22T19:38:08.283Z
Answers.UserDisplayName: user14984725
Body: <p>Please be forgiving to a video file format newbie, who has travelled far and wide all over the Web in search of a relatively simple question and hoped to get an answer (even a fairly complicated one would be fine!):</p>
  
  <blockquote>
    <p><strong>TL;DR:</strong> I have a broken MP4 which lacks a MOOV atom (neither at the beginning
    nor at the end). So, how do I create a <em>new</em> MOOV atom in order to fix the file?</p>
  </blockquote>
  
  <p>And now for the expanded question (if you bother to read it), which shows the homework I've done so far...</p>
  
  <h1>What solutions I've found so far...</h1>
  
  <p>A <a href="https://video.stackexchange.com/search?q=moov">quick search just here on video.stackexchange.com</a> will get you a few dozens of similar questions and variations on the theme; do that search on Google, and you'll get a few hundreds more; <a href="https://www.quora.com/How-can-I-repair-an-mov-file" rel="noreferrer">even Quora has a few answers</a>... To summarise <em>most</em> of them, here is what they <em>usually</em> say:</p>
  
  <ol>
  <li>"MP4 files can have a MOOV atom at the end (that's the usual way) but also at the beginning; here's a selection of N solutions to move the atom from one place to the other" (no, they aren't useful if you have <em>no</em> MOOV atom whatsoever)</li>
  <li>"You can use <code>ffmpeg</code> (or a gazillion similar utilities — most of which will use <code>ffmpeg</code>'s library anyway — or even VLC [some versions seem to have a way to automatically fix broken videos — not my case, though]) to somehow magically extract part of your broken file, split it into bits, or even split it into individual frames, then reencode, and eventually you'll get a few sequences of frames out of the corrupted video, or even, with luck, a bit of continuous video which will play (sometimes only under VLC, sometimes only under <code>mplayer</code>, sometimes requiring [insert favourite video player here])" (all these suggestions are very nice, but all assume that at least there is a MOOV atom <em>somewhere</em> — or else <em>all</em> will fail)</li>
  <li>"Some tools (or commercial applications) can deal with corrupt data on faulty disks/pen drives/memory cards, by reading sectors directly from the underlying media and bypassing the FAT or whatever filesystem layer is used by the operating system, thus at least being able to recover part of your video, even if it's (possibly) out of order, incomplete, etc." (this may all be true, but does not help in my case, where the file is pristine and there is no problem whatsoever with the hardware where it's currently stored — the file is just missing a MOOV atom, so none of these tools will help)</li>
  <li>"A few tools, such as <a href="https://github.com/anthwlock/untrunc" rel="noreferrer"><code>untrunc</code></a>, may be able to repair a broken file, especially if the MOOV atom is missing at the end of the file because the video camera abruptly had its power cut (or some similar situation). There are also several commercial software solutions available which do the same (and are easier to use) or even <a href="https://restore.media/" rel="noreferrer">web-based ones</a>. Commercial applications usually have a demo/trial mode where you can at least recover <em>some</em> data to give you an idea if your particular file is repairable or not. Usually, such software requires a video made by the same video camera under the same circumstances, to be able to push the missing data from that video to the corrupt file." (so far, I've not managed to find the 'magic tool' which does exactly what is claimed... <em>all</em> I've tested will fail with a missing MOOV atom... no matter if the 'test video' has it, which could easily be copied — assuming that this will 'fix' anything, of course).</li>
  </ol>
  
  <h1>Why none of the above actually helped me out</h1>
  
  <p>Things may be explained a bit differently in one case or another, but after going through dozens of descriptions of 'solutions' out there, I'd say that most will fall in one of those four cases. The fourth case, of course, is the only one that <em>may</em> help in my case, but, so far, I've tried pretty much everything which can run on a Mac — aye, including a few commercial apps — and <em>none</em> will deal with the issue.</p>
  
  <p>I've also found out that many of these tools — especially those that are commercial! — are little more than a GUI to <code>ffmpeg</code>/<code>libav</code>. Some even use hopelessly outdated versions of these; in some cases, they're compiled with them statically; in other cases, <code>ffmpeg</code> and its friends are packed with the application, which just calls it with whatever special parameters the developers have figured out that might help (or even work!) in most cases.</p>
  
  <p>While I'm pretty sure that some of the tools I tried out may have non-<code>ffmpeg</code>/<code>libav</code> code, they haven't worked, either. What I seem to be able to conclude is that anything depending on <code>ffmpeg</code>/<code>libav</code> code will <em>not</em> work without a valid MOOV atom. Therefore, the trick — if there's one! — is to somehow 'extract' a MOOV atom from either a different file and/or re-create the MOOV atom from the existing data. While the former seems to be the most popular approach (and, as said, I've tested a dozen or so apps using that approach), none worked in my case; as to the latter approach, if it exists at all, it's not explicitly named in any of the tools I've tested out, so I cannot say if that's possible at all (i.e. it <em>may</em> be a very obscure and undocumented feature of <code>ffmpeg</code> but, so far, I have not come across an answer which mentions such feature; of course, commercial tools, for obvious reasons, may simply not document what exactly their tool is doing 'under the hood').</p>
  
  <p>Whew. Wordy, I know! Let me just give you some assurance that, although I hardly understand what I'm talking about — namely, the complex structure of an MP4/MOV file — I have certainly done my best to figure out what is wrong with my file, and why all attempts I've tried out so far have utterly failed. My apologies in advance if I'm assuming wrong things about the MP4 format and/or just saying rubbish which makes no sense (such as 'reconstructing a MOOV atom out of existing frames on a movie' — perhaps such a thing is <em>impossible</em> to do, for reasons I don't understand).</p>
  
  <h1>What I know about my file...</h1>
  
  <ol>
  <li>It certainly has data in it (i.e. not just garbage). Several of those utilities correctly figure out that it's a QuickTime stream; some can even identify a few atoms.</li>
  </ol>
  
  <p>Here is an example from <code>mp4dump</code>:</p>
  
  <pre><code>[ftyp] size=8+12
    major_brand = qt  
    minor_version = 0
    compatible_brand = qt  
  [wide] size=8+0
  </code></pre>
  
  <p>And this is the output from <code>mp4info</code>:</p>
  
  <pre><code>File:
    major brand:      qt  
    minor version:    0
    compatible brand: qt  
    fast start:       yes
  
  No movie found in the file
  </code></pre>
  
  <p>(weird that it knows about 'fast start', though...)</p>
  
  <p>Here is the output of my own hacked utility (see below):</p>
  
  <pre><code>[ftyp]
          Major brand: qt  
          Minor brand: 0
          Compatible brands: [qt  ]
  
  [wide]
          Size: 8
          Start: 20
  
  [mdat]
          Size: 2305577342
          Start: 28
  </code></pre>
  
  <p>But none can find a single MOOV atom. Photoshop can import 'noise' from some frames — they <em>look</em> like frames, though, just so noisy that they become 'random pixels', that is, it's pretty much impossible to figure out what exactly that frame is supposed to be...</p>
  
  <ol start="2">
  <li>I have 'similar' files, generated by the same video camera (the iPhone 8's 'selfie' camera in landscape format), so I can easily extract an existing MOOV atom (or any other) and 'glue' it elsewhere on an existing file, a procedure many of the mentioned tools consider a possible solution to a 'missing' MOOV atom — but none are actually able to do that with <em>my</em> video...</li>
  </ol>
  
  <h1>What I can theoretically do to fix things</h1>
  
  <h2>(or: An attempt to start to answer my own question...)</h2>
  
  <p>I'm just a humble amateur programmer, which means that fully developing a <em>new</em> tool in order just to fix my own video is very likely out of the question (and furthermore I have no time for that). The best I can promise to do if nobody has an answer is to figure out how MP4 encoders actually generate a MOOV atom from the existing data and see if I can adapt <a href="https://github.com/alfg/mp4" rel="noreferrer">an existing tool</a> to 'regenerate' the MOOV atom from scratch (note: I did hack it a bit to show the contents of all atoms it can find inside the file when the MOOV atom is missing, the output of which I've given before)... alas, I think that this <em>might</em> be impossible if one does not know some basic things about the video file itself (after all, these 'basic things' are stored on the MOOV atom!), but I'm happy to be proven wrong on that — especially because I can 'guesstimate' many of those 'basic things' by simply reading the MOOV atom from a video file generated under similar circumstances...</p>
  
  <p>Here is such an example (tracks 3 and 4 are not really fundamental):</p>
  
  <pre><code>found avc1
  File:
    file Size:    16072874
    brands:   qt  , [qt  ]
  
  Movie:
    duration: 6859 ms / 600 (00:00:11:431)
    fragments:    false
    timescale:    600
  
  Found 4 Tracks
  
  Track 1:
    flags:    15 ENABLED IN-MOVIE IN-PREVIEW
    id:       1
    type:     Video
    duration: 6859 ms
    language: und
    width:    1920
    height:   1080
    media:
      sample count:   184
      timescale:      600
      duration:       6859 (media timescale units)
      duration:       11431 (ms)
    display width:         1920
    display height:        1080
    frame rate (computed): 16.10
  
  Track 2:
    flags:    15 ENABLED IN-MOVIE IN-PREVIEW
    id:       2
    type:     Sound
    duration: 6859 ms
    language: und
    width:    0
    height:   0
    media:
      sample count:   495
      timescale:      44100
      duration:       506880 (media timescale units)
      duration:       11493 (ms)
  </code></pre>
  
  <p>Theoretically, with a bit more hacking, I can also extract the precise position where each track begins and ends (assuming that's how the MP4 format works!) and whatever information may be needed to 'reconstruct' the MOOV atom...</p>
  
  <h1>What help I actually need</h1>
  
  <p>I do have access to the PDFs with the <a href="https://github.com/alfg/mp4/blob/master/docs/ISO_IEC_14496-12-2005(E)-04-01.pdf" rel="noreferrer">ISO/IEC 14496-12 standard which defines the MP4 file format</a> but I haven't read them yet. In essence, what I need to <em>understand</em> is how MOOV atoms are created/generated from existing video data. I'm fine with downloading and installing any tool which I haven't mentioned previously (so long as they work either under macOS or any non-GUI Linux — I <em>might</em> be able to <em>temporarily</em> get access to a Windows 10 machine if I'm assured that there is a solution that will work under Windows). I'm also willing to change or adapt existing open-source tools, so long as I can get some pointers on how to actually 'generate' the MOOV atom from existing video data (preferably written in <code>Go</code> or <code>PHP</code>, but I'm ok with <code>C</code>, <code>C++</code>, <code>C#</code> or Python [in decreasing order of preference], or, well, Perl or JavaScript... I'm just not willing to install Java :-P and I'd really need a lot to get persuaded to use Ruby, Rust, or whatever language is currently fashionable...).</p>
  
  <p>If you read until the end, my heartfelt thanks in advance :-)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-23T15:15:54.220Z
Comments.Text: I'm scared to ask, but curious, how did you end up in this situation, what is the video content you are recovering?
Comments.UserDisplayName: Ryan Leach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-23T20:21:47.327Z
Comments.Text: Care to share the corrupt file?
Comments.UserDisplayName: BreadEagles
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-02T20:37:50.137Z
Comments.Text: *cough* thanks for your questions/suggestions but let's just say that this particular video might not be safe for the workplace...
Comments.UserDisplayName: Gwyneth Llewelyn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-02T20:37:55.223Z
Comments.Text: @RyanTheLeach, as far as I could figure it out, what seemed to have happened was that the video capturing app on my iPhone unexpectedly crashed, just seconds before the end of the movie... so it had already captured all the _data_, but still hadn't finished writing out the _index_. I have no idea if that makes sense or not to you guys, but it _seems_ that this was the case. In other words: if the _index_ had somehow 'survived' the crash, I would probably lose _some_ video (and sound sync might be gone, too), but at least I would get _something_. But without a MOOV atom... no luck!
Comments.UserDisplayName: Gwyneth Llewelyn
Tags: <mp4><file-formats>
Title: Need help to fix a broken MP4 which lacks a MOOV atom
UserDisplayName: Gwyneth Llewelyn
ThreadText: # Need help to fix a broken MP4 which lacks a MOOV atom
  
  (Asked by: username_0 on 2019-12-12)
  
  Please be forgiving to a video file format newbie, who has travelled far and wide all over the Web in search of a relatively simple question and hoped to get an answer (even a fairly complicated one would be fine!):
  
  > **TL;DR:** I have a broken MP4 which lacks a MOOV atom (neither at the beginning
  > nor at the end). So, how do I create a *new* MOOV atom in order to fix the file?
  
  And now for the expanded question (if you bother to read it), which shows the homework I've done so far...
  
  # What solutions I've found so far...
  
  A [quick search just here on video.stackexchange.com](https://video.stackexchange.com/search?q=moov) will get you a few dozens of similar questions and variations on the theme; do that search on Google, and you'll get a few hundreds more; [even Quora has a few answers](https://www.quora.com/How-can-I-repair-an-mov-file)... To summarise *most* of them, here is what they *usually* say:
  
  1. "MP4 files can have a MOOV atom at the end (that's the usual way) but also at the beginning; here's a selection of N solutions to move the atom from one place to the other" (no, they aren't useful if you have *no* MOOV atom whatsoever)
  2. "You can use `ffmpeg` (or a gazillion similar utilities — most of which will use `ffmpeg`'s library anyway — or even VLC [some versions seem to have a way to automatically fix broken videos — not my case, though]) to somehow magically extract part of your broken file, split it into bits, or even split it into individual frames, then reencode, and eventually you'll get a few sequences of frames out of the corrupted video, or even, with luck, a bit of continuous video which will play (sometimes only under VLC, sometimes only under `mplayer`, sometimes requiring [insert favourite video player here])" (all these suggestions are very nice, but all assume that at least there is a MOOV atom *somewhere* — or else *all* will fail)
  3. "Some tools (or commercial applications) can deal with corrupt data on faulty disks/pen drives/memory cards, by reading sectors directly from the underlying media and bypassing the FAT or whatever filesystem layer is used by the operating system, thus at least being able to recover part of your video, even if it's (possibly) out of order, incomplete, etc." (this may all be true, but does not help in my case, where the file is pristine and there is no problem whatsoever with the hardware where it's currently stored — the file is just missing a MOOV atom, so none of these tools will help)
  4. "A few tools, such as [`untrunc`](https://github.com/anthwlock/untrunc), may be able to repair a broken file, especially if the MOOV atom is missing at the end of the file because the video camera abruptly had its power cut (or some similar situation). There are also several commercial software solutions available which do the same (and are easier to use) or even [web-based ones](https://restore.media/). Commercial applications usually have a demo/trial mode where you can at least recover *some* data to give you an idea if your particular file is repairable or not. Usually, such software requires a video made by the same video camera under the same circumstances, to be able to push the missing data from that video to the corrupt file." (so far, I've not managed to find the 'magic tool' which does exactly what is claimed... *all* I've tested will fail with a missing MOOV atom... no matter if the 'test video' has it, which could easily be copied — assuming that this will 'fix' anything, of course).
  
  # Why none of the above actually helped me out
  
  Things may be explained a bit differently in one case or another, but after going through dozens of descriptions of 'solutions' out there, I'd say that most will fall in one of those four cases. The fourth case, of course, is the only one that *may* help in my case, but, so far, I've tried pretty much everything which can run on a Mac — aye, including a few commercial apps — and *none* will deal with the issue.
  
  I've also found out that many of these tools — especially those that are commercial! — are little more than a GUI to `ffmpeg`/`libav`. Some even use hopelessly outdated versions of these; in some cases, they're compiled with them statically; in other cases, `ffmpeg` and its friends are packed with the application, which just calls it with whatever special parameters the developers have figured out that might help (or even work!) in most cases.
  
  While I'm pretty sure that some of the tools I tried out may have non-`ffmpeg`/`libav` code, they haven't worked, either. What I seem to be able to conclude is that anything depending on `ffmpeg`/`libav` code will *not* work without a valid MOOV atom. Therefore, the trick — if there's one! — is to somehow 'extract' a MOOV atom from either a different file and/or re-create the MOOV atom from the existing data. While the former seems to be the most popular approach (and, as said, I've tested a dozen or so apps using that approach), none worked in my case; as to the latter approach, if it exists at all, it's not explicitly named in any of the tools I've tested out, so I cannot say if that's possible at all (i.e. it *may* be a very obscure and undocumented feature of `ffmpeg` but, so far, I have not come across an answer which mentions such feature; of course, commercial tools, for obvious reasons, may simply not document what exactly their tool is doing 'under the hood').
  
  Whew. Wordy, I know! Let me just give you some assurance that, although I hardly understand what I'm talking about — namely, the complex structure of an MP4/MOV file — I have certainly done my best to figure out what is wrong with my file, and why all attempts I've tried out so far have utterly failed. My apologies in advance if I'm assuming wrong things about the MP4 format and/or just saying rubbish which makes no sense (such as 'reconstructing a MOOV atom out of existing frames on a movie' — perhaps such a thing is *impossible* to do, for reasons I don't understand).
  
  # What I know about my file...
  
  1. It certainly has data in it (i.e. not just garbage). Several of those utilities correctly figure out that it's a QuickTime stream; some can even identify a few atoms.
  
  Here is an example from `mp4dump`:
  
  ```
  [ftyp] size=8+12
    major_brand = qt  
    minor_version = 0
    compatible_brand = qt  
  [wide] size=8+0
  
  ```
  
  And this is the output from `mp4info`:
  
  ```
  File:
    major brand:      qt  
    minor version:    0
    compatible brand: qt  
    fast start:       yes
  
  No movie found in the file
  
  ```
  
  (weird that it knows about 'fast start', though...)
  
  Here is the output of my own hacked utility (see below):
  
  ```
  [ftyp]
          Major brand: qt  
          Minor brand: 0
          Compatible brands: [qt  ]
  
  [wide]
          Size: 8
          Start: 20
  
  [mdat]
          Size: 2305577342
          Start: 28
  
  ```
  
  But none can find a single MOOV atom. Photoshop can import 'noise' from some frames — they *look* like frames, though, just so noisy that they become 'random pixels', that is, it's pretty much impossible to figure out what exactly that frame is supposed to be...
  
  2. I have 'similar' files, generated by the same video camera (the iPhone 8's 'selfie' camera in landscape format), so I can easily extract an existing MOOV atom (or any other) and 'glue' it elsewhere on an existing file, a procedure many of the mentioned tools consider a possible solution to a 'missing' MOOV atom — but none are actually able to do that with *my* video...
  
  # What I can theoretically do to fix things
  
  ## (or: An attempt to start to answer my own question...)
  
  I'm just a humble amateur programmer, which means that fully developing a *new* tool in order just to fix my own video is very likely out of the question (and furthermore I have no time for that). The best I can promise to do if nobody has an answer is to figure out how MP4 encoders actually generate a MOOV atom from the existing data and see if I can adapt [an existing tool](https://github.com/alfg/mp4) to 'regenerate' the MOOV atom from scratch (note: I did hack it a bit to show the contents of all atoms it can find inside the file when the MOOV atom is missing, the output of which I've given before)... alas, I think that this *might* be impossible if one does not know some basic things about the video file itself (after all, these 'basic things' are stored on the MOOV atom!), but I'm happy to be proven wrong on that — especially because I can 'guesstimate' many of those 'basic things' by simply reading the MOOV atom from a video file generated under similar circumstances...
  
  Here is such an example (tracks 3 and 4 are not really fundamental):
  
  ```
  found avc1
  File:
    file Size:    16072874
    brands:   qt  , [qt  ]
  
  Movie:
    duration: 6859 ms / 600 (00:00:11:431)
    fragments:    false
    timescale:    600
  
  Found 4 Tracks
  
  Track 1:
    flags:    15 ENABLED IN-MOVIE IN-PREVIEW
    id:       1
    type:     Video
    duration: 6859 ms
    language: und
    width:    1920
    height:   1080
    media:
      sample count:   184
      timescale:      600
      duration:       6859 (media timescale units)
      duration:       11431 (ms)
    display width:         1920
    display height:        1080
    frame rate (computed): 16.10
  
  Track 2:
    flags:    15 ENABLED IN-MOVIE IN-PREVIEW
    id:       2
    type:     Sound
    duration: 6859 ms
    language: und
    width:    0
    height:   0
    media:
      sample count:   495
      timescale:      44100
      duration:       506880 (media timescale units)
      duration:       11493 (ms)
  
  ```
  
  Theoretically, with a bit more hacking, I can also extract the precise position where each track begins and ends (assuming that's how the MP4 format works!) and whatever information may be needed to 'reconstruct' the MOOV atom...
  
  # What help I actually need
  
  I do have access to the PDFs with the [ISO/IEC 14496-12 standard which defines the MP4 file format](https://github.com/alfg/mp4/blob/master/docs/ISO_IEC_14496-12-2005(E)-04-01.pdf) but I haven't read them yet. In essence, what I need to *understand* is how MOOV atoms are created/generated from existing video data. I'm fine with downloading and installing any tool which I haven't mentioned previously (so long as they work either under macOS or any non-GUI Linux — I *might* be able to *temporarily* get access to a Windows 10 machine if I'm assured that there is a solution that will work under Windows). I'm also willing to change or adapt existing open-source tools, so long as I can get some pointers on how to actually 'generate' the MOOV atom from existing video data (preferably written in `Go` or `PHP`, but I'm ok with `C`, `C++`, `C#` or Python [in decreasing order of preference], or, well, Perl or JavaScript... I'm just not willing to install Java :-P and I'd really need a lot to get persuaded to use Ruby, Rust, or whatever language is currently fashionable...).
  
  If you read until the end, my heartfelt thanks in advance :-)
  
  **Tags:** mp4, file-formats
  
  > **Comments:**
  > **username_1**: I'm scared to ask, but curious, how did you end up in this situation, what is the video content you are recovering?  
  > **username_2**: Care to share the corrupt file?  
  > **username_0**: *cough* thanks for your questions/suggestions but let's just say that this particular video might not be safe for the workplace...  
  > **username_0**: @RyanTheLeach, as far as I could figure it out, what seemed to have happened was that the video capturing app on my iPhone unexpectedly crashed, just seconds before the end of the movie... so it had already captured all the _data_, but still hadn't finished writing out the _index_. I have no idea if that makes sense or not to you guys, but it _seems_ that this was the case. In other words: if the _index_ had somehow 'survived' the crash, I would probably lose _some_ video (and sound sync might be gone, too), but at least I would get _something_. But without a MOOV atom... no luck!  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_6 on 2021-01-22. Score: 3 | Accepted answer
  
  duplicate of [How to recover a broken mp4 file: moov atom not found](https://unix.stackexchange.com/questions/493897/how-to-recover-a-broken-mp4-file-moov-atom-not-found) at unix.stackexchange.com - especially since you're looking for a linux/macos solution
  
  limitation: the [untrunc](https://github.com/ponchio/untrunc) tool needs a working similar video file
  
  
  ---
  
  ### Answer by username_3 on 2020-02-23. Score: 6
  
  As you said you have similar files, you may try the following:
  
  ```
  1) any good mp4 file with the same resolution and bitrate to generate the header files:
  recover_mp4.exe good.mp4 --analyze
  
  2) recover streams from the corrupted file, for example:
  recover_mp4.exe bad.mp4 recovered.h264 recovered.aac
  
  3) join audio and video with ffmpeg:
  ffmpeg.exe -r 30 -i recovered.h264 -i recovered.aac -bsf:a aac_adtstoasc -c:v copy -c:a copy recovered.mp4
  
  ```
  
  recover\_mp4 : <https://codecpack.co/download/recover-mp4.html>
  ffmpeg: <https://www.ffmpeg.org/>
  
  I've just covered a mp4 with the above method - although sound is still corrupted, video is all good.
  
  > **Comments:**
  > **username_0**: Sorry for just answering today… I _did_, in fact, come across that tool; I just had two problems with it — there is _only_ a Windows version for it (I have a Mac, an iPad, an iPhone, and easy access to all sorts of Linux variants, but I do _not_ have Windows...); and allegedly the programmer behind that tool, while still offering the old version for free, has moved on to create a [video recovery service](https://restore.media). The preview mode did _not_ fix my issue, and I wasn't keen in paying for the commercial solution, which _may_ not have worked either...  
  > **username_4**: Dear username_3 Your comment saved me - I repaired my broken mp4 file. Thanks!  
  
  ---
  
  ### Answer by username_5 on 2021-04-12. Score: 3
  
  The `mdat` box in a MP4 contains the media payload but it is freeform. It is as good as gibberish on its own. The `moov` box identifies how many tracks there are, which codecs and their parameters those tracks contain, which portions of the data in the `mdat` correspond to which tracks, what their timestamps are..etc.
  
  What MP4 repair utilities do, is use the track and codec descriptions from the `moov` box of the reference file and transpose them to the repair candidate. Then they use heuristics to identify each track's data in the candidate. This relies on the codec of each track sporting some consistent & known signature to locate the start of each packet. The timestamps are however unrecoverable. So, if there's no reference `moov` or a way to create a similar one, the file is essentially unrecoverable.
  
  
  ---
  
  