001/******************************************************************************* 002 * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved. 003 * 004 * This file is part of AVPKit. 005 * 006 * AVPKit is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Lesser General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * AVPKit is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with AVPKit. If not, see <http://www.gnu.org/licenses/>. 018 *******************************************************************************/ 019 020package com.avpkit.mediatool.demos; 021 022 023import com.avpkit.mediatool.IMediaReader; 024import com.avpkit.mediatool.IMediaViewer; 025import com.avpkit.mediatool.ToolFactory; 026 027/** 028 * Using {@link IMediaReader}, takes a media container, finds the first video 029 * stream, decodes that stream, and plays the video. 030 * 031 * @author aclarke 032 * @author trebor 033 */ 034 035public class DecodeAndPlayVideo 036{ 037 038 /** 039 * Takes a media container (file) as the first argument, opens it, opens up a 040 * Swing window and displays video frames with the right 041 * timing. 042 * 043 * @param args 044 * Must contain one string which represents a filename 045 */ 046 047 public static void main(String[] args) 048 { 049 if (args.length <= 0) 050 throw new IllegalArgumentException( 051 "must pass in a filename as the first argument"); 052 053 String filename = args[0]; 054 055 // create a new reader 056 057 IMediaReader reader = ToolFactory.makeReader(filename); 058 059 // 060 // Create a MediaViewer object and tell it to play video only 061 // 062 reader.addListener(ToolFactory.makeViewer(IMediaViewer.Mode.VIDEO_ONLY)); 063 064 // read out the contents of the media file, and sit back and watch 065 066 while (reader.readPacket() == null) 067 do {} while(false); 068 069 } 070}