Add: metadata of pixel format

pull/209/head
xufulong 3 years ago
parent acff1caeaf
commit c9f7a1d058
  1. 1
      app/src/main/cpp/metadata/ffmpeg_media_retriever.c
  2. 21
      app/src/main/cpp/metadata/metadata_util.c
  3. 2
      app/src/main/cpp/metadata/metadata_util.h
  4. 4
      app/src/main/java/com/frank/ffmpeg/activity/ProbeFormatActivity.kt
  5. 10
      app/src/main/java/com/frank/ffmpeg/metadata/FFmpegMediaRetriever.java

@ -199,6 +199,7 @@ int set_data_source_inner(State **state_ptr, const char* path) {
set_file_size(state->pFormatCtx); set_file_size(state->pFormatCtx);
set_frame_rate(state->pFormatCtx, state->video_st); set_frame_rate(state->pFormatCtx, state->video_st);
set_sample_rate(state->pFormatCtx, state->audio_st); set_sample_rate(state->pFormatCtx, state->audio_st);
set_pixel_format(state->pFormatCtx, state->video_st);
set_channel_count(state->pFormatCtx, state->audio_st); set_channel_count(state->pFormatCtx, state->audio_st);
set_channel_layout(state->pFormatCtx, state->audio_st); set_channel_layout(state->pFormatCtx, state->audio_st);
set_video_resolution(state->pFormatCtx, state->video_st); set_video_resolution(state->pFormatCtx, state->video_st);

@ -6,9 +6,10 @@
#include "metadata_util.h" #include "metadata_util.h"
#include <stdio.h> #include <stdio.h>
#include "include/libavutil/pixdesc.h"
void set_duration(AVFormatContext *ic) { void set_duration(AVFormatContext *ic) {
char value[30] = "0"; char value[20] = "0";
long duration = 0; long duration = 0;
if (ic) { if (ic) {
@ -22,7 +23,7 @@ void set_duration(AVFormatContext *ic) {
} }
void set_file_size(AVFormatContext *ic) { void set_file_size(AVFormatContext *ic) {
char value[30] = "0"; char value[20] = "0";
int64_t size = ic->pb ? avio_size(ic->pb) : -1; int64_t size = ic->pb ? avio_size(ic->pb) : -1;
sprintf(value, "%"PRId64, size); sprintf(value, "%"PRId64, size);
@ -69,17 +70,23 @@ void set_channel_count(AVFormatContext *ic, AVStream *stream) {
} }
void set_channel_layout(AVFormatContext *ic, AVStream *stream) { void set_channel_layout(AVFormatContext *ic, AVStream *stream) {
char value[10] = "0"; char value[20] = "0";
if (stream) { if (stream) {
av_get_channel_layout_string(value, 10, av_get_channel_layout_string(value, 20,
stream->codecpar->channels, stream->codecpar->channel_layout); stream->codecpar->channels, stream->codecpar->channel_layout);
av_dict_set(&ic->metadata, CHANNEL_LAYOUT, value, 0); av_dict_set(&ic->metadata, CHANNEL_LAYOUT, value, 0);
} }
} }
void set_video_resolution(AVFormatContext *ic, AVStream *video_st) { void set_pixel_format(AVFormatContext *ic, AVStream *stream) {
char value[30] = "0"; if (stream) {
const char *name = av_get_pix_fmt_name(stream->codecpar->format);
av_dict_set(&ic->metadata, PIXEL_FORMAT, name, 0);
}
}
void set_video_resolution(AVFormatContext *ic, AVStream *video_st) {
char value[20] = "0";
if (video_st) { if (video_st) {
sprintf(value, "%d", video_st->codecpar->width); sprintf(value, "%d", video_st->codecpar->width);
av_dict_set(&ic->metadata, VIDEO_WIDTH, value, 0); av_dict_set(&ic->metadata, VIDEO_WIDTH, value, 0);
@ -102,7 +109,7 @@ void set_rotation(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st) {
} }
void set_frame_rate(AVFormatContext *ic, AVStream *video_st) { void set_frame_rate(AVFormatContext *ic, AVStream *video_st) {
char value[30] = "0"; char value[20] = "0";
if (video_st && video_st->avg_frame_rate.den && video_st->avg_frame_rate.num) { if (video_st && video_st->avg_frame_rate.den && video_st->avg_frame_rate.num) {
double d = av_q2d(video_st->avg_frame_rate); double d = av_q2d(video_st->avg_frame_rate);

@ -23,6 +23,7 @@ static const char *MIME_TYPE = "mime_type";
static const char *SAMPLE_RATE = "sample_rate"; static const char *SAMPLE_RATE = "sample_rate";
static const char *CHANNEL_COUNT = "channel_count"; static const char *CHANNEL_COUNT = "channel_count";
static const char *CHANNEL_LAYOUT = "channel_layout"; static const char *CHANNEL_LAYOUT = "channel_layout";
static const char *PIXEL_FORMAT = "pixel_format";
static const int SUCCESS = 0; static const int SUCCESS = 0;
static const int FAILURE = -1; static const int FAILURE = -1;
@ -34,6 +35,7 @@ void set_codec(AVFormatContext *ic, int i);
void set_sample_rate(AVFormatContext *ic, AVStream *stream); void set_sample_rate(AVFormatContext *ic, AVStream *stream);
void set_channel_count(AVFormatContext *ic, AVStream *stream); void set_channel_count(AVFormatContext *ic, AVStream *stream);
void set_channel_layout(AVFormatContext *ic, AVStream *stream); void set_channel_layout(AVFormatContext *ic, AVStream *stream);
void set_pixel_format(AVFormatContext *ic, AVStream *stream);
void set_video_resolution(AVFormatContext *ic, AVStream *video_st); void set_video_resolution(AVFormatContext *ic, AVStream *video_st);
void set_rotation(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st); void set_rotation(AVFormatContext *ic, AVStream *audio_st, AVStream *video_st);
void set_frame_rate(AVFormatContext *ic, AVStream *video_st); void set_frame_rate(AVFormatContext *ic, AVStream *video_st);

@ -177,6 +177,10 @@ class ProbeFormatActivity : BaseActivity() {
if (channelLayout != null) if (channelLayout != null)
resultBuilder.append("channelLayout:$channelLayout\n") resultBuilder.append("channelLayout:$channelLayout\n")
val pixelFormat = retriever.extractMetadata(FFmpegMediaRetriever.METADATA_KEY_PIXEL_FORMAT)
if (pixelFormat != null)
resultBuilder.append("pixelFormat:$pixelFormat\n")
mHandler.obtainMessage(MSG_INFO, resultBuilder.toString()).sendToTarget() mHandler.obtainMessage(MSG_INFO, resultBuilder.toString()).sendToTarget()
// Retrieve frame with timeUs // Retrieve frame with timeUs

@ -313,16 +313,20 @@ public class FFmpegMediaRetriever {
*/ */
public static String METADATA_KEY_MIME_TYPE = "mime_type"; public static String METADATA_KEY_MIME_TYPE = "mime_type";
/** /**
* The metadata key to retrieve the mime type. * The metadata key to retrieve sample rate.
*/ */
public static String METADATA_KEY_SAMPLE_RATE = "sample_rate"; public static String METADATA_KEY_SAMPLE_RATE = "sample_rate";
/** /**
* The metadata key to retrieve the mime type. * The metadata key to retrieve channel count.
*/ */
public static String METADATA_KEY_CHANNEL_COUNT = "channel_count"; public static String METADATA_KEY_CHANNEL_COUNT = "channel_count";
/** /**
* The metadata key to retrieve the mime type. * The metadata key to retrieve channel layout.
*/ */
public static String METADATA_KEY_CHANNEL_LAYOUT = "channel_layout"; public static String METADATA_KEY_CHANNEL_LAYOUT = "channel_layout";
/**
* The metadata key to retrieve pixel format.
*/
public static String METADATA_KEY_PIXEL_FORMAT = "pixel_format";
} }

Loading…
Cancel
Save