2017-05-05 29 views
0

エンコードされたドメインでビデオを読み込み、フレームのサイズや期間などの情報を取得できるコードを作成しました。 AVPacketクラスは変数としてデータで構成されます。私はそれを読むことができますが、それはバイト配列なので、私はそれを読みやすい形式で使うことはできません。このデータを別のビデオファイルとの比較に使用したいと思います。助けてください。FFMPEGを使用して、エンコードされたビデオからAVPacketの重要な情報を抽出する方法

void CFfmpegmethods::VideoRead(){ 
av_register_all(); 
avformat_network_init(); 
ofstream outdata; 
const char *url = "H:\\Sanduni_projects\\Sample_video.mp4"; 
AVDictionary *options = NULL; 
AVFormatContext *s = avformat_alloc_context(); //NULL; 

AVPacket *pkt = new AVPacket(); 

//open an input stream and read the header 
int ret = avformat_open_input(&s, url, NULL, NULL); 

//avformat_find_stream_info(s, &options); //finding the missing information 

if (ret < 0) 
    abort(); 

av_dict_set(&options, "video_size", "640x480", 0); 
av_dict_set(&options, "pixel_format", "rgb24", 0); 

if (avformat_open_input(&s, url, NULL, &options) < 0){ 
    abort(); 
} 

av_dict_free(&options); 

AVDictionaryEntry *e; 

if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) { 
    fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key); 
    abort(); 
} 

int i = 1; 
int j = 0; 
int64_t duration = 0; 
int size = 0; 
uint8_t *data = 0; //Unsigned integer type with a width of exactly 8 bits. 
int sum = 0; 

int total_size = 0; 
int total_duration = 0; 
int packet_size = 0; 
int64_t stream_index = 0; 
int64_t bit_rate = 0; 

//writing data to a file 
outdata.open("H:\\Sanduni_projects\\log.txt"); 

if (!outdata){ 
    cerr << "Error: file could not be opened" << endl; 
    exit(1); 
} 

//Split what is stored in the file into frames and return one for each call 
//returns the next frame of the stream 

while(1){ 
    int frame = av_read_frame(s, pkt); 
    if (frame < 0) break; 

    duration = pkt->duration; 
    size = pkt->size; 

    total_size = total_size + size; 
    total_duration = total_duration + duration; 

    cout << "frame:" << i << " " << size << " " << duration << endl; 
    data = pkt->data; 
    outdata << "Frame: " << i << " "; 
    outdata << data<< endl; 

    for (j = 0; j < size; j++){ 

    } 

    i++; 
    //pkt_no++; 
    //outdata << sum << endl;  
} 

//make the packet free 
av_packet_unref(pkt); 
delete pkt; 

cout << "total size: " << total_size << endl; 
cout << "total duration:" << total_duration << endl; 

outdata.close(); 

//Close the file after reading 
avformat_close_input(&s); 

}

+2

あなたの質問がありますか?あなたは持っている問題について説明していますが、あなたの質問には質問はありません。 – tambre

+0

「データ」パラメータの情報を印刷または使用し、それを比較に使用し、含まれている有用な情報を抽出します。 –

+0

それはあなたがしたいことです。今質問を作成し、それをあなたの...質問に追加してください。 – tambre

答えて

0

あなたがそれをしたいですかなぜ私が読みやすい形式で

を使用することはできませんか?あなたはあなたの詳細を出力したいAVPAcket?その後、AVFormatContextからこれらの詳細を取得する必要があります。 AVPacketにはstream_indexがあり、これを使用してパケットが表すストリームの詳細を取得できます。その他の有用な情報は、パケットのpts/dtsとサイズです。

AVPacket pkt = ...; 
AVFormatContext *s = ... ; 

AVStream* stream = s->streams[pkt.stream_index]; // get the stream 

基本的に、各メディアファイルには複数のストリームが含まれています。ファイルを開くときAVFormatContextは開いたファイルに関する情報を保存します。 AVFormatContext::streamsは、メディアファイルの一部であるストリームです(オーディオ、ビデオなど)。この方法で各AVPacketからパケットが表すAVStreamを得ることができます。 AVStreamでは、codecdurationのストリームとその他の有用なパラメータを検査できます。

+0

実際、私はそれを読む必要はありません。私はそれから有用な情報を抽出したいだけです。基本的には、DCT係数と動きベクトルを抽出することが可能かどうかを知りたいと思っています。私は比較のためにそれらを使いたい。 –

+0

@SanduniWickramasingheあなたはビットストリームと関連する[AVCodecContext](https://www.ffmpeg.org/doxygen/3.1/structAVCodecContext.html)に入る必要があるので、それは非常に簡単ではないでしょう。可能であれば、自分でビットストリームを解析する必要があります。そのためにh264bitstreamを試してください(あなたはH264を扱っていると仮定します) – Pavel

+0

私はそれを手に入れません。あなたはもっと詳しく記述できますか? –

関連する問題