ffmpeg change h264 to jpeg ok.
This commit is contained in:
parent
a4bd40a847
commit
1b7ff22112
|
@ -118,22 +118,22 @@ bool FfmpegDecoder::Init(void)
|
||||||
bool FfmpegDecoder::UnInit(void)
|
bool FfmpegDecoder::UnInit(void)
|
||||||
{
|
{
|
||||||
LogInfo("uninit %s\n", avcodec_get_name(mCodecId));
|
LogInfo("uninit %s\n", avcodec_get_name(mCodecId));
|
||||||
if (mFrame) {
|
|
||||||
av_frame_free(&mFrame);
|
|
||||||
mFrame = nullptr;
|
|
||||||
}
|
|
||||||
if (mCodecCtx) {
|
|
||||||
if (mCodecId != AV_CODEC_ID_H264) {
|
|
||||||
avcodec_free_context(&mCodecCtx);
|
|
||||||
mCodecCtx = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
av_packet_free(&mPacket);
|
av_packet_free(&mPacket);
|
||||||
mPacket = nullptr;
|
mPacket = nullptr;
|
||||||
if (mParser) {
|
if (mParser) {
|
||||||
av_parser_close(mParser);
|
av_parser_close(mParser);
|
||||||
mParser = nullptr;
|
mParser = nullptr;
|
||||||
}
|
}
|
||||||
|
// if (mCodecCtx) {
|
||||||
|
// // if (mCodecId != AV_CODEC_ID_H264) {
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
avcodec_free_context(&mCodecCtx);
|
||||||
|
mCodecCtx = nullptr;
|
||||||
|
if (mFrame) {
|
||||||
|
av_frame_free(&mFrame);
|
||||||
|
mFrame = nullptr;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void FfmpegDecoder::DecodeData(const void *data, const size_t &size, const unsigned long long &pts,
|
void FfmpegDecoder::DecodeData(const void *data, const size_t &size, const unsigned long long &pts,
|
||||||
|
|
|
@ -68,6 +68,10 @@ void FfmpegThumbnail::UnInit(void)
|
||||||
}
|
}
|
||||||
avformat_free_context(mOutputFormat);
|
avformat_free_context(mOutputFormat);
|
||||||
fx_system_v2("sync");
|
fx_system_v2("sync");
|
||||||
|
if (sws_ctx) {
|
||||||
|
sws_freeContext(sws_ctx);
|
||||||
|
sws_ctx = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bool FfmpegThumbnail::CreateThumbnail(const std::string &outputFile, const void *data, const size_t &size)
|
bool FfmpegThumbnail::CreateThumbnail(const std::string &outputFile, const void *data, const size_t &size)
|
||||||
{
|
{
|
||||||
|
@ -112,13 +116,13 @@ bool FfmpegThumbnail::CreateThumbnail(const std::string &outputFile, const void
|
||||||
av_dump_format(mOutputFormat, 0, outputFile.c_str(), 1);
|
av_dump_format(mOutputFormat, 0, outputFile.c_str(), 1);
|
||||||
/* open the output file, if needed */
|
/* open the output file, if needed */
|
||||||
// if (!(mOutputFormat->oformat->flags & AVFMT_NOFILE)) {
|
// if (!(mOutputFormat->oformat->flags & AVFMT_NOFILE)) {
|
||||||
ret = avio_open(&mOutputFormat->pb, outputFile.c_str(), AVIO_FLAG_WRITE);
|
// ret = avio_open(&mOutputFormat->pb, outputFile.c_str(), AVIO_FLAG_WRITE);
|
||||||
if (ret < 0) {
|
// if (ret < 0) {
|
||||||
char error_str[AV_ERROR_MAX_STRING_SIZE] = {0};
|
// char error_str[AV_ERROR_MAX_STRING_SIZE] = {0};
|
||||||
LogError("Could not open '%s': %s\n",
|
// LogError("Could not open '%s': %s\n",
|
||||||
outputFile.c_str(),
|
// outputFile.c_str(),
|
||||||
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret));
|
// av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret));
|
||||||
}
|
// }
|
||||||
LogInfo("Open output file\n");
|
LogInfo("Open output file\n");
|
||||||
// }
|
// }
|
||||||
av_dict_set_int(&opt, "use_editlist", 0, 0);
|
av_dict_set_int(&opt, "use_editlist", 0, 0);
|
||||||
|
@ -132,6 +136,7 @@ bool FfmpegThumbnail::CreateThumbnail(const std::string &outputFile, const void
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
av_dict_free(&opt);
|
av_dict_free(&opt);
|
||||||
|
// return true;
|
||||||
mDecoder->Init();
|
mDecoder->Init();
|
||||||
mEncoder->Init(mOutputFormat->flags);
|
mEncoder->Init(mOutputFormat->flags);
|
||||||
mStream->time_base = mEncoder->GetTimeBase();
|
mStream->time_base = mEncoder->GetTimeBase();
|
||||||
|
@ -148,7 +153,11 @@ void FfmpegThumbnail::GetDecodeDataCallback(AVFrame *frame)
|
||||||
output_frame->format = AV_PIX_FMT_YUV420P;
|
output_frame->format = AV_PIX_FMT_YUV420P;
|
||||||
output_frame->width = 640;
|
output_frame->width = 640;
|
||||||
output_frame->height = 480;
|
output_frame->height = 480;
|
||||||
int jpeg_buf_size = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, 640, 480, 1);
|
// output_frame->linesize[0] = 640; // Y plane 的跨度
|
||||||
|
// output_frame->linesize[1] = 320; // U/V planes 的跨度
|
||||||
|
// output_frame->linesize[2] = 320; // U/V planes 的跨度
|
||||||
|
|
||||||
|
int jpeg_buf_size = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, 1920, 2160, 1);
|
||||||
LogInfo("jpeg_buf_size: %d\n", jpeg_buf_size);
|
LogInfo("jpeg_buf_size: %d\n", jpeg_buf_size);
|
||||||
uint8_t *jpeg_buf = (uint8_t *)av_malloc(jpeg_buf_size);
|
uint8_t *jpeg_buf = (uint8_t *)av_malloc(jpeg_buf_size);
|
||||||
av_image_fill_arrays(
|
av_image_fill_arrays(
|
||||||
|
@ -169,8 +178,11 @@ void FfmpegThumbnail::GetDecodeDataCallback(AVFrame *frame)
|
||||||
|
|
||||||
if (mEncoder) {
|
if (mEncoder) {
|
||||||
mEncoder->EncodeData(output_frame, mStream, mEncodeCallback);
|
mEncoder->EncodeData(output_frame, mStream, mEncodeCallback);
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
|
av_frame_free(&output_frame);
|
||||||
|
av_free(jpeg_buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
void FfmpegThumbnail::GetEncodeDataCallback(AVPacket *pkt)
|
void FfmpegThumbnail::GetEncodeDataCallback(AVPacket *pkt)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user