1

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
9
  • 1
    Your ffmpeg is too old. Windows users can get a build from Zeranoe. -strict experimental is no longer needed when encoding 4:2:2 and 4:4:4.
    – llogan
    Feb 8, 2017 at 23:33
  • I will update it, and see if that fixes it.
    – J M
    Feb 9, 2017 at 2:14
  • I updated, and now I just get the stream of errors about invalid buffer size, exact same ones as mentioned above
    – J M
    Feb 9, 2017 at 3:00
  • 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
    Feb 9, 2017 at 3:38
  • 1
    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
    Feb 10, 2017 at 17:01

1 Answer 1

3

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"
3
  • Here is a new pastebin of that process. Can you just see if everything looks ok for this file? pastebin.com/rXBeRyGc I wasn't sure about the "pts has no value" outputs
    – J M
    Feb 10, 2017 at 17:44
  • Looks ok. Drop the framerate and only use it the output plays too fast or slow.
    – Gyan
    Feb 10, 2017 at 17:47
  • 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
    Feb 10, 2017 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.