I'm trying to use ffmpeg core package inside .net 6 dockerized project. I install ffmpeg core inside Dockerfile, reference actual package FFMpegCore inside solution but when I try to apply any of the commands from the ffmpeg core lib I'm getting error
An error occurred trying to start process './ffmpeg' with working directory '/var/task'. No such file or directory
Docker build is done with no error.
Dockerfile
FROM public.ecr.aws/lambda/dotnet:6 AS base
....
RUN apt-get install -y ffmpeg
....
FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .
As per ffmpeg core docs in order to use ffmpeg I need to set its binary folder, so I add ffmpeg.config.json
{
"BinaryFolder": "/var/task",
"TemporaryFilesFolder": "/tmp"
}
Actual error is being thrown when I try to execute following command
An error occurred trying to start process './ffmpeg' with working directory '/var/task'. No such file or directory
This is the place where error gets triggered
using FFMpegCore;
...
public class MyController : ControllerBase
{
public async Task<string> Get()
{
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(myfile))
.OutputToPipe(new StreamPipeSink(outputStream), options => options
.WithVideoCodec("vp9")
.ForceFormat("webm"))
.ProcessAsynchronously();
...
}
}
Update:
After changing BinaryFolder
location to /usr/bin
I'm getting following error
An error occurred trying to start process '/usr/bin/ffmpeg' with working directory '/var/task'. No such file or directory
Update #2 This is my complete Dockerfile
FROM public.ecr.aws/lambda/dotnet:6 AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN apt-get update \
&& apt-get install -y apt-utils libgdiplus libc6-dev \
&& apt-get install -y ffmpeg
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .
CodePudding user response:
You're telling it that the binary is in /var/task
in ffmpeg.config.json
, but apt-get install -y ffmpeg
installs ffmpeg in /usr/bin
. Change the BinaryFolder
config value to that like this
{
"BinaryFolder": "/usr/bin",
"TemporaryFilesFolder": "/tmp"
}
You also need to install ffmpeg
at a point in the Dockerfile where it'll end up in the final image. Right now you install it in the build/publish part of the Dockerfile which isn't used for the final image.
Try this instead
FROM public.ecr.aws/lambda/dotnet:6 AS base
# Install ffmpeg
RUN mkdir /ffmpeg && \
cd /ffmpeg && \
yum -y install tar xz && \
curl https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -o ffmpeg.tar.xz -s && \
tar -xf ffmpeg.tar.xz && \
mv ffmpeg-*-amd64-static/ffmpeg /usr/bin && \
cd / && \
rm -rf ffmpeg
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"
WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN dotnet publish "AWSServerless.csproj" \
--configuration Release \
--runtime linux-x64 \
--self-contained false \
--output /app/publish \
-p:PublishReadyToRun=true
FROM base AS final
WORKDIR /var/task
CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .