Add: sample_rate channel_count channel_layout

pull/209/head
xufulong 3 years ago
parent 6ba160954a
commit b235608263
  1. 11
      app/src/main/cpp/metadata/ffmpeg_media_retriever.c
  2. 34
      app/src/main/cpp/metadata/metadata_util.c
  3. 14
      app/src/main/cpp/metadata/metadata_util.h
  4. 40
      app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java

@ -153,7 +153,6 @@ int set_data_source_l(State **ps, const char* path) {
State *state = *ps;
AVDictionary *options = NULL;
av_dict_set(&options, "icy", "1", 0);
av_dict_set(&options, "user-agent", "FFmpegMetadataRetriever", 0);
state->pFormatCtx = avformat_alloc_context();
@ -174,8 +173,6 @@ int set_data_source_l(State **ps, const char* path) {
return FAILURE;
}
set_duration(state->pFormatCtx);
// Find the first audio and video stream
for (i = 0; i < state->pFormatCtx->nb_streams; i++) {
if (state->pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_index < 0) {
@ -197,11 +194,15 @@ int set_data_source_l(State **ps, const char* path) {
stream_component_open(state, video_index);
}
set_duration(state->pFormatCtx);
set_mimetype(state->pFormatCtx);
set_filesize(state->pFormatCtx);
set_file_size(state->pFormatCtx);
set_frame_rate(state->pFormatCtx, state->video_st);
set_sample_rate(state->pFormatCtx, state->audio_st);
set_channel_count(state->pFormatCtx, state->audio_st);
set_channel_layout(state->pFormatCtx, state->audio_st);
set_video_resolution(state->pFormatCtx, state->video_st);
set_rotation(state->pFormatCtx, state->audio_st, state->video_st);
set_framerate(state->pFormatCtx, state->audio_st, state->video_st);
*ps = state;
return SUCCESS;

@ -21,12 +21,12 @@ void set_duration(AVFormatContext *ic) {
av_dict_set(&ic->metadata, DURATION, value, 0);
}
void set_filesize(AVFormatContext *ic) {
void set_file_size(AVFormatContext *ic) {
char value[30] = "0";
int64_t size = ic->pb ? avio_size(ic->pb) : -1;
sprintf(value, "%"PRId64, size);
av_dict_set(&ic->metadata, FILESIZE, value, 0);
av_dict_set(&ic->metadata, FILE_SIZE, value, 0);
}
void set_mimetype(AVFormatContext *ic) {
@ -39,7 +39,6 @@ void set_mimetype(AVFormatContext *ic) {
void set_codec(AVFormatContext *ic, int i) {
const char *codec_type = av_get_media_type_string(ic->streams[i]->codecpar->codec_type);
if (!codec_type) {
return;
}
@ -53,6 +52,31 @@ void set_codec(AVFormatContext *ic, int i) {
}
}
void set_sample_rate(AVFormatContext *ic, AVStream *stream) {
char value[10] = "0";
if (stream) {
sprintf(value, "%d", stream->codecpar->sample_rate);
av_dict_set(&ic->metadata, SAMPLE_RATE, value, 0);
}
}
void set_channel_count(AVFormatContext *ic, AVStream *stream) {
char value[10] = "0";
if (stream) {
sprintf(value, "%d", stream->codecpar->channels);
av_dict_set(&ic->metadata, CHANNEL_COUNT, value, 0);
}
}
void set_channel_layout(AVFormatContext *ic, AVStream *stream) {
char value[10] = "0";
if (stream) {
av_get_channel_layout_string(value, 10,
stream->codecpar->channels, stream->codecpar->channel_layout);
av_dict_set(&ic->metadata, CHANNEL_LAYOUT, value, 0);
}
}
void set_video_resolution(AVFormatContext *ic, AVStream *video_st) {
char value[30] = "0";
@ -86,7 +110,7 @@ void set_rotation(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st) {
}
}
void set_framerate(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st) {
void set_frame_rate(AVFormatContext *ic, AVStream *video_st) {
char value[30] = "0";
if (video_st && video_st->avg_frame_rate.den && video_st->avg_frame_rate.num) {
@ -100,7 +124,7 @@ void set_framerate(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st)
sprintf(value, "%1.0fk", d / 1000);
}
av_dict_set(&ic->metadata, FRAMERATE, value, 0);
av_dict_set(&ic->metadata, FRAME_RATE, value, 0);
}
}

@ -15,23 +15,29 @@ static const char *DURATION = "duration";
static const char *AUDIO_CODEC = "audio_codec";
static const char *VIDEO_CODEC = "video_codec";
static const char *ROTATE = "rotate";
static const char *FRAMERATE = "framerate";
static const char *FILESIZE = "filesize";
static const char *FRAME_RATE = "frame_rate";
static const char *FILE_SIZE = "file_size";
static const char *VIDEO_WIDTH = "video_width";
static const char *VIDEO_HEIGHT = "video_height";
static const char *MIME_TYPE = "mime_type";
static const char *SAMPLE_RATE = "sample_rate";
static const char *CHANNEL_COUNT = "channel_count";
static const char *CHANNEL_LAYOUT = "channel_layout";
static const int SUCCESS = 0;
static const int FAILURE = -1;
void set_duration(AVFormatContext *ic);
void set_filesize(AVFormatContext *ic);
void set_file_size(AVFormatContext *ic);
void set_mimetype(AVFormatContext *ic);
void set_codec(AVFormatContext *ic, int i);
void set_sample_rate(AVFormatContext *ic, AVStream *stream);
void set_channel_count(AVFormatContext *ic, AVStream *stream);
void set_channel_layout(AVFormatContext *ic, AVStream *stream);
void set_video_resolution(AVFormatContext *ic, AVStream *video_st);
int get_metadata_internal(AVFormatContext *ic, AVDictionary **metadata);
void set_rotation(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st);
void set_framerate(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st);
void set_frame_rate(AVFormatContext *ic, AVStream *video_st);
const char* extract_metadata_internal(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st, const char* key);
#endif /*METADATA_UTIL_H_*/

@ -264,48 +264,42 @@ public class FFmpegMediaRetriever {
*/
public static String METADATA_KEY_FILENAME = "filename";
/**
* The metadata key to retrieve the main language in which the work is performed, preferably
* in ISO 639-2 format. Multiple languages can be specified by separating them with commas.
* The metadata key to retrieve the main language.
*/
public static String METADATA_KEY_LANGUAGE = "language";
/**
* The metadata key to retrieve the name of the work.
* The metadata key to retrieve the name.
*/
public static String METADATA_KEY_TITLE = "title";
/**
* The metadata key to retrieve the number of this work in the set, can be in form current/total.
* The metadata key to retrieve the general bitrate.
*/
public static String METADATA_KEY_TRACK = "track";
public static String METADATA_KEY__BITRATE = "bitrate";
/**
* The metadata key to retrieve the total bitrate of the bitrate variant that the current stream
* is part of.
*/
public static String METADATA_KEY_VARIANT_BITRATE = "bitrate";
/**
* The metadata key to retrieve the duration of the work in milliseconds.
* The metadata key to retrieve the duration in milliseconds.
*/
public static String METADATA_KEY_DURATION = "duration";
/**
* The metadata key to retrieve the audio codec of the work.
* The metadata key to retrieve the audio codec.
*/
public static String METADATA_KEY_AUDIO_CODEC = "audio_codec";
/**
* The metadata key to retrieve the video codec of the work.
* The metadata key to retrieve the video codec.
*/
public static String METADATA_KEY_VIDEO_CODEC = "video_codec";
/**
* This key retrieves the video rotation angle in degrees, if available.
* This key retrieves the video degree of rotation.
* The video rotation angle may be 0, 90, 180, or 270 degrees.
*/
public static String METADATA_KEY_VIDEO_ROTATION = "rotate";
/**
* This metadata key retrieves the average framerate (in frames/sec).
* This metadata key retrieves the average frame rate (in frames/sec).
*/
public static String METADATA_KEY_FRAMERATE = "framerate";
public static String METADATA_KEY_FRAME_RATE = "frame_rate";
/**
* The metadata key to retrieve the file size in bytes.
*/
public static String METADATA_KEY_FILESIZE = "filesize";
public static String METADATA_KEY_FILE_SIZE = "file_size";
/**
* The metadata key to retrieve the video width.
*/
@ -318,5 +312,17 @@ public class FFmpegMediaRetriever {
* The metadata key to retrieve the mime type.
*/
public static String METADATA_KEY_MIME_TYPE = "mime_type";
/**
* The metadata key to retrieve the mime type.
*/
public static String METADATA_KEY_SAMPLE_RATE = "sample_rate";
/**
* The metadata key to retrieve the mime type.
*/
public static String METADATA_KEY_CHANNEL_COUNT = "channel_count";
/**
* The metadata key to retrieve the mime type.
*/
public static String METADATA_KEY_CHANNEL_LAYOUT = "channel_layout";
}

Loading…
Cancel
Save