質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

FFmpeg

FFmpegは、動画と音声を交換できるフリーソフトウェアです。UNIX系OSから派生した、MS-DOSから操作するコマンドラインツールです。libavcodecやlibavformat、libswscale、libavfilterなどを含みます。ライセンスは、コンパイルの際のオプションによりLGPLもしくはGPLに決定されます。対応コーデックや使用できるオプションが多く、幅広く利用されています。

Q&A

解決済

1回答

1756閲覧

C# FFmepg API [Unable to load DLL 'avcodec.59 under ]の対処方法が知りたい

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

FFmpeg

FFmpegは、動画と音声を交換できるフリーソフトウェアです。UNIX系OSから派生した、MS-DOSから操作するコマンドラインツールです。libavcodecやlibavformat、libswscale、libavfilterなどを含みます。ライセンスは、コンパイルの際のオプションによりLGPLもしくはGPLに決定されます。対応コーデックや使用できるオプションが多く、幅広く利用されています。

0グッド

0クリップ

投稿2022/07/22 09:42

提示コードですが以下のここですのコード部で以下のError部の例外が発生します。これはなぜでしょうか?dllは追加しています。ファイル名をavcodec.59avcodec.59.dll等に名前を変更しましたがロードされません。またinput.flacのファイルが.exeと同じ場所にあります。
何が原因で.dllファイルが読めないのでしょうか?

イメージ説明
dllファイル:https://www.dlldownloader.com/avcodec-dll/

参考コード: https://github.com/Ruslan-B/FFmpeg.AutoGen/blob/master/FFmpeg.AutoGen.Examples.Encode/Program.cs

Error

1System.DllNotFoundException: 'Unable to load DLL 'avcodec.59 under C:\Users\yw325\Desktop\ConsoleApp1\ConsoleApp1\bin\Debug\net6.0\': The specified module could not be found.' 2

cs

1using FFmpeg.AutoGen; 2 3internal unsafe class Program 4{ 5 static int Main(string[] args) 6 { 7 AVFrame* frame; 8 AVPacket* pkt; 9 int i, j, k, ret; 10 short* samples; 11 float t, tincr; 12 13 if (args.Length <= 0) 14 { 15 string executable = Environment.GetCommandLineArgs()[0]; 16 //Console.Error.WriteLine($"Usage: {executable} <output file>"); 17 //return 0; 18 } 19 20 var filename = "input.flac"; 21 22 /* find the MP2 encoder */ 23 AVCodec* codec = ffmpeg.avcodec_find_encoder(AVCodecID.AV_CODEC_ID_MP2);//ここです。 24 if (codec == null) 25 { 26 Console.Error.WriteLine("Codec not found"); 27 return 1; 28 } 29 30 AVCodecContext* c = ffmpeg.avcodec_alloc_context3(codec); 31 if (c == null) 32 { 33 Console.Error.WriteLine("Could not allocate audio codec context"); 34 return 1; 35 } 36 37 /* put sample parameters */ 38 c->bit_rate = 64000; 39 40 /* check that the encoder supports s16 pcm input */ 41 c->sample_fmt = AVSampleFormat.AV_SAMPLE_FMT_S16; 42 if (!check_sample_fmt(codec, c->sample_fmt)) 43 { 44 string sampleFormat = ffmpeg.av_get_sample_fmt_name(c->sample_fmt); 45 Console.Error.WriteLine($"Encoder does not support sample format {sampleFormat}"); 46 return 1; 47 } 48 49 /* select other audio parameters supported by the encoder */ 50 c->sample_rate = select_sample_rate(codec); 51 c->channel_layout = select_channel_layout(codec); 52 c->channels = ffmpeg.av_get_channel_layout_nb_channels(c->channel_layout); 53 54 /* open it */ 55 if (ffmpeg.avcodec_open2(c, codec, null) < 0) 56 { 57 Console.Error.WriteLine($"Could not open codec"); 58 return 1; 59 } 60 61 using BinaryWriter output = new BinaryWriter(new FileStream(filename, FileMode.Create)); 62 63 /* packet for holding encoded output */ 64 pkt = ffmpeg.av_packet_alloc(); 65 if (pkt == null) 66 { 67 Console.Error.WriteLine($"could not allocate the packet"); 68 return 1; 69 } 70 71 /* frame containing input raw audio */ 72 frame = ffmpeg.av_frame_alloc(); 73 if (frame == null) 74 { 75 Console.Error.WriteLine($"Could not allocate audio frame"); 76 return 1; 77 } 78 79 frame->nb_samples = c->frame_size; 80 frame->format = (int)c->sample_fmt; 81 frame->channel_layout = c->channel_layout; 82 83 /* allocate the data buffers */ 84 ret = ffmpeg.av_frame_get_buffer(frame, 0); 85 if (ret < 0) 86 { 87 Console.Error.WriteLine($"Could not allocate audio data buffers"); 88 return 1; 89 } 90 91 /* encode a single tone sound */ 92 t = 0.0f; 93 tincr = (float)(2 * Math.PI * 440.0 / c->sample_rate); 94 for (i = 0; i < 200; i++) 95 { 96 /* make sure the frame is writable -- makes a copy if the encoder 97 * kept a reference internally */ 98 ret = ffmpeg.av_frame_make_writable(frame); 99 if (ret < 0) 100 return 1; 101 samples = (short*)frame->data[0]; 102 103 for (j = 0; j < c->frame_size; j++) 104 { 105 samples[2 * j] = (short)(Math.Sin(t) * 10000); 106 107 for (k = 1; k < c->channels; k++) 108 samples[2 * j + k] = samples[2 * j]; 109 t += tincr; 110 } 111 encode(c, frame, pkt, output); 112 } 113 114 /* flush the encoder */ 115 encode(c, null, pkt, output); 116 117 ffmpeg.av_frame_free(&frame); 118 ffmpeg.av_packet_free(&pkt); 119 ffmpeg.avcodec_free_context(&c); 120 121 return 0; 122 } 123 124 static void encode(AVCodecContext* ctx, AVFrame* frame, AVPacket* pkt, BinaryWriter output) 125 { 126 int ret; 127 128 /* send the frame for encoding */ 129 ret = ffmpeg.avcodec_send_frame(ctx, frame); 130 if (ret < 0) 131 { 132 Console.Error.WriteLine($"Error sending the frame to the encoder"); 133 Environment.Exit(1); 134 } 135 136 /* read all the available output packets (in general there may be any 137 * number of them */ 138 while (ret >= 0) 139 { 140 ret = ffmpeg.avcodec_receive_packet(ctx, pkt); 141 if (ret == ffmpeg.AVERROR(ffmpeg.EAGAIN) || ret == ffmpeg.AVERROR_EOF) 142 return; 143 else if (ret < 0) 144 { 145 Console.Error.WriteLine($"Error encoding audio frame"); 146 Environment.Exit(1); 147 } 148 149 output.Write(new ReadOnlySpan<byte>(pkt->data, pkt->size)); 150 ffmpeg.av_packet_unref(pkt); 151 } 152 } 153 154 /* check that a given sample format is supported by the encoder */ 155 static bool check_sample_fmt(AVCodec* codec, AVSampleFormat sample_fmt) 156 { 157 AVSampleFormat* p = codec->sample_fmts; 158 159 while (*p != AVSampleFormat.AV_SAMPLE_FMT_NONE) 160 { 161 if (*p == sample_fmt) 162 return true; 163 p++; 164 } 165 return false; 166 } 167 168 /* just pick the highest supported samplerate */ 169 static int select_sample_rate(AVCodec* codec) 170 { 171 int best_samplerate = 0; 172 173 if (codec->supported_samplerates == null) 174 return 44100; 175 176 int* p = codec->supported_samplerates; 177 while (*p != 0) 178 { 179 if (best_samplerate != 0 || Math.Abs(44100 - *p) < Math.Abs(44100 - best_samplerate)) 180 best_samplerate = *p; 181 p++; 182 } 183 return best_samplerate; 184 } 185 186 /* select layout with the highest channel count */ 187 static ulong select_channel_layout(AVCodec* codec) 188 { 189 ulong* p; 190 ulong best_ch_layout = 0; 191 int best_nb_channels = 0; 192 193 if (codec->channel_layouts == null) 194 return ffmpeg.AV_CH_LAYOUT_STEREO; 195 196 p = codec->channel_layouts; 197 while (*p != 0) 198 { 199 int nb_channels = ffmpeg.av_get_channel_layout_nb_channels(*p); 200 201 if (nb_channels > best_nb_channels) 202 { 203 best_ch_layout = *p; 204 best_nb_channels = nb_channels; 205 } 206 p++; 207 } 208 209 return best_ch_layout; 210 } 211}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

以下のDLLファイルを使ってみてください。
https://github.com/Ruslan-B/FFmpeg.AutoGen/tree/master/FFmpeg/bin/x64
NuGetにあるFFmpeg.AutoGen5.0.0なのでgithubのreleaseに置かれているファイルは古いですね。

投稿2022/07/22 10:54

umed0025

総合スコア851

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問