<p>For files already encoded to AVI, you'll have to extract the video to a raw HEVC stream first:</p>

<pre><code>ffmpeg -i in.avi -c copy -map 0:v -f hevc in.265
</code></pre>

<p>and then</p>

<pre><code>ffmpeg -framerate 30 -i in.265 -i in.avi -c copy -map 0:v -map 1:a -video_track_timescale 1k fixed.mp4
</code></pre>

<p>Replace the framerate value with the true rate of the video.</p>

<hr>

<p>Encode new files to MP4 or MKV.</p>

<pre><code>ffmpeg -i "$origFile" -map 0 -c copy -c:v libx265 -preset slow -crf 28 "newFile.mp4"
</code></pre>

CC BY-SA 3.0
2017-02-10T17:44:52.203Z
Here is a new pastebin of that process. Can you just see if everything looks ok for this file? http://pastebin.com/rXBeRyGc  I wasn't sure about the "pts has no value" outputs
J M
CC BY-SA 3.0
2017-02-10T17:47:12.710Z
Looks ok. Drop the framerate and only use it the output plays too fast or slow.
Gyan
CC BY-SA 3.0
2017-02-10T17:50:23.120Z
Ok. Can you update the answer with one more part? If I have avi files that are not yet encoded to hevc, so ffprobe reports mpeg4 as the video codec. What process should I take to encode these to hevc files?
J M
CC BY-SA 3.0
2017-02-10T17:30:22.387Z
2017-02-10T18:10:29.963Z
2017-02-10T18:10:29.963Z
Gyan
<p>I have a script that is going through a media library and re-encoding files to HEVC with ffmpeg and using libx265. The default command I use is:</p>

<pre><code>ffmpeg -i "$origFile" -map 0 -c copy -c:v libx265 -preset slow -crf 28 "$newFile"
</code></pre>

<p>However, for some files this process fails, it outputs the following information about the video:</p>

<pre><code>Output #0, matroska, to 'test.mkv':
  Metadata:
    encoder         : Lavf56.15.105
    Stream #0:0: Video: hevc, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 23.98 fps
    Metadata:
      encoder         : Lavc57.14.100 libx265
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, 128 kb/s
Stream mapping:
  Stream #0:0 -&gt; #0:0 (rawvideo (native) -&gt; hevc (libx265))
  Stream #0:1 -&gt; #0:1 (copy)
</code></pre>

<p>And then, I just get the wall of errors that are printed below here: </p>

<pre><code>[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 295 &lt; expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 362 &lt; expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 5926 &lt; expected frame_size
1769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 406 &lt; expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument
</code></pre>

<p>I've tried following some other advice, since when I try and read the codec, it says "rawvideo", and using commands like <code>ffmpeg -f rawvideo -pix_fmt yuv420p....</code>, but that also does not work. If anyone has any insight or ability to help explain how to overcome this issue, it would be really appreciated. I've included the ffprobe output for this particular file as well if that is helpful:</p>

<pre><code>ffprobe version N-76479-gc878082 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --e
nable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-li
bass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libf
reetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libm
p3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable
-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --en
able-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libv
o-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-deckli
nk --enable-zlib
  libavutil      55.  5.100 / 55.  5.100
  libavcodec     57. 14.100 / 57. 14.100
  libavformat    57. 14.100 / 57. 14.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 14.101 /  6. 14.101
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.100 /  2.  0.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from '109 - The Voices of the Dead.avi':
  Metadata:
    encoder         : Lavf56.15.105
  Duration: 00:58:35.47, start: 0.000000, bitrate: 359 kb/s
    Stream #0:0: Video: rawvideo, bgr24, 1024x576, 219 kb/s, SAR 1:1 DAR 16:9, 23.98 fps,
23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 128 kb/s
</code></pre>

CC BY-SA 3.0
2017-02-08T23:33:10.740Z
Your `ffmpeg` is too old. Windows users can get a build from [Zeranoe](https://ffmpeg.zeranoe.com/builds/). `-strict experimental` is [no longer needed](http://git.videolan.org/?p=ffmpeg.git;a=commit;h=0dd201d947e213887960fe8835586c0b0d73a40e) when encoding 4:2:2 and 4:4:4.
llogan
CC BY-SA 3.0
2017-02-09T02:14:16.917Z
I will update it, and see if that fixes it.
J M
CC BY-SA 3.0
2017-02-09T03:00:15.453Z
I updated, and now I just get the stream of errors about invalid buffer size, exact same ones as mentioned above
J M
CC BY-SA 3.0
2017-02-09T03:38:23.163Z
What created the input file? Can anything else properly decode it? Are you sure it's bgr24, 1024x576, 24000/1001 frame rate? Can you show the complete console output from the command?
llogan
CC BY-SA 3.0
2017-02-09T04:18:37.813Z
@LordNeckbeard I do not know what created the input, it was a downloaded video file, not my own creation. The entire console input is huge, but I will try and run/copy and put it up on pastebin sometime tomorrow. It is just the error repeating over and over and over again.
J M
CC BY-SA 3.0
2017-02-09T05:13:46.080Z
Basically, rawvideo is uncompressed full raster, so every frame is of identical bytesize and that's what FFmpeg expects. However, it's complaining that some frame sizes are (much) smaller than expected. A downloaded file will almost certainly not have a rawvideo stream. Even the input video stream bitrate suggests that. Try adding `-c:v h264` before `-i` . If that doesn't work, try `-c:v mpeg4`
Gyan
CC BY-SA 3.0
2017-02-10T16:41:21.903Z
@Mulvya So, I'm actually wondering if I created them somehow. Here is a console output of a video I re-encoded from mpeg4 to hevc (http://pastebin.com/3KXjcmxZ) just this morning. This uses the exact same settings as all my other videos (see above post). You can see in the console output, it says the output format at the end is hevc, but if I use ffprobe on the new file, it detects that it is rawvideo? This does not happen for all my videos though
J M
CC BY-SA 3.0
2017-02-10T17:01:13.493Z
That explains it. FFmpeg isn't set to write any tags for HEVC in AVI. Your 'rawvideo stream' is most probably HEVC. Don't encode to AVI if possible. If you have to, add `-vtag hvc1`
Gyan
CC BY-SA 3.0
2017-02-10T17:07:36.530Z
@Mulvya should/can I remux the avi files to something else first? What would you recommend? The videos that are reading as rawvideo, can I "fix" them somehow? Looking through the list, I'm pretty sure all the videos that are failed in this way, are in fact AVI files
J M
<ffmpeg><h265>
Re-encode with ffmpeg using libx265 - rawvideo
J M
# Re-encode with ffmpeg using libx265 - rawvideo

(Asked by: username_0 on 2017-02-08)

I have a script that is going through a media library and re-encoding files to HEVC with ffmpeg and using libx265. The default command I use is:
ffmpeg -i "$origFile" -map 0 -c copy -c:v libx265 -preset slow -crf 28 "$newFile"

However, for some files this process fails, it outputs the following information about the video:
Output #0, matroska, to 'test.mkv':
  Metadata:
    encoder         : Lavf56.15.105
    Stream #0:0: Video: hevc, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 23.98 fps
    Metadata:
      encoder         : Lavc57.14.100 libx265
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (copy)

And then, I just get the wall of errors that are printed below here: 
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 295 < expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 362 < expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 5926 < expected frame_size
1769472
Error while decoding stream #0:0: Invalid argument
[rawvideo @ 000000c56052c920] Invalid buffer size, packet size 406 < expected frame_size 1
769472
Error while decoding stream #0:0: Invalid argument

I've tried following some other advice, since when I try and read the codec, it says "rawvideo", and using commands like ffmpeg -f rawvideo -pix_fmt yuv420p...., but that also does not work. If anyone has any insight or ability to help explain how to overcome this issue, it would be really appreciated. I've included the ffprobe output for this particular file as well if that is helpful:
ffprobe version N-76479-gc878082 Copyright (c) 2007-2015 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --e
nable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-li
bass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libf
reetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libm
p3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable
-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --en
able-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libv
o-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-deckli
nk --enable-zlib
  libavutil      55.  5.100 / 55.  5.100
  libavcodec     57. 14.100 / 57. 14.100
  libavformat    57. 14.100 / 57. 14.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 14.101 /  6. 14.101
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.100 /  2.  0.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from '109 - The Voices of the Dead.avi':
  Metadata:
    encoder         : Lavf56.15.105
  Duration: 00:58:35.47, start: 0.000000, bitrate: 359 kb/s
    Stream #0:0: Video: rawvideo, bgr24, 1024x576, 219 kb/s, SAR 1:1 DAR 16:9, 23.98 fps,
23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 128 kb/s

**Tags:** ffmpeg, h265

> **Comments:**
> **username_1**: Your `ffmpeg` is too old. Windows users can get a build from [Zeranoe](https://ffmpeg.zeranoe.com/builds/). `-strict experimental` is [no longer needed](http://git.videolan.org/?p=ffmpeg.git;a=commit;h=0dd201d947e213887960fe8835586c0b0d73a40e) when encoding 4:2:2 and 4:4:4.  
> **username_0**: I will update it, and see if that fixes it.  
> **username_0**: I updated, and now I just get the stream of errors about invalid buffer size, exact same ones as mentioned above  
> **username_1**: What created the input file? Can anything else properly decode it? Are you sure it's bgr24, 1024x576, 24000/1001 frame rate? Can you show the complete console output from the command?  
> **username_0**: @LordNeckbeard I do not know what created the input, it was a downloaded video file, not my own creation. The entire console input is huge, but I will try and run/copy and put it up on pastebin sometime tomorrow. It is just the error repeating over and over and over again.  
> **username_2**: Basically, rawvideo is uncompressed full raster, so every frame is of identical bytesize and that's what FFmpeg expects. However, it's complaining that some frame sizes are (much) smaller than expected. A downloaded file will almost certainly not have a rawvideo stream. Even the input video stream bitrate suggests that. Try adding `-c:v h264` before `-i` . If that doesn't work, try `-c:v mpeg4`  
> **username_0**: @Mulvya So, I'm actually wondering if I created them somehow. Here is a console output of a video I re-encoded from mpeg4 to hevc (http://pastebin.com/3KXjcmxZ) just this morning. This uses the exact same settings as all my other videos (see above post). You can see in the console output, it says the output format at the end is hevc, but if I use ffprobe on the new file, it detects that it is rawvideo? This does not happen for all my videos though  
> **username_2**: That explains it. FFmpeg isn't set to write any tags for HEVC in AVI. Your 'rawvideo stream' is most probably HEVC. Don't encode to AVI if possible. If you have to, add `-vtag hvc1`  
> **username_0**: @Mulvya should/can I remux the avi files to something else first? What would you recommend? The videos that are reading as rawvideo, can I "fix" them somehow? Looking through the list, I'm pretty sure all the videos that are failed in this way, are in fact AVI files  

---

## 1 answers

### Answer by username_2 on 2017-02-10. Score: 3 | Accepted answer

For files already encoded to AVI, you'll have to extract the video to a raw HEVC stream first:
ffmpeg -i in.avi -c copy -map 0:v -f hevc in.265

and then
ffmpeg -framerate 30 -i in.265 -i in.avi -c copy -map 0:v -map 1:a -video_track_timescale 1k fixed.mp4

Replace the framerate value with the true rate of the video.

Encode new files to MP4 or MKV.
ffmpeg -i "$origFile" -map 0 -c copy -c:v libx265 -preset slow -crf 28 "newFile.mp4"

> **Comments:**
> **username_0**: Here is a new pastebin of that process. Can you just see if everything looks ok for this file? http://pastebin.com/rXBeRyGc  I wasn't sure about the "pts has no value" outputs  
> **username_2**: Looks ok. Drop the framerate and only use it the output plays too fast or slow.  
> **username_0**: Ok. Can you update the answer with one more part? If I have avi files that are not yet encoded to hevc, so ffprobe reports mpeg4 as the video codec. What process should I take to encode these to hevc files?  

---

