Log in

View Full Version : Encoding errors from ffmpeg x265 pass 2 which succeeded in pass 1.


rupeshforu3
6th December 2021, 17:35
Hi I am Rupesh from India and I have a PC with Linux installed and I have large size YouTube and WhatsApp MP4 files with codec x264. I want to convert these files into MP4 files with codec x265.

I have tested to convert these files using ffmpeg command x265 pass 1 and Linux shell script and I have successfully completed without any errors but I want to use ffmpeg tool x265 pass 2 to do the same job but I can't.


I got the following code from ffmpeg website and first I have tried to convert a single file and after that I have tried to use the similar code in Linux shell script.




ffmpeg -y -i source.mp4 -filter_threads 3 -profile:v main -preset medium -c:v libx265 -x265-params pass=1 -an -f null /dev/null && \

ffmpeg -i source.mp4 -c:v libx265 -x265-params pass=2 -c:a aac -b:a 48k -ar 44100 source_compressed.mp4




Upon running the above command I am able to see .log and .cue files in the current directory.

For all cases I got only the following two errors.






[libx265 @ 0x742200] Cannot open libx265 encoder.

Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

[aac @ 0x745300] Qavg: 33846.148

[aac @ 0x745300] 2 frames left in the queue on closing

Conversion failed!

localhost:~/to convert #







[libx265 @ 0x10e43c0] Cannot open libx265 encoder.

Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Conversion failed!



The code I have executed without pass 2 is the following.


ffmpeg -y -i source.mp4 -filter_threads 3 -profile:v main -preset medium -c:v libx265 -c:a aac -b:a 48k -ar 44100 source_compressed.mp4



Can you suggest why I can't do the same job in pass 2 of ffmpeg command which has been successfull in pass 1 of ffmpeg command x265.


Regards,
Rupesh.



Sent from my LM-G710 using Tapatalk

rupeshforu3
6th December 2021, 17:47
I thought that pass 2 encoding and command line tools like ffmpeg, x265 produces more quality output than guis.

Sent from my LM-G710 using Tapatalk

kolak
6th December 2021, 19:10
What if you do this:

...-x265-params pass=1 -an -f null - &&

You don't need 2 pass encode. Do 1 pass just add -crf 24 to control bitrate. If you see encoder produces too high bitrate (compared to source) raise crf value.

rupeshforu3
9th December 2021, 09:39
Can you say what is the meaning of the following option

-profile:v main --preset medium

Does the above option helps producing quality output.

Sent from my LM-G710 using Tapatalk

Boulder
9th December 2021, 14:01
You'll want to read this: https://x265.readthedocs.io/en/stable/cli.html

I'd use main10 profile and preset slower or slow for better quality.

benwaggoner
10th December 2021, 00:09
I thought that pass 2 encoding and command line tools like ffmpeg, x265 produces more quality output than guis.
The encoder is the encoder, gui or not. The output will be identical if the same frames are processed with the same parameters and encoder version.

rupeshforu3
10th December 2021, 03:57
How to limit the cpu usage while running ffmpeg tool and x265 in Linux.

Sent from my LM-G710 using Tapatalk

rupeshforu3
10th December 2021, 05:43
I have solved this issue by the following option

-cpucount 3

Where my processor consists of 4 cores.

Another issue is suppose the input mp4 video file consists of bitrate 160 kbps then after converting this particular file the output mp4 video file consists of bitrate 250 kbps.

In the above bitrate is video bitrate not audio bitrate.

I have seen the properties of source and output mp4 video files in media info.

Can you suggest how to convert the x264 mp4 video file into x265 mp4 video file with the same video bitrate as input video file.

Sent from my LM-G710 using Tapatalk

benwaggoner
10th December 2021, 06:20
Can you suggest how to convert the x264 mp4 video file into x265 mp4 video file with the same video bitrate as input video file.
Simply set --bitrate to your desired value. It's a reencode in any case, so you might need more or less bits to retain a similar quality than the original.

2-pass VBR encoding would improve quality of a fixed bitrate, if you actually need that.

rupeshforu3
10th December 2021, 08:06
Simply set --bitrate to your desired value. It's a reencode in any case, so you might need more or less bits to retain a similar quality than the original.

2-pass VBR encoding would improve quality of a fixed bitrate, if you actually need that.
It's not possible for me to use 2 pass encoding and why I said already in the current thread.

See the following link which is similar to my need.

https://stackoverflow.com/questions/40699328/how-to-use-the-information-from-ffprobe-to-use-with-ffmpeg-is-there-a-shortcut

Sent from my LM-G710 using Tapatalk

rupeshforu3
10th December 2021, 10:25
Hi ffprobe tool can be used to extract the bitrate of the source input mp4 video file which later can be used in ffmpeg command as below.

ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1 input.mp4

Actually the above process is working with one file I mean I have used ffprobe tool to get the video bitrate and after that I have used it by invoking ffmpeg command by providing the bitrate value.

I want to apply the same process in a Linux shell script and run it and so I have developed a small shell script as below.

for i in *.mp4;

do name=`echo $i | cut -d'.' -f1`;
echo $name;

$temp=`ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1 $i`;

$br=`echo $temp | cut -d'=' -f1`;

ffmpeg -y -i "$i" -cpucount 3 -c:v libx265 -b:v $br -preset medium -c:a libfdk_aac -b:a 52k -ar 44100 "${name}_compressed.mp4";

# echo $br;
# echo $temp;
done

Upon running the above script I am getting the following errors.

syntax error near unexpected token `$temp=`ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1 $i`'

./ffmpeg_Linux_script_with variable.sh: line 4: =: command not found

./ffmpeg_Linux_script_with variable.sh: line 5: =: command not found

[NULL @ 0x30ab980] Unable to find a suitable output format for 'medium'

Can you suggest what's wrong with the above script.

Sent from my LM-G710 using Tapatalk

tonemapped
16th December 2021, 22:30
You seem to have made it overly complicated. The purpose you mention in another thread - to 'compress YouTube videos' - (not sure if VP9, AV1, H264) could be done with the GUIs you mention. Although for a very different purpose, I have a very simple macro set (I realise it's not ideal but it does the job - taking ~30GB of images and creating a video to work from).
ffmpeg -framerate 24000/1001 -i %6d.jpg -vcodec libx265 -crf 10 -pix_fmt yuv420p -y "output.mp4"

You could use CRF with a max bitrate, which would make more sense. Or if you insist on re-encoding a re-encoded video (why?), I'd do a three pass encode to get the most out of it. There is a difference in motion with two vs three pass.

And why the "-cpucount 3" on a 4C CPU? It makes no sense. Also, the licence for fdk_aac is not clear for redistributing (you link to your script in another thread)...

rupeshforu3
17th December 2021, 17:35
I have downloaded videos from youtube in android smartphone and after that I have transferred all the downloaded mp4 video files to my system.

There is an app called playtime which recursively shows all the properties of video files.

For all files i have seen video codec as avc and so I thought that the source video files are in h264.

While converting using ffmpeg tool i have seen many times as

(H264)-->(h265)

First I thought that h265 offers more compression at the same video bitrate of source h264 file.

Suppose my source file size is 100 mb and with bitrate as 150 kbps.

When crf 10 option is used the converted output video file size is 170 mb with video bitrate as 240 kbps.

When crf 20 option is used the converted output video file size is 150 mb with video bitrate as 200 kbps.

Here the lesson is as you give lowest crf value the more the output video file size is and if you give higher crf value the output video file size is lesser.

I have given option cpucount value 3 because when I have not used it and while running ffmpeg tool all my four cpu cores are always running at 99 percent and producing more heat. If this process runs for one hour my cpu may totally burn. After giving cpu option 3 I am free as always the cpu runs at lower temperatures.

I have used fdkaac codec and if you don't like use normal aac codec which is provided by default by all ffmpeg builds. My opinion is aac sound quality is not good than fdkaac.


2 pass encoding has lot of benifits regarding quality output video file at lowest possible size.

Sent from my LM-G710 using Tapatalk

rupeshforu3
17th December 2021, 17:51
I thought converting vp9 or anything else to x265 would reduce the output video file size a lot but it's not true.

There are other codecs like daala, av1 but I have not tried but I will try in future.

Sent from my LM-G710 using Tapatalk

rupeshforu3
19th December 2021, 16:19
Hi the main reason behind creating these scripts is to reduce the size group of video files. These scripts must be modified by people who are experts in video encoding concepts and distribute to others.




Upto now there are lot of guis for ffmpeg tool but there are no proper scripts. Using guis are not always recommend because you can't achieve what you want using them. For example in some guis you can't how much cpu resources you want to use. I have used upto 3 ffmpeg guis to compress the video file captured from android smartphone camera by giving video bitrate as 400 kbps in options window. The file has been compressed and after that I have opened the output video file in VLC media player and found that the image is stretched. I have not passed any option to stretch the image.




Many of you have android smartphone and capture videos from camera. I have captured video from android smartphone of size 400 mb with length just 4 minutes.




I have tried to compress this particular video file using ffmpeg gui but failed as the output video is stretched but I have used simple ffmpeg command and it compressed this particular video file to 6 mb by passing video bitrate as 400 kbps. The quality of both output video file and source file are almost same.




Many of you asked what is the need of re encoding a video file with same parameters and my answer is I forgot to provide a script to compress video file at specific video bitrate. So I have uploaded new script to source forge.




Let all of us collaborate and produce nice scripts to ffmpeg for our daily use.




Sent from my LM-G710 using Tapatalk

tonemapped
19th December 2021, 19:37
I have downloaded videos from youtube in android smartphone and after that I have transferred all the downloaded mp4 video files to my system.
Assuming we are talking about legal backups of copyright-free content, why do you download the clips in that way? youtube-dl exists...


There is an app called playtime which recursively shows all the properties of video files.
I've not heard of it. Mediainfo (with debug levels changed) is the best option with a GUI to show media file properties.


For all files i have seen video codec as avc and so I thought that the source video files are in h264.

While converting using ffmpeg tool i have seen many times as

(H264)-->(h265)

First I thought that h265 offers more compression at the same video bitrate of source h264 file.

Suppose my source file size is 100 mb and with bitrate as 150 kbps.

When crf 10 option is used the converted output video file size is 170 mb with video bitrate as 240 kbps.

When crf 20 option is used the converted output video file size is 150 mb with video bitrate as 200 kbps.
Why not use a 2-pass encode for a fixed size? You could even use a fast first-pass in order to reduce time (at the expense of quality:compression).


Here the lesson is as you give lowest crf value the more the output video file size is and if you give higher crf value the output video file size is lesser.
Well, generally yes (assuming default qcomp etc.). That's very basic.


I have given option cpucount value 3 because when I have not used it and while running ffmpeg tool all my four cpu cores are always running at 99 percent and producing more heat. If this process runs for one hour my cpu may totally burn. After giving cpu option 3 I am free as always the cpu runs at lower temperatures.I understand that upgrades are not always an option and India's climate can be harsh. How many threads do you allocate?


I have used fdkaac codec and if you don't like use normal aac codec which is provided by default by all ffmpeg builds. My opinion is aac sound quality is not good than fdkaac.
My concern is the terms of the licence for fdkaac (in binary form) for distribution in your script.


2 pass encoding has lot of benifits regarding quality output video file at lowest possible size.

Sent from my LM-G710 using TapatalkThree passes produces even better quality. If I don't use CRF, I always do 3-pass encodes as the extra time produces (generally) better clarity in scenes with motion.

I thought converting vp9 or anything else to x265 would reduce the output video file size a lot but it's not true.
VP9 is already similar to FOSS HEVC encoders, although I'm not a fan of it.


There are other codecs like daala, av1 but I have not tried but I will try in future.

Sent from my LM-G710 using TapatalkI would advise you stick with x265 if you're already limited with encoding hardware (unless you have dedicated AV1 hardware decoding).

Hi the main reason behind creating these scripts is to reduce the size group of video files. These scripts must be modified by people who are experts in video encoding concepts and distribute to others.

Upto now there are lot of guis for ffmpeg tool but there are no proper scripts. Using guis are not always recommend because you can't achieve what you want using them.That's simply incorrect. An understand of encoding is required to use command line, scripts or GUIs. Staxrip is probably one of the best (in my opinion) GUIs for x254, x265 and NVENC as of 2021.

For example in some guis you can't how much cpu resources you want to use. I have used upto 3 ffmpeg guis to compress the video file captured from android smartphone camera by giving video bitrate as 400 kbps in options window. The file has been compressed and after that I have opened the output video file in VLC media player and found that the image is stretched. I have not passed any option to stretch the image.That's a standard encoder flag. You can instruct the encoder to use n threads.

Many of you have android smartphone and capture videos from camera. I have captured video from android smartphone of size 400 mb with length just 4 minutes.And my Android phone captures 4K at over 90 mbps. I simply use x265 presets to reduce the size.


I have tried to compress this particular video file using ffmpeg gui but failed as the output video is stretched but I have used simple ffmpeg command and it compressed this particular video file to 6 mb by passing video bitrate as 400 kbps. The quality of both output video file and source file are almost same.I urge you to download Staxrip, select x265, select 2-pass and medium (there's not much point going to slow for YouTube re-encodes), set threads of 3 (or 6 of HT/SMT), and set the bitrate to whatever you believe is best. Leave the rest on defaults. Obviously select audio options.

rupeshforu3
20th December 2021, 11:32
Thanks for your suggestions.

I will try to stick to x265 and use staxrip.

Is it possible to play av1 and daala video files in android.

In the wikipedia pages of av1 and daala they said that video and audio are contained in mkv and ogg containers.

I think that we can play any mkv video file and so av1 and daala can be played.

Sent from my LM-G710 using Tapatalk

therube
20th December 2021, 19:01
For reference, PlayTime (https://www.dcmembers.com/skwire/download/playtime/).

"Quickly calculate the total play time of a list of most any music or movie file. That was the original request. Due to further user requests, PlayTime has since been expanded to be a fairly complete front-end for the MediaInfo library."

tonemapped
21st December 2021, 01:49
Thanks for your suggestions.

I will try to stick to x265 and use staxrip.

Is it possible to play av1 and daala video files in android.

In the wikipedia pages of av1 and daala they said that video and audio are contained in mkv and ogg containers.

I think that we can play any mkv video file and so av1 and daala can be played.

Sent from my LM-G710 using Tapatalk

1. There are many other GUIs out there, but I find Staxrip offers the right balance of easy encodes for beginners, as well as complex custom script loading for more experienced users.

2. Android's supported formats are listed here: https://developer.android.com/guide/topics/media/media-formats

3. Matroska is an excellent container with fairly wide support. Do you have a requirement for a different container?

4. Both AV1 and Daala are for video. Why do you want to use relatively unsupported (globally) formats when more mature options exist? Do you have hardware decoding for AV1 and Daala?

rupeshforu3
21st December 2021, 04:08
I have downloaded sample av1 file with file extension.mp4 in my android smartphone and opened it in es file explorer and it is playing well without any errors.

I have seen the properties of the above file in media info tool of video file and seen av1 codec.

aomedia is open source foundation for advanced video technologies. It's video codec is supported by all devices in the world.

Visit the following link.

https://aomedia.org/about/

Sent from my LM-G710 using Tapatalk

tonemapped
25th December 2021, 09:15
I have downloaded sample av1 file with file extension.mp4 in my android smartphone and opened it in es file explorer and it is playing well without any errors.

I have seen the properties of the above file in media info tool of video file and seen av1 codec.

aomedia is open source foundation for advanced video technologies. It's video codec is supported by all devices in the world.

Visit the following link.

https://aomedia.org/about/

Sent from my LM-G710 using Tapatalk

I know what AV1 is. So you're downloading videos from YouTube, re-encoding them on your PC, then playing them back on your phone? Why? If you want to save size, just reduce the resolution to 1024*576 (non-square) or something more standard, 840*480....