occivink / mpv-scripts

Various scripts for mpv
The Unlicense
417 stars 38 forks source link

Help with understanding this script for mpv please #49

Closed Hellen-arndt91 closed 3 years ago

Hellen-arndt91 commented 3 years ago

I am very new to mpv player and scripting in general, so please bear with me if I seem slow. I am only interested in the encode.lua script I want to create my own profile that will let me encode to .mp4 format I have gotten it to work with .webm files using the encode_webm.conf file the creator has provided. according to the instructions, these variables mean $f input filename $n incrementing number $x input extension so I simply took the encode_webm.conf file renamed it to encode_mp4.conf and changed the line output_format=$f_$n.webm to output_format=$f_$n.mp4 but its still encoding to .webm. Am I missing something else here? Thanks allot for your help.

occivink commented 3 years ago

Since you renamed encode_webm.conf to encode_mp4.conf, the command in input.conf should also be changed to KEY script-message-to encode set-timestamp encode_mp4. Otherwise everything else looks good, assuming the files are in the right place.

Hellen-arndt91 commented 3 years ago

Fist of all thank you so much for your prompt reply.

KEY script-message-to encode set-timestamp encode_mp4 Aah that was the missing puzzle! I really like the way you implemented this script, one is able to write to many file types with different keybinds this way.

Unfortunately I am not able to successfully createmp4or mp3 files (The two file types that I need the most) It does create a file with mp3/mp4 extension but mpv closes when I drop them to its window. their file sizes are also 0 bytes

I have tested and was successfully able to create avi and mkv files by simply changing output_format=$f_$n.avi and output_format=$f_$n.mkv respectively.

I am also sure I have the files in their right paths, as when I moveencode_mkv.conf from its folder mpv fails in creating mkv files until I move it back. Likewise with ffmpeg in the mpv folder, when I move it I am not able to create video files.

Do you have any idea as why I am not able to create mp4or mp3files? I have grabbed the latest ffmpeg program but no luck sadly.

occivink commented 3 years ago

Can you paste the two .conf here? It might be some kind of incompatibility between ffmpeg flags and container. I have to admit that this encode script is not very easy to debug

Hellen-arndt91 commented 3 years ago

encode_avi.conf contains

only_active_tracks=no
preserve_filters=yes
append_filter=
codec=-an -sn -c:v libvpx -crf 10 -b:v 1000k
output_format=$f_$n.avi
output_directory=
detached=yes
ffmpeg_command=ffmpeg
print=yes

and encode_mkv.conf

only_active_tracks=no
preserve_filters=yes
append_filter=
codec=-an -sn -c:v libvpx -crf 10 -b:v 1000k
output_format=$f_$n.mkv
output_directory=
detached=yes
ffmpeg_command=ffmpeg
print=yes

I just change output_format=$f_$n.mkv line and of course place 2 script-message-to encode set-timestamp encode_mkv in conf file

Hellen-arndt91 commented 3 years ago

in my tests earlier , it does create a file with mp3/mp4 extension but mpv closes when I drop them to its window. their file sizes are also 0 bytes

occivink commented 3 years ago

so basically what's happening is that

  1. mp4 does not support libvpx-encoded video
  2. audio is disabled, so encoding to mp3 fails.

We can just tweak the codec= part in both cases to fix this, I think

In the mp3 case, you want to remove -an (which means no-audio roughly), add -vn (which means no video), and remove the entire -c:v libvpx -crf 10 -b:v 1000k part, which are parameters for the video codec. You can also specify parameters for the audio codec there (such as the bitrate), but if you're not somewhat familiar with the ffmpeg command line I would not do that just yet.

In the mp4 case, the libvpx codec is not supported by mp4. I would recommend replacing -c:v libvpx -crf 10 -b:v 1000k with -c:v libx264 -crf 20 which should work, and provide much better quality. If you want to keep the sound, you should also remove the -an part there.

Hellen-arndt91 commented 3 years ago

Its amazing what a few lines of code can but most of all the opensource community can do. I was able to get it to work! Thank you so much no just for helping me fix this but also breaking down your code and helping me understand. Ffmpeg is a library I plan using allot as I learn more, so its really cool to see it in action.

Thanks allot, Your scripts will make my work allot easier goin forward.

occivink commented 3 years ago

No problem, glad it worked out. If you have further questions you can ask here agian