Skip to main content

Video Format Conversion

Introduction to FFMPEG

FFMPEG is a free and opensource tool that can be used to convert images and videos to different formats. The tool can be used to convert any video file to MJPEG format so that it can be imported and played by the MJPEG decoder behavior.

Installing FFMPEG
Using the FFMPEG tool to convert MP4 videos to MJPEG

The following command can be used to convert an mp4 file into MJPEG format:

ffmpeg -i input.mp4 -c:v mjpeg -q:v 2 -pix_fmt yuvj420p -huffman optimal -vf "scale=400:225" -f mjpeg -t 10 output.mjpeg

The breakdown of the arguments in the command is as follow:

  • ffmpeg - The name of the tool
  • -i - Specifies the input file
  • -c:v mjpeg - Encodes all video channels with the mjpeg codec
  • -q:v 2 - This is the quality scale for the video stream. Values are from 1=best to 31=worst
  • -pix_fmt yuvj420p - Select the pixel format as YUV420
  • -huffman optimal - Use optimal huffman coding
  • -vf "scale=4--:225" - Set the output video resolution
  • -f mjpeg - force output file format as mjpeg
  • -t 10 - restrict length of output video to 10 seconds
  • output.jpeg - name of the output file