Body: <p>During a recent talk, I used a pass-through screen capture device to record a laptop's output to a projector.  The capture went perfectly until about an hour into the talk, when the speaker switched to a demo and changed some settings (resolution, and perhaps others).  The projector continued to display his demo just fine, but the screen capture file becomes so full of video artifacts at that point that it's impossible to understand what was on the screen.  You can see that something is there, and that there are some windows, but just barely.</p>
  
  <p>Is it possible to use ffmpeg or some other open source tool to repair a video damaged in that way?  I've tried re-encoding in the usual simple ways I've seen recommended, but that hasn't helped.  I've tried both ffmpeg and VLC for repair.  Maybe there's something I can do to extract the damaged part of the video but with the new settings active.  Is that possible?</p>
  
  <p>Thanks very much.</p>
  
  <p>P.S.: Here are the results of running ffprobe on the file:</p>
  
  <pre><code>&gt; ffprobe Encode_1080P_30.mp4 
  ffprobe version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2007-2017 the FFmpeg developers
    built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
    configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
    libavutil      54. 31.100 / 54. 31.100
    libavcodec     56. 60.100 / 56. 60.100
    libavformat    56. 40.101 / 56. 40.101
    libavdevice    56.  4.100 / 56.  4.100
    libavfilter     5. 40.101 /  5. 40.101
    libavresample   2.  1.  0 /  2.  1.  0
    libswscale      3.  1.101 /  3.  1.101
    libswresample   1.  2.101 /  1.  2.101
    libpostproc    53.  3.100 / 53.  3.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Encode_1080P_30.mp4':
    Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: qt  
    Duration: 01:11:01.40, start: 0.000000, bitrate: 1735 kb/s
  Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
  Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 1538 kb/s, 28.32 fps, 30 tbr, 30 tbn, 60 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-16T14:05:47.600Z
Comments.Text: How did you record the video, exactly? Using which tool etc.? My guess is that the bitstream still signals the old resolution (using the [H.264 SPS NAL unit](https://cardinalpeak.com/blog/the-h-264-sequence-parameter-set/)) while the actual frames are coded at a new one.
Comments.UserDisplayName: slhck
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-17T02:31:43.870Z
Comments.Text: I have a device that accepts HDMI in and passes that signal, unchanged, out via HDMI.  When I press a button, it also records that signal, as an mp4 file, on a flash drive I insert in another slot.  There are no other controls.
  
  That's my guess, too, but I don't know how to extract the frames and wrap them with the new resolution, or how to detect what that resolution is.  Do you have any ideas?
Comments.UserDisplayName: Arthur A. Gleckler
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-17T07:25:42.197Z
Comments.Text: My guess would be that you can extract the raw bitstream with `ffmpeg -i input.mp4 -c:v copy -an output.h264`, then find the sequence change, split the file there, and re-multiplex it. But that probably requires some (high level) bitstream parsing, going from NAL unit to NAL unit and checking what kind it is. (I have some code for that, but I have to see if I can publish it.)
Comments.UserDisplayName: slhck
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-17T09:23:06.567Z
Comments.Text: There you go: https://github.com/slhck/h26x-extractor – again, I don't know if that kind of splitting would actually work.
Comments.UserDisplayName: slhck
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-21T18:16:05.393Z
Comments.Text: Thank you very much.  I've downloaded and run h26x-extractor, but I'm not sure where to go from there.  Can you give me any insights based on the output?:
  
  [gist of transcript](https://gist.github.com/arthurgleckler/9d6110296802e43cb4c5efd3ca4cefe5)
Comments.UserDisplayName: Arthur A. Gleckler
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-22T20:25:46.533Z
Comments.Text: Hm, that seems weird. Lots of NAL units it cannot recognize. Now I'm not sure if it's not a problem with my code (it's not that thoroughly tested). Normally there should be lots of "coded slice" NALUs. But if you look inside the SPS data you will find the picture width in macro blocks, where one MB is 16 pixels wide. Can you spot a resolution change there?
Comments.UserDisplayName: slhck
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-24T03:51:10.310Z
Comments.Text: Thank you again, but this has gone far beyond my level of expertise.  Fortunately, when the demo started and I saw the speaker changing resolutions, I pointed the camera at the screen.  That's nowhere near as good as the screen capture would have been, but it at least let me get a useful video onto YouTube.
Comments.UserDisplayName: Arthur A. Gleckler
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-24T08:30:21.580Z
Comments.Text: I see, no worries, this can require quite a bit of forensics work.
Comments.UserDisplayName: slhck
Tags: <ffmpeg><h.264>
Title: How can I repair a video file that became corrupt after a settings change during recording?
UserDisplayName: Arthur A. Gleckler
ThreadText: # How can I repair a video file that became corrupt after a settings change during recording?
  
  (Asked by: username_0 on 2017-07-15)
  
  During a recent talk, I used a pass-through screen capture device to record a laptop's output to a projector. The capture went perfectly until about an hour into the talk, when the speaker switched to a demo and changed some settings (resolution, and perhaps others). The projector continued to display his demo just fine, but the screen capture file becomes so full of video artifacts at that point that it's impossible to understand what was on the screen. You can see that something is there, and that there are some windows, but just barely.
  
  Is it possible to use ffmpeg or some other open source tool to repair a video damaged in that way? I've tried re-encoding in the usual simple ways I've seen recommended, but that hasn't helped. I've tried both ffmpeg and VLC for repair. Maybe there's something I can do to extract the damaged part of the video but with the new settings active. Is that possible?
  
  Thanks very much.
  
  P.S.: Here are the results of running ffprobe on the file:
  
  ```
  > ffprobe Encode_1080P_30.mp4 
  ffprobe version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2007-2017 the FFmpeg developers
    built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
    configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
    libavutil      54. 31.100 / 54. 31.100
    libavcodec     56. 60.100 / 56. 60.100
    libavformat    56. 40.101 / 56. 40.101
    libavdevice    56.  4.100 / 56.  4.100
    libavfilter     5. 40.101 /  5. 40.101
    libavresample   2.  1.  0 /  2.  1.  0
    libswscale      3.  1.101 /  3.  1.101
    libswresample   1.  2.101 /  1.  2.101
    libpostproc    53.  3.100 / 53.  3.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Encode_1080P_30.mp4':
    Metadata:
  major_brand     : isom
  minor_version   : 512
  compatible_brands: qt  
    Duration: 01:11:01.40, start: 0.000000, bitrate: 1735 kb/s
  Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
  Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 1538 kb/s, 28.32 fps, 30 tbr, 30 tbn, 60 tbc (default)
  Metadata:
    handler_name    : VideoHandler
  
  ```
  
  **Tags:** ffmpeg, h.264
  
  > **Comments:**
  > **username_1**: How did you record the video, exactly? Using which tool etc.? My guess is that the bitstream still signals the old resolution (using the [H.264 SPS NAL unit](https://cardinalpeak.com/blog/the-h-264-sequence-parameter-set/)) while the actual frames are coded at a new one.  
  > **username_0**: I have a device that accepts HDMI in and passes that signal, unchanged, out via HDMI.  When I press a button, it also records that signal, as an mp4 file, on a flash drive I insert in another slot.  There are no other controls.  That's my guess, too, but I don't know how to extract the frames and wrap them with the new resolution, or how to detect what that resolution is.  Do you have any ideas?  
  > **username_1**: My guess would be that you can extract the raw bitstream with `ffmpeg -i input.mp4 -c:v copy -an output.h264`, then find the sequence change, split the file there, and re-multiplex it. But that probably requires some (high level) bitstream parsing, going from NAL unit to NAL unit and checking what kind it is. (I have some code for that, but I have to see if I can publish it.)  
  > **username_1**: There you go: https://github.com/username_1/h26x-extractor – again, I don't know if that kind of splitting would actually work.  
  > **username_0**: Thank you very much.  I've downloaded and run h26x-extractor, but I'm not sure where to go from there.  Can you give me any insights based on the output?:  [gist of transcript](https://gist.github.com/arthurgleckler/9d6110296802e43cb4c5efd3ca4cefe5)  
  > **username_1**: Hm, that seems weird. Lots of NAL units it cannot recognize. Now I'm not sure if it's not a problem with my code (it's not that thoroughly tested). Normally there should be lots of "coded slice" NALUs. But if you look inside the SPS data you will find the picture width in macro blocks, where one MB is 16 pixels wide. Can you spot a resolution change there?  
  > **username_0**: Thank you again, but this has gone far beyond my level of expertise.  Fortunately, when the demo started and I saw the speaker changing resolutions, I pointed the camera at the screen.  That's nowhere near as good as the screen capture would have been, but it at least let me get a useful video onto YouTube.  
  > **username_1**: I see, no worries, this can require quite a bit of forensics work.  
  
  ---
  
  ## 0 answers
  
  