Published on

Preview or Test Video or Audio File with FFmpeg

Authors
  • avatar
    Name
    Hieu Cao
    Twitter

Why Preview or Test Media Files?

Before performing operations like conversion, trimming, or merging, it’s often useful to preview or test media files to:

  • Verify File Integrity: Ensure files are not corrupted.
  • Analyze Metadata: Check properties like duration, codec, and resolution.
  • Save Time: Avoid unnecessary processing of incorrect files.

Previewing Video or Audio

You can quickly play a part of your media file to preview its content using FFmpeg’s -ss and -t options.

Play a Specific Segment

ffmpeg -ss 00:01:00 -i input.mp4 -t 10 -c copy preview.mp4
  • -ss 00:01:00: Start 1 minute into the video.
  • -i input.mp4: Specify the input file.
  • -t 10: Duration of 10 seconds.
  • -c copy: Copy streams without re-encoding for speed.

Play a Video Stream

To test playback of a video stream directly:

ffplay input.mp4

FFplay is a simple media player included with FFmpeg.


Testing File Properties

View Metadata

Check basic information like codec, resolution, and duration:

ffmpeg -i input.mp4

Analyze Detailed Metadata with FFprobe

FFprobe provides more detailed information about your media file:

ffprobe input.mp4

Sample output:

Duration: 00:03:15.12, start: 0.000000, bitrate: 192 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 1920x1080, 25 fps
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp

Checking Specific Streams

Video Stream

To view only video stream details:

ffprobe -select_streams v -show_streams input.mp4

Audio Stream

To view only audio stream details:

ffprobe -select_streams a -show_streams input.mp4

Best Practices for Testing Media Files

  1. Use FFprobe for Metadata: Get comprehensive details about your files.
  2. Preview Short Segments: Save time by only checking a small portion.
  3. Verify Integrity: Ensure streams are not corrupted before proceeding with editing or encoding.

Conclusion

Previewing and testing media files with FFmpeg ensures you work efficiently and avoid unnecessary processing. With simple commands like -ss, -t, and FFprobe, you can quickly analyze, verify, and play your media files before diving into more intensive tasks.