Converting an entire folder of videos to PSP format?

Started by flyhigh, July 30, 2020, 12:00:16 PM

Previous topic - Next topic

eumagga0x2a

Bash scripting is hard :)

Quote from: flyhigh on August 02, 2020, 02:43:45 AM
Thank you for the code. Initially, I got a Could not find *.mp4 error,

This means that there are no .mp4 files in the folder (maybe there are .MP4 files, I can't know, you should proactively catch such possibilities and either modify the command line to match the environment yourself or supply sufficient information to me to do it for you). What I missed is that if globbing pattern /media/flyhigh/5TB/source/*.mp4 cannot be expanded to a list of matches, the variable $file gets set to the literal pattern, thus resulting in the error above. To avoid this, it is necessary to set (and then unset) the nullglob option:

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mp4; do ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename "$file")" --quit; done; shopt -u nullglob

Quote
then I changed for file in /media/flyhigh/5TB/source/*.mp4 to for file in /media/flyhigh/5TB/source/

..which doesn't make sense. Changing the matching pattern to /media/flyhigh/5TB/source/ makes the globbing fail thus $file is the pattern itself. As the pattern cannot be loaded (it is not a video file but a directory), Avidemux tries to save to /mnt/2TB Desktop/Videos/PSP/source without actually having a video loaded.

Quoteand the new error I started getting on some of the files became Error seeking to 0ms and the files were resaving into my PSP folder without actually changing container to mp4 or becoming smaller at all.

I don't have an explanation why it was resaving anything at all. Replacing the command with echo

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mp4; do echo "\""$file"\" --> \"/mnt/2TB Desktop/Videos/PSP/$(basename "$file")\"" --quit; done; shopt -u nullglob

would allow to understand what is actually passed as arguments to Avidemux.

Please keep in mind that the current Avidemux command line doesn't touch audio and video codecs. If you leave them at the default (copy), then the codecs used in the source files must be compatible with the Mp4 muxer in PSP mode.

flyhigh

Quote from: eumagga0x2a on August 04, 2020, 07:58:44 PM
I'm sorry for the inconvenience because of CleanTalk false-positives. I cannot do anything about it, unfortunately, except of reposting your message in the topic. Sometimes trying to post from a private browser window helps, sometimes changing the IP address (e.g. by disconnecting and reconnecting the power supply of the router) turns out to be effective.

Quotethe files in my base folder are .mkv files and not mp4. Doing so seems to not provide any errors but it also doesn't convert the files again and just resaves them in my PSP directory.

The file are for sure converted, just the extension remains .mkv. You can batch-rename them after the fact using

shopt -s nullglob; OLDDIR=$(pwd); cd "/mnt/2TB Desktop/Videos/PSP"; for i in *.mkv; do mv -v "$i" "$(echo "$i" | sed 's/mkv$/mp4/')"; done; cd "$OLDDIR"; shopt -u nullglob

or integrate this into the Avidemux command line as

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mkv; do ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename -s .mkv "$file").mp4" --quit; done; shopt -u nullglob

It looks like command worked in saving 2 files in my PSP folder. However, I terminated the process early because the files didn't look reconverted as the size/resolution did not go down which is also part of converting these videos for PSP use that I can successfully do on the GUI. I'm thinking how the source.py file was truncated from the original GUI generated .py file could be the reason why.

It also seems I can post here again. I have no problem with you posting my original message when I was having trouble posting on the board, though it might clutter the focus of the topic a bit so I don't find it necessary as we still haven't arrived at the solution.

eumagga0x2a

Oops, for some inexplicable reason (probably had a command line with "--video-codec Copy" in sight in another window, a typical context mixup), I wrongly assumed you would want copy mode. Thus I kept only the part of the project script doing pure format conversion, i.e. the file format was converted to PSP, but the video and audio remained unfiltered and not re-encoded.

Please replace source.py with

adm = Avidemux()

adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=2", "MinIdr=0", "MaxIdr=250", "i_scenecut_threshold=40"
, "intra_refresh=False", "MaxBFrame=2", "i_bframe_adaptive=0", "i_bframe_bias=0", "i_bframe_pyramid=0", "b_deblocking_filter=False", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0", "cabac=True"
, "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=False", "analyze.b_i4x4=True", "analyze.b_i8x8=False", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=0", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
, "ratecontrol.ip_factor=1.000000", "ratecontrol.pb_factor=1.000000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=480", "height=208", "algo=1", "sourceAR=3", "targetAR=1", "lockAR=True", "roundup=False")
adm.addVideoFilter("addBorder", "left=0", "right=0", "top=32", "bottom=32")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=160");
adm.audioSetMixer(0, "STEREO");
adm.audioSetResample(0, 48000)
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")


(I dropped calls from the project script which reflected a particular file used to produce the script, the calls to audioSetDrc and audioSetShift reflect the default, but do no harm).

I wonder whether you really want post-processing, which is always skipped when a hardware-accelerated decoder is used. I left the call to setPostProc in the script, but you might consider dropping it if this sort of filtering is not intentional or when the VDPAU hw decoder is enabled.

flyhigh

I let it run for two videos to convert and both successfully played on my PSP! However, the aspect ratio of the converted videos for some reason ended up being wider than the aspect ratio of my source files, resulting in a vertically squeezed video with black bars on the top and bottom. Both my source aspect ratio and PSP (destination) aspect ratio are 16:9.

Also, with this almost figured out I would be interested in being able to apply a subtitle filter in a batch process as well. I have a ~100 episode series with subtitles of the same base name as the episode but *.ass extension. What would be the way to add applying the subtitle filter in a batch process as well? Thanks again for all of your help so far I wouldn't have been able to figure this out on my own.

eumagga0x2a

Quote from: flyhigh on August 05, 2020, 03:19:01 PM
However, the aspect ratio of the converted videos for some reason ended up being wider than the aspect ratio of my source files, resulting in a vertically squeezed video with black bars on the top and bottom.

The result is exactly as specified in the filter chain of "Resize" and "Add Border" filters. If the target resolution is meant to match the typical anamorphic NTSC 720x480 resolution at 16:9 display aspect ratio, you should specify just that in the "Resize" filter (don't care about all the helpers, just input 720 and 480), dispose of the addBorder filter, configure x264 with appropriate SAR instead of asking for vui.sar_height and vui.sar_width being equal 1 and force 16:9 aspect ratio in the settings of the MP4 muxer.

QuoteAlso, with this almost figured out I would be interested in being able to apply a subtitle filter in a batch process as well. I have a ~100 episode series with subtitles of the same base name as the episode but *.ass extension. What would be the way to add applying the subtitle filter in a batch process as well?

That wouldn't be very easy as it will be necessary either to automatically rewrite the .py file or to repeatedly create and then delete a symbolic link with constant name and path but different target.

eumagga0x2a

Because of unfixable CleanTalk false positives, I copy the content of the PM here:

Quote from: flyhigh on August 05, 2020, 05:30:27 PM
I got blacklisted again for who knows what reason. Would appreciate/not mind if you posted in the forum but here's my reply:

QuoteThe result is exactly as specified in the filter chain of "Resize" and "Add Border" filters. If the target resolution is meant to match the typical anamorphic NTSC 720x480 resolution at 16:9 display aspect ratio, you should specify just that in the "Resize" filter (don't care about all the helpers, just input 720 and 480), dispose of the addBorder filter, configure x264 with appropriate SAR instead of asking for vui.sar_height and vui.sar_width being equal 1 and force 16:9 aspect ratio in the settings of the MP4 muxer.

Um so would this be how the new .py file should look?

adm = Avidemux()

adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=2", "MinIdr=0", "MaxIdr=250", "i_scenecut_threshold=40"
, "intra_refresh=False", "MaxBFrame=2", "i_bframe_adaptive=0", "i_bframe_bias=0", "i_bframe_pyramid=0", "b_deblocking_filter=False", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0", "cabac=True"
, "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=False", "analyze.b_i4x4=True", "analyze.b_i8x8=False", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=0", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
, "ratecontrol.ip_factor=1.000000", "ratecontrol.pb_factor=1.000000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=480", "height=208", "algo=1", "sourceAR=3", "targetAR=1", "lockAR=True", "roundup=False")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=160");
adm.audioSetMixer(0, "STEREO");
adm.audioSetResample(0, 48000)
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")


All I did was remove the addVideoFilter line.

QuoteThat wouldn't be very easy as it will be necessary either to automatically rewrite the .py file or to repeatedly create and then delete a symbolic link with constant name and path but different target.

Is there not a way to call the base name of the file to become the base name of the .ass file?

#####################################################################

And now for the reply:

Quote from: flyhigh on August 05, 2020, 05:30:27 PM
Um so would this be how the new .py file should look?

adm = Avidemux()

adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1",

If you would like to make pixel square, then yes, else you should setup x264 with the proper sample aspect ratio (vui.sar_* parameters).

Quoteadm.addVideoFilter("swscale", "width=480", "height=208", "algo=1", "sourceAR=3", "targetAR=1", "lockAR=True", "roundup=False")

I can hardly imagine that PSP cannot handle standard NTSC resolution. Why not "width=720", "height=480"? In any case 480/208 is not even remotely close to 16/9.

Quote
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

Again, correct if you don't want or cannot use a standard resolution, else wrong.

QuoteAll I did was remove the addVideoFilter line.

No, this is not sufficient.

Quote
QuoteThat wouldn't be very easy as it will be necessary either to automatically rewrite the .py file or to repeatedly create and then delete a symbolic link with constant name and path but different target.

Is there not a way to call the base name of the file to become the base name of the .ass file?

Yes, sure, this would be a small part of the solution.

eumagga0x2a

Fullquote from PM:

Quote from: flyhigh on August 07, 2020, 04:24:54 PM
Not sure if the message I sent before got through but I was able to successfully convert 4 episodes with the correct aspect ratio and no bars/squeezing using this as my source.py file:

adm = Avidemux()

adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=2", "MinIdr=0", "MaxIdr=250", "i_scenecut_threshold=40"
, "intra_refresh=False", "MaxBFrame=2", "i_bframe_adaptive=0", "i_bframe_bias=0", "i_bframe_pyramid=0", "b_deblocking_filter=False", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0", "cabac=True"
, "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=False", "analyze.b_i4x4=True", "analyze.b_i8x8=False", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=0", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
, "ratecontrol.ip_factor=1.000000", "ratecontrol.pb_factor=1.000000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=480", "height=272", "algo=1", "sourceAR=3", "targetAR=1", "lockAR=True", "roundup=False")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"jpn")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=160");
adm.audioSetMixer(0, "STEREO");
adm.audioSetResample(0, 48000)
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")


Also for reference, here's the terminal code that worked with the source.py file:

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mkv; do ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename -s .mkv "$file").mp4" --quit; done; shopt -u nullglob

Only issue now is I just noticed avidemux was never carrying over subtitles from the source video, not sure how to do this with GUI either. Any idea how to make avidemux pull embedded subtitles from the source video and carry them into the destination files?

#####################################################################

480/272 = 30/17 which is indeed very close to 16/9, but I really wonder whether it is required to go that much down with resolution. Could you please enlighten me?

QuoteOnly issue now is I just noticed avidemux was never carrying over subtitles from the source video

Avidemux supports only video and audio tracks, no other types of data streams. Patches implementing support for soft subtitles in all required parts of the application – core, editor, demuxers (matroska, mp4, mpegts) as well as appropriate libavformat-based muxers – warmly welcome.

To hardcode external subtitles into video stream, add the libass video filter like

adm.addVideoFilter("ssa", "font_scale=1.000000", "line_spacing=0.100000", "subtitleFile=/path/to/subtitles.ssa", "fontDirectory=/usr/share/fonts/truetype/", "extractEmbeddedFonts=1"
, "topMargin=0", "bottomMargin=0", "displayAspectRatio=0")


where /path/to/subtitles.ssa would be a symlink pointing to a matching real subtitle file for the given source video.

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mkv; do rm "/path/to/subtitles.ssa" 2>/dev/null; ln -s "/media/flyhigh/5TB/source/$(basename -s .mkv "$file").ssa" "/path/to/subtitles.ssa" && ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename -s .mkv "$file").mp4" --quit; rm "/path/to/subtitles.ssa"; done; shopt -u nullglob

You need to check the script whether the assumption regarding external subtitle file names holds and also substitue "/path/to/subtitles.ssa" placeholder with a real target. Please note that symlink must be created on a Linux filesystem.

flyhigh

Quote from: eumagga0x2a on August 09, 2020, 10:36:04 AM
Quote from: flyhigh on August 09, 2020, 10:12:04 AM
I use a VPN by default logging in through my normal browser, not private or incognito or anything like that. However, when I try posting without the VPN I still got the same error. Not sure why unless it's a country ban since I live in Japan.

I can only relay what other users, who were equally unjustly blocked by CleanTalk, reported. Trying to post from a private browser window or from a different browser was among some solutions that worked (sometimes, of course), so you might try this as well. CleanTalk is a "black box", entirely opaque.

QuoteAs for the actual troubleshooting, I tried implementing your proposed solution and made the following source.py file


adm.addVideoFilter("ssa", "font_scale=1.000000", "line_spacing=0.100000", "subtitleFile=/path/to/subtitles.ssa",


[...] I got this error [...]

/path/to/subtitles.ssa was meant as placeholder to be modified by you to match a real path.

Trying to post from private browsing.

I'm a bit confused on how I'm supposed to modify the "subtitleFile=/path/to/subtitles.ssa" line, since as mentioned before the filename in the path will change every iteration of the video cycle and I'm not seeing/understanding anything in the code that would replace that exact line with the basefilename.ass title. Though your understanding of code is definitely much higher than mine.

Also, it looks like posting from private browsing worked for now.

eumagga0x2a

Quote from: flyhigh on August 09, 2020, 11:52:47 AM
I'm a bit confused on how I'm supposed to modify the "subtitleFile=/path/to/subtitles.ssa" line, since as mentioned before the filename in the path will change every iteration of the video cycle

This is exactly the problem the code should solve. The real .ass file filename is different for each video file, but the symlink to that file is named always the same. The symlink is deleted and recreated on each iteration.

Quoteand I'm not seeing/understanding anything in the code that would replace that exact line with the basefilename.ass title.

One-liners are generally difficult to read. A usual multi-line bash script would be much easier to handle. The part

rm "/path/to/subtitles.ssa" 2>/dev/null; ln -s "/media/flyhigh/5TB/source/$(basename -s .mkv "$file").ssa" "/path/to/subtitles.ssa" &&

of the command line takes care of deleting the symlink (throwing away the error message if the symlink doesn't exist) and creating a new symlink with a new target but at the same location. As already mentioned, the real path to symlink must point to a location on a Linux filesystem (else no symlink possible).


flyhigh

#24
Successfully converted >200 episodes! So in summary, my source files are .mkv files in the directory /media/flyhigh/5TB/source/, my destination directory to save the converted files is /mnt/2TB Desktop/Videos/PSP/. I have an AppImage of avidemux in my home directory, so the code to batch convert becomes

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mkv; do ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename -s .mkv "$file").mp4" --quit; done; shopt -u nullglob
With the source.py file for HD (16:9 aspect ratio) files being

adm = Avidemux()

adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=2", "MinIdr=0", "MaxIdr=250", "i_scenecut_threshold=40"
, "intra_refresh=False", "MaxBFrame=2", "i_bframe_adaptive=0", "i_bframe_bias=0", "i_bframe_pyramid=0", "b_deblocking_filter=False", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0", "cabac=True"
, "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=False", "analyze.b_i4x4=True", "analyze.b_i8x8=False", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=0", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
, "ratecontrol.ip_factor=1.000000", "ratecontrol.pb_factor=1.000000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=480", "height=272", "algo=1", "sourceAR=3", "targetAR=1", "lockAR=True", "roundup=False")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"jpn")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=160");
adm.audioSetMixer(0, "STEREO");
adm.audioSetResample(0, 48000)
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

Though this should be squeezing my image a bit with 480x272 being a little bit more square than 16:9 I liked using all of the PSP screen more and the slight aspect ratio change was unnoticable for me.

Then for a series I have with subtitles, I made a blank text document named subtitles.ssa to use as a dummy file for the symlink, then used your suggested bash script

shopt -s nullglob; for file in /media/flyhigh/5TB/source/*.mkv; do rm "/media/flyhigh/5TB/source/subtitles.ssa" 2>/dev/null; ln -s "/media/flyhigh/5TB/source/$(basename -s .mkv "$file").ass" "/media/flyhigh/5TB/source/subtitles.ssa" && ./avidemux_2.7.6.appImage --load "$file" --run /media/flyhigh/5TB/source/source.py --save "/mnt/2TB Desktop/Videos/PSP/$(basename -s .mkv "$file").mp4" -j8 --quit; rm "/media/flyhigh/5TB/source/subtitles.ssa"; done; shopt -u nullglob
The associated source.py for this was then

adm = Avidemux()
adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=1000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=30", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=2", "MinIdr=0", "MaxIdr=250", "i_scenecut_threshold=40"
, "intra_refresh=False", "MaxBFrame=2", "i_bframe_adaptive=0", "i_bframe_bias=0", "i_bframe_pyramid=0", "b_deblocking_filter=False", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0", "cabac=True"
, "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=False", "analyze.b_i4x4=True", "analyze.b_i8x8=False", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=3", "analyze.chroma_offset=0", "analyze.me_method=0", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
, "ratecontrol.ip_factor=1.000000", "ratecontrol.pb_factor=1.000000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
adm.addVideoFilter("swscale", "width=368", "height=272", "algo=1", "sourceAR=1", "targetAR=1", "lockAR=True", "roundup=False")
adm.addVideoFilter("addBorder", "left=56", "right=56", "top=0", "bottom=0")
adm.addVideoFilter("ssa", "font_scale=1.000000", "line_spacing=0.100000", "subtitleFile=/media/flyhigh/5TB/source/subtitles.ssa", "fontDirectory=/usr/share/fonts/truetype/", "extractEmbeddedFonts=1", "topMargin=0", "bottomMargin=0", "displayAspectRatio=0")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"jpn")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=160");
adm.audioSetMixer(0, "STEREO");
adm.audioSetResample(0, 48000)
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=1", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

The aspect ratio for this source is 4:3 so there are borders added to the sides to make up for the change in aspect ratio. This successfully converted 110 episodes with subtitles for use on a PSP with hardcoded subtitles. This solves the issue I was having so I appreciate the help. Only thing now is I would love to find out how to convert videos with embedded subtitles without needing the subtitle files separate but I'll have to cross my fingers hoping I come across it. Thank you.

EDIT: Also, it looks like I can successfully post without entering a private browser and the forum looks updated? Definite improvement.

eumagga0x2a

Quote from: flyhigh on August 10, 2020, 08:12:25 AMThen for a series I have with subtitles, I made a blank text document named
subtitles.ssa to use as a dummy file for the symlink,[/code]

Why? This was unnecessary. Just to give rm something to delete?? The command
ln -stakes care of creating the symlink.

Quote from: undefinedOnly thing now is I would love to find out how to convert videos with embedded subtitles without needing the subtitle files separate

This should be possible with ffmpeg.