我正在尝试像FFMPEG Metadata Wrapper一样使用Xuggler(我只需要MP4 / M4V视频章节列表)。
到目前为止,我还没有找到解决方案。 任何人都可以帮助我吗?
我只能得到以下信息:
final String filename = "...path...";
IContainer container = IContainer.make();
int result = container.open(filename, IContainer.Type.READ, null);
if (result < 0)
throw new RuntimeException("Failed to open media file");
int numStreams = container.getNumStreams();
long duration = container.getDuration();
long fileSize = container.getFileSize();
long bitRate = container.getBitRate();
System.out.println("Number of streams: " + numStreams);
System.out.println("Duration (ms): " + duration);
System.out.println("File Size (bytes): " + fileSize);
System.out.println("Bit Rate: " + bitRate);
for (int i = 0; i < numStreams; i++) {
IStream stream = container.getStream(i);
IStreamCoder coder = stream.getStreamCoder();
System.out.println("*** Start of Stream Info ***");
System.out.printf("stream %d: ", i);
System.out.printf("type: %s; ", coder.getCodecType());
System.out.printf("codec: %s; ", coder.getCodecID());
System.out.printf("duration: %s; ", stream.getDuration());
System.out.printf("start time: %s; ", container.getStartTime());
System.out.printf("timebase: %d/%d; ", stream.getTimeBase().getNumerator(),
stream.getTimeBase().getDenominator());
System.out.printf("coder tb: %d/%d; ", coder.getTimeBase().getNumerator(),
coder.getTimeBase().getDenominator());
System.out.println();
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
System.out.printf("sample rate: %d; ", coder.getSampleRate());
System.out.printf("channels: %d; ", coder.getChannels());
System.out.printf("format: %s", coder.getSampleFormat());
} else if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
System.out.printf("width: %d; ", coder.getWidth());
System.out.printf("height: %d; ", coder.getHeight());
System.out.printf("format: %s; ", coder.getPixelType());
System.out.printf("frame-rate: %5.2f; ", coder.getFrameRate().getDouble());
}
System.out.println();
System.out.println("*** End of Stream Info ***");
更新07.06.2017 我只是用VLCJ尝试过,但我仍然无法获得章节列表。
File file = new File("ia_ISL_13_r720P.m4v");
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "vlc64/");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
MediaPlayerFactory mpf = new MediaPlayerFactory();
EmbeddedMediaPlayer emp = mpf.newEmbeddedMediaPlayer();
MediaMeta mediaMeta = mpf.getMediaMeta(file.getAbsolutePath(), true);
MediaMetaData asMediaMetaData = mediaMeta.asMediaMetaData();
System.out.println(asMediaMetaData.getAlbum());
System.out.println(asMediaMetaData.getArtist());
System.out.println(asMediaMetaData.getTitle());
emp.prepareMedia(file.getAbsolutePath());
emp.play();
emp.nextChapter(); // -> GO NEXT CHAPTER - SUCCESS
List<List<String>> allChapterDescriptions = emp.getAllChapterDescriptions();
for (List<String> list : allChapterDescriptions) {
for (String string : list) {
System.out.println(string);
}
}
答案 0 :(得分:0)
我在C#项目中使用它我觉得与你正在做的类似,非常相似...... 这里有一个带有mp4和m4v章节的列表框,旧的mp4和m4v文件接缝工作正常,但我遇到了新的问题(2014 - &gt;)
using Mp4Chapters;
// more code here...
private void readChapters(string inputFull)
{
using (var str = File.OpenRead(this.inputFull))
{
var extractor = new ChapterExtractor(new StreamWrapper(str));
extractor.Run();
// build the listbox
foreach (var c in extractor.Chapters ?? new ChapterInfo[0])
{
this.lb_chapters.Items.Add(new { chapterTime = c.Time, chapterName = c.Name });
}
}
}
其他选项是使用ffmpeg解析视频文件并读取结果:
ffmpeg -i ia_ISL_13_r720P.m4v -f ffmetadata metadata.txt
我希望这有帮助,让我知道。 (对不起英语,不是我的主要语言)