Zend certified PHP/Magento developer

FFMpeg autorotate video and image output

I have a video which I’m trying to downscale to a video output, and also create a thumbnail image at every 2 seconds using a single FFMpeg command(hardware accelerated). Following is the command:

ffmpeg -hwaccel cuvid -hwaccel_output_format cuda -i "inputVideo.mov" -vf "scale_cuda=1280:720,hwdownload,format=nv12,setsar=1:1" -c:v h264_nvenc -profile:v main -level:v 4 -b:v 2500K "outputVideo.mp4" -vf "scale_cuda=160:90,hwdownload,format=nv12, fps=0.5,setsar=1:1" "thumbnailOutputs_%04d.jpg"

But the input video has a rotation parameter(180 degrees) in its metadata, and based on the FFMpeg Documentation the command automatically rotates the output. I don’t want my outputs to be rotated.

-autorotate Automatically rotate the video according to file metadata. Enabled by default, use -noautorotate to disable it.

I changed my command to add -noautorotate. It fixed the video output, but the image outputs are still getting rotated. I even tried separating the the command for images and using -noautorotate but still doesn’t work.

Also, an interesting observation is the command behaves differently when i dont use hardware acceleration. Following is a normal cpu based command:

ffmpeg  -i "inputVideo.mov" -c:v libx264 -profile:v main -level:v 4 -b:v 2500K -vf "scale=1280:720,setsar=1:1" "outputVideo.mp4" -vf fps=0.5 -s 160X90 "thumbnailOutputs_%04d.jpg"

Following are the observations:

Hardware accleration commands (nvenc)

default command

  • video – Upside down❌ (rotated 180 degrees)
  • images – Upside down❌ (rotated 180 degrees)

command with -noautorotate flag

  • video – Correct✅
  • images – Upside down❌ (rotated 180 degrees)

CPU commands (libx264)

default command

  • video – Correct✅
  • images – Correct✅

command with -noautorotate flag

  • video – Correct✅
  • images – Upside down❌ (rotated 180 degrees)

Link to the input video used: Input Video used