From 94141e1e9022e6993cbf047c24d1ff411876bf94 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Fri, 17 Nov 2017 15:29:20 +0100 Subject: [PATCH 1/4] convert pix fmt Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/6af1864b0e2c85c74d2825a91f062ccbd30a97c5 Author: Jacek Jendrzej Date: 2017-11-17 (Fri, 17 Nov 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libarmbox/video.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libarmbox/video.cpp b/libarmbox/video.cpp index 41e283d..203439e 100644 --- a/libarmbox/video.cpp +++ b/libarmbox/video.cpp @@ -44,6 +44,7 @@ extern "C" { #include #include +#include } #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_VIDEO, this, args) @@ -193,10 +194,10 @@ void write_frame(AVFrame* in_frame, FILE* fp) av_packet_unref(&pkt); } } - avcodec_close(codec_context); - av_free(codec_context); } } + avcodec_close(codec_context); + av_free(codec_context); } } } @@ -210,8 +211,22 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) av_frame_free(&frame); return -1; } - write_frame(frame, fp); - av_frame_free(&frame); + AVFrame *dest_frame = av_frame_alloc(); + if(dest_frame){ + dest_frame->height = (frame->height/2)*2; + dest_frame->width = (frame->width/2)*2; + dest_frame->format = AV_PIX_FMT_YUV420P; + av_frame_get_buffer(dest_frame, 32); + struct SwsContext *convert = NULL; + convert = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, dest_frame->width, dest_frame->height, AV_PIX_FMT_YUVJ420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); + if(convert){ + sws_scale(convert, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize); + sws_freeContext(convert); + } + write_frame(dest_frame, fp); + av_frame_free(&frame); + av_frame_free(&dest_frame); + } } return 0; From a26ee00f5122db52dfd912dada6f927050003490 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Fri, 17 Nov 2017 16:20:42 +0100 Subject: [PATCH 2/4] fix possible memleak Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/d18ff77a51ad92308fd7a068785a7f8199d19c79 Author: Jacek Jendrzej Date: 2017-11-17 (Fri, 17 Nov 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libarmbox/video.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarmbox/video.cpp b/libarmbox/video.cpp index 203439e..8b1d708 100644 --- a/libarmbox/video.cpp +++ b/libarmbox/video.cpp @@ -224,9 +224,9 @@ int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) sws_freeContext(convert); } write_frame(dest_frame, fp); - av_frame_free(&frame); av_frame_free(&dest_frame); } + av_frame_free(&frame); } return 0; From f57478547e1a72c1c3eb0b9a4c010da49b169b87 Mon Sep 17 00:00:00 2001 From: TangoCash Date: Fri, 17 Nov 2017 20:23:43 +0100 Subject: [PATCH 3/4] porting av converter to sh4 Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/1e7092932c61c9d8b0bb17e8b07a1ef38752a88c Author: TangoCash Date: 2017-11-17 (Fri, 17 Nov 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libspark/video.cpp | 149 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 5 deletions(-) diff --git a/libspark/video.cpp b/libspark/video.cpp index 16f0477..3e331d9 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -41,6 +41,13 @@ #include +extern "C" +{ +#include +#include +#include +} + #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_VIDEO, this, args) #define lt_info(args...) _lt_info(TRIPLE_DEBUG_VIDEO, this, args) #define lt_debug_c(args...) _lt_debug(TRIPLE_DEBUG_VIDEO, NULL, args) @@ -157,6 +164,140 @@ out: } +void init_parameters(AVFrame* in_frame, AVCodecContext *codec_context) +{ + /* put sample parameters */ + codec_context->bit_rate = 400000; + /* resolution must be a multiple of two */ + codec_context->width = (in_frame->width/2)*2; + codec_context->height = (in_frame->height/2)*2; + /* frames per second */ + codec_context->time_base = (AVRational ) { 1, 60 }; + codec_context->gop_size = 10; /* emit one intra frame every ten frames */ + codec_context->max_b_frames = 1; + codec_context->pix_fmt = AV_PIX_FMT_YUV420P; +} + +void write_frame(AVFrame* in_frame, FILE* fp) +{ + if(in_frame == NULL || fp == NULL) + return; + AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO); + if (codec) + { + AVCodecContext *codec_context = avcodec_alloc_context3(codec); + if (codec_context) + { + init_parameters(in_frame, codec_context); + if (avcodec_open2(codec_context, codec, 0) != -1){ + AVPacket pkt; + av_init_packet(&pkt); + /* encode the image */ + int got_output = 0; + int ret = avcodec_encode_video2(codec_context, &pkt, in_frame, &got_output); + if (ret != -1){ + if (got_output){ + fwrite(pkt.data, 1, pkt.size, fp); + av_packet_unref(&pkt); + } + int i =1; + for (got_output = 1; got_output; i++){ + /* get the delayed frames */ + in_frame->pts = i; + ret = avcodec_encode_video2(codec_context, &pkt, 0, &got_output); + if (ret != -1 && got_output){ + fwrite(pkt.data, 1, pkt.size, fp); + av_packet_unref(&pkt); + } + } + } + } + avcodec_close(codec_context); + av_free(codec_context); + } + } +} + +int decode_frame(AVCodecContext *codecContext,AVPacket &packet, FILE* fp) +{ + int decode_ok = 0; + AVFrame *frame = av_frame_alloc(); + if(frame){ + if ((avcodec_decode_video2(codecContext, frame, &decode_ok, &packet)) < 0 || !decode_ok){ + av_frame_free(&frame); + return -1; + } + AVFrame *dest_frame = av_frame_alloc(); + if(dest_frame){ + dest_frame->height = (frame->height/2)*2; + dest_frame->width = (frame->width/2)*2; + dest_frame->format = AV_PIX_FMT_YUV420P; + av_frame_get_buffer(dest_frame, 32); + struct SwsContext *convert = NULL; + convert = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format, dest_frame->width, dest_frame->height, AV_PIX_FMT_YUVJ420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); + if(convert){ + sws_scale(convert, frame->data, frame->linesize, 0, frame->height, dest_frame->data, dest_frame->linesize); + sws_freeContext(convert); + } + write_frame(dest_frame, fp); + av_frame_free(&dest_frame); + } + av_frame_free(&frame); + } + return 0; + +} + +AVCodecContext* open_codec(AVMediaType mediaType, AVFormatContext* formatContext) +{ + int stream_index = av_find_best_stream(formatContext, mediaType, -1, -1, NULL, 0); + if (stream_index >=0 ){ + AVCodecContext * codecContext = formatContext->streams[stream_index]->codec; + if(codecContext){ + AVCodec *codec = avcodec_find_decoder(codecContext->codec_id); + if(codec){ + if ((avcodec_open2(codecContext, codec, NULL)) != 0){ + return NULL; + } + } + return codecContext; + } + } + return NULL; +} + +int image_to_mpeg2(const char *image_name, const char *encode_name) +{ + int ret = 0; + av_register_all(); + avcodec_register_all(); + + AVFormatContext *formatContext = avformat_alloc_context(); + if (formatContext && (ret = avformat_open_input(&formatContext, image_name, NULL, NULL)) == 0){ + AVCodecContext *codecContext = open_codec(AVMEDIA_TYPE_VIDEO, formatContext); + if(codecContext){ + AVPacket packet; + av_init_packet(&packet); + if ((ret = av_read_frame(formatContext, &packet)) !=-1){ + FILE* fp = fopen(encode_name, "wb"); + if(fp){ + if(decode_frame(codecContext, packet, fp) != 1){ + /* add sequence end code to have a real mpeg file */ + uint8_t endcode[] = { 0, 0, 1, 0xb7 }; + fwrite(endcode, 1, sizeof(endcode), fp); + } + fclose(fp); + } + av_free_packet(&packet); + } + avcodec_close(codecContext); + } + avformat_close_input(&formatContext); + } + av_free(formatContext); + return 0; +} + cVideo::cVideo(int, void *, void *, unsigned int unit) { lt_debug("%s unit %u\n", __func__, unit); @@ -424,10 +565,10 @@ void cVideo::SetVideoMode(analog_mode_t mode) void cVideo::ShowPicture(const char * fname, const char *_destname) { lt_debug("%s(%s)\n", __func__, fname); - static const unsigned char pes_header[] = { 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x80, 0x00, 0x00 }; + //static const unsigned char pes_header[] = { 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x80, 0x00, 0x00 }; + static const unsigned char pes_header[] = {0x0, 0x0, 0x1, 0xe0, 0x00, 0x00, 0x80, 0x80, 0x5, 0x21, 0x0, 0x1, 0x0, 0x1}; static const unsigned char seq_end[] = { 0x00, 0x00, 0x01, 0xB7 }; char destname[512]; - char cmd[512]; char *p; int mfd; struct stat st, st2; @@ -468,9 +609,7 @@ void cVideo::ShowPicture(const char * fname, const char *_destname) u.actime = time(NULL); u.modtime = st2.st_mtime; /* it does not exist or has a different date, so call ffmpeg... */ - sprintf(cmd, "ffmpeg -y -f mjpeg -i '%s' -s 1280x720 -aspect 16:9 '%s' Date: Sat, 18 Nov 2017 08:22:13 +0100 Subject: [PATCH 4/4] align gststreamer findallpids to eplayers logic Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/b614ab9f12205b9777aafb575f178178f6b4e4b1 Author: TangoCash Date: 2017-11-18 (Sat, 18 Nov 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libarmbox/playback_gst.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarmbox/playback_gst.cpp b/libarmbox/playback_gst.cpp index e4b19d9..0ef2c4f 100644 --- a/libarmbox/playback_gst.cpp +++ b/libarmbox/playback_gst.cpp @@ -919,7 +919,7 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu language->clear(); - for (i = 0; i < n_audio; i++) + for (i = 0; i < n_audio && i < *numpida; i++) { // apids apids[i]= real_apids[i] ? real_apids[i] : i;