title: Out of memory on ffmpeg when converting to H265
body: <p>I've a bunch of video files, mostly H264. To save storage, I wrote a batch script, that converts all of them to H265 using ffmpeg. Problem: Some files cause ffmpeg to use ALL my memory (24 GB). Then it crashes (cause it try to allocate even more RAM), which stops the converting process. </p>
  
  <p>I think that these files are corrupt in some kind. Because with other files, it works well with low memory consumption. Now I want to reject those broken ones, so that unattended converting is possible. </p>
  
  <p><em>How is it possible to detect such corruption? Can ffmpeg do this, or is a third party tool required?</em></p>
  
  <h3>My ffmpeg call</h3>
  
  <pre><code>set crf=20
  set codec=265
  
  ffmpeg -hide_banner -i "!fullSourcePath!" -c:v libx%codec% -crf %crf% "%targetPath%\!targetFileName!"
  </code></pre>
  
  <h3>mkvalidator can't help</h3>
  
  <p><a href="https://matroska.org/downloads/mkvalidator.html" rel="nofollow noreferrer">mkvalidator</a> says that a corrupt file is valid:</p>
  
  <pre><code>mkvalidator.exe "V:\Filme\_LegacyFormat\22 Jump Street.mkv"
  ........................................................................................................................
  WRN0D0: There are 5306 bytes of void data..
  
  mkvalidator 0.5.0: the file appears to be valid
          file created with libebml v1.3.0 + libmatroska v1.4.1 / mkvmerge v6.9.1 ('Blue Panther') 64bit built on Apr 18 2014 18:23:38
  </code></pre>
  
  <h3>eac3to331 can't help, too</h3>
  
  <p>I found the tool <a href="https://www.ecosia.org/search?q=eac3to&amp;addon=chrome&amp;addonversion=2.0.3" rel="nofollow noreferrer">eac3to331</a>, which has a <code>check</code> flag. But it gave me no errors, although the tested file seems corrupt (cause my PC to crash after several minutes running ffmpeg)</p>
  
  <pre><code>eac3to.exe -check "V:\Filme\_LegacyFormat\22 Jump Street.mkv"
  MKV, 1 video track, 2 audio tracks, 1 subtitle track, 1:51:57, 24p /1.001
  1: h264/AVC, English, 1920x808 24p /1.001 (240:101)
  2: DTS, German, 5.1 channels, 1509kbps, 48kHz
  3: DTS, English, 5.1 channels, 1509kbps, 48kHz
  4: Subtitle (SRT), German
  v01 Extracting video track number 1...
  a02 Extracting audio track number 2...
  a03 Extracting audio track number 3...
  s04 Extracting subtitle track number 4...
  Video track 1 contains 161039 frames.
  eac3to processing took 1 minute, 26 seconds.
  Done.
  </code></pre>