<p>In the search of a better answer a possible way could be:</p>

<pre><code>ffmpeg -i video.mkv -c copy video_fixed.mkv
</code></pre>

<p>However I'm pretty sure there are some extra options that can make the result even better..</p>

CC BY-SA 4.0
2018-06-16T00:03:28.877Z
Works for me every time I have some kind of issue with the meta data, timestamps, or container info. And it's very fast, usually faster than 400x playspeed.
user3643
CC BY-SA 4.0
2018-08-03T19:52:34.553Z
This command saved my butt, to be frankly.
neverMind9
CC BY-SA 4.0
2024-02-24T22:33:40.830Z
What does it even do it looks like a copy | paste to me?
Ricardo Bohner
CC BY-SA 4.0
2024-02-27T22:44:07.490Z
@RicardoBohner do you mean the answer or the command? in case of the answer it was originally posted by me 1 day before the selected one, regarding the command instead it does a copy but also reading the data and checking for integrity fixes the stream.
user3450548
CC BY-SA 4.0
2024-02-28T00:39:35.157Z
I meant the command, and I didn't know that ffmpeg did integrity fixes when using the copy codec...thanks for clarification.
Ricardo Bohner
CC BY-SA 3.0
2016-04-21T23:34:15.213Z
2016-04-21T23:34:15.213Z
user3450548
<p>I've tested lot of solutions and software. I love cli commands, so using ffmpeg you can fix your video file with no hassle. Try the next command if you came here searching some useful fix:</p>
<pre><code>ffmpeg -vcodec mpeg4 -b:v 7561k -qscale:v 2 -acodec aac -ac 2 -async 1 -strict experimental ./video_fixed.mp4 -threads 0 -i damage_file.mp4
</code></pre>
<p>Good luck !</p>

CC BY-SA 4.0
2020-09-27T22:40:04.657Z
This will probably work, but the file will be HUGE! Better so just use H264 again, like: `ffmpeg.exe -i "input.mp4" -c:v libx264 -crf 22 -preset slow output.mp4`
kett
CC BY-SA 4.0
2022-11-29T17:34:22.157Z
this is the only thing that worked. Can you please explain the flags? why does it work and how can it be optimized
AK_
CC BY-SA 4.0
2022-12-07T15:52:19.470Z
I had a video which I composed of 3 separate videos with -f concat and -safe 0, however, while the result played in VLC, in Davinci I could only see the video up to the first merge point (audio was still fine, though). After that Davinci showed a red media offline message. I first tried simply ffmpeg -c copy to fix the video but that did not work, however this re-encoding worked.
Henno
CC BY-SA 4.0
2024-12-18T16:06:47.047Z
I had an mp4 that didn't have a thumbnail and claimed wrong resolution in properties. Doing `ffmpeg -i input.mp4 output.mp4` didn't fix it, but converting to avi did, showing thumbnail and correct resolution. Instead of avi we can change the codec with `-c:v mpeg4` to fix it also. I tried `-c:v libx264` but didn't work since it already was that codec. So it seems the only way to fix it is to switch codec/format then switch back. Also when first converting we have to use `-q:v 0` to not lose quality. `ffmpeg -i input.mp4 -c:v mpeg4 -q:v 0 output1.mp4` then `ffmpeg -i output1.mp4 output2.mp4`.
Puddle
CC BY-SA 4.0
2024-12-18T16:11:52.870Z
Also if you do the avi way `ffmpeg -i input.mp4 -q:v 0 output1.avi` then `ffmpeg -i output1.avi output2.mp4`, you get the same `output2.mp4`. They generate the same md5 hash.
Puddle
CC BY-SA 4.0
2020-06-26T11:36:52.950Z
2020-06-26T11:36:52.950Z
user4056
<p>If parts of the file reside on physically bad sectors, or for whatever reason, the OS cannot serve the whole file to FFmpeg, then naturally FFmpeg can't do anything about that. You should get a utility which can ignore those portions and write the salvageable parts to a new file, like <a href="http://www.gnu.org/software/ddrescue/ddrescue.html" rel="noreferrer">ddrescue</a>.</p>

<p>Now, if the file protocol is not the cause of errors, you can try</p>

<pre><code>ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv
</code></pre>

CC BY-SA 3.0
2017-05-26T18:52:27.980Z
This works, but fails without `-c copy`.  Surprising that it doesn't work during recode.
intuited
CC BY-SA 4.0
2019-04-13T18:16:17.187Z
Even with that, I'm still getting `Invalid data found when processing input` -- and ffmpeg gives up.
Mikhail T.
CC BY-SA 4.0
2019-10-22T16:52:48.853Z
Nice solution... if the moov atom (on a MP4 file) is still present somewhere. What if it's not even there?
Gwyneth Llewelyn
CC BY-SA 4.0
2020-01-06T23:26:22.303Z
It works at my end with surprising goodness :)
shirish
CC BY-SA 4.0
2022-06-25T05:35:54.227Z
Not worked:
`moov atom not found
video.mp4: Invalid data found when processing input`
57ar7up
CC BY-SA 4.0
2023-05-02T07:45:20.463Z
This unfortunately consistently destroys any video file for me that I originally created with either OBS or ffmpeg
aggregate1166877
CC BY-SA 4.0
2024-06-06T08:30:56.283Z
@aggregate1166877 it creates a new file, so it can't destroy anything...
user924
CC BY-SA 4.0
2024-06-06T11:40:07.743Z
@user924 I don't mean that it deletes the old file, I mean that the new file is completely broken. English is not my first language, maybe I used phrasing not valid in English.
aggregate1166877
CC BY-SA 3.0
2016-04-22T05:39:06.470Z
2016-04-22T05:39:06.470Z
Gyan
<p>It happened me many times that I could end up in corrupted video files:</p>

<ul>
<li>video downloaded from official sources but with torrent and for some reason not all the pieces are there in .mkv, .ts or .mp4</li>
<li>records in .ts format where at a certain point the data is missing</li>
<li>copied videos from an old hard drive with damaged sectors</li>
</ul>

<p>When I play this videos with VLC or other players they plays till a certain point and then instantly exits. Sometimes I can try to skip the bad part but I could meet another bad sector and have an insta-quit again.</p>

<p>Question is:</p>

<p>Can I fix this problems (I suppose stream and keyframes related) with ffmpeg and maybe in a -c copy fashion so I haven't to recompress everything?</p>

<p>What I want to achieve is a full lenght video where the missing parts are skipped, I prefer a glitch rather than having my videos crash.</p>

CC BY-SA 3.0
2017-12-01T10:40:18.977Z
See also: https://superuser.com/questions/538829/repairing-corrupt-mp4
awiebe
<ffmpeg><h.264>
Fix bad files and streams with ffmpeg so VLC and other players would not crash
user3450548
# Fix bad files and streams with ffmpeg so VLC and other players would not crash

(Asked by: username_0 on 2016-04-21)

It happened me many times that I could end up in corrupted video files:

* video downloaded from official sources but with torrent and for some reason not all the pieces are there in .mkv, .ts or .mp4
* records in .ts format where at a certain point the data is missing
* copied videos from an old hard drive with damaged sectors

When I play this videos with VLC or other players they plays till a certain point and then instantly exits. Sometimes I can try to skip the bad part but I could meet another bad sector and have an insta-quit again.

Question is:

Can I fix this problems (I suppose stream and keyframes related) with ffmpeg and maybe in a -c copy fashion so I haven't to recompress everything?

What I want to achieve is a full lenght video where the missing parts are skipped, I prefer a glitch rather than having my videos crash.

**Tags:** ffmpeg, h.264

> **Comments:**
> **username_1**: See also: https://superuser.com/questions/538829/repairing-corrupt-mp4  

---

## 3 answers

### Answer by username_10 on 2016-04-22. Score: 70 | Accepted answer

If parts of the file reside on physically bad sectors, or for whatever reason, the OS cannot serve the whole file to FFmpeg, then naturally FFmpeg can't do anything about that. You should get a utility which can ignore those portions and write the salvageable parts to a new file, like ddrescue.
Now, if the file protocol is not the cause of errors, you can try
ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv

> **Comments:**
> **username_11**: This works, but fails without `-c copy`.  Surprising that it doesn't work during recode.  
> **username_12**: Even with that, I'm still getting `Invalid data found when processing input` -- and ffmpeg gives up.  
> **username_13**: Nice solution... if the moov atom (on a MP4 file) is still present somewhere. What if it's not even there?  
> **username_14**: It works at my end with surprising goodness :)  
> **username_15**: Not worked: `moov atom not found video.mp4: Invalid data found when processing input`  
> **username_16**: This unfortunately consistently destroys any video file for me that I originally created with either OBS or ffmpeg  
> **username_17**: @username_16 it creates a new file, so it can't destroy anything...  
> **username_16**: @username_17 I don't mean that it deletes the old file, I mean that the new file is completely broken. English is not my first language, maybe I used phrasing not valid in English.  

---

### Answer by username_0 on 2016-04-21. Score: 7

In the search of a better answer a possible way could be:
ffmpeg -i video.mkv -c copy video_fixed.mkv

However I'm pretty sure there are some extra options that can make the result even better..

> **Comments:**
> **username_2**: Works for me every time I have some kind of issue with the meta data, timestamps, or container info. And it's very fast, usually faster than 400x playspeed.  
> **username_3**: This command saved my butt, to be frankly.  
> **username_4**: What does it even do it looks like a copy | paste to me?  
> **username_0**: @RicardoBohner do you mean the answer or the command? in case of the answer it was originally posted by me 1 day before the selected one, regarding the command instead it does a copy but also reading the data and checking for integrity fixes the stream.  
> **username_4**: I meant the command, and I didn't know that ffmpeg did integrity fixes when using the copy codec...thanks for clarification.  

---

### Answer by username_5 on 2020-06-26. Score: 4

I've tested lot of solutions and software. I love cli commands, so using ffmpeg you can fix your video file with no hassle. Try the next command if you came here searching some useful fix:
ffmpeg -vcodec mpeg4 -b:v 7561k -qscale:v 2 -acodec aac -ac 2 -async 1 -strict experimental ./video_fixed.mp4 -threads 0 -i damage_file.mp4

Good luck !

> **Comments:**
> **username_6**: This will probably work, but the file will be HUGE! Better so just use H264 again, like: `ffmpeg.exe -i "input.mp4" -c:v libx264 -crf 22 -preset slow output.mp4`  
> **username_7**: this is the only thing that worked. Can you please explain the flags? why does it work and how can it be optimized  
> **username_8**: I had a video which I composed of 3 separate videos with -f concat and -safe 0, however, while the result played in VLC, in Davinci I could only see the video up to the first merge point (audio was still fine, though). After that Davinci showed a red media offline message. I first tried simply ffmpeg -c copy to fix the video but that did not work, however this re-encoding worked.  
> **username_9**: I had an mp4 that didn't have a thumbnail and claimed wrong resolution in properties. Doing `ffmpeg -i input.mp4 output.mp4` didn't fix it, but converting to avi did, showing thumbnail and correct resolution. Instead of avi we can change the codec with `-c:v mpeg4` to fix it also. I tried `-c:v libx264` but didn't work since it already was that codec. So it seems the only way to fix it is to switch codec/format then switch back. Also when first converting we have to use `-q:v 0` to not lose quality. `ffmpeg -i input.mp4 -c:v mpeg4 -q:v 0 output1.mp4` then `ffmpeg -i output1.mp4 output2.mp4`.  
> **username_9**: Also if you do the avi way `ffmpeg -i input.mp4 -q:v 0 output1.avi` then `ffmpeg -i output1.avi output2.mp4`, you get the same `output2.mp4`. They generate the same md5 hash.  

---

