Answers.Body: <p>Kudos to Japsu.</p>
  
  <p>If you don't want to bother with compiling code and using command line tools, you can use a video repair service.
  <a href="http://mp4repair.org" rel="nofollow">http://mp4repair.org</a> provides free preview and diagnostics.</p>
  
  <p>-- Benoît
  (disclaimer: I'm affiliated with this website)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-26T16:44:52.233Z
Answers.LastActivityDate: 2012-06-29T13:09:32.530Z
Answers.LastEditDate: 2012-06-29T13:09:32.530Z
Answers.UserDisplayName: Benoit Joossen
Answers.Body: <p>First of all, if I remember correctly, the DV format is intra-only, and thus if there is various damage that has happened to your video, there should be a relatively big chance of getting at least something out -- given that the file isn't completely broken in the most relevant of places.</p>
  
  <p>A good way of checking if there's at least some kind of sanity left in the file is indeed by the aforementioned <code>ffmpeg|avconv -i input.avi</code> or <code>ffprobe|avprobe input.avi</code>. If ffmpeg/avconv and/or the related probe application can 'see' the format as well as other information there's at least some hope that the file actually still contains some of the things you're hoping it contains.</p>
  
  <p>As for actual recovery attempts, I would actually first make a copy of the file (backups are generally useful, even if it's a backup of possibly broken data), and try to open it with Avery Lee's <a href="http://www.virtualdub.org/" rel="nofollow">VirtualDub</a>, as I remember it having one of the good general AVI reconstruction mechanisms I've seen so far. If you are lucky and there's enough data for VirtualDub to actually do something with the file, it should ask if you want to repair/reconstruct the index and so forth. After that you can set both audio and video to 'Direct stream copy', and just remux with another file name, and see if that works.</p>
  
  <p>Another way to try and salvage it is to use ffmpeg/avconv, and use the stream copying function there (of course this might not work at all in case ffmpeg/avconv or the related probe application cannot see what container/video/audio format the file is). <code>ffmpeg|avconv -i input.avi -vcodec copy -acodec copy out.avi</code></p>
  
  <p>A yet another way to try and salvage something is by trying out the now-discontinued <a href="http://www.alexander-noe.com/video/amg/" rel="nofollow">AVI-Mux GUI</a>. I have not tried it myself, but I have some hazy memories of people fixing their broken AVI files by remuxing with it a few years ago.</p>
  
  <p><strong>Edit</strong>:
  And of course the so-called final destination would be to see if there are any chunk-like entities in the file, and manually recreating the AVI header and friends before it either via scripting or with a hex editor, looking at the related <a href="http://wiki.multimedia.cx/index.php?title=Microsoft_Audio/Video_Interleaved" rel="nofollow">technical documentation</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T20:22:31.280Z
Answers.Text: `ffprobe my_broken_file.avi` produces the following output: https://gist.github.com/042c28df252120eb74db
  
  So the format seems to be recognized as DV+PCM. However, `ffmpeg -acodec copy -vcodec copy -i my_broken_file.avi recovered.avi` only produces a very short (~1 MB) file that's no more intelligible as the original.
Answers.UserDisplayName: Santtu Pajukanta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T20:30:04.637Z
Answers.Text: VirtualDub fails to load the video file, stating `The file "my_broken_file.avi" is of an unknown or unsupported file type.` :(
Answers.UserDisplayName: Santtu Pajukanta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T20:31:36.177Z
Answers.Text: AVI-Mux GUI crashes when I try to load the file. :((
Answers.UserDisplayName: Santtu Pajukanta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T20:51:50.353Z
Answers.Text: DivFix++ 0.34 says `Input is not an AVI file`.
Answers.UserDisplayName: Santtu Pajukanta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T22:09:33.633Z
Answers.Text: @Japsu: Option placement matters. You're attempting to apply `-acodec copy -vcodec copy` to the input. Possibly a moot point with your ffmpeg version as it is probably applying those options to the output, but newer ffmpeg may be more strict about option placement.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T23:02:01.583Z
Answers.Text: @LordNeckbeard: Right, thanks. Have corrected it to `-i` first now.
  
  With the help of a friendly C coder, we're actually taking the "final destination" now - that is to say, regenerating a RIFF AVI header. Expect results tomorrow.
Answers.UserDisplayName: Santtu Pajukanta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-19T18:32:34.687Z
Answers.LastActivityDate: 2012-06-20T18:58:23.430Z
Answers.LastEditDate: 2012-06-20T18:58:23.430Z
Answers.UserDisplayName: JEEB
Body: <p><strong>Short version:</strong> I believe I have truncated but otherwise valid AVI/DV files that won't play in any player I've tried (Adobe Premiere, MPC HC, VLC). I assume the stream data is intact but truncated, and the container is damaged. Are the files still recoverable and how would I accomplish this?</p>
  
  <p><strong>Long version:</strong> Having finished a recording from a Sony AnyCast workstation with two cameras to a FireWire hard disk drive, I accidentially unplugged the hard disk drive without "disconnecting" (unmounting) it first.</p>
  
  <p>The result was a corrupted ext3 filesystem that would not mount under the Windows Ext2 IFS setup I was using to download the videos, so I connected the hard disk to a Linux laptop and ran e2fsck on it. After this, I was able to list the directory and copy the files, but the files appeared corrupted.</p>
  
  <p>I'm working under the assumption that I've only lost some data at the end of the two video files. (This might prove false as e2fsck might have wrecked havoc on them.) That would mean I have 1,5 hours (x2) of unscathed DV stream. Unfortunately, my layman analysis concludes that these lost bits must have contained some information vital to the container format.</p>
  
  <p>Note that all I have are the files copied to an NTFS volume from the fsck'ed ext3 volume. I no longer have access to the original hard disk drive.</p>
  
  <p>Dear StackExchange, please help me find a way to recover and reconstruct these files! I suspect what I would need is some software that would guess or be told the information usually contained in the container header, copy the stream data and write it into a new, valid container file.</p>
  
  <p><strong>Edit:</strong> I believe the format is DV instead of MPEG2.</p>
  
  <p><strong>Edit2:</strong> It seems that the broken files do <em>not</em> in fact have an AVI header at all - they should begin with the bytes "RIFF" which they do not. <code>ffprobe</code> <em>does</em> recognize the stream format, though:</p>
  
  <pre><code>[dv @ 0xefb8a0] Estimating duration from bitrate, this may be inaccurate
  Input #0, dv, from '120610-1-001.avi':
    Duration: 02:08:36.84, start: 0.000000, bitrate: 28799 kb/s
      Stream #0.0: Video: dvvideo, yuv420p, 720x576, 28800 kb/s, PAR 64:45 DAR 16:9, 25 tbr, 25 tbn, 25 tbc
      Stream #0.1: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
  </code></pre>
  
  <p><strong>Edit3:</strong> Thanks to Matti "Lumpio-" Virkkunen, we've finally got the video files fixed. He wrote a good 400 lines of C that did exactly what @JEEB suggested: crafted an AVI header and searched for things that look like AVI chunks, copying them over to the output file. A long AVI file needs a new header between every gigabyte or so, and the program simply fixes the broken first section and then copies the following sections as-is. The <a href="https://gist.github.com/2959531" rel="nofollow">source code for <code>fixavi.c</code></a> can be found on Gist.</p>
  
  <p>Please note that details such as codecs, audio sample rate and video frame rate are hard-coded in the source, so if you need to replicate this process, please adapt the source to your needs. I found <a href="http://www.alexander-noe.com/video/documentation/avi.pdf" rel="nofollow">Alexander Noe's AVI format guide</a> a good reference on the AVI file format.</p>
  
  <p><strong>Edit4:</strong> And as <code>fixavi.c</code> does not create an index at the end of the AVI file, I simply used <code>./fixavi broken.avi recovered_without_index.avi; ffmpeg -i recovered_without_index.avi -acodec copy -vcodec copy recovered_with_index.avi</code> to make one.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-18T21:47:33.537Z
Comments.Text: can you get it to open in VLC, if there's anything to open, it can , which will at least tell you it's possible to recover
Comments.UserDisplayName: Phasefire
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-19T06:39:08.180Z
Comments.Text: Does `ffmpeg -i FILE` (or better yet, `ffprobe FILE`) return any sane result for the file?
Comments.UserDisplayName: AKX
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-19T20:32:14.467Z
Comments.Text: @AKX yes, it returns this: https://gist.github.com/042c28df252120eb74db
Comments.UserDisplayName: Santtu Pajukanta
Tags: <video><ffmpeg>
Title: How do I recover truncated AVI/DV video?
UserDisplayName: Santtu Pajukanta
ThreadText: # How do I recover truncated AVI/DV video?
  
  (Asked by: username_0 on 2012-06-18)
  
  **Short version:** I believe I have truncated but otherwise valid AVI/DV files that won't play in any player I've tried (Adobe Premiere, MPC HC, VLC). I assume the stream data is intact but truncated, and the container is damaged. Are the files still recoverable and how would I accomplish this?
  
  **Long version:** Having finished a recording from a Sony AnyCast workstation with two cameras to a FireWire hard disk drive, I accidentially unplugged the hard disk drive without "disconnecting" (unmounting) it first.
  
  The result was a corrupted ext3 filesystem that would not mount under the Windows Ext2 IFS setup I was using to download the videos, so I connected the hard disk to a Linux laptop and ran e2fsck on it. After this, I was able to list the directory and copy the files, but the files appeared corrupted.
  
  I'm working under the assumption that I've only lost some data at the end of the two video files. (This might prove false as e2fsck might have wrecked havoc on them.) That would mean I have 1,5 hours (x2) of unscathed DV stream. Unfortunately, my layman analysis concludes that these lost bits must have contained some information vital to the container format.
  
  Note that all I have are the files copied to an NTFS volume from the fsck'ed ext3 volume. I no longer have access to the original hard disk drive.
  
  Dear StackExchange, please help me find a way to recover and reconstruct these files! I suspect what I would need is some software that would guess or be told the information usually contained in the container header, copy the stream data and write it into a new, valid container file.
  
  **Edit:** I believe the format is DV instead of MPEG2.
  
  **Edit2:** It seems that the broken files do *not* in fact have an AVI header at all - they should begin with the bytes "RIFF" which they do not. `ffprobe` *does* recognize the stream format, though:
  
  ```
  [dv @ 0xefb8a0] Estimating duration from bitrate, this may be inaccurate
  Input #0, dv, from '120610-1-001.avi':
    Duration: 02:08:36.84, start: 0.000000, bitrate: 28799 kb/s
      Stream #0.0: Video: dvvideo, yuv420p, 720x576, 28800 kb/s, PAR 64:45 DAR 16:9, 25 tbr, 25 tbn, 25 tbc
      Stream #0.1: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
  
  ```
  
  **Edit3:** Thanks to Matti "Lumpio-" Virkkunen, we've finally got the video files fixed. He wrote a good 400 lines of C that did exactly what @username_4 suggested: crafted an AVI header and searched for things that look like AVI chunks, copying them over to the output file. A long AVI file needs a new header between every gigabyte or so, and the program simply fixes the broken first section and then copies the following sections as-is. The [source code for `fixavi.c`](https://gist.github.com/2959531) can be found on Gist.
  
  Please note that details such as codecs, audio sample rate and video frame rate are hard-coded in the source, so if you need to replicate this process, please adapt the source to your needs. I found [Alexander Noe's AVI format guide](http://www.alexander-noe.com/video/documentation/avi.pdf) a good reference on the AVI file format.
  
  **Edit4:** And as `fixavi.c` does not create an index at the end of the AVI file, I simply used `./fixavi broken.avi recovered_without_index.avi; ffmpeg -i recovered_without_index.avi -acodec copy -vcodec copy recovered_with_index.avi` to make one.
  
  **Tags:** video, ffmpeg
  
  > **Comments:**
  > **username_1**: can you get it to open in VLC, if there's anything to open, it can , which will at least tell you it's possible to recover  
  > **username_2**: Does `ffmpeg -i FILE` (or better yet, `ffprobe FILE`) return any sane result for the file?  
  > **username_0**: @username_2 yes, it returns this: https://gist.github.com/042c28df252120eb74db  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_4 on 2012-06-19. Score: 5 | Accepted answer
  
  First of all, if I remember correctly, the DV format is intra-only, and thus if there is various damage that has happened to your video, there should be a relatively big chance of getting at least something out -- given that the file isn't completely broken in the most relevant of places.
  
  A good way of checking if there's at least some kind of sanity left in the file is indeed by the aforementioned `ffmpeg|avconv -i input.avi` or `ffprobe|avprobe input.avi`. If ffmpeg/avconv and/or the related probe application can 'see' the format as well as other information there's at least some hope that the file actually still contains some of the things you're hoping it contains.
  
  As for actual recovery attempts, I would actually first make a copy of the file (backups are generally useful, even if it's a backup of possibly broken data), and try to open it with Avery Lee's [VirtualDub](http://www.virtualdub.org/), as I remember it having one of the good general AVI reconstruction mechanisms I've seen so far. If you are lucky and there's enough data for VirtualDub to actually do something with the file, it should ask if you want to repair/reconstruct the index and so forth. After that you can set both audio and video to 'Direct stream copy', and just remux with another file name, and see if that works.
  
  Another way to try and salvage it is to use ffmpeg/avconv, and use the stream copying function there (of course this might not work at all in case ffmpeg/avconv or the related probe application cannot see what container/video/audio format the file is). `ffmpeg|avconv -i input.avi -vcodec copy -acodec copy out.avi`
  
  A yet another way to try and salvage something is by trying out the now-discontinued [AVI-Mux GUI](http://www.alexander-noe.com/video/amg/). I have not tried it myself, but I have some hazy memories of people fixing their broken AVI files by remuxing with it a few years ago.
  
  **Edit**:
  And of course the so-called final destination would be to see if there are any chunk-like entities in the file, and manually recreating the AVI header and friends before it either via scripting or with a hex editor, looking at the related [technical documentation](http://wiki.multimedia.cx/index.php?title=Microsoft_Audio/Video_Interleaved).
  
  > **Comments:**
  > **username_0**: `ffprobe my_broken_file.avi` produces the following output: https://gist.github.com/042c28df252120eb74db  So the format seems to be recognized as DV+PCM. However, `ffmpeg -acodec copy -vcodec copy -i my_broken_file.avi recovered.avi` only produces a very short (~1 MB) file that's no more intelligible as the original.  
  > **username_0**: VirtualDub fails to load the video file, stating `The file "my_broken_file.avi" is of an unknown or unsupported file type.` :(  
  > **username_0**: AVI-Mux GUI crashes when I try to load the file. :((  
  > **username_0**: DivFix++ 0.34 says `Input is not an AVI file`.  
  > **username_5**: @Japsu: Option placement matters. You're attempting to apply `-acodec copy -vcodec copy` to the input. Possibly a moot point with your ffmpeg version as it is probably applying those options to the output, but newer ffmpeg may be more strict about option placement.  
  > **username_0**: @LordNeckbeard: Right, thanks. Have corrected it to `-i` first now.  With the help of a friendly C coder, we're actually taking the "final destination" now - that is to say, regenerating a RIFF AVI header. Expect results tomorrow.  
  
  ---
  
  ### Answer by username_3 on 2012-06-26. Score: 0
  
  Kudos to Japsu.
  
  If you don't want to bother with compiling code and using command line tools, you can use a video repair service.
  <http://mp4repair.org> provides free preview and diagnostics.
  
  -- Benoît
  (disclaimer: I'm affiliated with this website)
  
  
  ---
  
  