Skip to content

Commit

Permalink
Update to ffmpeg5.0 (#625)
Browse files Browse the repository at this point in the history
Co-authored-by: quangtt-starify <[email protected]>
  • Loading branch information
Truong-Thanh-Quang and quangtt-starify authored Sep 15, 2023
1 parent 6cae62e commit ff63396
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PackageReference Include="FFmpeg.AutoGen" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PackageReference Include="FFmpeg.AutoGen" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
11 changes: 3 additions & 8 deletions Unosquare.FFME/Common/MediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ private static List<StreamInfo> ExtractStreams(AVFormatContext* inputContext)
var s = inputContext->streams[i];

var codecContext = ffmpeg.avcodec_alloc_context3(null);

#pragma warning disable CS0618 // Type or member is obsolete

// ffmpeg.avcodec_parameters_to_context(codecContext, s->codecpar);
ffmpeg.avcodec_copy_context(codecContext, s->codec);
#pragma warning restore CS0618 // Type or member is obsolete
ffmpeg.avcodec_parameters_to_context(codecContext, s->codecpar);

var bitsPerSample = codecContext->codec_type == AVMediaType.AVMEDIA_TYPE_AUDIO ?
ffmpeg.av_get_bits_per_sample(codecContext->codec_id) : 0;
Expand Down Expand Up @@ -150,7 +145,7 @@ private static List<StreamInfo> ExtractStreams(AVFormatContext* inputContext)
bitsPerSample * codecContext->channels * codecContext->sample_rate :
codecContext->bit_rate,
MaxBitRate = codecContext->rc_max_rate,
InfoFrameCount = s->codec_info_nb_frames,
InfoFrameCount = (int)s->nb_frames,
TimeBase = s->time_base,
SampleFormat = codecContext->sample_fmt,
SampleRate = codecContext->sample_rate,
Expand Down Expand Up @@ -258,7 +253,7 @@ private static List<ChapterInfo> ExtractChapters(AVFormatContext* ic)
StartTime = c->start.ToTimeSpan(c->time_base),
EndTime = c->end.ToTimeSpan(c->time_base),
Index = i,
ChapterId = c->id,
ChapterId = (int)c->id,
Metadata = FFDictionary.ToDictionary(c->metadata)
};

Expand Down
4 changes: 2 additions & 2 deletions Unosquare.FFME/Container/MediaComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ protected MediaComponent(MediaContainer container, int streamIndex)
#pragma warning disable CS0618 // Type or member is obsolete

// Set default codec context options from probed stream
// var setCodecParamsResult = ffmpeg.avcodec_parameters_to_context(CodecContext, Stream->codecpar);
var setCodecParamsResult = ffmpeg.avcodec_copy_context(CodecContext, Stream->codec);
var setCodecParamsResult = ffmpeg.avcodec_parameters_to_context(CodecContext, Stream->codecpar);

#pragma warning restore CS0618 // Type or member is obsolete

if (setCodecParamsResult < 0)
Expand Down
6 changes: 4 additions & 2 deletions Unosquare.FFME/Container/MediaContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,14 @@ private void StreamInitializeInputContext()
// Flags
InputContext->flags |= opts.FlagDiscardCorrupt ? ffmpeg.AVFMT_FLAG_DISCARD_CORRUPT : InputContext->flags;
InputContext->flags |= opts.FlagEnableFastSeek ? ffmpeg.AVFMT_FLAG_FAST_SEEK : InputContext->flags;
InputContext->flags |= opts.FlagEnableLatmPayload ? ffmpeg.AVFMT_FLAG_MP4A_LATM : InputContext->flags;

// InputContext->flags |= opts.FlagEnableLatmPayload ? ffmpeg.AVFMT_FLAG_MP4A_LATM : InputContext->flags;
InputContext->flags |= opts.FlagEnableNoFillIn ? ffmpeg.AVFMT_FLAG_NOFILLIN : InputContext->flags;
InputContext->flags |= opts.FlagGeneratePts ? ffmpeg.AVFMT_FLAG_GENPTS : InputContext->flags;
InputContext->flags |= opts.FlagIgnoreDts ? ffmpeg.AVFMT_FLAG_IGNDTS : InputContext->flags;
InputContext->flags |= opts.FlagIgnoreIndex ? ffmpeg.AVFMT_FLAG_IGNIDX : InputContext->flags;
InputContext->flags |= opts.FlagKeepSideData ? ffmpeg.AVFMT_FLAG_KEEP_SIDE_DATA : InputContext->flags;

// InputContext->flags |= opts.FlagKeepSideData ? ffmpeg.AVFMT_FLAG_KEEP_SIDE_DATA : InputContext->flags;
InputContext->flags |= opts.FlagNoBuffer ? ffmpeg.AVFMT_FLAG_NOBUFFER : InputContext->flags;
InputContext->flags |= opts.FlagSortDts ? ffmpeg.AVFMT_FLAG_SORT_DTS : InputContext->flags;
InputContext->flags |= opts.FlagStopAtShortest ? ffmpeg.AVFMT_FLAG_SHORTEST : InputContext->flags;
Expand Down
2 changes: 1 addition & 1 deletion Unosquare.FFME/Container/VideoFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal VideoFrame(AVFrame* frame, VideoComponent component)
continue;

// Parse 3 bytes at a time
for (var p = 0; p < sideData->size; p += 3)
for (var p = 0; p < (int)sideData->size; p += 3)
{
var packet = new ClosedCaptionPacket(TimeSpan.FromTicks(StartTime.Ticks + p), sideData->data, p);
if (packet.PacketType == CaptionsPacketType.NullPad || packet.PacketType == CaptionsPacketType.Unrecognized)
Expand Down

0 comments on commit ff63396

Please sign in to comment.