This note wrties some FFmpeg command I used when preparing ICRA 2027 supplementary video.

Official document

[https://ffmpeg.org/documentation.html]

Download

After downloading it in Windows, we get three executables: bin/

add ffmpeg to the path

Let the Bash know where ffmpeg.exe is, and no need to write the full path any more.

nano ~/.bashrc
export PATH="$PATH:/c/Users/JXZ/Downloads/ffmpeg-master-latest-win64-gpl/ffmpeg-aster-latest-win64-gpl/bin"

Verify after source ~/.bashrc :

# shows the above directory
which ffmpeg

or

ffmpeg -version

video conversion

  1. The experimemt videos collected via ROS node is encoded by MJPEG, which cannot be opened by the default palyer on Windows (can be opened by VLC), nor can it be decoded in Davinci Resolve 21. MJPEG, however, is suitable for image acquisition and frame-by-frame processing, since each frame is a JPEG image and independently compressed. In order to open the video in Davinci, the codec needs to be changed from mjpeg to h264.
    ffmpeg -i "input.mp4" \
    -c:v libx264 \
    -crf 18 \
    -preset medium \
    -pix_fmt yuv420p \
    -an \
    "output_h264.mp4"
    

batch conversion

mkdir -p h264
for f in experiment*.mp4; do
    ffmpeg -i "$f" \
        -c:v libx264 \
        -crf 18 \
        -preset medium \
        -pix_fmt yuv420p \
        -an \
        "h264/${f%.mp4}_h264.mp4"
done

For instance, $f is experiment01.mp4, then ${f%.mp4} gives experiment01 by removing the suffix .mp4.

  1. Davinci Resolve exports clips as .mov, using the following command to change it to .mp4. Only change the container while keeping the codec.
    ffmpeg -i "input.mov" -c copy "output.mp4"
    

video compression

ffmpeg -i "ICRA_master.mov" \
-c:v libx264 \
-b:v 800k \
-preset slow \
-pix_fmt yuv420p \
-an \
-movflags +faststart \
"ICRA_final.mp4"