VideoHelp Forum

+ Reply to Thread
Results 1 to 9 of 9
Thread
  1. Hi

    I have a recording made of a recent school event which we are hoping to give to parents as they were unable to attend due to Covid. Unfortunately, the camera (an old DV camcorder) obviously had a problem with the record heads and there is frame corruption about every 1s which has led to 1-frame of dropped audio (samples go to 0) which amounts to 960 samples @ 48KHZ. I have attached a short (~4s) sample which shows it quite clearly (I think).

    I have tried the Audacity repair feature (that only works up to 128 samples) and am still experimenting with more detailed plugins etc. but this is way above my skillset and I was hoping someone here might have some advice. I'm quite happy learning new tools and generally technically minded but don't have much experience with audio editing and would greatly appreciate any assistance here.

    Thanks.
    Image Attached Files
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    You could try the free trial of Izotope RX 8, Spectral repair/replace,
    but you'd have to do the sections one at a time

    EDIT I just realized the trial does not allow you to save the repaired file,
    but for something like this you could employ Audacity to record the file as you play it back -
    https://manual.audacityteam.org/man/tutorial_recording_computer_playback_on_windows.html
    Last edited by davexnet; 16th Aug 2021 at 14:10.
    Quote Quote  
  3. Thanks davexnet - I have something working with ffmpeg at the moment but if that flops I might give Izotope + Audacity idea a go.
    Quote Quote  
  4. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Ok. If you could elaborate on your ffmpeg solution it might help others in the future
    Quote Quote  
  5. In case this may give ideas to others, now I've got a solution that is not perfect, but about all I can achieve in the time I have spare, this is what I did:

    Problem:
    An old and apparently worn DV camcorder was used to record a school play, but the heads have a problem causing 1-2 frames to get corrupted every 1 second or so. Manifested as the odd frame with missed/garbled pixels and hard-silence (i.e. samples = 0) on the audio track because, I'm guessing, of corrupt bitstream rather than actually sampling 0s. The glitchy video was distracting but not intolerable whereas the skipped audio was making it unintelligible at points.

    Eventual solution:
    Since the skipped audio as a stream of hard-0s, the ffmpeg detect-silence filter was very effective at finding the start and end points by looking for -80dB for > 39ms (1 frame = 40ms). I then turned these start and end points into a list of cuts to select the good(ish) video between each clip, extracted these clips and then concatenated them back together which results in the original video getting the silenced frames cut out.

    How I did it:
    This is undoubtedly NOT the best way, and the result is far from perfect (silences drifted throughout video w.r.t. frame boundaries, not all video frames had silence, skipped silences still lead to some "popping" etc.) but it was good enough for a one-off solution and produced tolerable output. The BASH script I eventually came up with is below (don't judge me - it's very Heath-Robinson/Rube-Goldberg) for anyone who's interested but I can't attach any example of the corrupt files as they're from a school play and it wouldn't be appropriate.

    Code:
    files=(tape1.avi)
    files+=(tape2-1.avi)
    files+=(tape2-2.avi)
    
    for f in ${files[*]} ; do
    
      b=`basename $f`
      r=${b/avi/dv}
      
      # Recoding just to clear up stream errors that crept in somewhere (save as .dv instead of .avi)
      echo "Working on $f..."
      if [[ ! -r $r ]] ; then
        echo "  Recoding $f to $r (clean up stream errors)..."
        rm -f $r
        ffmpeg -i $f -s pal -r pal -aspect 16:9 -ar 48000 -ac 2 $r 2>$r.recode.log
      fi
      
      # Find silences in terms of start and end times, convert these to whole frames and then output
      # an ffmpeg extract commnad from after previous silence to start of current one.
      # NOTE: Silences initially aligned on frame boundaries but seem to drift. I opted to cut the last
      #       frame with any silence in it and the number of frames containing silence which sometimes left
      #       a bit of silence at end of last uncut frame - trade off between audio and video skips.
      # NOTE: Needed one ffmpeg command per cut as large number of cuts resulted in "too-many open files"
      #       error when done in one go. Very slow at end of long files - could be optimised.
      echo "  Finding silence..."
      rm $r.split.ffs
      ffmpeg -i $r -af silencedetect=noise=-80dB:d=0.035 -f null - 2>&1 | \
        tr '\r' '\n' | \
        awk 'BEGIN {s=0}; /silence_end/ {d=int(($8+0.039)/0.04)*0.04; e=int($5/0.04)*0.04; printf "%8.2f %8.2f\n", s, e-d+0.04; s=e+0.04}' |
        awk 'BEGIN {n=1}; {printf "printf .; ffmpeg -i <fname> -c:v copy -c:a copy -ss %s -to %s clips/%06d.dv 2>/dev/null\n",$1,$2,n++}' |
        sed "s/<fname>/$r/" >> $r.split.ffs
      echo 'printf "\n"' >> $r.split.ffs
      
      # Run the ffmpeg commands created above to generate sequentially-named files
      rm -rf clips; mkdir -p clips
      . $r.split.ffs
      
      # Prepare list of files to be concatenated and do it.
      rm -f $r.concat-files.txt
      for clip in `ls -1 clips/*.dv` ; do
        echo "file '$clip'" >> $r.concat-files.txt
      done
      rm -f fixed.$r
      ffmpeg -f concat -i $r.concat-files.txt -c copy fixed.$r
      
      # Extract audio for audio-cleanup in audacity.
      ffmpeg -i fixed.$r -c:a pcm_s16le -vn fixed.$r.wav
      
      # TODO: Once complete, clean up audio in audacity (clip-fix, click-removal, low-pass filter) and write out to fixed.$r.clean.wav
    
      # Recombine video and audio into DV encoded AVI
      ffmpeg -i fixed.$r -i fixed.$r.clean.wav -map 0:0 -map 1:0 -c:v copy -c:a pcm_s16le fixed.$r.final.avi
    
      echo "Finished $r."
      
    done
    Quote Quote  
  6. Just as an experiment I manually copied the prior 40 ms of audio over the missing 40 ms gaps with a manual copy/paste in Audacity. There were some clicks at some of the transitions (these could be reduced with a click remover filter) but I was surprised at how well it worked. The process could probably be automated and wouldn't require any changes to the video track.
    Image Attached Files
    Quote Quote  
  7. Thanks jagabo.

    Tried something similar, but there are several thousand of these silences and I couldn't find an "easy" way to copy previous n-seconds of audio and paste it back in. I know I could uses the same ffmpeg method, export the n-seconds prior to a silence then export the silence with the copied bit replacing the audio then reconcatenate everything but I only had so much time. But now I think about it, I could also take the m-vidframes of the silenced bit(since these are often "bad" too) and replace with the frame from before the cut too......

    Aaaarghh - now it's in my head, so again big thanks!!!

    Quote Quote  
  8. I don't do much audio editing. But it seems to me you could mix two audio tracks, the original, and one with a 40 ms delay. Any time the original track drops to zero substitute the delayed track.
    Quote Quote  
  9. Any ideas how to do the mixing only when main track is silent (I can extract the times of the silences easily enough)?

    I originally tried this by mixing the two tracks all the time but that gave some hysterically bad echo (as you might expect).

    I could maybe use an ffmpeg audio filter to mute all audio on the shifted track except during the silences and then just mix.......
    Quote Quote  



Similar Threads