The transcoder function is to convert video and audio resources into video files in m3u8 format suitable for client preview. The interface is used by the executable program to update progress and results.

# Video formats supported by the transcoder: MP4, MOV, WMV, M2V, MPG

# Audio formats supported by the transcoder: MP3, FLAC, AAC, M4A

# Install the transcoder runtime environment

Suppose the current system is ubuntu 18.04.

  1. update linux installer source
apt update;
apt upgrade;
apt install default-jre
  1. Install QT and ffmpeg related libraries
apt-get install qt5-default
apt install libavutil55
apt install libavcodec57
apt install libavformat57
apt install libswresample2
apt install libswscale4
apt install libqt5multimedia5
apt install libqt5multimedia5-plugins
  1. Install the transcoder Put the transcoder (opens new window) into the running directory (eg /opt/bsedit).

# Transcoder parameter description

Run the transcoder on the command line and you can see the following output.

image.png

Name Description
-h, --help Display help documentation
-v, --version Display version number
-o <output> Specify the output file path, if the path ends with mp4, convert to video, if the path ends with m4a, convert to audio
--slice-duration <duration> The duration of the transcoding slice, in milliseconds, if set <=0, it will not be sliced ​​
--video-size <size> Specifies the length of the short side of the output video
--crf <crf> Specify the crf parameter of the output video
--fps <fps> Specify the fps parameter of the output video
--gop-size <gop size> Specify the gop parameter of the output video
--video-decoding-threads <thread count> Specify the number of decoding threads
--video-encoding-threads <thread count> Specify the number of encoding threads
--sample-rate <sample rate> Specifies the sample rate of the output audio
--channel-count <channel count> Specify the number of channels to output audio
--audio-bitrate <bitrate> Specify the bitrate of the output audio
--generate-thumbnails Specify whether to output thumbnails
--thumbnail-size <size> Specifies the length of the short side of the output thumbnail
--thumbnail-interval <interval> Specifies the time interval for output thumbnails
--generate-cover Specify whether to output cover
--cover-size <size> Specifies the length of the short side of the output cover
--cover-timestamp <timestamp> Specify the time code of the video corresponding to the output cover
--host <host> Specify the network host address of the output m3u8 file
--asset-uuid <uuid> Specify the uuid name of the shard that outputs the m3u8 file
--callback-url <url> Specify the callback interface address of the transcoder
--task-id <id> Specify transcoding task ID
--generate-waveform Specifies whether to output audio waveforms
--waveform-groups-per-second <groups per second> Specify the number of waveform samples per second
--generate-alpha-channel Specifies whether to transcode channel video
--only-generate-waveform Specifies whether to output only waveforms
--only-generate-thumbnails Generate thumbnails only
--generate-audio-data Generate audio data
--only-generate-audio-data only generate audio data
--start-time <start-time> Transcode crop in point
--end-time <end-time> Transcode crop out point
source Video or audio local address or network address to be transcoded
--multiple-audio-streams Specifies whether to output multi-track audio

# Example

An example of transcoding a video file into a video fragment

./NvTranscoder \
    -o output.mp4 \
    --slice-duration 5000 \
    --video-size 480 \
    --crf 27 \
    --fps 25 \
    --gop-size 25 \
    --sample-rate 44100 \
    --channel-count 2 \
    --audio-bitrate 64000 \
    --generate-thumbnails \
    --thumbnail-size 128 \
    --thumbnail-interval 1000 \
    --generate-cover \
    --cover-size 256 \
    --cover-timestamp 0 \
    --host http://localhost \
    --asset-uuid uuid \
    --callback-url http://localhost \
    --task-id 1 \
    --generate-waveform \
    --waveform-groups-per-second 150 \
    https://bsedit-1257467088.cos.ap-beijing.myqcloud.com/test/wudao.mp4

An example of transcoding a video file into an audio segment

./NvTranscoder \
    -o output.m4a \
    --slice-duration 30000 \
    --video-size 480 \
    --crf 27 \
    --fps 25 \
    --gop-size 25 \
    --sample-rate 44100 \
    --channel-count 2 \
    --audio-bitrate 64000 \
    --generate-thumbnails \
    --thumbnail-size 128 \
    --thumbnail-interval 1000 \
    --generate-cover \
    --cover-size 256 \
    --cover-timestamp 0 \
    --host http://localhost \
    --asset-uuid uuid \
    --callback-url http://localhost \
    --task-id 1 \
    --generate-waveform \
    --waveform-groups-per-second 150 \
    https://bsedit-1257467088.cos.ap-beijing.myqcloud.com/test/wudao.mp4

# program exit code

The interface judges whether the transcoding is successful according to the program exit code

Transcoder exit code Success
0 yes
non-zero no

# Docker way to run the transcoder

If the libc library version of the Linux system is lower than 2.27, you should use Docker to run the transcoder.

# Install Docker

Reference Docker official website (opens new window)

# Pull cloud clipping image

docker pull shanwuzhongjian/meishesdk-bsedit:1.0.1

# run the container

docker run -itd <imageId>

# test transcoding

docker exec -w /opt/bsedit <containerId> \
    ./NvTranscoder \
     -o output.m4a \
     --slice-duration 30000 \
     --video-size 480 \
     --crf 27 \
     --fps 25 \
     --gop-size 25 \
     --sample-rate 44100 \
     --channel-count 2 \
     --audio-bitrate 64000 \
     --generate-thumbnails \
     --thumbnail-size 128 \
     --thumbnail-interval 1000 \
     --generate-cover \
     --cover-size 256 \
     --cover-timestamp 0 \
     --host http://localhost \
     --asset-uuid uuid \
     --callback-url http://localhost \
     --task-id 1 \
     --generate-waveform \
     --waveform-groups-per-second 150 \
     https://bsedit-1257467088.cos.ap-beijing.myqcloud.com/test/wudao.mp4

The slices generated after transcoding are in the /opt/bsedit directory of the container

# Example of receiving a transcoding callback

Download the example demo-0.0.1-SNAPSHOT.jar (opens new window), create the configuration file application.properties

server.port             = 8080
trancoderContainerId    = 8405c24f7354          // container id
outputFileUuid          = outfile-uuid

run the jar package

java -jar demo-0.0.1-SNAPSHOT.jar --spring.config.location=./application.properties &

Enter the container, and restart nginx after modifying the nginx server configuration file (/etc/nginx/sites-available/default) in the container

    // Comment out the default configuration
    #location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri $uri/ =404;
    #}

    // Change to the following configuration
    location / {
        proxy_pass http://<Host intranet IP>:8080;
    }

Call the interface to start transcoding

curl http://localhost:8080/startTranscoder

Go to /opt/bsedit in the container to view the transcoding result