News:

--

Main Menu

Script with "inputBox"

Started by nastyphoenix, December 26, 2021, 09:38:55 AM

Previous topic - Next topic

nastyphoenix

Hello all.
My question is very simple :
Is there a way with "python for avidemux" to ask something to the user with an "inputbox" or like a "read" command in shell ?

At the end of the .py I need to set the markers and it is a user input.

My idea is to write with the bash the adm.markerA (and B) values from a user input in the .py script (with a combination of sed and printf command) before launching it.


Thanks in advance.

I put my code below so you can see exactly what is my final goal.

This is the bash I have done to load a video sequence from the rushes of my hunting camera (it is not the final version just a WorkInProgress).

echo "********** Create Your Sequence **********"
read -p "Enter First File : " fileToLoad
read -p "Enter Last File : " lastFileToAppend

firstFileToAppend=$(($fileToLoad +1))

for (( file = $firstFileToAppend; file <= $lastFileToAppend; file++ ))

#for file in $(seq -w "$firstFileToAppend" 1 "$lastFileToAppend")
    do
       
        printf -v file4char %04d $file
       
        mylinetmp="--append /media/theflyingman/Share/Coolife/DSCF"$file4char".AVI"
        myline=$myline" "$mylinetmp
    done

printf -v fileToLoad %04d $fileToLoad

myline="flatpak run org.avidemux.Avidemux --load /media/theflyingman/Share/Coolife/DSCF"$fileToLoad".AVI "$myline" \
--run /media/theflyingman/Share/Coolife/Scripts/load_herisson.py"

exec $myline

This bash call the .py below (thanks to eumagga0x2a for the fadeToBlack help) :

# Load My Preset

adm = Avidemux()
ed = Editor()

adm.videoCodecSetProfile("x264", "herisson")

adm.audioCodec(0, "FDK_AAC", "bitrate=96", "afterburner=True", "profile=2", "sbr=False")

adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")

# if not ed.nbSegments():
#    return

effectDuration = 1 * 1000 # in ms
videoDuration = ed.getVideoDuration() / 1000 # microseconds --> milliseconds
# effectStart = videoDuration
# if videoDuration <= effectDuration * 2:
#    effectDuration = videoDuration / 2

# effectStart =  effectStart - effectDuration 
effectStart = videoDuration - effectDuration

adm.addVideoFilter("fadeToBlack", "startFade=" + str(effectStart), "endFade=" + str(videoDuration), "inOut=False", "toBlack=True")
adm.addVideoFilter("lumaonly")

# Settings Markers
# adm.markerA = 0
# adm.markerB = 10000000

# adm.save("/media/theflyingman/Share/Coolife/savetest.mp4")

At the end of the .py I need to set the markers and it is a user input.

My idea is to write with the bash the adm.markerA (and B) values from a user input in the .py script (with a combination of sed and printf command) before launching it.


eumagga0x2a

#1
The natural way to use timestamps matching markers A and B in Avidemux-internal scripts is via markerA and markerB members of Avidemux(). The user should load video (or be presented with Avidemux with video already loaded on command line), set markers, then use a script stored in her ~/.avidemux6/custom directory via "Custom" menu.

You can prompt user to enter a timestamp and use this input along the lines of

ed = Editor()
gui = Gui()
dia = DialogFactory("Please enter some time value")
timestamp = DFTimeStamp("Time:",0,ed.getVideoDuration()/1000)
dia.addControl(timestamp)
if not dia.show():
    return
gui.displayInfo("Info", "You have entered time value of " + str(timestamp.value) + " ms")

but this is entirely backwards IMHO.


Quote from: nastyphoenix on December 26, 2021, 09:38:55 AMadm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True")

The provided configuration for the MP4 muxer is invalid since ages already.

nastyphoenix

Hello eumagga0x2a

For the setContainer
I will set the it to MP4V2 ; it is how I done manually.
adm = Avidemux()
adm.setContainer("MP4V2")

I will set the marker with the bash
read -p markerA
sed -e -i "s/^adm.marker.*/adm.markerA = $markerA/g"  forTest_load_herisson.py

I love your answer for the dialog because now I know how to do it even if I won't use it in this case.

Thanks a lot you are the best. :)

eumagga0x2a

Quote from: nastyphoenix on December 27, 2021, 08:52:40 AMI will set the it to MP4V2

Please don't. MP4v2 is an obsolete, deprecated muxer awaiting removal. Please use MP4, but with a valid configuration.

eumagga0x2a

Quote from: nastyphoenix on December 27, 2021, 08:52:40 AMI will set the marker with the bash

Please don't do that either. Markers are set automatically to zero and to video duration, else it is the user's business to choose suitable pictures. Finally, they should be set with full precision to match a frame exactly (the latter requirement has been made less strict in 2.8.0, but still it may have unexpected effects in case of mismatch).

nastyphoenix

Ok I think I understand.

So I will do that for setContainer

adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")
I always set my Markers with the "picture by picture" forward. I know it is not accurate and I may use keyframe but for these videos accuracy is not really important.
When I need an accurate cut I use
ffmpeg -i $file -vcodec libx264 -b:v $bitrate -ss $start -to $end -acodec copy $outputfile.mp4 before joining the rushes.

It is very kind of you to be so helpfull and so didactic.
I learn a lot with your explanations.

eumagga0x2a

Quote from: nastyphoenix on December 27, 2021, 10:41:29 AMI always set my Markers with the "picture by picture" forward. I know it is not accurate

Why? On the contrary, this is perfectly accurate and recommended way to fine-tune cut points when re-encoding. Just using arbitrary values (like user input) as timestamps is generally dangerous. When timestamps are all a multiple of a millisecond like with 1000/25000 ("PAL" timebase-wise) constant FPS videos, this is at least feasible, but for time bases like 1001/24000 ("Film"), 1001/30000 ("NTSC") or variable FPS videos created by modern smartphones, it is almost impossible for a human to guess a uint64_t value with full precision.

Quote from: nastyphoenix on December 27, 2021, 10:41:29 AMI may use keyframe

Using keyframes as cut points is mandatory in copy mode, completely irrelevant when re-encoding.

nastyphoenix

QuoteWhy? On the contrary, this is perfectly accurate and recommended way to fine-tune cut points when re-encoding.
I'm stupid because when I do -ss -to with ffmpeg I used the values 00:00:00.000 given by avidemux.
I use keyframe when I cut some others videos without re-encoding.

However I was thinking that, if a user choose for example 00:00:37.500 for markerB value, avidemux will automatically transforms it to 00:00:37.480 or 00:00:37.520 (in my case I have one P-Frame every 00:00:00.040).

So if I want a user input the user has to check with avidemux the exact timestamp for the markers' values.

eumagga0x2a

Quote from: nastyphoenix on December 27, 2021, 12:37:01 PMSo if I want a user input the user has to check with avidemux the exact timestamp for the markers' values.

For reliable results, yes. This is also the whole raison d'être for Avidemux – to see where you cut :-)

nastyphoenix

So I just have to say you a big Thank You and finish my bash.

eumagga0x2a