Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int DLNAUtil_GetMediaThumbnailAtPath(char * fromMediaPath, char * toMediaPath, float atDuration) {
- float duration = DLNAUtil_GetMediaDurationSecAtPath(fromMediaPath);
- float targetDuration = 0;
- AVCodecContext *codec_ctx;
- AVCodec *codec;
- int video_stream_index;
- if (atDuration < 0) targetDuration = duration / 2;
- else if (atDuration > duration) targetDuration = duration;
- else targetDuration = atDuration;
- init();
- AVFormatContext *fmt_ctx = NULL;
- int ret = av_open_input_file(&fmt_ctx, fromMediaPath, NULL, 0, NULL);
- if (ret >= 0 && fmt_ctx) {
- codec = NULL;
- codec_ctx = NULL;
- video_stream_index = -1;
- for (int i = 0; i < fmt_ctx->nb_streams; i++) {
- codec_ctx = fmt_ctx->streams[i]->codec;
- if (CODEC_TYPE_VIDEO != codec_ctx->codec_type) {
- continue;
- }
- if (NULL == (codec = avcodec_find_decoder(codec_ctx->codec_id))) {
- printf("\n%s, codec not found.\n", __func__);
- continue;
- }
- if (0 != (avcodec_open(codec_ctx, codec))) {
- printf("\n%s, can not open codec\n", __func__);
- codec = NULL;
- continue;
- }
- video_stream_index = i;
- break;
- }
- if (video_stream_index == -1 || codec_ctx->width == 0 || codec_ctx->height == 0) {
- if (codec != NULL) {
- printf("\n%s, codec:%d, %dx%d\n", __func__, codec, codec_ctx->width, codec_ctx->height);
- avcodec_close(codec_ctx);
- }
- av_close_input_file(fmt_ctx);
- return -1;
- }
- printf("\n%s, videoIndex:%d, codec:%d, %dx%d\n", __func__, video_stream_index, codec, codec_ctx->width, codec_ctx->height);
- return video_stream_index ;
- int ret2 = av_seek_frame(fmt_ctx, 0, (targetDuration * AV_TIME_BASE), 0);
- if (ret2 >= 0) {
- AVPacket *pkt = NULL;
- //int ret3 = av_read_frame(fmt_ctx, pkt);
- while(av_read_frame(fmt_ctx, pkt) >= 0) {
- if (pkt->stream_index == 0);
- }
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement