Hi Charlie,
I implemented the following class based on your sample code for creating snapshots (with necessary modifications to call this from another java class method):
public class WMSSnapshotCreator extends ModuleBase {
Object lock = new Object();
public void createSnapshotLive(IApplicationInstance appInstance, String streamName) {
getLogger().info("********** WMSSnapshotCreator::createSnapshotLive(): Stream Name: " + streamName + " **********");
String fileName = “”;
MediaStreamMap streams = appInstance.getStreams();
IMediaStream stream = streams.getStream(streamName);
if(stream != null) {
AMFPacket packet = stream.getLastKeyFrame();
if (packet != null) {
fileName = streamName + “_” + packet.getAbsTimecode() + “.flv”;
//getLogger().info("********** WMSSnapshotCreator::createSnapshotLive(): fileName: " + fileName + " **********");
File newFile = stream.getStreamFileForWrite();
String filePath = newFile.getPath().substring(0, newFile.getPath().length() - 4) + “_” + packet.getAbsTimecode() + “.flv”;
//getLogger().info("********** WMSSnapshotCreator::createSnapshotLive(): FLV Thumbnail File Path: " + filePath + " **********");
//get the flv thumbnail file name alone from the file path
int fileNameIndex = 0 ;
//get the index of last occurence of ‘’ in the file path
fileNameIndex = filePath.lastIndexOf(’\’) ;
String flvFileName = “” ;
if(fileNameIndex != -1) {
flvFileName = filePath.substring(fileNameIndex + 1) ;
} else {
flvFileName = null ;
}
getLogger().info("********** WMSSnapshotCreator::createSnapshotLive(): FLV Thumbnail File Name: " + flvFileName + " **********");
try {
synchronized(lock) {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filePath), false));
FLVUtils.writeHeader(out, 0, null);
FLVUtils.writeChunk(out, packet.getDataBuffer(), packet.getSize(), 0, (byte)packet.getType());
out.close();
}
getLogger().info("********** WMSSnapshotCreator::createSnapshotLive(): Snapshot Created Successfully **********");
} catch (Exception e) {
getLogger().error("********** WMSSnapshotCreator::createSnapshotLive(): Error Creating Snapshot !!!" + e.toString() + " **********");
}
}
} else {
getLogger().error("********** WMSSnapshotCreator::createSnapshotLive(): Error Creating Snapshot - NULL Stream !!!" + " **********");
}
}
} //End of WMSSnapshotCreator
I am calling createSnapshotLive() using the following code:
WMSSnapshotCreator creator = new WMSSnapshotCreator() ;
creator.createSnapshotLive(appInstance, streamName) ;
with proper values for appInstance and streamName.
Behavior noticed:
An .flv file with a single frame gets created (with a size of about 3 KB) as expected.
NOTE:
My streamtype is ‘rtp-live-record’ and the codecs I am using are H.264 and AAC.
A bigger .flv file gets created with the audio / video data as expected and it can be played out in VLC.
Requirement and Issues:
I need to convert the .flv thumbnail to .jpg thumbnail now. For this, I tried using the FFmpeg binaries as suggested in some Wowza posts. But when I do this with the single frame .flv file, I am getting the following error in command prompt:
Command:
ffmpeg -i mob1@nist.gov_mob2@nist.gov_3739073223_20090304_145240_1236158594066.flv -vframes 1 -an -f rawvideo -s 160x120 -y mob1@nist.gov_mob2@nist.gov_3739073223_20090304_145240_1236158594066.jpg
Logs:
FFmpeg version SVN-r15815, Copyright © 2000-2008 Fabrice Bellard, et al.
configuration: --enable-memalign-hack --enable-postproc --enable-swscale --ena
ble-gpl --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame –
enable-libvorbis --enable-libtheora --enable-libx264 --enable-libxvid --disable-
ffserver --disable-vhook --enable-avisynth --enable-pthreads
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 3. 0 / 52. 3. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 6. 1 / 0. 6. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Nov 13 2008 10:28:29, gcc: 4.2.4 (TDM-1 for MinGW)
[h264 @ 0x28a7f0]no frame!
[flv @ 0x289660]Could not find codec parameters (Video: h264, yuv420p)
[flv @ 0x289660]Could not find codec parameters (Audio: 0x0000, 0 channels, s16)
mob1@nist.gov_mob2@nist.gov_3739073223_20090304_145240_1236158594066.flv: could not find codec parameters
Can you please let me know why I am getting such an error from FFmpeg? Am I doing anything wrong?
Regards,
Senthil