ffmpeg – convert mov files to mp4

Ffmpeg -I mov-file -b <bit-rate> mp4-file

Calculate bit rate as desired file size in bits / duration of video in seconds

e.g., for 100MB file and 20 min video, bit rate should be 100e6*8/(20*60)

Us -b:v to set bitrate for video and -b:a to set bitrate for audio

$ ffmpeg -i foo.mov -b:v 800k -b:a 128k foo.mp4

References:

more useful commands using chatgpt 🙂

how can i check the resolution of a mp4 file using ffmpeg?

To check the resolution of an MP4 file using ffmpeg, you can use the following command:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 input.mp4

Explanation of the Command:

  1. ffprobe: This is a tool bundled with ffmpeg for analyzing media files.
  2. -v error: Suppresses all output except for errors.
  3. -select_streams v:0: Selects the first video stream (index 0).
  4. -show_entries stream=width,height: Extracts only the width and height information from the video stream.
  5. -of csv=p=0: Formats the output as plain CSV without any header or additional information.
  6. input.mp4: Replace this with the path to your MP4 file.

Example Output:

If the resolution of the video is 1920×1080, the output will be:

1920,1080

Alternative Command Using ffmpeg:

If you prefer using ffmpeg directly, you can use:

ffmpeg -i input.mp4 2&gt;&amp;1 | grep Video

This will output a line containing the video stream details, including the resolution. For example:

Stream #0:0: Video: h264 (High), yuv420p, 1920x1080, 30 fps, 30 tbr, 90k tbn, 180k tbc

Here, 1920x1080 is the resolution.

Notes:

  • ffprobe is preferred for precise, programmatic extraction of metadata.
  • If ffmpeg or ffprobe is not installed, you can install it via your package manager (e.g., apt, brew, or choco) or download it from the official FFmpeg website.

i have a mp4 file at 3840,2160 resolution. how can i re-encode it to 1080p using ffmpeg?

To re-encode a 3840×2160 resolution MP4 file to 1080p (1920×1080) using ffmpeg, you can use the following command:

ffmpeg -i input.mp4 -vf scale=1920:1080 -c:v libx264 -preset fast -crf 23 -c:a aac -b:a 128k output_1080p.mp4

Explanation of the Command:

  1. -i input.mp4: Specifies the input file.
  2. -vf scale=1920:1080: Applies a video filter (-vf) to scale the resolution to 1920×1080.
  3. -c:v libx264: Sets the video codec to H.264 for encoding.
  4. -preset fast: Specifies the encoding speed/quality trade-off. Other options include ultrafast, fast, medium (default), and slow.
  5. -crf 23: Sets the Constant Rate Factor (CRF) for quality. Lower values produce higher quality (and larger files), while higher values reduce quality (and file size). The range is typically 18–28, with 23 being a good default.
  6. -c:a aac: Specifies AAC audio codec for encoding audio.
  7. -b:a 128k: Sets the audio bitrate to 128 kbps.
  8. output_1080p.mp4: Specifies the name of the output file.

Optional Adjustments:

  • Keep the Aspect Ratio: If the original video doesn’t have a 16:9 aspect ratio, and you want to keep the aspect ratio, replace scale=1920:1080 with:

    -vf "scale=1920:-2"
    

    This ensures the height is adjusted automatically to maintain the original aspect ratio.

  • Hardware Acceleration: To speed up the process, use hardware encoders (if supported by your GPU), such as:

    • NVIDIA NVENC:
      -c:v h264_nvenc
      
    • Intel Quick Sync:
      -c:v h264_qsv
      
    • AMD VCE:
      -c:v h264_amf
      

Example with NVIDIA NVENC:

ffmpeg -i input.mp4 -vf scale=1920:1080 -c:v h264_nvenc -preset fast -b:v 5M -c:a aac -b:a 128k output_1080p.mp4

This will use NVIDIA’s NVENC hardware encoder, which is much faster than software encoding.

Verify Output:

After encoding, you can verify the resolution using:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 output_1080p.mp4

How to concatenate two videos?

this solution has worked for me on Windows:

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4

How to extract video from mp4

ffmpeg -i foo.mp4 -an -vcodec copy foo-video_only.mp4
This entry was posted in Computers and tagged . Bookmark the permalink.

Leave a comment