カバーアートをmp3やoggファイルで読み書きするのにTagLibを使用したいと思いますが、例は見つかりませんでした。誰かが私にいくつかの例を教えてもらえますか?これについての詳細はどこで調べるべきですか?TagLibを使ってカバーアートをさまざまなオーディオ形式で読み書きするにはどうすればよいですか?
8
A
答えて
6
私はmp3ファイルで動作するようになった。あなたがoggのためにそれを適用できるかどうかを確認してください
幸運。
PS ::このタグ付けは、はるかに難しいです。別のlibを探す必要があります。
/*********************************************************************************************************************************
*Description: A simple program using taglib to extract pictures attached to mp3 id3v2 tags
*Author: Dr Deo [at] stackoverflow *dot* com
*AOB: I hope you will find this useful and are free to use it for anything, but there is no waranty and use at your own risk :)
*********************************************************************************************************************************
*/
#include<iostream>
#include<stdio.h>
/*taglib specific includes*/
#include<tbytevector.h>//ByteVector
#include<mpegfile.h>//mp3 file
#include<id3v2tag.h>//tag
#include<id3v2frame.h>//frame
#include <attachedPictureFrame.h>//attachedPictureFrame
using namespace std ;
using namespace TagLib::ID3v2 ;
int main(int argc, char * argv[])
{
if(argc !=2)
{
cout<<"usage: drag an mp3 file on to the program and it will extract the attached image"<<endl<<endl;
system("pause");//on linux you can replace this with cin.get()
exit(1);
}
TagLib::MPEG::File mp3File(argv[1]);
Tag * mp3Tag;
FrameList listOfMp3Frames;
AttachedPictureFrame * pictureFrame;
mp3Tag= mp3File.ID3v2Tag();
if(mp3Tag)
{
listOfMp3Frames = mp3Tag->frameListMap()["APIC"];//look for picture frames only
if(!listOfMp3Frames.isEmpty())
{
FrameList::ConstIterator it= listOfMp3Frames.begin();
for(; it != listOfMp3Frames.end() ; it++)
{
pictureFrame = static_cast<AttachedPictureFrame *> (*it);//cast Frame * to AttachedPictureFrame*
//Warning. format of picture assumed to be jpg. This may be false, for example it may be png.
FILE * fout;
fopen_s(&fout, "outputFile.jpg", "wb");
cout<<"processing the file "<< argv[1] <<endl<<endl;
fwrite(pictureFrame->picture().data(), pictureFrame->picture().size(), 1, fout);
fclose(fout);
cout<<" The picture has been written to \t outputFile.jpg \nRemember that the file type .jpg is just assumed for simplicity"<<endl<<endl;
}
}
else cerr<<"there seem to be no picture frames (APIC) frames in this file"<<endl<<endl;
}
else cerr<<"the file "<<argv[1]<<"does not appear to have any mp3 tags"<<endl<<endl;
system("pause");//on linux you can replace this with cin.get()
return 0;
}
3
Ogg Vorbisタグはテキストのみです(したがってカバーアートはサポートしていません)。 MP3の場合、これは他のソリューションよりもややクリーンです:
using namespace TagLib;
struct Image
{
Image(const String &m = String(), const ByteVector &d = ByteVector()) :
mimeType(m), data(d) {}
String mimeType;
ByteVector data;
};
static Image getImage(const ID3v2::Tag *tag)
{
ID3v2::FrameList frames = tag->frameList("APIC");
if(frames.isEmpty())
{
return Image();
}
ID3v2::AttachedPictureFrame *frame =
static_cast<ID3v2::AttachedPictureFrame *>(frames.front());
return Image(frame->mimeType(), frame->picture());
}
static void setImage(ID3v2::Tag *tag, const Image &image)
{
ID3v2::FrameList frames = tag->frameList("APIC");
ID3v2::AttachedPictureFrame *frame = 0;
if(frames.isEmpty())
{
frame = new TagLib::ID3v2::AttachedPictureFrame;
tag->addFrame(frame);
}
else
{
frame = static_cast<ID3v2::AttachedPictureFrame *>(frames.front());
}
frame->setPicture(image.data);
frame->setMimeType(image.mimeType);
}
9
ここはmp3とm4aのバージョンです。
#include <mpegfile.h>
#include <attachedpictureframe.h>
#include <id3v2tag.h>
#include <mp4file.h>
#include <mp4tag.h>
#include <mp4coverart.h>
#include <iostream>
class ImageFile : public TagLib::File
{
public:
ImageFile(const char *file) : TagLib::File(file)
{
}
TagLib::ByteVector data()
{
return readBlock(length());
}
private:
virtual TagLib::Tag *tag() const { return 0; }
virtual TagLib::AudioProperties *audioProperties() const { return 0; }
virtual bool save() { return false; }
};
int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cout << "Usage: setcover <mp3|m4a> cover.jpg" << std::endl;
return 1;
}
TagLib::String fileName = argv[1];
TagLib::String fileType = fileName.substr(fileName.size() - 3).upper();
ImageFile imageFile(argv[2]);
if (fileType == "M4A")
{
// read the image file
TagLib::MP4::CoverArt coverArt((TagLib::MP4::CoverArt::Format) 0x0D, imageFile.data());
// read the mp4 file
TagLib::MP4::File audioFile(argv[1]);
// get the tag ptr
TagLib::MP4::Tag *tag = audioFile.tag();
// get the items map
TagLib::MP4::ItemListMap itemsListMap = tag->itemListMap();
// create cover art list
TagLib::MP4::CoverArtList coverArtList;
// append instance
coverArtList.append(coverArt);
// convert to item
TagLib::MP4::Item coverItem(coverArtList);
// add item to map
itemsListMap.insert("covr", coverItem);
tag->save();
//audioFile.save();
}
else if (fileType == "MP3")
{
TagLib::MPEG::File audioFile(argv[1]);
TagLib::ID3v2::Tag *tag = audioFile.ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
frame->setMimeType("image/jpeg");
frame->setPicture(imageFile.data());
tag->addFrame(frame);
audioFile.save();
}
else
{
std::cout << fileType << " is unsupported." << std::endl;
}
}
2
ここには、Oggを含む完全なソリューションがあります。非公式なやり方は、ファイルをbase64でエンコードしてメタデータに埋め込むことでした。現在、FLACピクチャブロック(画像データまたはfile:// URLを含む可能性があります)をbase64エンコードする方法が提案されています(より良い方法)。
関連する問題
- 1. さまざまなビデオファイル形式からメタデータを抽出するにはどうすればよいですか?
- 2. Delphiでは、通貨データタイプをさまざまな通貨でさまざまな形式で表示するにはどうすればよいですか?
- 3. さまざまなテーマを使ってタブレットアプリケーションを作成するにはどうすればよいですか?
- 4. Javaでさまざまな図形を描画するにはどうすればよいですか?私はどのライブラリを使うべきですか?
- 5. C#でOpenXML形式SDKを使用している形式の単語からデータを読み取るにはどうすればよいですか?
- 6. Javaで書式付き入力を読み取るにはどうすればよいですか?
- 7. iPhone AudioServicesCreateSystemSoundIDはどのようなオーディオ形式をサポートしていますか?
- 8. Djangoで日付を書式設定するときにローカライズされた「短い形式」を使用するにはどうすればよいですか?
- 9. javascriptを使用してテキストファイルを読み書きするにはどうすればよいですか?
- 10. さまざまな.variablesでddplyを使用するにはどうすればよいですか?
- 11. 再生フレームワークを使って読み込みページを書くにはどうすればいいですか?
- 12. さまざまな読み取りおよび書き込みdbサーバーでEFを使用する
- 13. さまざまなGoogle Maps APIを使用するにはどうすればよいですか?
- 14. wpfドキュメントビューアでさまざまなファイル形式を表示できますか?
- 15. ユーザーの希望日+時間形式を読み取るにはどうすればよいですか?
- 16. pythonパッケージ(PyXLL)を.zipファイル(さまざまなファイル形式を含む)で囲んで正しくインストールするにはどうすればいいですか?
- 17. さまざまな形式の文字列をintのリストに変換するにはどうすればよいですか? (パイソン)
- 18. iOSアプリをさまざまな言語のFlashでローカライズするにはどうすればよいですか?
- 19. さまざまなリソースファイルで共通のViewModelを作成するにはどうすればよいですか?
- 20. バックボーンアプリでさまざまなURLを指定するにはどうすればよいですか?
- 21. Excel VBAでさまざまなオプションのシートを保護するにはどうすればよいですか?
- 22. CMSでさまざまな数のカスタムフィールドを実装するにはどうすればよいですか?
- 23. ZedGraphヒストグラムでさまざまな色を設定するにはどうすればよいですか?
- 24. フォームビルダークラスでさまざまなメソッドを作成するにはどうすればよいですか?
- 25. C#でxml形式のキーペアをPEM形式に変更するにはどうすればよいですか?
- 26. HTML5オーディオ要素が読み込まれているかどうかを確認するにはどうすればよいですか?
- 27. Cassandraの読み取り/書き込みパフォーマンスを改善するにはどうすればよいですか?
- 28. Androidでさまざまな色のコードを割り当てるにはどうすればいいですか?
- 29. rabbitmqにさまざまなデータを送信するにはどうすればよいですか?
- 30. このコードをさまざまなウィンドウサイズに拡大するにはどうすればよいですか?
ウィキペディアは、その可能性が高い以下のコードのみmp3のために働くように、mp3とoggのは、異なるタグフォーマットを持っていることを言います。この記事を参照してくださいhttp://en.wikipedia.org/wiki/ID3 –