LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to fix an upsidedown video? (https://www.linuxquestions.org/questions/linux-general-1/how-to-fix-an-upsidedown-video-4175660101/)

linustalman 08-31-2019 04:53 AM

How to fix an upsidedown video?
 
Hi.

I've got a video that's upsidedown. How can this be fixed? Preferably without reencoding?

Thanks.

petelq 08-31-2019 05:57 AM

You can do it with ffmpeg. Something like
Code:

ffmpeg -i in.mp4 -vf "transpose=2" out.mp4
The only problem is I can't remember the transpose number.I think it's 1 to 4, so you could experiment. You might get it right first time or have to scrap 3 files.

linustalman 08-31-2019 09:26 AM

Quote:

Originally Posted by petelq (Post 6031602)
You can do it with ffmpeg. Something like
Code:

ffmpeg -i in.mp4 -vf "transpose=2" out.mp4
The only problem is I can't remember the transpose number.I think it's 1 to 4, so you could experiment. You might get it right first time or have to scrap 3 files.

I tried all 4 numbers - the orientation was always wrong. I think something is up with my original video/encoding method though (I originally converted from .mp4 to .mkv) - your command is likely fine.

This did work but it did not keep the video as VP8 and Vorbis (it only kept Vorbis)
Code:

ffmpeg -i 1.mkv -vf vflip,hflip -r 30 -qscale 0 -acodec copy 2.mkv

Firerat 08-31-2019 09:38 AM

try
Code:

-vf "transpose=2,transpose=2"

Firerat 08-31-2019 09:47 AM

you could just do this in playback with mpv

Code:

mpv video.mp4 -vf "transpose=2,transpose=2"
of using ffmpeg you would need to re-encode

teckk 08-31-2019 12:20 PM

Rotate, from my notes.
Code:

ffmpeg -i infile.mp4 ... -vf "transpose=1" outfile.mp4

0 = 90CounterCLockwise and Vertical Flip
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

Rotate clockwise 90 deg twice to flip
Code:

ffmpeg -i input.mp4 -vf "transpose=1,transpose=1" output.mp4
Or
Code:

ffmpeg -i input2.mp4 -vf "rotate=PI/1" output2.mp4

Firerat 08-31-2019 02:26 PM

ahh, yeah the flip might be important

linustalman 09-01-2019 09:16 AM

Quote:

Originally Posted by Firerat (Post 6031664)
you could just do this in playback with mpv

Code:

mpv video.mp4 -vf "transpose=2,transpose=2"
of using ffmpeg you would need to re-encode

Hi Firerat. That didn't work for me.

Code:

mpv 1.mkv -vf "transpose=2,transpose=2"
Output:
Code:

Option vf: transpose doesn't exist.
Error parsing option vf (option could not be parsed)
Setting command line option '--vf=transpose=2,transpose=2' failed.
Exiting... (Fatal error)


linustalman 09-01-2019 09:17 AM

How could I convert a .mp4 video to have VP8 & Vorbis (to a .mkv or .webm file) and keep the same quality?

linustalman 09-01-2019 09:21 AM

Quote:

Originally Posted by Firerat (Post 6031662)
try
Code:

-vf "transpose=2,transpose=2"

That worked but it didn't keep VP8 but did keep Vorbis (I use the MediaInfo program to show the codecs).

Firerat 09-01-2019 09:23 AM

odd

Code:

mpv --version
mpv 0.29.1 Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
  libavutil      56.14.100 (runtime 56.22.100)
  libavcodec      58.18.100 (runtime 58.35.100)
  libavformat    58.12.100 (runtime 58.20.100)
  libswscale      5.1.100 (runtime 5.3.100)
  libavfilter    7.16.100 (runtime 7.40.101)
  libswresample  3.1.100 (runtime 3.3.100)
ffmpeg version: 4.1.4-1+b2

I guess you could be missing the filter package

libavfilter7 in sid
you will need libavfilter6 if you are still on stretch

linustalman 09-01-2019 09:29 AM

Quote:

Originally Posted by Firerat (Post 6031971)
odd

Code:

mpv --version
mpv 0.29.1 Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
  libavutil      56.14.100 (runtime 56.22.100)
  libavcodec      58.18.100 (runtime 58.35.100)
  libavformat    58.12.100 (runtime 58.20.100)
  libswscale      5.1.100 (runtime 5.3.100)
  libavfilter    7.16.100 (runtime 7.40.101)
  libswresample  3.1.100 (runtime 3.3.100)
ffmpeg version: 4.1.4-1+b2

I guess you could be missing the filter package

libavfilter7 in sid
you will need libavfilter6 if you are still on stretch

Looks like I'm out of luck. No problem. At least I know your code works fine - I'll note it for future reference. :-)

Code:

mpv --version
Code:

mpv 0.23.0 (C) 2000-2016 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
  libavutil      55.34.101
  libavcodec      57.64.101
  libavformat    57.56.101
  libswscale      4.2.100
  libavfilter    6.65.100
  libswresample  2.3.100
ffmpeg version: 3.2.14-1~deb9u1


Firerat 09-01-2019 09:44 AM

wait you can recode with the filter?

by default ffmpeg will encode to h264 and vorbis


Code:

ffmpeg -i inputfile.mkv \
  -c:v vp8 \
  -c:a copy \
  -vf "transpose=2,transpose=2" \
    outputfile.mkv

that will use whatever defaults vp8 has

to get full list of codecs
ffmpeg -codecs



personally, I do like
Code:

nice -n 19 ffmpeg \
  -hide_banner \
  -i input.mkv \
  -map 0 \
  -c:s copy \
  -c:a libopus -af aformat="channel_layouts=7.1|5.1|stereo" \
  -c:v copy \
  -c:v:0 libx265 \
  -pix_fmt yuv420p10le \
  -preset fast \
  -x265-params level=4.1:crf=20 \
  output-fast-opus-crf20-10bit.mkv

but adjust the preset and crf depending what kind of speed/quality/size I want/need

crf 20 is probably over the top
28 is the default , but I find I can see difference
take a sample

Code:

ffmpeg -ss 00:04:30.0 -t 00:03:00.0 -i input.mkv -c copy sample.mkv
that will copy a 3min sample starting at 4min 30 seconds
and try different values on the sample

you will see/hear the quality diff, and get an idea of how large the file will be and how long it will take

edit: the bold will effect both the size and quality

ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, or placebo

ultrafast is , well fastest, will make the smallest file but the least quality
veryslow , slowest , largest , best quality

the crf , higher the number the lower the quality/size

linustalman 09-07-2019 09:43 AM

Quote:

Originally Posted by Firerat (Post 6031978)

...

Code:

ffmpeg -ss 00:04:30.0 -t 00:03:00.0 -i input.mkv -c copy sample.mkv
...

No luck. It's still upsidedown. I made the video on a Fairphone 2 with Ubuntu Touch. It had issues with recording upside down videos but that was fixed in OTA 10. The conversion of the FP2 mp4 file to another format is the issue.

Firerat 09-07-2019 10:41 AM

to recap
in post 10 you said it worked BUT was no longer VP8 ( ffmpeg defaults to AVC and Vorbis)

This will keep the vp8 codec and the vorbis
Code:

ffmpeg -i inputfile.mkv \
  -c:v vp8 \
  -c:a copy \
  -vf "transpose=2,transpose=2" \
    outputfile.mkv

I only used the \ to break up the line for easier reading

Code:

ffmpeg -i inputfile.mkv -c:v vp8 -c:a copy -vf "transpose=2,transpose=2" outputfile.mkv
( \<enter> , basically we are telling the shell to ignore the <enter> ;) )


But I don't know what the quality will be like

If you really want to keep the VP8 codec you will have to play with it to get the best quality ( or acceptable ), I don't know vp8 or vp9 settings I would ned to research them.

If the codec is not so important
Code:

ffmpeg -i inputfile.mkv \
  -c:v libx265 \
  -preset medium \
  -x265-params crf=24
  -c:a copy \
  -vf "transpose=2,transpose=2" \
    outputfile.mkv

might keep the size down and the quality high ( enough )

you could play with the crf
lower numbers will give better quality and higher filesize
higher numbers with give lesser quality and smaller filesize

The preset
ultrafast superfast veryfast faster fast medium slow slower veryslow
< - - - less quality smaller size < - - > higher quality larger size >

the HEVC codec may be more difficult to 'play' depending on device.


I hope that makes sense


All times are GMT -5. The time now is 06:18 AM.