11

The Raspberry Pi will do hardware accelerated h264 encoding when recording video from the camera board. How can I encode h264 (using hardware acceleration) when the source images are not coming directly from the camera?

Are there any command line tools that support this?

If no, what APIs should I be looking at to make this possible?

  • What are you encoding, and how so currently? - are you converting video files, rendering them from images and sound, etc... – Wilf Jun 5 '14 at 23:00
  • @Wilf I'm interested in this in general, however I do have a present application: encoding a time lapse directly to video. I can't use raspivid because I need low framerates between 1/5 and 2 fps. Also, raspivid auto-exposure goes into oscillations under my lighting conditions (low light). So I want to use raspistill, but encode directly to video so the result doesn't take up too much space (as JPEGs would). As a second application I want to post process each frame in real time using Mathematica (will take a lot of CPU time), and then send them to be encoded into h264. – Szabolcs Jun 6 '14 at 3:17
  • 1
    @Wilf I do have a partial solution which I think should be possible to make work: the idea is something like raspiyuv -o - | rpi-encode-yuv (roughly) where the rpi-encode-yuv tool is from here. The frame size is hard-coded in this tool, so you need to change it at the beginning of the C file and recompile. Unfortunately I haven't managed to get a properly aligned output yet, as raspiyuv doesn't seem to encode the frame size into its output. I get a gradually shifting picture that eventually turns to garbage. Still working on it. – Szabolcs Jun 6 '14 at 3:20
8

GStreamer is included in Raspbian and with its OpenMAX plugin it will use the hardware encoding capabilities of the Raspberry Pi.

See this link for a tutorial on doing what you're looking for: https://www.raspberrypi.org/forums/viewtopic.php?t=72435

If you're interested in transcoding, I've just posted an answer to another question that might interest you: What speed can I expect from the hardware-H264-encoding?

  • Thanks! I cannot test this right now but will accept in advance based on your tutorial. – Szabolcs Apr 12 '15 at 21:34
1

Looks like by compiling ffmpeg by yourself, on RPi3B+ you can get

ENCODING HIGH-COMPLEXITY 30 FPS VIDEO FROM A 1920 X 1080 JPEG IMAGE SEQUENCE – SIGNIFICANT MOTION AND INTRAFRAME DETAIL – HIGH QUALITY SETTINGS:

Software-Based H.264 Encoding (CPU): 2.6 FPS (11.5 times slower than real time)

Hardware-Based H.264 Encoding (GPU): 6.3 FPS (4.8 times slower than real time)

ENCODING HIGH-COMPLEXITY 30 FPS VIDEO FROM A 640 X 480 JPEG IMAGE SEQUENCE – SIGNIFICANT MOTION AND INTRAFRAME DETAIL – HIGH QUALITY SETTINGS:

Software-Based H.264 Encoding (CPU): 18 FPS (1.7 times slower than real time)

Hardware-Based H.264 Encoding (GPU): 38 FPS (1.3 times FASTER than real time)

The script to help achieve all this is in a forum thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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