Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > High Efficiency Video Coding (HEVC)

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th December 2021, 17:35   #1  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
Encoding errors from ffmpeg x265 pass 2 which succeeded in pass 1.

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.


Code:
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.




Code:
[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 #


Code:
[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.

Code:
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 is offline   Reply With Quote
Old 6th December 2021, 17:47   #2  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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
rupeshforu3 is offline   Reply With Quote
Old 6th December 2021, 19:10   #3  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
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.

Last edited by kolak; 6th December 2021 at 19:16.
kolak is offline   Reply With Quote
Old 9th December 2021, 09:39   #4  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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
rupeshforu3 is offline   Reply With Quote
Old 9th December 2021, 14:01   #5  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
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.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 10th December 2021, 00:09   #6  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,750
Quote:
Originally Posted by rupeshforu3 View Post
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.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 10th December 2021, 03:57   #7  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
How to limit the cpu usage while running ffmpeg tool and x265 in Linux.

Sent from my LM-G710 using Tapatalk

Last edited by rupeshforu3; 10th December 2021 at 04:16.
rupeshforu3 is offline   Reply With Quote
Old 10th December 2021, 05:43   #8  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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

Last edited by rupeshforu3; 10th December 2021 at 05:46.
rupeshforu3 is offline   Reply With Quote
Old 10th December 2021, 06:20   #9  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,750
Quote:
Originally Posted by rupeshforu3 View Post
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.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 10th December 2021, 08:06   #10  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
Quote:
Originally Posted by benwaggoner View Post
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/...ere-a-shortcut

Sent from my LM-G710 using Tapatalk
rupeshforu3 is offline   Reply With Quote
Old 10th December 2021, 10:25   #11  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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

Last edited by rupeshforu3; 10th December 2021 at 10:28.
rupeshforu3 is offline   Reply With Quote
Old 16th December 2021, 22:30   #12  |  Link
tonemapped
Video Fanatic
 
tonemapped's Avatar
 
Join Date: Jul 2021
Location: Surrey
Posts: 89
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).
Quote:
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)...
__________________
PC: R9 5900X | 32GB 3600 MT/s RAM | 2*1TB NVMe | RTX 3080 | water-cooled

NAS: SM 48-bay 240TB+ storage | Xeon 1220 | 32GB DDR4 ECC

HTPC: Pentium J5005 | 16GB RAM | 256GB SSD | 15W

Last edited by tonemapped; 16th December 2021 at 22:34.
tonemapped is offline   Reply With Quote
Old 17th December 2021, 17:35   #13  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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 is offline   Reply With Quote
Old 17th December 2021, 17:51   #14  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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 is offline   Reply With Quote
Old 19th December 2021, 16:19   #15  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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
rupeshforu3 is offline   Reply With Quote
Old 19th December 2021, 19:37   #16  |  Link
tonemapped
Video Fanatic
 
tonemapped's Avatar
 
Join Date: Jul 2021
Location: Surrey
Posts: 89
Quote:
Originally Posted by rupeshforu3 View Post
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...

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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).

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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?

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
2 pass encoding has lot of benifits regarding quality output video file at lowest possible size.

Sent from my LM-G710 using Tapatalk
Three 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.

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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
I would advise you stick with x265 if you're already limited with encoding hardware (unless you have dedicated AV1 hardware decoding).

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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.

Quote:
Originally Posted by rupeshforu3 View Post
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.
__________________
PC: R9 5900X | 32GB 3600 MT/s RAM | 2*1TB NVMe | RTX 3080 | water-cooled

NAS: SM 48-bay 240TB+ storage | Xeon 1220 | 32GB DDR4 ECC

HTPC: Pentium J5005 | 16GB RAM | 256GB SSD | 15W
tonemapped is offline   Reply With Quote
Old 20th December 2021, 11:32   #17  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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

Last edited by rupeshforu3; 20th December 2021 at 15:58.
rupeshforu3 is offline   Reply With Quote
Old 20th December 2021, 19:01   #18  |  Link
therube
Registered User
 
Join Date: Aug 2013
Posts: 191
For reference, 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."

Last edited by therube; 20th December 2021 at 19:04.
therube is offline   Reply With Quote
Old 21st December 2021, 01:49   #19  |  Link
tonemapped
Video Fanatic
 
tonemapped's Avatar
 
Join Date: Jul 2021
Location: Surrey
Posts: 89
Quote:
Originally Posted by rupeshforu3 View Post
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/.../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?
__________________
PC: R9 5900X | 32GB 3600 MT/s RAM | 2*1TB NVMe | RTX 3080 | water-cooled

NAS: SM 48-bay 240TB+ storage | Xeon 1220 | 32GB DDR4 ECC

HTPC: Pentium J5005 | 16GB RAM | 256GB SSD | 15W
tonemapped is offline   Reply With Quote
Old 21st December 2021, 04:08   #20  |  Link
rupeshforu3
Registered User
 
rupeshforu3's Avatar
 
Join Date: Mar 2021
Posts: 86
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

Last edited by rupeshforu3; 21st December 2021 at 05:27.
rupeshforu3 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 21:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.