Я разрабатываю приложение для Android, которое использует FFmpeg для получения метаданных аудио. Я знаю, что можно программно получить обложку альбома с помощью FFMpeg. Однако после декодирования изображения (видеокадра в формате MP3) как сгенерировать файл изображения (PNG) для использования в приложении? Я обыскал все, но не нашел работающего примера.
#include
#include
void retrieve_album_art(const char *path, const char *album_art_file) {
int i, ret = 0;
if (!path) {
printf("Path is NULL\n");
return;
}
AVFormatContext *pFormatCtx = avformat_alloc_context();
printf("Opening %s\n", path);
// open the specified path
if (avformat_open_input(&pFormatCtx, path, NULL, NULL) != 0) {
printf("avformat_open_input() failed");
goto fail;
}
// read the format headers
if (pFormatCtx->iformat->read_header(pFormatCtx) < 0) {
printf("could not read the format header\n");
goto fail;
}
// find the first attached picture, if available
for (i = 0; i < pFormatCtx->nb_streams; i++)
if (pFormatCtx->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) {
AVPacket pkt = pFormatCtx->streams[i]->attached_pic;
FILE* album_art = fopen(album_art_file, "wb");
ret = fwrite(pkt.data, pkt.size, 1, album_art);
fclose(album_art);
av_free_packet(&pkt);
break;
}
if (ret) {
printf("Wrote album art to %s\n", album_art_file);
}
fail:
av_free(pFormatCtx);
// this line crashes for some reason...
//avformat_free_context(pFormatCtx);
}
int main() {
avformat_network_init();
av_register_all();
const char *path = "some url";
const char *album_art_file = "some path";
retrieve_album_art(path, album_art_file);
return 0;
}
Я разрабатываю приложение для Android, которое использует FFmpeg для получения метаданных аудио. Я знаю, что можно программно получить обложку альбома с помощью FFMpeg. Однако после декодирования изображения (видеокадра в формате MP3) как сгенерировать файл изображения (PNG) для использования в приложении? Я обыскал все, но не нашел работающего примера.
Изменить, вот решение:
[code]#include #include
void retrieve_album_art(const char *path, const char *album_art_file) { int i, ret = 0;
// open the specified path if (avformat_open_input(&pFormatCtx, path, NULL, NULL) != 0) { printf("avformat_open_input() failed"); goto fail; }
// read the format headers if (pFormatCtx->iformat->read_header(pFormatCtx) < 0) { printf("could not read the format header\n"); goto fail; }
// find the first attached picture, if available for (i = 0; i < pFormatCtx->nb_streams; i++) if (pFormatCtx->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { AVPacket pkt = pFormatCtx->streams[i]->attached_pic; FILE* album_art = fopen(album_art_file, "wb"); ret = fwrite(pkt.data, pkt.size, 1, album_art); fclose(album_art); av_free_packet(&pkt); break; }
if (ret) { printf("Wrote album art to %s\n", album_art_file); }
fail: av_free(pFormatCtx); // this line crashes for some reason... //avformat_free_context(pFormatCtx); }
int main() { avformat_network_init(); av_register_all();
Я пытался сделать повторную выборку с FFMPEG, но я все время обнаруживал проблемы в своем коде. /> Поэтому я поместил код повторной выборки вручную, потому что я знаю, что стерео. av_opt_set_sample_fmt(swr_ctx, in_sample_fmt , codec_ctx->sample_fmt,...
Я не могу получить изображение обложки видеоигры из моего html-документа, которое будет отображаться при отображении названия игры с помощью моей функции javascript. Я не уверен, что делать, и не смог найти ничего похожего на мою проблему при поиске...
У меня есть файл MP3, и когда я читаю его с помощью Windows Media Player, у него есть обложка альбома, поэтому мне интересно, есть ли способ получить эту обложку в JavaScript или jQuery