How to Play Audio and Video on Raspberry Pi

How to Play Audio and Video on Raspberry Pi

How to Play Video

To play a video, please use cd to navigate to the terminal’s video file location, then type the following command:

omxplayer example.mp4
This will play example.mp4 in fullscreen. Press Ctrl + C to exit.
On Raspberry Pi 4, hardware support for MPEG2 and VC-1 codecs has been removed, so we recommend using the VLC application, which supports these formats in software.Additionally, VLC also supports H264 and the new HEVC codecs.

Sample Video

You can find a sample video of the animated film Big Buck Bunny on Raspberry Pi. To play it, enter the following command in the terminal window:

omxplayer /opt/vc/src/hello_pi/hello_video/test.h264
On Raspberry Pi 4, use the following command for H264 files:
omxplayer /opt/vc/src/hello_pi/hello_video/test.h264
Or for H264, VC1, or MPEG2
vlc /opt/vc/src/hello_pi/hello_video/test.h264
When using VLC, you can improve playback performance by wrapping the raw H264 stream (e.g., from the Raspberry Pi camera module) easily with `ffmpeg`. Playback is also improved if VLC runs in fullscreen; select fullscreen from the user interface, or you can add the –fullscreen option in the vlc command line. This example command converts video.h264 to containerized video.mp4 at 30 fps.
ffmpeg -r 30 -i video.h264 -c:v copy video.mp4

Options During Playback

There are many options available during playback, operated by pressing the appropriate keys. Not all options are available on all files. You can use omxplayer –keys to display the key binding list:
    1           decrease speed    2           increase speed    <           rewind    >           fast forward    z           show info    j           previous audio stream    k           next audio stream    i           previous chapter    o           next chapter    n           previous subtitle stream    m           next subtitle stream    s           toggle subtitles    w           show subtitles    x           hide subtitles    d           decrease subtitle delay (- 250 ms)    f           increase subtitle delay (+ 250 ms)    q           exit omxplayer    p / space   pause/resume    -           decrease volume    + / =       increase volume    left arrow  seek -30 seconds    right arrow seek +30 seconds    down arrow  seek -600 seconds    up arrow    seek +600 seconds

Background Playback

If you run omxplayer in the background without tty (user input), it will terminate immediately, so to run successfully, you need to use the –no-keys option to tell omxplayer that no user input is required.
omxplayer --no-keys example.mp3 &
Add & at the end of the command to run in the background. Then you can check the status of this background job using the jobs command. By default, the job will finish when `omxplayer` has completed playback, but if needed, you can always stop it using the kill command.
$ jobs[1]-  Running             omxplayer --no-keys example.mp3 &$ kill %1$[1]-  Terminated          omxplayer --no-keys example.mp3 &

Leave a Comment