Programming Thread

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

0 Members and 1 Guest are viewing this topic.

the-pi-guy

Quote from: Legend on Jan 07, 2025, 12:44 AMWhat do you mean? Like the app auto updates but doesn't restart?
I want to be able to make updates to my personal application on one computer, and just dump it on the server, and have it know what to do with it. 

Legend

I love getting to work on fun challenging problems.

I asked OpenAI's premium model to do something and it said "This is, frankly, one of the most challenging tasks I've seen." It went a bit crazy trying to write the code and gave up and "faked" it (it directly said this in a comment rant). It also hallucinated quotes of mine.

kitler53

so what is actually challenging or did it just choke?
         

Featured Artist: Emily Rudd

Legend

Quote from: kitler53 on Jan 17, 2025, 06:58 PMso what is actually challenging or did it just choke?
The AI is normally arrogant like a stack overflow user. It'll completely ignore the finer details of even easy problems and just throw out code that does something else.

This is the first time it's done something like the above. I think it's just because I finally got it to understand the requirements.



In this case it's actually challenging though. My current code works for my needs but it uses a massive lookup table and a lot of enumeration. Would be nice to improve so I tried passing the challenge off to AI  ::)

the-pi-guy

Spoiler for Hidden:
<div class="codeheader"><span class="code floatleft">Code</span> <a class="codeoperation smf_select_text">Select</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="Shrink" data-expand-txt="Expand">Expand</a></div><code class="bbc_code">using System;<br>using System.IO;<br>using NAudio.Wave;<br><br>class Program<br>{<br>&nbsp; &nbsp; static void Main(string&#91;] args)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; // Load the original audio file<br>&nbsp; &nbsp; &nbsp; &nbsp; string originalFilePath = &quot;original_audio.wav&quot;;<br>&nbsp; &nbsp; &nbsp; &nbsp; string replacementFilePath = &quot;replacement_audio.wav&quot;;<br>&nbsp; &nbsp; &nbsp; &nbsp; string outputFilePath = &quot;updated_audio.wav&quot;;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; using (var reader = new WaveFileReader(originalFilePath))<br>&nbsp; &nbsp; &nbsp; &nbsp; using (var replacement = new WaveFileReader(replacementFilePath))<br>&nbsp; &nbsp; &nbsp; &nbsp; using (var writer = new WaveFileWriter(outputFilePath, reader.WaveFormat))<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int segmentStartTime = 5000; // Start time in milliseconds<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int segmentEndTime = 10000; // End time in milliseconds<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Copy audio before the replacement<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long segmentStartBytes = segmentStartTime * bytesPerMillisecond;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; long segmentEndBytes = segmentEndTime * bytesPerMillisecond;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the audio before the segment to replace<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(reader, writer, segmentStartBytes);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the replacement audio<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(replacement, writer, replacement.Length);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Skip the replaced segment in the original audio<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reader.Position = segmentEndBytes;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the audio after the replaced segment<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyAudio(reader, writer, reader.Length - segmentEndBytes);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Audio replacement completed!&quot;);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; private static void CopyAudio(WaveFileReader reader, WaveFileWriter writer, long bytesToCopy)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; byte&#91;] buffer = new byte[1024];<br>&nbsp; &nbsp; &nbsp; &nbsp; while (bytesToCopy &gt; 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int bytesRead = reader.Read(buffer, 0, (int)Math.Min(buffer.Length, bytesToCopy));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (bytesRead == 0) break;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.Write(buffer, 0, bytesRead);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytesToCopy -= bytesRead;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br><br></code><br><br>

Saving this for later.

the-pi-guy

Spoiler for Hidden:
<div class="codeheader"><span class="code floatleft">Code</span> <a class="codeoperation smf_select_text">Select</a> <a class="codeoperation smf_expand_code hidden" data-shrink-txt="Shrink" data-expand-txt="Expand">Expand</a></div><code class="bbc_code"><br><br>#!/bin/bash<br><br># Define the target resolution and bitrate<br>BITRATE=&quot;5000k&quot;<br><br># Function to process a video file<br>process_video() {<br>&nbsp; &nbsp; local file=&quot;$1&quot;<br>&nbsp; &nbsp; local output_file=&quot;${file%.*}_converted.mp4&quot;<br><br>&nbsp; &nbsp; # Check if the converted file already exists<br>&nbsp; &nbsp; if [[ -f &quot;$output_file&quot; ]]; then<br>&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Skipping $file: Converted file already exists.&quot;<br>&nbsp; &nbsp; &nbsp; &nbsp; return<br>&nbsp; &nbsp; fi<br><br>&nbsp; &nbsp; echo &quot;Processing $file...&quot;<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; # Extract video resolution, audio codec, and subtitle format<br>&nbsp; &nbsp; resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 &quot;$file&quot; | awk -F &#39;,&#39; &#39;{print $1&quot;x&quot;$2}&#39;)<br>&nbsp; &nbsp; audio_codec=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 &quot;$file&quot;)<br>&nbsp; &nbsp; subtitle_codec=$(ffprobe -v error -select_streams s:0 -show_entries stream=codec_name -of csv=p=0 &quot;$file&quot;)<br><br>&nbsp; &nbsp; # Build the ffmpeg command dynamically<br>&nbsp; &nbsp; ffmpeg_cmd=&quot;ffmpeg -i \&quot;$file\&quot;&quot;<br><br>&nbsp; &nbsp; # If it&#39;s a 4K video, downscale to 1080p<br>&nbsp; &nbsp; if [[ &quot;$resolution&quot; == &quot;3840x2160&quot; || &quot;$resolution&quot; == &quot;4096x2160&quot; ]]; then<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -vf scale=1920:1080 -b:v $BITRATE -c:v libx264 -preset medium -crf 23&quot;<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -c:v copy&quot;<br>&nbsp; &nbsp; fi<br><br>&nbsp; &nbsp; # Convert AAC audio to AC3 if necessary<br>&nbsp; &nbsp; if [[ &quot;$audio_codec&quot; == &quot;aac&quot; ]]; then<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -c:a ac3 -b:a 384k&quot;<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -c:a copy&quot;<br>&nbsp; &nbsp; fi<br><br>&nbsp; &nbsp; # Convert PGS subtitles if necessary<br>&nbsp; &nbsp; if [[ &quot;$subtitle_codec&quot; == &quot;pgs_subtitle&quot; ]]; then<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -c:s mov_text&quot;<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; ffmpeg_cmd+=&quot; -c:s copy&quot;<br>&nbsp; &nbsp; fi<br><br>&nbsp; &nbsp; # Set output file name<br>&nbsp; &nbsp; ffmpeg_cmd+=&quot; \&quot;$output_file\&quot;&quot;<br><br>&nbsp; &nbsp; # Execute the command<br>&nbsp; &nbsp; eval $ffmpeg_cmd<br><br>&nbsp; &nbsp; echo &quot;Finished processing $file.&quot;<br>}<br><br># Traverse all folders and process video files<br>find . -type f \( -name &quot;*.mp4&quot; -o -name &quot;*.mkv&quot; \) | while read -r file; do<br>&nbsp; &nbsp; process_video &quot;$file&quot;<br>done<br><br>echo &quot;Processing complete!&quot;<br><br><br><br><br><br><br></code><br><br><br><br><br><br>

Had copilot generate this for me. I'm sure it'll need some adjustments...  Still looking through it. 

the-pi-guy

^ probably won't end up being necessary. 

I was at my parent's house and I wasn't able to watch one of the Plex movies. The audio codec wasn't compatible with their TV, except for a couple of commentary audio tracks. Not even the transcoded version was playable.

Plex is supposed to handle this automatically, and it's probable that there was a setting on the client that wasn't set right. 

But I am adjusting some other options in Plex, so maybe I won't need it.